Skip to content

Commit

Permalink
fix: "show" cmd error for packages without stable versions (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored May 2, 2024
1 parent de10288 commit fb0e006
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
12 changes: 10 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"dependencies": {
"kolorist": "^1.8.0",
"node-stream-zip": "^1.15.0"
"node-stream-zip": "^1.15.0",
"semiver": "^1.1.0"
}
}
18 changes: 16 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { Bun, getPkgManager, PkgManagerName, YarnBerry } from "./pkg_manager";
import { downloadDeno, getDenoDownloadUrl } from "./download";
import { getNpmPackageInfo, getPackageMeta } from "./api";
import semiver from "semiver";

const NPMRC_FILE = ".npmrc";
const BUNFIG_FILE = "bunfig.toml";
Expand Down Expand Up @@ -201,10 +202,23 @@ export async function showPackageInfo(raw: string) {

const meta = await getPackageMeta(pkg);
if (pkg.version === null) {
if (meta.latest === undefined) {
let latest = meta.latest;
if (latest === undefined) {
throw new Error(`Missing latest version for ${pkg}`);
} else if (latest === null) {
// When no stable version is published: `latest === null`. We need to
// manually find the latest pre-release version
const versions = Object.keys(meta.versions);

if (versions.length === 0) {
throw new Error(`Could not find published version for ${pkg}`);
}

versions.sort(semiver);
pkg.version = versions[0];
} else {
pkg.version = latest;
}
pkg.version = meta.latest!;
}

const versionCount = Object.keys(meta.versions).length;
Expand Down
12 changes: 12 additions & 0 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,4 +788,16 @@ describe("show", () => {
process.cwd(),
);
});

it("should show package information for pre-release only packages", async () => {
const output = await runJsr(
["show", "@fresh/update"],
process.cwd(),
undefined,
true,
);
const txt = kl.stripColors(output);
assert.ok(txt.includes("latest: -"));
assert.ok(txt.includes("npm tarball:"));
});
});

0 comments on commit fb0e006

Please sign in to comment.