Skip to content

Commit 0c33947

Browse files
fix(reify): report added count for fresh linked installs (#9661)
Under `install-strategy=linked`, a fresh `npm install` that actually creates `.store` entries and symlinks printed `up to date, audited N packages` instead of `added N packages`, misleading users and CI into thinking nothing changed. `reify-output` counts adds with `actualTree.inventory.has(d.ideal)`. Under the linked strategy the diff's `ideal` nodes belong to the isolated store tree (locations under `node_modules/.store/<key>/node_modules/<name>`), while the `actualTree` returned after reify is the logical hoisted-layout tree. The two never share node identity, so the lookup always failed and `added` stayed `0`. The ADD branch now also counts a node when it is a real store package node (`isInStore && !isLink`), which maps 1:1 to a hoisted package add. This excludes the internal store symlinks and the top-level consumer symlink, so the count matches hoisted for registry dependencies (verified: `minimatch` 4/4, `rimraf` 12/12, `express` 69/69). Omitted/incompatible optional deps have no store entry and are still not counted, and hoisted behavior is unchanged. Known limitations (tracked separately): workspace and `file:`/`npm link` additions are represented as links rather than store nodes under linked, so they are not yet counted here — counting them is entangled with the self-link bug (#9398) and the undeclared-workspaces bug (#9618). The `--json` `add[].path` for a counted store package points to its `.store` realpath rather than a logical `node_modules/<name>` path. ## References Fixes #9623
1 parent 541c286 commit 0c33947

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎lib/utils/reify-output.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const reifyOutput = (npm, arb, extras = {}) => {
6666
if (showDiff) {
6767
output.standard(`${chalk.green('add')} ${d.ideal.name} ${d.ideal.package.version}`)
6868
}
69-
if (actualTree.inventory.has(d.ideal)) {
69+
// Linked store packages live under .store, absent from the logical actualTree, so identity lookup misses them; count each store package node (non-link).
70+
if (actualTree.inventory.has(d.ideal) || (d.ideal.isInStore && !d.ideal.isLink)) {
7071
summary.added++
7172
summary.add.push({
7273
name: d.ideal.name,

‎tap-snapshots/test/lib/utils/reify-output.js.test.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ exports[`test/lib/utils/reify-output.js TAP added packages should be looked up w
1010
added 1 package in {TIME}
1111
`
1212

13+
exports[`test/lib/utils/reify-output.js TAP added packages should be looked up within returned tree linked store package counted though absent from actualTree > must match snapshot 1`] = `
14+
15+
added 1 package in {TIME}
16+
`
17+
1318
exports[`test/lib/utils/reify-output.js TAP added packages should be looked up within returned tree missing added pkg in inventory > must match snapshot 1`] = `
1419
1520
up to date in {TIME}

‎test/lib/utils/reify-output.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,25 @@ t.test('added packages should be looked up within returned tree', async t => {
391391

392392
t.matchSnapshot(out)
393393
})
394+
395+
t.test('linked store package counted though absent from actualTree', async t => {
396+
const out = await mockReify(t, {
397+
actualTree: {
398+
name: 'foo',
399+
inventory: {
400+
has: () => false,
401+
},
402+
},
403+
diff: {
404+
children: [
405+
{ action: 'ADD', ideal: { path: 'test/baz', name: 'baz', isInStore: true, isLink: false, package: { version: '1.0.0' } } },
406+
{ action: 'ADD', ideal: { path: 'test/baz-link', name: 'baz', isInStore: false, isLink: true, package: { version: '1.0.0' } } },
407+
],
408+
},
409+
})
410+
411+
t.matchSnapshot(out)
412+
})
394413
})
395414

396415
t.test('prints dedupe difference on dry-run', async t => {

0 commit comments

Comments
 (0)