Skip to content

Commit d60317d

Browse files
authored
fix(cli): install package beta version if the beta CLI is used (#1065)
1 parent ffc538a commit d60317d

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import semver from "semver";
2+
3+
export const getSolvroConfigInstallTag = (version: string) =>
4+
semver.prerelease(version)?.[0] === "beta" ? "beta" : "latest";

src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { PackageJson } from "../utils/package-json";
1111
import { polishConfirm } from "../utils/polish-confirm";
1212
import { printIntro } from "../utils/print-intro";
1313
import { printOutro } from "../utils/print-outro";
14+
import { getSolvroConfigInstallTag } from "./get-solvro-config-install-tag";
1415
import { installCommitLint } from "./install-commitlint";
1516
import { installEslint } from "./install-eslint";
1617
import { installGithubActions } from "./install-ga";
@@ -209,6 +210,7 @@ async function main() {
209210
// Install the base package
210211
await packageJson.install("@solvro/config", {
211212
dev: true,
213+
version: getSolvroConfigInstallTag(packageJsonData.version),
212214
alwaysUpdate: !isNonInteractive,
213215
});
214216

src/utils/package-json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export class PackageJson {
238238
if (
239239
options.alwaysUpdate === true ||
240240
(options.version != null &&
241+
semver.validRange(options.version) != null &&
241242
!(await this.doesSatisfy(package_, options.version)))
242243
) {
243244
await runWithSpinner({

tests/install-tag.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { getSolvroConfigInstallTag } from "../src/cli/get-solvro-config-install-tag";
4+
5+
describe("getSolvroConfigInstallTag", () => {
6+
it("uses the beta dist-tag for beta CLI versions", () => {
7+
expect(getSolvroConfigInstallTag("3.0.0-beta.8")).toBe("beta");
8+
});
9+
10+
it("uses the latest dist-tag for stable CLI versions", () => {
11+
expect(getSolvroConfigInstallTag("3.0.0")).toBe("latest");
12+
});
13+
14+
it("uses the latest dist-tag for non-beta prereleases", () => {
15+
expect(getSolvroConfigInstallTag("3.0.0-alpha.1")).toBe("latest");
16+
});
17+
});

0 commit comments

Comments
 (0)