Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "show" cmd error for packages without stable versions #83

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:"));
});
});
Loading