Skip to content

Commit ced9b60

Browse files
fix(server): Vite+ update checks use the Node vp i -g installs with
`vp env exec node` runs the system Node under `vp env off`, while `vp i -g` always installs with Vite+'s managed Node and its bundled npm. Ask `vp env current --json` for the managed Node instead, and fall back to `npm view` when it reports a system Node, an uninstalled one, or bad JSON. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9c20c1a commit ced9b60

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎packages/provider-core/src/server/maintenanceResolver.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ it.layer(
432432
const vitePlusNodePath = NodePath.join(tempDir, "vite-plus-node/bin/node");
433433
const binaryPath = NodePath.join(tempDir, ".vite-plus/bin/package-tool");
434434
writeExecutable(binaryPath);
435-
const advise = (env: NodeJS.ProcessEnv, vitePlusPacks: string) =>
435+
const advise = (env: NodeJS.ProcessEnv, vitePlusPacks: string, nodeSource = "lts") =>
436436
resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
437437
binaryPath,
438438
env: { PATH: npmBinDir, ...env },
@@ -441,7 +441,11 @@ it.layer(
441441
ChildProcessSpawner.ChildProcessSpawner,
442442
// `vp i -g` runs the npm beside Vite+'s Node; `npm view` ignores min-release-age.
443443
stdoutSpawner((command, args) => {
444-
if (command === "vp") return `${vitePlusNodePath}\n`;
444+
if (command === "vp") {
445+
return JSON.stringify({
446+
node: { source: nodeSource, bin_path: vitePlusNodePath, installed: true },
447+
});
448+
}
445449
if (command === npmPath) {
446450
return args[0] === "view" ? '"1.2.0"' : "example-package-tool-1.2.0.tgz\n";
447451
}
@@ -466,6 +470,14 @@ it.layer(
466470
latestVersion: "1.1.0",
467471
});
468472
expect((yield* advise({}, "1.2.0"))?.latestVersion).toBe("1.2.0");
473+
// Install never uses the system Node `vp env off` reports, so this falls back to `npm view`.
474+
expect(
475+
(yield* advise(
476+
{ npm_config_min_release_age: "7", VP_HOME: "system-first" },
477+
"1.1.0",
478+
"system PATH",
479+
))?.latestVersion,
480+
).toBe("1.2.0");
469481
}).pipe(
470482
Effect.provide(ProviderLatestVersions.layer),
471483
Effect.provideService(

‎packages/provider-core/src/server/maintenanceResolver.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,32 @@ function parseNpmPackVersion(stdout: string, packageName: string): string | null
486486
return version && !/\s/.test(version) ? version : null;
487487
}
488488

489-
// `vp i -g` installs through the npm beside Vite+'s Node, which can differ from PATH's npm.
489+
const decodeVitePlusCurrentEnv = Schema.decodeUnknownOption(
490+
Schema.fromJsonString(
491+
Schema.Struct({
492+
node: Schema.Struct({
493+
source: Schema.String,
494+
bin_path: Schema.String,
495+
installed: Schema.Boolean,
496+
}),
497+
}),
498+
),
499+
);
500+
501+
// `vp i -g` installs through the npm beside Vite+'s managed Node, even under `vp env off`, and
502+
// `vp env current` names that Node unless it reports a system one, which install does not use.
490503
// Pack honours npm's min-release-age and `before`, which `npm view` ignores, and resolves
491504
// `@latest` the way install does. `--json=false` keeps its output to the tarball name.
492505
const resolveVitePlusInstallableLatestVersion = Effect.fn(
493506
"resolveVitePlusInstallableLatestVersion",
494507
)(function* (packageName: string, env: NodeJS.ProcessEnv, platform: NodeJS.Platform) {
495508
const path = yield* Path.Path;
496-
const nodePath = nonEmptyString(
497-
yield* runProbe("vp", ["env", "exec", "node", "-p", "process.execPath"], env),
498-
);
499-
if (!nodePath || !path.isAbsolute(nodePath)) return null;
500-
const npmPath = path.join(path.dirname(nodePath), platform === "win32" ? "npm.cmd" : "npm");
509+
const current = yield* runProbe("vp", ["env", "current", "--json"], env);
510+
const node = current ? Option.getOrUndefined(decodeVitePlusCurrentEnv(current))?.node : undefined;
511+
if (!node?.installed || node.source === "system PATH" || !path.isAbsolute(node.bin_path)) {
512+
return null;
513+
}
514+
const npmPath = path.join(path.dirname(node.bin_path), platform === "win32" ? "npm.cmd" : "npm");
501515
const packed = yield* runProbe(
502516
npmPath,
503517
["pack", "--dry-run", "--json=false", "--global", `${packageName}@latest`],

0 commit comments

Comments
 (0)