Skip to content

refactor(env): select the project Node.js version in one place - #3498

Merged
fengmk2 merged 3 commits into
mainfrom
refactor/select-project-node-version
Nov 21, 2026
Merged

fengmk2 merged 3 commits into
mainfrom
refactor/select-project-node-version

Conversation

@fengmk2

@fengmk2 fengmk2 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Stacked on #3489.

Before this PR, Node.js version selection had two fallback chains that had to agree:

  • vp_js_runtime::download_runtime_for_project, which runs before vp commands
  • resolve_project_version_source in vp_global_cli, which vp env current, vp env which, vp env use, and the shims use

ensure_project_runtime calls both for the same project. During review, #3489 had to fix two drifts between them: a wrong fallback directory and a missing warning. Both paths now call select_project_node_version in vp_js_runtime. It walks up to the first source, validates it, falls back within the same directory, and returns the lower-priority constraints for the compatibility check.

Behavior changes:

Case Before After
vp env current, vp env which, vp env use, or a shim cache miss, with a valid .node-version or devEngines.runtime and an invalid engines.node No warning warning: invalid version '…' in engines.node, ignoring, as vp commands already print
vp commands with an invalid engines.node above a valid .nvmrc The warning printed twice The warning prints once

Other changes:

  • The walk returns the package.json it already parsed. The fallback reads package.json again only beside a .node-version, and vp commands no longer read an ancestor manifest a second time.
  • select_project_node_version validates a devEngines.runtime entry with one call, both when the entry selects the version and when it is only a constraint. The separate fallback, constraint, and validated_version helpers are gone.
  • resolve_project_version_source returns ProjectNodeVersion directly, so the global CLI's ProjectVersionSource copy is gone. VersionSource::as_str replaces the String allocations in the shim cache check.
  • is_valid_version, normalize_version, and read_package_json are no longer exported from vp_js_runtime, because no other crate uses them.

🤖 Generated with Claude Code

@fengmk2
fengmk2 added this pull request to stack #3499 November 19, 2026 16:19
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://refactor-select-project-node-version-viteplus-dev.voidzero-docs.workers.dev (commit 39eaceb)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://269ccddd-viteplus-dev.voidzero-docs.workers.dev 39eaceb 2026-11-21T03:19:01.739Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://cc001de4-viteplus-dev.voidzero-docs.workers.dev d9ee33f 2026-11-20T16:15:59.635Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c45be2fc-viteplus-dev.voidzero-docs.workers.dev dc0474f 2026-11-20T15:30:05.470Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://54f15621-viteplus-dev.voidzero-docs.workers.dev e9a4edc 2026-11-20T14:42:40.248Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://89d5d53e-viteplus-dev.voidzero-docs.workers.dev 38f2cf7 2026-11-20T01:36:04.421Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://395a8ba9-viteplus-dev.voidzero-docs.workers.dev 8a56b93 2026-11-19T16:20:25.755Z Visit the dashboard ↗

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

CLI artifact sizes (39eaceb)

Final release artifacts built by the canonical build-upstream and build-windows-cli actions.
The dist rows use the Linux build. The core total excludes .node files to match the release artifact.

Artifact Format Base PR Change
packages/cli/dist Directory total 2.38 MiB 2.38 MiB 0 B (0.00%)
packages/core/dist Directory total 4.11 MiB 4.11 MiB 0 B (0.00%)
Combined package dist Directory total 6.49 MiB 6.49 MiB 0 B (0.00%)
vp (Linux x64) Binary 8.51 MiB 8.50 MiB -8.00 KiB (-0.09%)
vp (Linux x64) gzip -9 3.89 MiB 3.89 MiB -88 B (-0.00%)
NAPI (Linux x64) Binary 37.22 MiB 37.22 MiB 0 B (0.00%)
NAPI (Linux x64) gzip -9 14.86 MiB 14.86 MiB 0 B (0.00%)
vp (macOS ARM64) Binary 5.57 MiB 5.57 MiB -16 B (-0.00%)
vp (macOS ARM64) gzip -9 3.32 MiB 3.32 MiB -419 B (-0.01%)
NAPI (macOS ARM64) Binary 43.77 MiB 43.77 MiB 0 B (0.00%)
NAPI (macOS ARM64) gzip -9 19.01 MiB 19.01 MiB 0 B (0.00%)
vp (Windows x64) Binary 6.59 MiB 6.59 MiB -1.50 KiB (-0.02%)
vp (Windows x64) gzip -9 3.01 MiB 3.01 MiB -244 B (-0.01%)
NAPI (Windows x64) Binary 33.18 MiB 33.18 MiB 0 B (0.00%)
NAPI (Windows x64) gzip -9 13.60 MiB 13.60 MiB +3 B (+0.00%)
Trampoline (Windows x64) Binary 13.50 KiB 13.50 KiB 0 B (0.00%)
Trampoline (Windows x64) gzip -9 7.09 KiB 7.09 KiB 0 B (0.00%)
Installer (Windows x64) Binary 4.69 MiB 4.69 MiB 0 B (0.00%)
Installer (Windows x64) gzip -9 2.25 MiB 2.25 MiB +37 B (+0.00%)

@fengmk2
fengmk2 force-pushed the refactor/select-project-node-version branch from 38f2cf7 to e9a4edc Compare November 20, 2026 14:41
Base automatically changed from triagebot/fix-2882 to main November 20, 2026 15:29
@fengmk2
fengmk2 force-pushed the refactor/select-project-node-version branch from ba1e380 to dc0474f Compare November 20, 2026 15:29
@fengmk2 fengmk2 self-assigned this Nov 20, 2026
@fengmk2
fengmk2 marked this pull request as ready for review November 20, 2026 15:29
@fengmk2
fengmk2 requested a review from cpojer November 20, 2026 15:30
@fengmk2
fengmk2 force-pushed the refactor/select-project-node-version branch from dc0474f to d9ee33f Compare November 20, 2026 16:14
fengmk2 and others added 3 commits November 21, 2026 11:18
download_runtime_for_project and the global CLI's
resolve_project_version_source each had their own fallback chain over
the lower-priority sources. Both now call select_project_node_version
in vp_js_runtime, which validates the first source, falls back within
the same directory, and returns the lower-priority constraints for the
compatibility check.

- The walk returns the package.json it already parsed, so the fallback
  reads it again only beside a .node-version.
- A source that the walk already validated is not validated again, so an
  invalid engines.node or .nvmrc warns once in vp commands.
- vp env current and the shims now also warn about an invalid
  engines.node below a valid .node-version or devEngines.runtime, as vp
  commands already did.
- The fallback helpers and validated_version are now private.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vp env which now uses the shared selection, so it reports the invalid
engines.node constraint below devEngines.runtime, as vp exec already
did. The snapshot is the runner's recorded output from CI (Linux and
macOS recorded the same text).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- select_project_node_version validates the devEngines.runtime entry
  with one call in both roles, so validated_version,
  dev_engines_runtime_fallback, dev_engines_runtime_constraint, and the
  separate warning helper are gone.
- It takes VersionResolution apart by value, so the shim fast path no
  longer copies the source and project paths.
- The walk no longer returns a manifest for .nvmrc, which nothing read.
- check_version_compatibility takes the selection. Its source guards
  could no longer be false.
- resolve_project_version_source returns ProjectNodeVersion, so the
  ProjectVersionSource copy and its String source are gone.
  VersionSource::as_str replaces the String allocations for comparisons
  and warning labels.
- Unused vp_js_runtime exports are dropped, and the stale
  js_executor.rs comments are fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2
fengmk2 force-pushed the refactor/select-project-node-version branch from d9ee33f to 39eaceb Compare November 21, 2026 03:18
@fengmk2
fengmk2 merged commit 3f29ac3 into main Nov 21, 2026
79 checks passed
@fengmk2
fengmk2 deleted the refactor/select-project-node-version branch November 21, 2026 03:46
@fengmk2 fengmk2 mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants