Skip to content

Commit

Permalink
fix(arborist): check placed node children for missing deps (npm#7746)
Browse files Browse the repository at this point in the history
This addresses an edge case where a dep could be placed in the tree
with unsatisfied indirect dependencies (see test case).
  • Loading branch information
Trevor Burnham authored and TrevorBurnham committed Aug 25, 2024
1 parent e674987 commit 9a6738d
Show file tree
Hide file tree
Showing 43 changed files with 46,386 additions and 14,973 deletions.
4 changes: 4 additions & 0 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,12 @@ This is a one-time fix-up, please be patient...
}

// lastly, also check for the missing deps of the node we placed,
// as well as any missing deps of the new node's children,
// and any holes created by pruning out conflicted peer sets.
this.#depsQueue.push(placed)
for (const child of placed.children.values()) {
this.#depsQueue.push(child)
}
for (const dep of pd.needEvaluation) {
this.#depsSeen.delete(dep)
this.#depsQueue.push(dep)
Expand Down
9 changes: 9 additions & 0 deletions workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ t.test('update a node without updating a child that has bundle deps', t => {
}))
})

t.test('restore missing parent while preserving child node', async t => {
const path = fixture(t, 'lockfile-with-missing-parent')
await reify(path)
const parentPath = `${path}/node_modules/globby`
t.equal(fs.statSync(`${parentPath}/package.json`).isFile(), true, 'parent has package.json')
const childPath = `${path}/node_modules/globby/node_modules/minimatch`
t.equal(fs.statSync(`${childPath}/package.json`).isFile(), true, 'child has package.json')
})

t.test('optional dependency failures', t => {
const cases = [
'optional-dep-tgz-missing',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "lockfile-with-missing-parent",
"version": "1.0.0",
"dependencies": {
"glob": "7.1.6",
"globby": "1.2.0",
"minimatch": "3.0.3"
}
}
Loading

0 comments on commit 9a6738d

Please sign in to comment.