Skip to content

fix(arborist): drop self-link materialization for undeclared workspaces#9399

Open
manzoorwanijk wants to merge 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-strategy-undeclared-workspace-self-link
Open

fix(arborist): drop self-link materialization for undeclared workspaces#9399
manzoorwanijk wants to merge 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-strategy-undeclared-workspace-self-link

Conversation

@manzoorwanijk
Copy link
Copy Markdown
Contributor

@manzoorwanijk manzoorwanijk commented May 24, 2026

In continuation of our exploration of using install-strategy=linked in the Gutenberg monorepo, which powers the WordPress Block Editor.

Summary

In install-strategy=linked, every workspace not listed in the root package.json's deps was getting a self-symlink inside its own node_modules/ (e.g. packages/test/node_modules/@namespace/test -> ..).
The workspace did not declare itself as a dependency; the link was a side effect of #9076 parking the workspace IsolatedLink off-root.
pnpm does not create such a self-link — packages that need to self-resolve by name are expected to use Node's exports-based self-referencing.

Fix

Keep the workspace IsolatedLink in the tree (so --workspace filters resolve undeclared workspaces and install scripts still run via the diff's unchanged-link path), but mark it isUndeclaredWorkspaceLink = true and treat it as tree-only:

  • #extractOrLink returns early for these links, so no symlink is materialized on disk.
  • #cleanOrphanedStoreEntries excludes them from the valid set, so any stale self-link from an older npm version is swept on the next install.
  • The link is no longer added to workspace.children.

The only behavior change is that require('<self-name>') from inside an undeclared workspace without an exports field no longer resolves.
This matches pnpm and the strict-isolation intent of #9076.
Cross-workspace dep links, declared-workspace root symlinks, and workspace postinstall execution are unaffected.

References

Fixes #9398
Related to #9076

@manzoorwanijk manzoorwanijk force-pushed the fix/linked-strategy-undeclared-workspace-self-link branch from a1934f3 to 4059d99 Compare May 24, 2026 00:37
In install-strategy=linked, every workspace not listed in root's deps
got a self-symlink at <ws>/node_modules/<wsName> as a side effect of
parking its IsolatedLink off-root. Keep the Link in the tree so install
scripts and --workspace filters still work, but mark it as tree-only
so the reifier skips materialization and the orphan sweep removes any
stale self-link left over from an older npm version.

Fixes npm#9398
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-strategy-undeclared-workspace-self-link branch from 4059d99 to 53ef290 Compare May 24, 2026 00:46
@manzoorwanijk manzoorwanijk marked this pull request as ready for review May 24, 2026 02:39
@manzoorwanijk manzoorwanijk requested review from a team as code owners May 24, 2026 02:39
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.

[BUG] install-strategy=linked creates an unnecessary self-link inside every undeclared workspace's node_modules/

1 participant