Skip to content

Commit

Permalink
feat: allow excluding pre-release versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Jul 28, 2024
1 parent e9fa3c6 commit d7edf20
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const getLatestVersion = async (): Promise<string | undefined> => {
/**
* Fetches the list of Biome versions from the npm registry.
*/
export const getAllVersions = async (): Promise<string[] | undefined> => {
export const getAllVersions = async (
includePrereleases = true,
): Promise<string[] | undefined> => {
try {
const response = await request(
"https://registry.npmjs.org/@biomejs/biome",
Expand All @@ -31,10 +33,18 @@ export const getAllVersions = async (): Promise<string[] | undefined> => {
const body = (await response.body.json()) as any;

const unsortedVersions = Object.keys(body.versions).map((version) => {
return semver.coerce(version);
return semver.coerce(version, { includePrerelease: true });
});

return rsort(unsortedVersions as SemVer[]).map(
const filteredVersions = unsortedVersions.filter((version) => {
if (!includePrereleases) {
return version?.prerelease.length === 0;
}

return true;
});

return rsort(filteredVersions as SemVer[]).map(
(version) => version.version,
);
} catch {
Expand Down
1 change: 1 addition & 0 deletions test/suites/detector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
detectFromPackageJson,
detectFromPnpmLockfile,
detectFromYarnLockfile,
getAllVersions,
} from "../../src";

const mocks = {
Expand Down
16 changes: 16 additions & 0 deletions test/suites/versions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from "bun:test";
import { getAllVersions } from "../../src";

describe("versions", () => {
it("does not return pre-release versions when specified", async () => {
const versions = await getAllVersions(false);

expect(versions).not.toContain("1.8.4-nightly.a579bf7");
});

it("returns pre-release versions when specified", async () => {
const versions = await getAllVersions(true);

expect(versions).toContain("1.8.4-nightly.a579bf7");
});
});

0 comments on commit d7edf20

Please sign in to comment.