Repository navigation
Vite symlink-GVS serving compat (#315) - #318
Conversation
Write node_modules/.modules.yaml and backport Vite's own fs.allow sniff into ejected <8.1 vite so the dev server serves nub's global virtual store. Default-on, NUB_VITE_COMPAT=0 opt-out. Works-without-nub, CAS pristine. Claude-Session: https://claude.ai/code/session_01Xuh9u8b93eMNu53fTQTWX7
The first cut only detected a top-level node_modules/vite, missing the primary #315 case: library-embedded frameworks (Astro/SvelteKit/VitePress) whose vite is a transitive dep with no top-level symlink. apply() now discovers vite across top-level + node_modules/.nub/vite@* and writes .modules.yaml whenever vite is anywhere in the graph. Force-materialize is scoped to a directly-declared vite (the only shape whose loaded vite is the ejected copy the backport patches); a library-embedded framework loads its vite from the shared store, covered by Unit A for Vite >= 8.1. Also fixes the matrix driver (require() cannot load a .yaml file; transitive-vite detection; realpath eject classification). Claude-Session: https://claude.ai/code/session_01Xuh9u8b93eMNu53fTQTWX7
…obber (#315) Self-review (correctness + impact-analysis) surfaced four issues, all fixed: - P0 (Linux/Windows CAS corruption): the ejected dist files are HARDLINKS to the content-addressed store, so an in-place fs::write (O_TRUNC) truncated the shared inode and corrupted the global store (masked on macOS by copy-on-write materialization). patch_one now writes a temp sibling + atomic rename, severing the hardlink so the CAS blob is never touched. Adds a hardlink-integrity regression test that fails if the in-place write ever returns. - Vite compat now runs on nub add / nub update, not only nub install. - write_modules_yaml refuses to clobber a foreign (pnpm) .modules.yaml state file — writes only when absent or over its own single-key JSON stub. - Root resolution targets the dir that actually holds node_modules, so a stray ancestor lockfile can't point the writer at a node_modules-less parent. Claude-Session: https://claude.ai/code/session_01Xuh9u8b93eMNu53fTQTWX7
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
ℹ️ No critical issues — two observations worth a look, both non-blocking.
Reviewed changes — a PM-agnostic, works-without-nub fix for Vite dev servers rejecting store-resident modules (403 … outside of Vite serving allow list) when nub's virtual store lives outside the project root.
- Add
vite_compatmodule — newcrates/nub-cli/src/pm_engine/vite_compat.rswith two units:.modules.yamlwrite (Unit A, all Vite versions) and a CAS-safedist/nodecodegen backport for Vite < 8.1 (Unit B), both gated on vite-in-graph + theNUB_VITE_COMPATopt-out. - Wire post-install hook —
apply_vite_compatruns after a successfulrun_install/run_add/run_update(neverrun_ci, whose store is already project-local), resolving the install root fromsession.detected.dir/ cwd. - Conditional force-materialize —
nub_setting_defaultsappendsvitetoforceMaterializePackagesonly whenstore_locality == Defaultand the manifest declares vite directly, so the < 8.1 backport reaches the ejected project-local copy. - Docs +
NUB_VITE_COMPAT— install docs gain a Vite section and the knob is listed in the nub-identity config surface. - Matrix harness —
tests/vite-compat/(README +driver.sh+scaffold.sh) validates both tiers against real framework installs at the HTTP layer.
The mechanism is sound and the seams are clean: aube never writes .modules.yaml itself (it uses .aube-state), so Unit A doesn't collide with engine state; forceMaterializePackages matches on exact package name (HashSet::contains), so ,vite is safe; the CAS-hardlink regression guard test is a genuine safety net. Fail-open throughout and idempotent across re-installs.
ℹ️ Workspace-member vite doesn't get the < 8.1 backport
The force-materialize decision reads only the resolved identity root's manifest, which in a monorepo is the workspace root. If vite is declared directly by a member package (not the root), manifest_declares_vite returns false, so vite is never ejected project-local and Unit B's dist backport can't fire for that member. Vite ≥ 8.1 is still covered by Unit A's .modules.yaml, so this only bites a member on Vite < 8.1 — a narrow case adjacent to the already-documented library-embedded gap.
Technical details
# Workspace-member direct-dep vite is not force-materialized under GVS
## Affected sites
- `crates/nub-cli/src/pm_engine/mod.rs:2170-2177` — `force_materialize` gate calls `manifest_declares_vite(detected.map(|d| d.dir).unwrap_or(cwd))`; `detected.dir` is the identity walk-up dir (workspace root), not the member.
- `crates/nub-cli/src/pm_engine/vite_compat.rs:186-196` — `manifest_declares_vite` reads a single `package.json` at `root`.
## Required outcome
- Decide whether a member-declared vite under a workspace should get the < 8.1 backport. If yes, the eject decision needs to see member manifests, not just the root.
## Open questions for the human
- Is the workspace-member shape in scope for #315, or is it acceptable to leave it in the same documented-gap bucket as library-embedded Vite < 8.1? The reported repro (Astro 7 pinning Vite 8.1.3) is covered by Unit A regardless, so this may be intentional deferral.ℹ️ Harness default NUB path is worktree-specific
driver.sh and the README default NUB to ~/.cache/nub/worktrees/vite-build-target/fast/nub — the author's build path, not something a fresh checkout produces. It's overridable via the NUB env var and this is a manual dev harness (not CI-wired), so it's low-stakes, but the next person running it will hit a missing-binary error unless they read closely.
Technical details
# tests/vite-compat harness defaults to a machine-specific nub path
## Affected sites
- `tests/vite-compat/driver.sh:33` — `NUB="${NUB:-$HOME/.cache/nub/worktrees/vite-build-target/fast/nub}"`
- `tests/vite-compat/README.md:42` — `export NUB=~/.cache/nub/worktrees/vite-build-target/fast/nub # or target/fast/nub`
## Required outcome
- A default that a plain checkout produces (e.g. `target/fast/nub` or `target/release/nub`), or drop the default and require `NUB` explicitly so the failure is a clear "set NUB" message.Claude Opus | 𝕏
The disk-materialize embedder default seeds a version-blind "vite" name for any direct-dep vite, but vite >= 8.1 reads node_modules/.modules.yaml from the shared store natively (#318 Unit A, written post-install regardless of eject) and needs no eject. The name-seed dragged vite plus its whole ancestor-closure project-local for zero benefit, defeating global-store dedup for the vite frameworks (kit, plugin-svelte, vitefu, svelte-check, adapter-auto). Prune the "vite" name-seed in the version-aware closure hook plan_from_flags, which sees the resolved version. vite < 8.1 stays covered by the existing vite_lt_8_1 dep_path auto-seed, so its eject is unchanged; vite >= 8.1 now stays symlinked to the global store and is served via .modules.yaml. Claude-Session: https://claude.ai/code/session_01Xuh9u8b93eMNu53fTQTWX7
* fix(install): stop force-materializing vite >= 8.1 and its closure The disk-materialize embedder default seeds a version-blind "vite" name for any direct-dep vite, but vite >= 8.1 reads node_modules/.modules.yaml from the shared store natively (#318 Unit A, written post-install regardless of eject) and needs no eject. The name-seed dragged vite plus its whole ancestor-closure project-local for zero benefit, defeating global-store dedup for the vite frameworks (kit, plugin-svelte, vitefu, svelte-check, adapter-auto). Prune the "vite" name-seed in the version-aware closure hook plan_from_flags, which sees the resolved version. vite < 8.1 stays covered by the existing vite_lt_8_1 dep_path auto-seed, so its eject is unchanged; vite >= 8.1 now stays symlinked to the global store and is served via .modules.yaml. Claude-Session: https://claude.ai/code/session_01Xuh9u8b93eMNu53fTQTWX7 * test(install): cover the mixed vite <8.1/>=8.1 graph; note provenance-blind prune Self-review follow-up: add a mixed-graph test (embedded vite<8.1 + direct vite>=8.1) asserting the name-keyed executor still materializes both copies, locking in that the prune never regresses the mixed case. Note in the comment that the "vite" filter is provenance-blind (also strips a user's explicit seed), which is fine since <8.1 is re-seeded and >=8.1 works symlinked. Claude-Session: https://claude.ai/code/session_01Xuh9u8b93eMNu53fTQTWX7
|
Shipped in v0.3.0: https://github.com/nubjs/nub/releases/tag/v0.3.0 |

Vite dev servers 403 store-resident modules under nub's machine-global virtual store (
~/.cache/nub/pm/virtual-store, outside the project root):403 … is outside of Vite serving allow list. Vite realpath-checks every/@fs-served module againstserver.fs.allow(default[workspaceRoot]), and a store-resident dep served raw (framework client entries, dev-toolbar modules, SSR/optimizeDeps-excluded deps) falls outside it. pnpm never hits this — its virtual store is project-local, under the workspace root.The fix
One mechanism, PM-agnostic, works-without-nub, CAS-pristine — default-on,
NUB_VITE_COMPAT=0opts out. Gated on Vite being in the graph.node_modules/.modules.yaml. On install, whenever Vite is anywhere in the graph, write JSON{"virtualStoreDir":"<abs store>"}at the workspace root. Vite 8.1+ reads it natively (fix: apply correct fs restrictions for pnpm gvs vitejs/vite#22415) and allows the store. Covers direct and library-embedded Vite..modules.yamlsniff at itsfs.allow-default site (let allowDirs = server.fs.allow;for v6/v7,[searchForWorkspaceRoot(root)]for v5). The inserted sniff is YAML-tolerant and PM-agnostic — it reads whatevervirtualStoreDirany tool wrote; nub's store path lives only in the data file, never in the patch. Idempotent, fail-open (a missing anchor is a no-op, never a broken Vite).The fix lives on disk in
node_modulesand injects nothing at runtime, so it works whether or not nub is in the process — a teammate on plain Vite, or CI, gets the same result.Library-embedded frameworks
A framework like Astro is store-resident and loads its Vite through a store-to-store sibling symlink — the shared store copy, not the project-local ejected copy — so the dist backport can't reach it CAS-safely. Unit A covers those for Vite ≥ 8.1 (the store Vite reads
.modules.yamlnatively), which is the reported #315 shape: Astro 7 +@astrojs/reactpins Vite 8.1.3. A framework pinning Vite < 8.1 that does not set its ownfs.allow(VitePress already does) is the remaining gap — it shrinks as the ecosystem moves to Vite 8.1+; closing it would mean patching the shared store copy, a separate call.Validation
Matrix harness under
tests/vite-compat/(README + driver). Verified against real installs:@astrojs/react/dist/client.jsvia/@fs403→200, works-without-nub (npx astro dev)vite dev, bare CLI, no nubNUB_VITE_COMPAT=0.modules.yaml, no eject, byte-identical defaultCloses #315