Skip to content

fix(core): resolve bundled Rolldown bindings via platform packages - #2313

Merged
fengmk2 merged 6 commits into
mainfrom
rfc/core-binding-resolution
Aug 4, 2026
Merged

fix(core): resolve bundled Rolldown bindings via platform packages#2313
fengmk2 merged 6 commits into
mainfrom
rfc/core-binding-resolution

Conversation

@fengmk2

@fengmk2 fengmk2 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Closes #2054. Design: rfcs/core-binding-resolution.md. Solid edges are declared dependencies; dashed is an undeclared runtime require.

Before

flowchart TD
  app["user project"] --> vp["vite-plus"]
  vp -->|"dependency, exact pin"| core["@voidzero-dev/vite-plus-core<br>(bundled Rolldown)"]
  vp -->|"optionalDependencies x8,<br>injected at publish"| plat["@voidzero-dev/vite-plus-*<br>platform packages (merged .node)"]
  core -.->|"require('vite-plus/binding'),<br>undeclared"| vp
  linkStyle 3 stroke:#d33,stroke-width:2px
Loading

Release-built core reaches its Rolldown binding by requiring back into vite-plus, an undeclared cycle that only resolves through pnpm's hidden hoist. pnpm enable-global-virtual-store, Yarn PnP, and standalone core installs (the vite alias) fail with Cannot find module 'vite-plus/binding'.

After

flowchart TD
  app["user project"] --> vp["vite-plus"]
  vp -->|"dependency, exact pin"| core["@voidzero-dev/vite-plus-core<br>(bundled Rolldown)"]
  vp -->|"optionalDependencies x8,<br>injected at publish"| plat["@voidzero-dev/vite-plus-*<br>platform packages (merged .node)"]
  core -->|"optionalDependencies x8,<br>injected at publish"| plat
Loading

Core's bundled Rolldown requires the same platform packages vite-plus already uses, declared through optionalDependencies injected at publish time. No new packages, no cycle, core works standalone, and package managers dedupe the shared platform package.

@netlify

netlify Bot commented Aug 4, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit db02d35
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a7183ee547e65000835f65a

@fengmk2 fengmk2 self-assigned this Aug 4, 2026
@fengmk2
fengmk2 force-pushed the rfc/core-binding-resolution branch from f6f8ce8 to fcca21b Compare August 4, 2026 02:02
@fengmk2 fengmk2 added test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: create-e2e Run `vp create` e2e tests preview-build Publish this PR's commits to the registry bridge as preview builds test: sfw labels Aug 4, 2026
@fengmk2

fengmk2 commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Native binary sizes (db02d35)

Final release artifacts built by the canonical build-upstream and build-windows-cli actions.

Artifact Format Base PR Change
vp (Linux x64) Binary 10.52 MiB 10.52 MiB 0 B (0.00%)
vp (Linux x64) gzip -9 4.55 MiB 4.55 MiB 0 B (0.00%)
NAPI (Linux x64) Binary 33.61 MiB 33.61 MiB 0 B (0.00%)
NAPI (Linux x64) gzip -9 13.02 MiB 13.02 MiB 0 B (0.00%)
vp (macOS ARM64) Binary 7.84 MiB 7.84 MiB 0 B (0.00%)
vp (macOS ARM64) gzip -9 3.95 MiB 3.95 MiB 0 B (0.00%)
NAPI (macOS ARM64) Binary 40.92 MiB 40.92 MiB 0 B (0.00%)
NAPI (macOS ARM64) gzip -9 17.24 MiB 17.24 MiB -15 B (-0.00%)
vp (Windows x64) Binary 8.42 MiB 8.42 MiB 0 B (0.00%)
vp (Windows x64) gzip -9 3.67 MiB 3.67 MiB 0 B (0.00%)
NAPI (Windows x64) Binary 27.77 MiB 27.77 MiB 0 B (0.00%)
NAPI (Windows x64) gzip -9 10.86 MiB 10.86 MiB +2 B (+0.00%)
Trampoline (Windows x64) Binary 203.00 KiB 203.00 KiB 0 B (0.00%)
Trampoline (Windows x64) gzip -9 97.91 KiB 97.91 KiB 0 B (0.00%)
Installer (Windows x64) Binary 4.47 MiB 4.47 MiB 0 B (0.00%)
Installer (Windows x64) gzip -9 2.09 MiB 2.09 MiB -1 B (-0.00%)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: fcca21bee9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Registry bridge build (3a79c35)

This commit build is published to the registry bridge, which serves these as ordinary npm versions (every other package proxies to npmjs):

Package Version
vite-plus 0.0.0-commit.3a79c350a1c28c9f491c7c4642e42ed426dda78d
@voidzero-dev/vite-plus-core 0.0.0-commit.3a79c350a1c28c9f491c7c4642e42ed426dda78d

Install the Vite+ CLI built from this commit, then migrate a project:

# macOS / Linux
curl -fsSL https://vite.plus | VP_PR_VERSION=2313 bash
# Windows (PowerShell)
$env:VP_PR_VERSION="2313"; irm https://vite.plus/ps1 | iex

After installing, upgrade the current project's vite-plus to this test build with:

vp migrate

Or point your package manager at the bridge registry https://registry-bridge.viteplus.dev/:

Package manager Registry config
npm / pnpm / Bun .npmrc: registry=https://registry-bridge.viteplus.dev/
Yarn (v2+) .yarnrc.yml: npmRegistryServer: "https://registry-bridge.viteplus.dev/"

Then pin the build (vite aliases to vite-plus-core; pnpm can use a catalog, npm an overrides entry):

{
  "devDependencies": {
    "vite-plus": "0.0.0-commit.3a79c350a1c28c9f491c7c4642e42ed426dda78d",
    "vite": "npm:@voidzero-dev/vite-plus-core@0.0.0-commit.3a79c350a1c28c9f491c7c4642e42ed426dda78d"
  }
}

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🐳 Docker preview image

Built from this PR's registry bridge build:

Image Compressed size
ghcr.io/voidzero-dev/vite-plus:pr-2313 236MB
# remove any stale local copy from a previous run, then pull fresh
docker rmi ghcr.io/voidzero-dev/vite-plus:pr-2313 2>/dev/null; docker pull ghcr.io/voidzero-dev/vite-plus:pr-2313

Quick check:

docker run --rm ghcr.io/voidzero-dev/vite-plus:pr-2313 vp --version

See docs/guide/docker.md for usage.

@fengmk2

fengmk2 commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

Verified the bridge build (fcca21b) against the issue repro (https://github.com/jong-kyung/repro-vite-plus-2054, pnpm enableGlobalVirtualStore: true).

Baseline (repro as published, vite-plus@0.2.2):

vite realpath: ~/Library/pnpm/store/v11/links/@voidzero-dev/vite-plus-core/0.2.2/.../package.json
Error: Cannot find module 'vite-plus/binding'

This build (catalog pinned to 0.0.0-commit.fcca21bee9fa82419c9d0d85541393bf7dd2cace, fresh lockfile, bridge registry):

vite realpath: ~/Library/pnpm/store/v11/links/@voidzero-dev/vite-plus-core/0.0.0-commit.fcca21be.../package.json
rolldown loaded: function

Same layout, core still resolving from the global store realpath, now working. Mechanism checks on the installed artifacts:

  • Installed core declares all 8 @voidzero-dev/vite-plus-<platform> optionalDependencies at the commit version (injected at publish; the committed package.json stays pin-free), and the darwin-arm64 package is a resolvable sibling of core's store realpath.
  • The loader chunk carries 8 version guards at the commit version (the new core stamp in reusable-release-build.yml) and 19 untouched upstream guards at Rolldown 1.2.2 for platforms Vite+ does not ship.
  • NAPI_RS_ENFORCE_VERSION_CHECK=1 passes: the guard is live and matching again, after being dead code in previously published releases.
  • import('vite/rolldown') reports VERSION === "1.2.2", the bundled Rolldown version, no longer rewritten to the vite-plus version.

@fengmk2
fengmk2 marked this pull request as ready for review August 4, 2026 03:27
@fengmk2
fengmk2 force-pushed the rfc/core-binding-resolution branch from 8fc4ef5 to 3a79c35 Compare August 4, 2026 03:33
@fengmk2 fengmk2 added preview-build Publish this PR's commits to the registry bridge as preview builds and removed preview-build Publish this PR's commits to the registry bridge as preview builds labels Aug 4, 2026
fengmk2 added 5 commits August 4, 2026 13:53
Release-built core resolves bundled Rolldown's native binding through
vite-plus/binding, an export of a package core never declares, which
breaks pnpm enable-global-virtual-store, Yarn PnP, and standalone core
installs. The RFC keeps the per-platform rewrite direction from PR #2067
but moves the platform optionalDependencies pins out of the committed
package.json and into the publish pipeline, mirroring how napi-rs
injects the same packages into vite-plus.
Release builds now rewrite each supported @rolldown/binding-<platform>
require to @voidzero-dev/vite-plus-<platform> (suffixes derived from the
CLI's napi.targets via parseTriple) instead of collapsing all of them to
vite-plus/binding, and rewrite each branch's version guard to core's
version in the same specifier-anchored pattern. Branches for platforms
Vite+ does not ship, the WASI fallback, and Rolldown's public VERSION
export stay untouched, and the build fails if the rewrite counts diverge
from the napi-rs loader shape.

publish-native-addons.ts mirrors the napi-injected platform pins from
packages/cli/package.json into core's optionalDependencies in both npm
and pkg-pr-new modes, so core declares what its loader requires while
the committed package.json stays pin-free and release version bumps,
the dirty-tree check, and preview builds keep working.
reusable-release-build.yml stamps packages/core/package.json so preview
builds bake guard versions that match the bridge-served platform
packages.

Closes #2054

See rfcs/core-binding-resolution.md for the design.
binding-resolution-layout.spec.ts rebuilds pnpm's enable-global-virtual-store
shape with stub packages and requires through it in a child process: the old
collapsed rewrite fails with the exact #2054 error, the transform output
resolves through the declared platform package, and the re-armed version
guard rejects a mismatched platform package under
NAPI_RS_ENFORCE_VERSION_CHECK. A PTY snapshot case cannot cover this because
snapshot installs use dev-built core, which embeds the .node in dist and
never takes the rewritten path.

Writing the spec surfaced a transform gap: the guard rewrite only matched
the bundled-chunk __require( form. It now also matches plain require( for
raw CJS loader output; the build.ts count assertion would have caught the
miss, but the transform should handle both.
The export existed only for the old collapsed @rolldown/binding-* rewrite.
Nothing imports the specifier: the CLI loads its binding through a relative
import, and no repo, dist, snapshot, or ecosystem reference exists. Old
published cores that require it always pair with an old vite-plus through
the exact version pin, so removal cannot strand them. The binding/ files
still ship for the CLI's own relative import.
The rewrite transform now reports which platform suffixes it redirected,
and the release build asserts set equality with the published platforms
instead of a specifier/guard count ratio, so a dropped or renamed loader
branch fails the build by name instead of shipping a partial rewrite.
The platform-package prefix derives from the CLI's napi.packageName in
both the transform and the publish script, removing three hard-coded
copies of the scope string.

Also: lazy-load @napi-rs/cli in build.ts (release-only, ~120ms saved on
every dev core build), share one fresh package.json read in
publish-native-addons.ts via readJsonFile, single-source the workflow's
stamp/verify file list through GITHUB_ENV, simplify the guard regex and
both specs, and shrink core BUNDLING.md's derived mapping table to
examples plus a pointer at the napi.targets table.
@fengmk2
fengmk2 force-pushed the rfc/core-binding-resolution branch from 3a79c35 to e872dae Compare August 4, 2026 05:53
@fengmk2
fengmk2 merged commit 0a5e76e into main Aug 4, 2026
105 checks passed
@fengmk2
fengmk2 deleted the rfc/core-binding-resolution branch August 4, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview-build Publish this PR's commits to the registry bridge as preview builds test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: sfw

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid circular binding resolution between vite-plus-core and vite-plus

2 participants