[BUG] install-strategy=linked never reports removed packages: --dry-run shows nothing, --json says removed: 0, and the root `dependencies` script is skipped

未关闭
#10,355 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@ultimate-kiran 已经在做这个了。

开始于 2026年11月26日。

  • #10362 来自 @ultimate-kiran —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
javascript, nodejs
领域
devtools

调研方向

Start in workspaces/arborist/lib/arborist/reify.js, at #buildLinkedActualForDiff and #cleanOrphanedStoreEntries, to see why the linked-strategy diff never contains a REMOVE and why cleanup is skipped on dry runs. Reproduce with the steps in the issue, comparing hoisted and linked output for npm uninstall and --json. Done when linked reports the removed count in summary, dry-run and JSON, and the root dependencies script runs on removal.

由索引模型根据 Issue 内容生成。

描述

Bug Needs Triage Triage Requested
Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

With install-strategy=linked, npm never reports the packages it removes. Compared with the default (hoisted) strategy, using the same project:

Command hoisted linked
npm uninstall e (removes 4 packages) removed 4 packages up to date
npm uninstall e --dry-run removed 4 packages up to date (then the real run removes 4)
npm prune --dry-run lists remove b, remove a up to date (then the real npm prune removes them)
npm uninstall e --json "removed": 4 "removed": 0
root dependencies lifecycle script on uninstall runs does not run

So under linked, a dry run tells you nothing will change and then the real command removes packages, tooling that reads the --json counts sees zeros, and the documented dependencies script ("run after any operations that modify the node_modules directory IF changes occurred") is skipped.

The packages are removed correctly on disk; only the reporting is wrong.

Cause: #buildLinkedActualForDiff in workspaces/arborist/lib/arborist/reify.js builds the actual side of the linked diff only from ideal-tree children, so the diff never contains a REMOVE. #cleanOrphanedStoreEntries deletes the removed packages after the diff, but doesn't report them, and it's skipped entirely on --dry-run. reify-output and the dependencies script both rely on the diff.

Expected Behavior

Removals under install-strategy=linked are reported like under the default strategy: in the summary, in --dry-run (without removing anything), and in --json. The root dependencies script runs when packages are removed.

Steps To Reproduce

Any registry package with a dependency works; for example:

mkdir linked-repro && cd linked-repro && npm init -y
npm install --install-strategy=linked which@4
npm uninstall which --install-strategy=linked --dry-run   # up to date
npm uninstall which --install-strategy=linked --json      # "removed": 0

Compare with --install-strategy=hoisted, which reports removed 2 packages in both cases.

For the lifecycle script, add "scripts": { "dependencies": "node -e \"console.log('dependencies ran')\"" } to package.json and run npm install and then npm uninstall with each strategy (add --foreground-scripts to see the output).

Environment
  • npm: 12.2.3 (latest branch)
  • Node.js: 24.20.0
  • OS Name: Windows 11 (the cause is platform-independent)
主要语言
JavaScript
星标
10.3k
派生
5k
平均合并
4 天 11 小时
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

npm/cli 的其他 Issue

查看 npm/cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。