Skip to content

fix(dependency-resolver): patch react-env's tsconfig extends for the global virtual store - #10572

Closed
zkochan wants to merge 10 commits into
teambit:masterfrom
zkochan:gvs-react-env-patch
Closed

zkochan wants to merge 10 commits into
teambit:masterfrom
zkochan:gvs-react-env-patch

Conversation

@zkochan

@zkochan zkochan commented Aug 5, 2026

Copy link
Copy Markdown
Member

Ships a patch for @teambit/react.react-env's phantom tsconfig dependency under the global virtual store.

Blocked — do not merge. Split out of #10567 so that PR is not held up by this.

The problem

@teambit/react.react-env 1.x ships a tsconfig whose extends names @teambit/react/typescript/tsconfig.json without declaring @teambit/react. That resolved only by TypeScript walking up node_modules into the workspace, which a package in the shared store cannot do — so under the global virtual store bit status reports:

File '@teambit/react/typescript/tsconfig.json' not found.

and is clean without it. NODE_PATH and the ESM loader cannot cover it: TypeScript resolves extends with its own resolver and consults neither. The patch inlines the extended config so no resolution is needed — the only form that works from an arbitrary location in the shared store.

Why it is blocked

react-env 2.x already inlines the config, so the phantom dependency only exists on the 1.x line. That makes the patch key version-sensitive:

key 1.x workspaces 2.x workspaces
@teambit/react.react-env (this PR) applies fails to apply
@teambit/react.react-env@1 applies ERR_PNPM_UNUSED_PATCH

pnpm fails an install when a configured patch matches no installed package (crates/patching/src/verify.rs, verify_patches). allow_unused_patches defaults to false and is not exposed through @pnpm/napi — 12.0.0-rc.0 accepts patchedDependencies only.

So neither key is safe today. This repo itself resolves only react-env 2.0.3, so merging as-is would break its own global-virtual-store installs.

Unblocking

Once a napi release exposes allowUnusedPatches:

  1. change the key to @teambit/react.react-env@1
  2. pass allowUnusedPatches so workspaces on 2.x do not fail

Then this is mergeable.

Notes

  • Built on top of feat(dependency-resolver): opt-in support for pnpm's global virtual store #10567 (gvs) — it depends on enableGlobalVirtualStore(). Until that lands, the diff here shows its commits too; only the last commit belongs to this PR.
  • The patch-shipping mechanism works as-is: shouldCopyNonSupportedFiles copies patches/*.patch into dist, same as the existing fixtures/cafile.txt. No build changes needed.
  • Verified applying on a workspace resolving react-env 1.0.97 / 1.0.109 / 1.0.131 / 1.0.132 — all four take the patch, which is why the key is unversioned here.

zkochan and others added 9 commits August 5, 2026 22:29
`_calculateFinalFileName` stripped the extension from the whole path, so
any dot in a parent directory was treated as the extension:
`bit doctor --archive /tmp/my.dir/report` wrote `/tmp/my.tar` instead of
`/tmp/my.dir/report.tar`.

Strip the extension from the last path segment only. Unrelated to the
rest of this branch - it surfaced because the e2e temp dir contains a
dot, which is why `doctor-infra.e2e.ts` fails locally but passes on CI.
…tore

With `enableGlobalVirtualStore` on, dependency directories are created
once in a store shared by every workspace and capsule on the machine
instead of being re-created inside each `node_modules/.pnpm`. On real
workspaces that collapses the project-local virtual store from 20832 to
529 entries (and 4017 to 258), leaving only the injected components.

Off by default. Enable per workspace under
`teambit.dependencies/dependency-resolver`, machine-wide with
`bit config set enable_global_virtual_store true`, or per run with
`BIT_ENABLE_GLOBAL_VIRTUAL_STORE` (which is how the e2e suite runs the
whole matrix under it).

Making it behave identically to the project-local layout needed four
fixes:

- The core aspects are phantom dependencies of every published env and
  aspect. Project-locally a package in `node_modules/.pnpm` resolves
  them by walking up into the workspace's root `node_modules`; nothing
  in a shared store can walk up into a workspace, so every env failed to
  load. Mirror the installation's core-aspect links at the root of the
  store, which every slot in it can reach, and key that store per bit
  installation so two of them cannot shadow each other's aspects.
- A workspace that authors the core aspects (the bit repo) bridges them
  into the hoisted store only until they compile, then removes the
  bridge. That is right project-locally and fatal from a shared store,
  so under it the bridge stays, repointed at the compiled workspace copy.
- `getInjectedDirs` reports an injected copy absolute when it cannot be
  made relative to the lockfile dir - which under a shared store is
  always. `compiler.task.ts` joined it onto the capsule root regardless,
  hard-linking build artifacts into a path that does not exist.
- Capsules stay on the project-local store. A capsule is a self-contained
  build sandbox and TypeScript's declaration emit depends on that: it
  names an inferred type through the package that declares it, which it
  can only do while that package is inside the capsule. Moving env and
  aspect packages out made `bit build` of any custom env fail with
  TS2742.

Also adds `patchedDependencies` and `packageExtensions` passthrough.
`packageExtensions` is not optional under a shared store: it is the only
way to satisfy a phantom dependency of a published package, since the
package now lives outside the project and can no longer reach whatever
the project hoisted.

`bit deps diagnose` and the prune step read the current lockfile instead
of assuming `node_modules/.pnpm` holds the packages, and the global store
is skipped for `nodeLinker: hoisted`, which uses no virtual store.
Three suites hand-wrote paths that only exist in the project-local
virtual store, so they broke under the global one even though the
behaviour they check was fine:

- `install.e2e` and `node-linker.e2e` asserted on `node_modules/.pnpm`
  directly. New `helper.fs.getVirtualStoreDirNames()` reads the current
  lockfile when the directory holds no package dirs, which yields the
  same names either way.
- `dependency-resolver.e2e` verified dependency overrides by reading
  `node_modules/.pnpm/<depPath>/node_modules/<dep>/package.json`. New
  `helper.fs.readPackageJsonOfChain(['rimraf','glob','inflight','once'])`
  walks the chain the way Node resolves it, so it is correct under the
  project-local, global and hoisted layouts alike.

Adds `global-virtual-store.e2e.ts` covering the store itself: deps are
not created in the workspace, they resolve out of the shared store, the
current lockfile still records them, the component loads and compiles,
and a patched dependency is applied to the shared copy.
Documents `enableGlobalVirtualStore`, `globalVirtualStoreDir` and
`patchedDependencies`, and adds the script that installs a locally built
pnpm engine over the published `@pnpm/napi` - needed until a release
carries the options this branch passes (pnpm/pnpm#13648).
`my-react-env.bit-env.ts` opened with `// @bit-no-check`, which turns off
Bit's dependency detection for the file. Its imports - notably
`@teambit/react.react-env` - therefore never reached the component's
generated manifest, so the env only resolved them by reaching packages
the workspace had hoisted.

That is a phantom dependency, and it stops working the moment the
package is not inside the project any more: under the global virtual
store the env fails to load with `Cannot find module
'@teambit/react.react-env'`. Nothing in this fixture needs dependency
detection off - `@ts-nocheck`, which is what the tsconfig scenario
actually relies on, stays.

None of the real env components in the workspaces this was checked
against carry `@bit-no-check`, and they resolve correctly either way.
… global virtual store

The core aspects are phantom dependencies of every published env: required
without being declared, provided by the running bit installation. Under the
project-local virtual store an env resolves them by walking up out of
node_modules/.pnpm into the workspace root. Under the global virtual store the
env lives in the shared store with no workspace above it, so that fails.

Bit worked around this by mirroring the core aspects at the root of the virtual
store, which forced a <storeDir>/bit-links/<installationId> root private to one
bit installation: no slot reuse across bit versions or with other pnpm
projects, a full re-materialization of ~275k directories on every bit upgrade,
and nothing to prune stale roots.

Use pnpm's documented mechanism for hoisted dependencies in this layout
instead. The privately hoisted directory stays project-local at
node_modules/.pnpm/node_modules even under the global virtual store, and is
reached from a store slot via NODE_PATH. Link the core aspects there and put it
on NODE_PATH during bootstrap - pnpm does that for the shims it writes, but bit
runs from bvm and loads aspects in its own process.

Nothing is written inside the store, so pnpm's shared <storeDir>/links can be
used: slots are reused across bit versions and with every other pnpm project,
upgrades stay incremental, and pnpm store prune accounts for them.

Node ignores NODE_PATH for ESM. Core aspects and published env dists are
CommonJS today; @pnpm/plugin-esm-node-path is the escape hatch if that changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… in ESM too

NODE_PATH covers only CommonJS - Node ignores it for ESM entirely. Bit supports
ESM components, so an ESM package in the shared store could not reach the
hoisted directory at all, leaving the workaround covering only half the problem.

Register an ESM loader whose resolve hook retries a failed bare specifier
against the NODE_PATH entries. Registered in bit's own process via
module.register, and exported through NODE_OPTIONS so the processes bit spawns -
env build steps, app servers, test workers - inherit it, since they resolve
their own dependencies and hit the same wall.

The loader and the --import registration are adapted from pnpm's
@pnpm/plugin-esm-node-path (MIT), inlined as a data URL so there is no file to
ship and no install step to depend on. Skipped when module.register is missing
(Node < 20.6); the CommonJS half still applies there.

Also generalize the surrounding comments: this is about phantom dependencies as
a class, not core aspects specifically. The core aspects are the case that
motivated it, but any under-declared package resolves the same way, which is why
the whole hoisted directory goes on the path rather than a hand-picked list.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The global virtual store work needs two engine changes that are now in a
released build: the napi surface for `enableGlobalVirtualStore`,
`globalVirtualStoreDir`, `packageExtensions` and `patchedDependencies`
(pnpm/pnpm#13648), and the fix for `link:` dependencies vanishing from
virtual-store slots (pnpm/pnpm#13658).

Verified on the released engine: a global-virtual-store install of the
opus-5 workspace reuses all 30,766 existing slots (creates none), leaves
the project-local `node_modules/.pnpm` empty, and still applies the
react-env tsconfig patch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…global virtual store

@teambit/react.react-env 1.x ships a tsconfig whose `extends` names
@teambit/react/typescript/tsconfig.json without declaring @teambit/react - a
phantom dependency in a published package. It resolved only by TypeScript
walking up node_modules into the workspace, which a package in the shared store
cannot do, so `bit status` reported "File '@teambit/react/typescript/
tsconfig.json' not found." under the global virtual store and was clean without
it.

NODE_PATH and the ESM loader cannot cover this: TypeScript resolves `extends`
with its own resolver and never consults either. Ship a patch that inlines the
extended config so no resolution is needed - the only form that works from any
location. Declaring the dependency instead would install a registry copy of a
core aspect, duplicating what has to stay a single host-provided instance.

BLOCKED, do not merge yet. react-env 2.x already inlines the config, so the
phantom dependency only exists on the 1.x line. The key therefore has to be
scoped (`@teambit/react.react-env@1`), but pnpm fails an install with
ERR_PNPM_UNUSED_PATCH when a configured patch matches no installed package
(crates/patching/src/verify.rs, `allow_unused_patches` defaults to false), and
that setting is not exposed through @pnpm/napi - 12.0.0-rc.0 accepts
`patchedDependencies` only. Keying it bare, as this commit does, makes it fail
to apply on 2.x instead.

Waiting on a napi release exposing allowUnusedPatches. Then: change the key to
`@teambit/react.react-env@1` and pass allowUnusedPatches so workspaces on 2.x,
including this repo, do not fail.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zkochan added a commit to pnpm/pnpm that referenced this pull request Aug 6, 2026
pnpm fails an install when a configured patch matches no installed
package (ERR_PNPM_UNUSED_PATCH). The CLI lets a workspace opt out via
allowUnusedPatches in pnpm-workspace.yaml, but the binding accepted
patchedDependencies only, so an embedder that ships its own patches had
no way to reach the setting.

Threads the flag through InstallOptions -> ConfigOverlay ->
Config::allow_unused_patches, which the fresh-lockfile path already reads
when it calls verify_patches. No engine-side change is needed; this is
purely the missing binding surface.

Bit needs it to ship a patch keyed to a version range
(`@teambit/react.react-env@1`) from its own config: workspaces that
resolve 2.x match no key and would otherwise fail the install. See
teambit/bit#10572.
zkochan added a commit to zkochan/bit that referenced this pull request Aug 7, 2026
…ript

rc.1 carries the slot-materialization dedup (pnpm/pnpm#13669), the last
engine change the global virtual store needed from a checkout, so the
script that installed a locally built engine over the released one goes
away as promised. It also adds `allowUnusedPatches`, which unblocks the
version-scoped patch approach parked in teambit#10572 if it is ever wanted over
the packageExtensions built-ins.

Verified on the released engine: two consecutive self-hosted
global-virtual-store installs of this repo (the workload whose peer
variants previously raced the link pass on every install), zero race
errors, lint green.

Co-Authored-By: Claude Fable 5 <[email protected]>
zkochan added a commit to zkochan/bit that referenced this pull request Aug 7, 2026
…ript

rc.1 carries the slot-materialization dedup (pnpm/pnpm#13669), the last
engine change the global virtual store needed from a checkout, so the
script that installed a locally built engine over the released one goes
away as promised. It also adds `allowUnusedPatches`, which unblocks the
version-scoped patch approach parked in teambit#10572 if it is ever wanted over
the packageExtensions built-ins.

Verified on the released engine: two consecutive self-hosted
global-virtual-store installs of this repo (the workload whose peer
variants previously raced the link pass on every install), zero race
errors, lint green.

Co-Authored-By: Claude Fable 5 <[email protected]>
@zkochan
zkochan marked this pull request as ready for review August 7, 2026 15:20
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

New Review Started

This review has been superseded by a new analysis

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

feat(dependency-resolver): global virtual store support + react-env tsconfig patch

✨ Enhancement 🧪 Tests 📝 Documentation 🐞 Bug fix ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Add opt-in pnpm global virtual store support with hoisted resolution for phantom dependencies.
• Ship a built-in patch for react-env 1.x tsconfig extends under the shared store.
• Update docs/tests and bump pnpm napi to 12.0.0-rc.0 for required install options.
Diagram

graph TD
  A["CLI bootstrap"] --> B["Hoisted resolution"] --> C["DependencyResolver"] --> D["DependencyInstaller"] --> E["pnpm engine"] --> F[("Global store")]
  C --> G["Built-in patch"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use pnpm packageExtensions for react-env phantom dependency
  • ➕ Avoids patch context brittleness (no byte-exact hunks).
  • ➕ Keeps changes declarative and version-range friendly.
  • ➖ Would install a registry copy of a core aspect (@teambit/react) when Bit must provide a single host instance.
  • ➖ Does not solve TypeScript tsconfig extends resolution if the file path is still unreachable in the shared store.
2. Vendor/override tsconfig at env consumption time (no patching)
  • ➕ No pnpm patching semantics or unused-patch failure modes.
  • ➕ Keeps dependency graph untouched.
  • ➖ More invasive: requires custom tsconfig generation/rewriting in tooling.
  • ➖ Harder to guarantee correctness across env versions and dist/source paths.
3. Key patch to @teambit/react.react-env@1 and allow unused patches
  • ➕ Avoids patch applying to react-env 2.x where it may not match.
  • ➕ Makes the intent explicit (only 1.x needs the patch).
  • ➖ Blocked on pnpm/@pnpm/napi exposing allowUnusedPatches (otherwise 2.x installs fail).
  • ➖ Still requires keeping patch hunks in sync across 1.x variants.

Recommendation: The global-virtual-store approach plus a built-in patch is a pragmatic way to keep workspace installs fast while preserving Bit's "host-provided core aspects" model. For the react-env issue specifically, patching (inlining the extended config) is preferable to packageExtensions because it avoids pulling a duplicate registry copy of a core aspect. Once @pnpm/napi exposes allowUnusedPatches, switching to a version-scoped patch key (@teambit/react.react-env@1) is the safest long-term strategy.

Files changed (25) +887 / -81

Enhancement (9) +415 / -7
dependencies.main.runtime.tsMake dependency diagnostics work under global virtual store +24/-2

Make dependency diagnostics work under global virtual store

• Adds a virtual-store entry reader that falls back to 'node_modules/.pnpm/lock.yaml' when '.pnpm' contains no package directories. Uses it for 'diagnoseDuplicateDeps' and 'diagnoseDrillDown'.

scopes/dependencies/dependencies/dependencies.main.runtime.ts

dependency-installer.tsPass global-virtual-store options and merge built-in patches +57/-1

Pass global-virtual-store options and merge built-in patches

• Extends installer wiring to pass 'enableGlobalVirtualStore', 'globalVirtualStoreDir', 'patchedDependencies', and 'packageExtensions' to the package manager. Adds a built-in patch for '@teambit/react.react-env' tsconfig when global virtual store is enabled and disables global store inside capsules to avoid TS2742 issues during env builds.

scopes/dependencies/dependency-resolver/dependency-installer.ts

dependency-linker.tsLink core aspects into hoisted store for global virtual store resolution +68/-3

Link core aspects into hoisted store for global virtual store resolution

• Adds 'linkCoreAspectsToHoistedStore()' to bridge Bit-provided core aspects into the project-local hoisted directory under global virtual store. Adjusts authored-core-aspect bootstrap handling to keep a bridge when global store is enabled and repoint it to the compiled workspace copy when available.

scopes/dependencies/dependency-resolver/dependency-linker.ts

dependency-resolver.main.runtime.tsImplement global virtual store enablement and store-dir selection +61/-0

Implement global virtual store enablement and store-dir selection

• Adds 'enableGlobalVirtualStore()' with precedence (env var, workspace config, global config key). Adds 'getGlobalVirtualStoreDir()' and a stable installation identifier helper; wires new config into the installer construction.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts

index.tsRe-export PackageExtension type +1/-0

Re-export PackageExtension type

• Exports 'PackageExtension' from the dependency-resolver public API so pnpm integration and config typing can reference it.

scopes/dependencies/dependency-resolver/index.ts

package-manager.tsExtend install options with global virtual store, patching, and extensions +41/-0

Extend install options with global virtual store, patching, and extensions

• Adds 'PackageExtension' type and extends 'PackageManagerInstallOptions' with 'enableGlobalVirtualStore', 'globalVirtualStoreDir', 'patchedDependencies', and 'packageExtensions'. Adds an optional 'getGlobalVirtualStoreDir()' hook to the package manager interface.

scopes/dependencies/dependency-resolver/package-manager.ts

lynx.tsPlumb global virtual store, patchedDependencies, and packageExtensions into pnpm install +11/-0

Plumb global virtual store, patchedDependencies, and packageExtensions into pnpm install

• Extends the pnpm install wrapper to accept and forward global-store and patch/extension options. Ensures the global store is disabled when 'nodeLinker' is 'hoisted' (no virtual store exists).

scopes/dependencies/pnpm/lynx.ts

pnpm.package-manager.tsSupport global virtual store dir computation and pass new install options +25/-0

Support global virtual store dir computation and pass new install options

• Passes global-store/patch/extension options through to the pnpm engine. Implements 'getGlobalVirtualStoreDir()' returning pnpm's shared '<storeDir>/links' by default (or config override).

scopes/dependencies/pnpm/pnpm.package-manager.ts

bootstrap.tsAdd NODE_PATH and ESM loader bridge for hoisted deps under global store +127/-1

Add NODE_PATH and ESM loader bridge for hoisted deps under global store

• Adds early bootstrap logic to include '<workspace>/node_modules/.pnpm/node_modules' in 'NODE_PATH' and registers an ESM loader (via 'module.register' and NODE_OPTIONS) that retries bare-specifier resolution from NODE_PATH entries. Ensures phantom dependencies remain resolvable when packages run from the global virtual store.

scopes/harmony/bit/bootstrap.ts

Bug fix (4) +111 / -3
compiler.task.tsFix injected-dir linking when injected paths are absolute +8/-1

Fix injected-dir linking when injected paths are absolute

• Handles absolute injected directory paths (produced under global virtual store) instead of always joining to capsulesRootDir. Prevents silently generating incorrect paths like '<capsulesRoot>/<absolute-store-path>'.

scopes/compilation/compiler/compiler.task.ts

react-env-tsconfig-extends.patchInline react-env tsconfig instead of extending an undeclared dependency +84/-0

Inline react-env tsconfig instead of extending an undeclared dependency

• Removes 'extends: @teambit/react/typescript/tsconfig.json' from react-env 1.x tsconfig and inlines the expected compiler options for both source and dist config paths. This avoids TypeScript 'extends' resolution from failing inside the shared store.

scopes/dependencies/dependency-resolver/patches/react-env-tsconfig-extends.patch

pnpm-prune-modules.tsMake pruning tolerant of global-store and lockfile-only installs +13/-1

Make pruning tolerant of global-store and lockfile-only installs

• Handles missing 'node_modules/.pnpm' (lockfile-only) and empty virtual store dirs (global-store case) by treating them as "nothing to prune".

scopes/dependencies/pnpm/pnpm-prune-modules.ts

doctor.main.runtime.tsFix --archive output path when parent directories contain dots +6/-1

Fix --archive output path when parent directories contain dots

• Corrects tar file naming to strip extensions from only the last path segment. Prevents truncating directory names like '/tmp/my.dir/report' into '/tmp/my.tar'.

scopes/harmony/doctor/doctor.main.runtime.ts

Tests (5) +90 / -15
my-react-env.bit-env.tsRemove redundant @bit-no-check directive in fixture +0/-1

Remove redundant @bit-no-check directive in fixture

• Drops the '@bit-no-check' comment (keeps '@ts-nocheck') to reduce fixture noise without affecting behavior.

components/legacy/e2e-helper/excluded-fixtures/workspace-with-tsconfig-issue/my-scope/envs/my-react-env/my-react-env.bit-env.ts

dependency-resolver.e2e.tsMake dependency override assertions resilient across virtual-store layouts +4/-12

Make dependency override assertions resilient across virtual-store layouts

• Replaces hard-coded '.pnpm/.../node_modules/...' file reads with chained resolution via the new e2e FS helper. This keeps tests valid under project-local and global virtual store modes.

e2e/harmony/dependency-resolver.e2e.ts

global-virtual-store.e2e.tsAdd e2e coverage for global virtual store behavior and patchedDependencies +82/-0

Add e2e coverage for global virtual store behavior and patchedDependencies

• Adds tests verifying workspace '.pnpm' contains no package dirs, dependencies link from the shared store, installs are recorded via lockfile parsing, and patches apply to the store-backed copy.

e2e/harmony/global-virtual-store.e2e.ts

install.e2e.tsUse virtual-store entry helper in optional dependency test +1/-1

Use virtual-store entry helper in optional dependency test

• Switches from reading 'node_modules/.pnpm' directly to 'getVirtualStoreDirNames()' so optional-deps assertions work under global virtual store.

e2e/harmony/install.e2e.ts

node-linker.e2e.tsRelax assertion to accept global-store symlink targets +3/-1

Relax assertion to accept global-store symlink targets

• Updates the hoisted nodeLinker test to accept symlinks pointing into either '.pnpm' or 'bit-links', matching both virtual store layouts.

e2e/harmony/node-linker.e2e.ts

Documentation (1) +37 / -0
dependency-resolver.mdxDocument global virtual store and patchedDependencies configuration +37/-0

Document global virtual store and patchedDependencies configuration

• Adds docs for 'enableGlobalVirtualStore', machine-wide enabling via config, and 'globalVirtualStoreDir'. Documents 'patchedDependencies' usage with an example.

scopes/dependencies/aspect-docs/dependency-resolver/dependency-resolver.mdx

Other (6) +234 / -56
constants.tsAdd global config key for enabling the global virtual store +6/-0

Add global config key for enabling the global virtual store

• Introduces CFG_ENABLE_GLOBAL_VIRTUAL_STORE to support machine-wide opt-in via 'bit config'. Documents precedence relative to workspace config overrides.

components/legacy/constants/constants.ts

e2e-fs-helper.tsAdd helpers for package-dir resolution and virtual store entry listing +46/-0

Add helpers for package-dir resolution and virtual store entry listing

• Adds Node-like chained package resolution to avoid hard-coded '.pnpm/<depPath>' assumptions. Adds 'getVirtualStoreDirNames()' which falls back to parsing 'node_modules/.pnpm/lock.yaml' when the global store is enabled.

components/legacy/e2e-helper/e2e-fs-helper.ts

pnpm-lock.yamlBump @pnpm/napi to 12.0.0-rc.0 and add helper deps +94/-54

Bump @pnpm/napi to 12.0.0-rc.0 and add helper deps

• Updates lockfile for @pnpm/napi rc.0 and adds 'yaml', 'resolve-from', and '@teambit/dependencies.pnpm.dep-path' required by new parsing/resolution helpers.

pnpm-lock.yaml

dependency-resolver-workspace-config.tsAdd workspace config surface for global store, patches, and packageExtensions +31/-1

Add workspace config surface for global store, patches, and packageExtensions

• Introduces config fields: 'enableGlobalVirtualStore', 'globalVirtualStoreDir', 'patchedDependencies', and 'packageExtensions' (typed). Documents intended semantics and why they matter under a shared store.

scopes/dependencies/dependency-resolver/dependency-resolver-workspace-config.ts

link-local-pnpm-engine.shAdd helper script to override @pnpm/napi with a local pacquet-napi build +56/-0

Add helper script to override @pnpm/napi with a local pacquet-napi build

• Adds a development script that replaces the platform binary and JS/typings for @pnpm/napi in workspace node_modules. Intended to unblock testing before required engine bindings are released.

scripts/link-local-pnpm-engine.sh

workspace.jsoncBump @pnpm/napi workspace dependency to 12.0.0-rc.0 +1/-1

Bump @pnpm/napi workspace dependency to 12.0.0-rc.0

• Updates the workspace dependency pin for @pnpm/napi to the rc release required by new install options wiring.

workspace.jsonc

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. NODE_OPTIONS guard too broad 🐞 Bug ☼ Reliability
Description
registerEsmNodePathLoader() skips adding the ESM loader --import flag whenever NODE_OPTIONS
contains the substring 'register', which can match unrelated flags (e.g. '--require
ts-node/register'). This prevents the loader from propagating to child processes, breaking ESM
resolution fallback via NODE_PATH in spawned processes under the global virtual store.
Code

scopes/harmony/bit/bootstrap.ts[R185-190]

+  const registration = `import{register}from'node:module';register(${JSON.stringify(loaderUrl)},${JSON.stringify(parentUrl)});`;
+  const importFlag = `--import=data:text/javascript,${encodeURIComponent(registration)}`;
+  if (process.env.NODE_OPTIONS?.includes('register')) return;
+  process.env.NODE_OPTIONS = process.env.NODE_OPTIONS
+    ? `${process.env.NODE_OPTIONS} ${importFlag}`
+    : importFlag;
Evidence
The code uses a generic includes('register') check before appending the --import=... flag, so
any NODE_OPTIONS containing 'register' can block loader propagation to spawned processes.

scopes/harmony/bit/bootstrap.ts[171-191]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`registerEsmNodePathLoader()` decides whether to append its `--import=...` registration by checking `process.env.NODE_OPTIONS?.includes('register')`. This is not specific to the loader being added and can cause false positives, skipping propagation.

### Issue Context
The ESM loader is required for Node ESM resolution to consult NODE_PATH (child processes included). Skipping the `NODE_OPTIONS` augmentation means spawned processes won’t have the loader even though the parent process registered it.

### Fix Focus Areas
- scopes/harmony/bit/bootstrap.ts[171-191]

### Proposed fix
- Replace the broad substring check with a specific check for this loader, e.g.:
 - `if (process.env.NODE_OPTIONS?.includes(importFlag)) return;`
 - or check for the encoded `loaderUrl`/a unique marker inside the `--import=data:text/javascript,...` payload.
- Keep appending alongside existing NODE_OPTIONS values; avoid suppressing the append based on unrelated `register` strings.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. echo uses Unicode em dash 📘 Rule violation ⚙ Maintainability
Description
The new shell script prints an em dash (—) in an error message, introducing a hardcoded Unicode
symbol in CLI output. This violates the requirement to avoid hardcoded Unicode symbols and keep CLI
output consistent across the repo.
Code

scripts/link-local-pnpm-engine.sh[R26-27]

+  echo "no built engine at $SO — run: (cd $PNPM_REPO && cargo build -p pacquet-napi --release)" >&2
+  exit 1
Evidence
PR Compliance ID 1 forbids hardcoded Unicode symbols in CLI output. The added script outputs an
error message containing a Unicode em dash (—).

CLAUDE.md: CLI Output Must Use Shared Output Formatter (No Hardcoded Chalk Styles or Unicode Symbols)
scripts/link-local-pnpm-engine.sh[26-27]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new CLI-facing `echo` message uses a Unicode em dash (`—`), which violates the repo rule forbidding hardcoded Unicode symbols in CLI output.

## Issue Context
The compliance checklist requires CLI output to avoid hardcoded Unicode symbols to prevent inconsistent output formatting across environments.

## Fix Focus Areas
- scripts/link-local-pnpm-engine.sh[26-27]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Broad react-env patch key 🐞 Bug ☼ Reliability
Description
DependencyInstaller.withBuiltInPatches injects an unversioned patchedDependencies entry for
'@teambit/react.react-env' whenever enableGlobalVirtualStore is on, so it will be attempted against
whatever version is installed. This repo resolves '@teambit/[email protected]', while the
shipped patch is content-sensitive, making global-virtual-store installs brittle (patch may fail to
apply cleanly or unintentionally rewrite config on incompatible versions).
Code

scopes/dependencies/dependency-resolver/dependency-installer.ts[R156-159]

+    const builtIn = {
+      '@teambit/react.react-env': path.join(__dirname, 'patches', 'react-env-tsconfig-extends.patch'),
+    };
+    return { ...builtIn, ...fromConfig };
Evidence
The installer unconditionally adds a built-in patch entry for @teambit/react.react-env (no
version) under global virtual store. The repo’s lockfile shows @teambit/[email protected] is
present, and the patch file is a context-sensitive diff that assumes a specific tsconfig.json
shape (removing an extends line), making cross-version application brittle.

scopes/dependencies/dependency-resolver/dependency-installer.ts[151-160]
pnpm-lock.yaml[36734-36736]
scopes/dependencies/dependency-resolver/patches/react-env-tsconfig-extends.patch[1-42]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`DependencyInstaller.withBuiltInPatches()` always injects a built-in patch keyed as `@teambit/react.react-env` (no version) when the global virtual store is enabled. Because patches are context-sensitive, this is brittle against react-env versions whose files differ.

### Issue Context
The repo lockfile includes `@teambit/[email protected]`, while the shipped patch edits `config/tsconfig.json` and `dist/config/tsconfig.json` by removing an `extends` line and inlining compilerOptions. Applying this patch to versions that don’t match the expected file content/layout is unsafe.

### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-installer.ts[133-161]
- scopes/dependencies/dependency-resolver/patches/react-env-tsconfig-extends.patch[1-84]
- pnpm-lock.yaml[36734-36736]

### Proposed fix
- Constrain the built-in patch mapping to a version range key (e.g. `@teambit/react.react-env@<2` if that is the intended scope), **or** dynamically inject the patch only when the installed package version/content matches (e.g. read installed version from the lockfile/manifest and conditionally add the entry).
- If conditional injection isn’t feasible, move this patch behind an explicit config opt-in so users only enable it when they know it matches their installed react-env versions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Dotfiles break virtual-store listing 🐞 Bug ≡ Correctness
Description
FsHelper.getVirtualStoreDirNames() returns early as soon as node_modules/.pnpm contains any entry
other than 'lock.yaml'/'node_modules', so hidden/metadata entries will prevent lock.yaml parsing and
yield incorrect results. This undermines the intended “lock.yaml is the per-workspace truth under
global virtual store” behavior and can make the new global-virtual-store e2e expectations
flaky/incorrect.
Code

components/legacy/e2e-helper/e2e-fs-helper.ts[R65-68]

+    const dirs = fs
+      .readdirSync(virtualStoreDir)
+      .filter((dirName) => dirName !== 'lock.yaml' && dirName !== 'node_modules');
+    if (dirs.length) return dirs;
Evidence
The new e2e helper only excludes lock.yaml and node_modules and returns early if anything
remains. In contrast, DependenciesMain.readVirtualStoreEntries() filters out entries starting with
'.' before applying the same “if any entries remain, return them; else parse lock.yaml” logic,
implying dotfiles are expected and should not count as package copies.

components/legacy/e2e-helper/e2e-fs-helper.ts[62-73]
scopes/dependencies/dependencies/dependencies.main.runtime.ts[613-622]
e2e/harmony/global-virtual-store.e2e.ts[28-39]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`FsHelper.getVirtualStoreDirNames()` treats any entry other than `lock.yaml` and `node_modules` as a package directory and returns it immediately, which prevents the lockfile-based fallback from ever running when the virtual store contains hidden/metadata entries.

### Issue Context
The production-side helper in `DependenciesMain.readVirtualStoreEntries()` explicitly filters out dotfiles before deciding whether to fall back to parsing `lock.yaml`, indicating hidden entries are expected and should be ignored.

### Fix Focus Areas
- components/legacy/e2e-helper/e2e-fs-helper.ts[62-73]
- scopes/dependencies/dependencies/dependencies.main.runtime.ts[613-622]
- e2e/harmony/global-virtual-store.e2e.ts[28-39]

### Proposed fix
- In `getVirtualStoreDirNames()`:
 - filter out entries starting with `.` (and ideally non-directories), not just `lock.yaml`/`node_modules`.
 - mirror the filtering logic used by `DependenciesMain.readVirtualStoreEntries()`.
- In `global-virtual-store.e2e.ts`, update the manual `readdirSync(...).filter(...)` assertion to also ignore dotfiles/metadata entries, so it asserts “no *package* dirs” rather than “no other entries at all.”

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Comment on lines +26 to +27
echo "no built engine at $SO — run: (cd $PNPM_REPO && cargo build -p pacquet-napi --release)" >&2
exit 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. echo uses unicode em dash 📘 Rule violation ⚙ Maintainability

The new shell script prints an em dash (—) in an error message, introducing a hardcoded Unicode
symbol in CLI output. This violates the requirement to avoid hardcoded Unicode symbols and keep CLI
output consistent across the repo.
Agent Prompt
## Issue description
A new CLI-facing `echo` message uses a Unicode em dash (`—`), which violates the repo rule forbidding hardcoded Unicode symbols in CLI output.

## Issue Context
The compliance checklist requires CLI output to avoid hardcoded Unicode symbols to prevent inconsistent output formatting across environments.

## Fix Focus Areas
- scripts/link-local-pnpm-engine.sh[26-27]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +156 to +159
const builtIn = {
'@teambit/react.react-env': path.join(__dirname, 'patches', 'react-env-tsconfig-extends.patch'),
};
return { ...builtIn, ...fromConfig };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Broad react-env patch key 🐞 Bug ☼ Reliability

DependencyInstaller.withBuiltInPatches injects an unversioned patchedDependencies entry for
'@teambit/react.react-env' whenever enableGlobalVirtualStore is on, so it will be attempted against
whatever version is installed. This repo resolves '@teambit/[email protected]', while the
shipped patch is content-sensitive, making global-virtual-store installs brittle (patch may fail to
apply cleanly or unintentionally rewrite config on incompatible versions).
Agent Prompt
### Issue description
`DependencyInstaller.withBuiltInPatches()` always injects a built-in patch keyed as `@teambit/react.react-env` (no version) when the global virtual store is enabled. Because patches are context-sensitive, this is brittle against react-env versions whose files differ.

### Issue Context
The repo lockfile includes `@teambit/[email protected]`, while the shipped patch edits `config/tsconfig.json` and `dist/config/tsconfig.json` by removing an `extends` line and inlining compilerOptions. Applying this patch to versions that don’t match the expected file content/layout is unsafe.

### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-installer.ts[133-161]
- scopes/dependencies/dependency-resolver/patches/react-env-tsconfig-extends.patch[1-84]
- pnpm-lock.yaml[36734-36736]

### Proposed fix
- Constrain the built-in patch mapping to a version range key (e.g. `@teambit/react.react-env@<2` if that is the intended scope), **or** dynamically inject the patch only when the installed package version/content matches (e.g. read installed version from the lockfile/manifest and conditionally add the entry).
- If conditional injection isn’t feasible, move this patch behind an explicit config opt-in so users only enable it when they know it matches their installed react-env versions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +185 to +190
const registration = `import{register}from'node:module';register(${JSON.stringify(loaderUrl)},${JSON.stringify(parentUrl)});`;
const importFlag = `--import=data:text/javascript,${encodeURIComponent(registration)}`;
if (process.env.NODE_OPTIONS?.includes('register')) return;
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS
? `${process.env.NODE_OPTIONS} ${importFlag}`
: importFlag;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Node_options guard too broad 🐞 Bug ☼ Reliability

registerEsmNodePathLoader() skips adding the ESM loader --import flag whenever NODE_OPTIONS
contains the substring 'register', which can match unrelated flags (e.g. '--require
ts-node/register'). This prevents the loader from propagating to child processes, breaking ESM
resolution fallback via NODE_PATH in spawned processes under the global virtual store.
Agent Prompt
### Issue description
`registerEsmNodePathLoader()` decides whether to append its `--import=...` registration by checking `process.env.NODE_OPTIONS?.includes('register')`. This is not specific to the loader being added and can cause false positives, skipping propagation.

### Issue Context
The ESM loader is required for Node ESM resolution to consult NODE_PATH (child processes included). Skipping the `NODE_OPTIONS` augmentation means spawned processes won’t have the loader even though the parent process registered it.

### Fix Focus Areas
- scopes/harmony/bit/bootstrap.ts[171-191]

### Proposed fix
- Replace the broad substring check with a specific check for this loader, e.g.:
  - `if (process.env.NODE_OPTIONS?.includes(importFlag)) return;`
  - or check for the encoded `loaderUrl`/a unique marker inside the `--import=data:text/javascript,...` payload.
- Keep appending alongside existing NODE_OPTIONS values; avoid suppressing the append based on unrelated `register` strings.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +65 to +68
const dirs = fs
.readdirSync(virtualStoreDir)
.filter((dirName) => dirName !== 'lock.yaml' && dirName !== 'node_modules');
if (dirs.length) return dirs;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

4. Dotfiles break virtual-store listing 🐞 Bug ≡ Correctness

FsHelper.getVirtualStoreDirNames() returns early as soon as node_modules/.pnpm contains any entry
other than 'lock.yaml'/'node_modules', so hidden/metadata entries will prevent lock.yaml parsing and
yield incorrect results. This undermines the intended “lock.yaml is the per-workspace truth under
global virtual store” behavior and can make the new global-virtual-store e2e expectations
flaky/incorrect.
Agent Prompt
### Issue description
`FsHelper.getVirtualStoreDirNames()` treats any entry other than `lock.yaml` and `node_modules` as a package directory and returns it immediately, which prevents the lockfile-based fallback from ever running when the virtual store contains hidden/metadata entries.

### Issue Context
The production-side helper in `DependenciesMain.readVirtualStoreEntries()` explicitly filters out dotfiles before deciding whether to fall back to parsing `lock.yaml`, indicating hidden entries are expected and should be ignored.

### Fix Focus Areas
- components/legacy/e2e-helper/e2e-fs-helper.ts[62-73]
- scopes/dependencies/dependencies/dependencies.main.runtime.ts[613-622]
- e2e/harmony/global-virtual-store.e2e.ts[28-39]

### Proposed fix
- In `getVirtualStoreDirNames()`:
  - filter out entries starting with `.` (and ideally non-directories), not just `lock.yaml`/`node_modules`.
  - mirror the filtering logic used by `DependenciesMain.readVirtualStoreEntries()`.
- In `global-virtual-store.e2e.ts`, update the manual `readdirSync(...).filter(...)` assertion to also ignore dotfiles/metadata entries, so it asserts “no *package* dirs” rather than “no other entries at all.”

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

zkochan added a commit to zkochan/bit that referenced this pull request Aug 7, 2026
…ript

rc.1 carries the slot-materialization dedup (pnpm/pnpm#13669), the last
engine change the global virtual store needed from a checkout, so the
script that installed a locally built engine over the released one goes
away as promised. It also adds `allowUnusedPatches`, which unblocks the
version-scoped patch approach parked in teambit#10572 if it is ever wanted over
the packageExtensions built-ins.

Verified on the released engine: two consecutive self-hosted
global-virtual-store installs of this repo (the workload whose peer
variants previously raced the link pass on every install), zero race
errors, lint green.

Co-Authored-By: Claude Fable 5 <[email protected]>
@zkochan

zkochan commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

covered by #10582

@zkochan zkochan closed this Aug 8, 2026
zkochan added a commit that referenced this pull request Aug 8, 2026
Opt-in support for pnpm's global virtual store: dependency directories
are created once in a store shared by every workspace on the machine,
instead of being re-created inside each `node_modules/.pnpm`. Capsules
deliberately keep the project-local layout — see below.

Every engine dependency is in a published `@pnpm/napi`: the settings
surface (pnpm/pnpm#13648) and the `link:` slot fix (pnpm/pnpm#13658) in
12.0.0-rc.0, and the slot-materialization dedup (pnpm/pnpm#13669) in
12.0.0-rc.1, which this branch pins. The local-engine bootstrap script
is gone.

## Effect

After a fresh install the project-local virtual store holds nothing but
`lock.yaml` and the hoisted `node_modules` — every dependency directory,
including injected workspace components, lives in the shared store:

| workspace | `node_modules/.pnpm` entries, no GVS | with GVS |
|---|---|---|
| a Bit Cloud workspace | 20832 | 0 |
| the bit repo itself | 6441 | 0 |
| bitdev-envs | 4017 | 0 |

Bit uses pnpm's own `<storeDir>/links`, so slots are reused across bit
versions and shared with every other pnpm project on the machine,
upgrades stay incremental, and `pnpm store prune` accounts for them.

Migration note: switching an existing workspace over does not remove
what the previous project-local store already contains — pnpm does not
prune it once the effective virtual store points elsewhere — so the old
directories linger until `node_modules/.pnpm` is deleted. New workspaces
never see them.

## Turning it on

Off by default. Per workspace under
`teambit.dependencies/dependency-resolver`, machine-wide with `bit
config set enable_global_virtual_store true`, or per run with
`BIT_ENABLE_GLOBAL_VIRTUAL_STORE=true`. It has no effect when
`nodeLinker` is `hoisted`, which uses no virtual store at all.

## What it took to behave identically

A shared store breaks one assumption that runs through Bit: that a
package can walk *up* out of `node_modules/.pnpm` into the workspace.
Consequences:

- **Core aspects (CJS).** Bit deliberately does not declare `@teambit/*`
core aspects as dependencies of the envs and aspects that use them —
they have to be the single copy from the running installation, and
declaring them would install duplicates. Project-locally they resolved
by walking up into the workspace root; nothing in a shared store can.
This branch uses pnpm's documented mechanism for hoisted dependencies in
this layout: the privately hoisted directory stays project-local at
`node_modules/.pnpm/node_modules` even under the global virtual store,
the core aspects are linked there, and `bootstrap` puts that directory
on `NODE_PATH` before any aspect loads. Nothing is written inside the
store itself, which is what allows the shared `<storeDir>/links` to be
used at all.
- **Core aspects (ESM).** Node ignores `NODE_PATH` for ESM, and bit
supports ESM components, so the same hoisted-directory fallback is
provided to the ESM resolver via a `module.register()` loader (adapted
from pnpm's `@pnpm/plugin-esm-node-path`, MIT), installed at bootstrap
and propagated to child processes through `NODE_OPTIONS`.
- **Phantom `tsconfig` `extends` in published envs.** TypeScript
resolves `extends` with its own resolver — neither `NODE_PATH` nor the
ESM loader applies — and several published envs extend a package they
never declare (`@teambit/react/typescript/tsconfig.json` from the node
mocha envs, `base-react-env`, `rspack.envs.react-env` and `react-env`
1.x; `rspack.envs.react-env/config/tsconfig.json` from `cloud-react`).
Project-locally the walk up out of `.pnpm` passed the privately hoisted
directory and caught these by accident. Fixed with pnpm's documented
remedy: built-in `packageExtensions` declaring the missing dependency
for the known envs, merged under the workspace's own `packageExtensions`
so users can cover third-party envs the same way. Extensions only add
what a manifest lacks, an unmatched entry is not an error (react-env's
is scoped to `@1` — 2.x inlined the config), and none of these envs
import their extends-target at runtime, so the added copy cannot shadow
the host-provided singletons. (#10572 explored a
`patchedDependencies`-based variant for react-env 1.x and is closed —
the extensions cover it.)
- **The bit repo itself.** A workspace that *authors* the core aspects
bridges them into the hoisted store only until they compile, then
removes the bridge. Right project-locally, fatal from a shared store.
The bridge now persists, repointed at the compiled workspace copy.
- **Injected dirs.** `getInjectedDirs` reports an injected copy absolute
when it cannot be made relative to the lockfile dir — under a shared
store, always. `compiler.task.ts` joined it onto the capsule root
regardless, hard-linking build artifacts into a path that does not
exist. (`node-modules-linker` and `workspace-compiler` already guarded
this; only that one site did not.)
- **`bit deps diagnose`.** Its duplicate-copy counts came from scanning
`node_modules/.pnpm`. The shared store holds every workspace's packages,
so it cannot answer that question for one workspace; the counts now come
from the current lockfile pnpm writes next to the hoisted directory,
whose dep paths map one-to-one onto the project-local directory names.
- **Capsules stay project-local.** A capsule is a self-contained build
sandbox and TypeScript's declaration emit depends on that: it names an
inferred type through the package that declares it, which it can only do
while that package sits inside the capsule. Moving env/aspect packages
out made `bit build` of any custom env fail with `TS2742`. Workspace
installs — the ones users wait on repeatedly — still get the shared
store.

## Also here: `patchedDependencies`

The branch adds pnpm's `patchedDependencies` as a dependency-resolver
setting (it began as the vehicle for the react-env `tsconfig` fix above,
and is useful on its own):

```json
{
  "teambit.dependencies/dependency-resolver": {
    "patchedDependencies": { "[email protected]": "patches/is-positive.patch" }
  }
}
```

Paths are relative to the workspace root. pnpm resolves a relative patch
path from the directory it is installing in, so capsule installs — which
run in the capsules directory — get the paths resolved against the
workspace root first; workspace installs keep the configured spelling,
which pnpm records in `pnpm-lock.yaml` and which must stay
machine-independent there.

## Self-hosting: a workspace whose node_modules provides the running bit

Both layouts are safe in steady state: repeat installs preserve the
top-level package directories the running process resolves from
(verified by sampling them through live installs), and the
end-of-install compile refreshes the per-variant copies. A layout
*switch* is different — it relocates every injected component package,
rebuilding the top-level directories from source, so their compiled
`dist` disappears mid-install and a bit running from them dies before
reaching the compile that would restore it, leaving `node_modules`
unusable. The installer now detects the combination (current layout read
off `.modules.yaml`, self-hosting by realpath of the running module) and
refuses up front with instructions to run the one-time transition from
an external bit installation.

With that and the engine fix, the bit repo itself runs under the global
virtual store: full install + compile of all 332 components, repeat
self-hosted installs in ~50s, `npm run lint` green. The repo's own tsc
needed the type-layer counterpart of the runtime bridges —
`tsconfig.json` `paths` routing react typings and `@teambit/*` through
the workspace's `node_modules`, since a published package's `.d.ts`
cannot reach undeclared `@types`/core aspects from a store slot either.

## Phantom dependencies, generally

A shared store makes an under-declared package fail loudly: it lives
outside the project, so nothing the project hoisted is on its resolution
path any more. That is a real constraint, not a bug to work around, and
it applies to pnpm generally rather than to Bit. Every failure this
branch hit was a genuine phantom dependency — an env's undeclared
`tsconfig` base, a fixture env with detection switched off
(`@bit-no-check` removed so the dependency gets declared),
`@teambit/webpack.webpack-bundler` requiring `events/` without declaring
it (covered by `packageExtensions`, documented in the aspect docs), and
the repo's own undeclared `@types/graceful-fs` (now declared).

## One CI change

`bit_pr` now runs on a temp lane (dropped `--keep-lane`). A reused PR
lane serves components unchanged since an earlier export with artifacts
from older commits, so capsules mix generations of `@teambit` packages
and cross-copy `instanceof` checks start failing — deterministic red
that looks exactly like branch breakage and defeats bisection (on this
branch: run 1 green on a fresh lane, every later push red, across 11
runs and 2 lanes). Filed as #10583; the temp-lane flow is
self-consistent per run.

## Testing

- New e2e: `global-virtual-store.e2e.ts` (nothing materialized in the
workspace, dependencies linked from the shared store, component loads
and compiles, patched dependencies under the store) and
`patched-dependencies.e2e.ts` (a workspace-relative patch applies both
in the workspace and in the capsule — verified to fail before the
capsule-path fix).
- The bit repo (332 components): full global-virtual-store install,
repeat self-hosted installs, transition guard verified in both
directions (clean refusal, workspace intact), lint green. Runs on the
released rc.1 engine.
- A Bit Cloud workspace, 105 components: wiped-`node_modules` install +
compile, slot reuse verified (a repeat install creates 0 of 30766
slots), core-aspect resolution through `NODE_PATH` verified positively
and negatively, `bit start` working.
- bitdev-envs (609 components, 20 apps): `bit app list` byte-identical
to the non-GVS baseline, apps running — against an earlier revision of
the core-aspect mechanism.
- The full e2e suite under `BIT_ENABLE_GLOBAL_VIRTUAL_STORE=true` was
run locally against an earlier revision: no GVS-specific failures (the
`validate command` failures reproduce with the store off). CI runs the
suite in its default store-off configuration, where this branch has been
green including the 40-shard e2e.

The first commit (`fix(doctor)`) is unrelated to the rest and can be
split out — it surfaced because the e2e temp dir contains a dot, which
is why `doctor-infra.e2e.ts` fails locally but passes on CI.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant