Skip to content

Commit ee6805d

Browse files
chore(deps): replace semver with verkit (#211)
Replace the direct `semver` dependency with `verkit` (`^0.5.0`) to use the same version library as the Vite+ CLI and tooling. Remove `@types/semver` because `verkit` includes TypeScript declarations. Use `normalize` and `normalizeRange` to preserve the existing cache version checks and Node selector validation across GitHub Actions, GitLab, and Azure Pipelines. Update the three runtime bundles. `@actions/cache` still requires `semver` as a transitive dependency. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: MK <fengmk2@gmail.com>
1 parent cab1ab9 commit ee6805d

11 files changed

Lines changed: 172 additions & 127 deletions

‎dist/azure/index.mjs‎

Lines changed: 17 additions & 20 deletions
Large diffs are not rendered by default.

‎dist/gitlab/index.mjs‎

Lines changed: 5 additions & 8 deletions
Large diffs are not rendered by default.

‎dist/index.mjs‎

Lines changed: 49 additions & 48 deletions
Large diffs are not rendered by default.

‎package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
"@actions/core": "^3.0.0",
1818
"@actions/exec": "^3.0.0",
1919
"@actions/glob": "^0.7.0",
20-
"semver": "^7.8.5",
20+
"verkit": "^0.5.0",
2121
"yaml": "^2.8.2",
2222
"zod": "^4.0.0"
2323
},
2424
"devDependencies": {
2525
"@e18e/eslint-plugin": "^0.8.1",
2626
"@types/node": "^24.0.0",
27-
"@types/semver": "^7.8.0",
2827
"fallow": "3.33.1",
2928
"typescript": "^7.0.0",
3029
"vite": "catalog:",

‎pnpm-lock.yaml‎

Lines changed: 13 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/ci/package-manager-cache.test.ts‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ function write(path: string, text = "fixture"): void {
1717
mkdirSync(dirname(path), { recursive: true });
1818
writeFileSync(path, text);
1919
}
20-
function fixture(name = "pnpm", platform: NodeJS.Platform = process.platform) {
20+
function fixture(name = "pnpm", platform: NodeJS.Platform = process.platform, version = "12.14.0") {
2121
const toolchain = createToolchainCachePlan(
2222
{ version: "1.3.0", nodeVersion: "24.22.0", projectDir: root },
2323
env,
2424
platform,
2525
)!;
2626
const manager = {
2727
name,
28-
version: "12.14.0",
28+
version,
2929
mode: "managed",
3030
bin_paths: {
3131
[name]: join(
3232
toolchain.data,
3333
"package_manager",
3434
name,
35-
"12.14.0",
35+
version,
3636
name,
3737
"bin",
3838
`${name}${platform === "win32" ? ".cmd" : ""}`,
@@ -83,14 +83,29 @@ describe("package manager cache selection", () => {
8383
expect(create()?.path).toBe(join(toolchain.data, "package_manager", name, "12.14.0"));
8484
},
8585
);
86-
it.each(["latest", "default", "^12.0.0", "../outside", "unknown"])(
87-
"skips unresolved version %s",
88-
(version) => {
89-
const { manager, create } = fixture();
90-
manager.version = version;
91-
expect(create()).toBeUndefined();
92-
},
93-
);
86+
it.each([
87+
"latest",
88+
"default",
89+
"^12.0.0",
90+
"../outside",
91+
"unknown",
92+
"v12.14.0",
93+
"12.14.0+build.1",
94+
"012.14.0",
95+
"12.14.0-rc.01",
96+
"9007199254740992.0.0",
97+
])("skips unresolved or noncanonical version %s", (version) => {
98+
const { create } = fixture("pnpm", process.platform, version);
99+
expect(create()).toBeUndefined();
100+
});
101+
it("accepts an exact prerelease package manager version", () => {
102+
const version = "12.14.0-rc.1";
103+
const { create, toolchain } = fixture("pnpm", process.platform, version);
104+
expect(create()).toMatchObject({
105+
version,
106+
path: join(toolchain.data, "package_manager", "pnpm", version),
107+
});
108+
});
94109
it("skips system managers, bundled npm, and unsupported layouts", () => {
95110
const { manager, create } = fixture();
96111
manager.mode = "system_first";

‎src/ci/package-manager-cache.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
33
import { lstatSync, readFileSync, realpathSync, statSync } from "node:fs";
44
import { homedir, tmpdir } from "node:os";
55
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6-
import { valid } from "semver";
6+
import { normalize } from "verkit";
77
import type { ToolchainCachePlan } from "./toolchain-cache.js";
88

99
const PACKAGE_MANAGERS = {
@@ -58,7 +58,7 @@ export function createPackageManagerCachePlan(
5858
manager.mode !== "managed" ||
5959
!Object.hasOwn(PACKAGE_MANAGERS, manager.name) ||
6060
typeof manager.version !== "string" ||
61-
valid(manager.version) !== manager.version
61+
normalize(manager.version) !== manager.version
6262
)
6363
return;
6464
const name = manager.name as PackageManagerName;

‎src/ci/project-node-version.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ describe("project Node selection for the installer", () => {
6868
expect(resolveProjectNodeVersion(root)).toBe(expected);
6969
});
7070

71+
it.each([
72+
"22.x",
73+
"~22.18.0",
74+
"^22.18.0 || >=24.11.0",
75+
"22.18.0 - 24.11.0",
76+
">=22.18.0 <23",
77+
"26.0.0-rc.1",
78+
"*",
79+
])("preserves the project Node selector %s", (version) => {
80+
const root = fixture({ "package.json": JSON.stringify({ engines: { node: version } }) });
81+
expect(resolveProjectNodeVersion(root)).toBe(version);
82+
});
83+
84+
it.each(["22.018.0", "22.18.0-rc.01", ">=not-a-version", "9007199254740992.0.0"])(
85+
"does not inherit a parent pin after invalid Node selector %s",
86+
(version) => {
87+
const root = fixture({ ".node-version": "24.11.0", "app/.node-version": version });
88+
expect(resolveProjectNodeVersion(join(root, "app"))).toBeUndefined();
89+
},
90+
);
91+
7192
it.each([
7293
["# comment\nnode\n", "latest"],
7394
["stable # comment\n", "latest"],

‎src/ci/project-node-version.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFileSync } from "node:fs";
22
import { dirname, join, resolve } from "node:path";
3-
import { validRange } from "semver";
3+
import { normalizeRange } from "verkit";
44

55
const VERSION_PREFIX_RE = /^v/;
66
const NODE_VERSION_ALIAS_RE = /^(?:lts|latest|lts\/(?:\*|[a-z]+|-\d+))$/i;
@@ -65,6 +65,6 @@ function parseNvmrc(content?: string): string | undefined {
6565
function normalize(value?: string): string | undefined {
6666
const version = value?.trim().replace(VERSION_PREFIX_RE, "");
6767
if (!version) return undefined;
68-
if (NODE_VERSION_ALIAS_RE.test(version) || validRange(version)) return version;
68+
if (NODE_VERSION_ALIAS_RE.test(version) || normalizeRange(version)) return version;
6969
return undefined;
7070
}

‎src/ci/toolchain-cache.test.ts‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,33 @@ afterEach(() => {
3838
});
3939

4040
describe("toolchain cache selection", () => {
41-
it.each(["latest", "^1.3.0", "0.2.9", "0.0.0-commit.1234567"])(
42-
"skips unsupported Vite+ selector %s",
43-
(version) => {
44-
expect(createToolchainCachePlan({ ...options, version }, env)).toBeUndefined();
45-
},
46-
);
47-
it.each([undefined, "lts", "22", "^22.18.0"])(
48-
"does not freeze Node selector %s",
49-
(nodeVersion) => {
50-
expect(
51-
createToolchainCachePlan({ ...options, nodeVersion, projectDir: root }, env),
52-
).toBeUndefined();
53-
},
54-
);
41+
it.each([
42+
"latest",
43+
"^1.3.0",
44+
"0.2.9",
45+
"0.0.0-commit.1234567",
46+
"v1.3.0",
47+
"1.3.0+build.1",
48+
"01.3.0",
49+
"1.3.0-rc.01",
50+
"9007199254740992.0.0",
51+
])("skips unsupported Vite+ selector %s", (version) => {
52+
expect(createToolchainCachePlan({ ...options, version }, env)).toBeUndefined();
53+
});
54+
it.each([
55+
undefined,
56+
"lts",
57+
"22",
58+
"^22.18.0",
59+
"22.018.0",
60+
"22.18.0+build.1",
61+
"22.18.0-rc.1",
62+
"9007199254740992.0.0",
63+
])("does not freeze Node selector %s", (nodeVersion) => {
64+
expect(
65+
createToolchainCachePlan({ ...options, nodeVersion, projectDir: root }, env),
66+
).toBeUndefined();
67+
});
5568
it("discovers exact project pins but gives explicit inputs priority", () => {
5669
writeFixture(join(root, ".node-version"), "24.15.0\n");
5770
expect(createToolchainCachePlan({ version: "1.3.0", projectDir: root }, env)?.nodeVersion).toBe(
@@ -63,8 +76,12 @@ describe("toolchain cache selection", () => {
6376
it("accepts immutable preview builds and normalizes a Node v prefix", () => {
6477
const version = `0.0.0-commit.${"a".repeat(40)}`;
6578
expect(
66-
createToolchainCachePlan({ ...options, version, nodeVersion: "v22.23.1" }, env)?.version,
67-
).toBe(version);
79+
createToolchainCachePlan({ ...options, version, nodeVersion: "v22.23.1" }, env),
80+
).toMatchObject({ version, nodeVersion: "22.23.1" });
81+
});
82+
it("accepts an exact prerelease version", () => {
83+
const version = "1.3.0-rc.1";
84+
expect(createToolchainCachePlan({ ...options, version }, env)?.version).toBe(version);
6885
});
6986
it.each(["VP_LOCAL_TGZ", "VP_LOCAL_BINARY", "VP_SKIP_DEPS_INSTALL", "VP_PR_VERSION"])(
7087
"bypasses %s",

0 commit comments

Comments
 (0)