Skip to content

fix(pm): keep npm workspace root edits out of the current member - #3535

Draft
SaKaNa-Y wants to merge 1 commit into
voidzero-dev:mainfrom
SaKaNa-Y:fix/npm-workspace-root-dependency-edits
Draft

SaKaNa-Y wants to merge 1 commit into
voidzero-dev:mainfrom
SaKaNa-Y:fix/npm-workspace-root-dependency-edits

Conversation

@SaKaNa-Y

Copy link
Copy Markdown
Contributor

Summary

From packages/app, vp remove -w testnpm2 can remove the dependency from both the root and app. The command succeeds even if app still imports the package. Adding a dependency with -w can also write an extra declaration to app.

For npm dependency edits, keep the caller's directory so relative package paths still work. Resolve the owning project before passing its path to npm as --prefix. On npm 8.5 and later, leave explicit workspace selections to npm. Earlier npm 8 versions need a membership check because a member can own another workspace with the same package names.

Command from app Intended dependency declarations
vp remove -w testnpm2 Remove from root. Keep app's declaration.
vp add -w --filter docs testnpm2 Add to root and docs.

Evidence

  • On the base revision, the npm 11 fixture wrote to app during a root-only add and removed app's dependency during a root-only remove. With this change, app keeps its declaration and lockfile entry. A separate Node import check also passed after removal.
  • The npm 8.1 fixture has two packages named docs. The base edited the inner project. The updated CLI edits the outer root and the requested outer docs. Four CLI snapshots passed across npm 8.1.0, 10.9.4 and 11.6.2.
  • On macOS, actual vp commands passed with npm 8.1.0, 8.19.4 and 11.19.0. Checks covered package-bearing install, caller-relative tarballs, explicit selectors and user-selected npmrc files. just check, just test and just lint passed.

Merge Danger

Door · Two-way. Blast radius · npm workspace dependency edits.

Root detection can start extra read-only npm processes. The prefix override also makes lifecycle scripts see the workspace root in npm_config_prefix and npm_config_global_prefix. A script that starts a global npm install can therefore target the project. An npm 8.1 global npmrc that changes its own prefix can also redirect the configuration lookup. These are open compatibility concerns for review.

The early npm 8 fallback rejects a combined root and member add of a local package before it changes the manifests. Those npm versions save the root-relative file path in the member too, which breaks the next install. npm fixed that behavior in 8.19.0. npm/cli#5350

A workspace member can become an implicit target of npm install and uninstall. Resolve the owning project before a root-only dependency edit, while keeping relative package arguments in the calling directory.

Use npm to verify membership on early npm 8 and preserve explicit workspace selections. Cover member dependency and lockfile retention, including nested workspaces with the same package name.

This branch has not been deployed

No deployments
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