Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Reset flags when initializing ideal from actual
Browse files Browse the repository at this point in the history
Fix: #193
Fix: npm/cli#2309

PR-URL: #194
Credit: @isaacs
Close: #194
Reviewed-by: @ruyadorno
  • Loading branch information
isaacs committed Dec 15, 2020
1 parent 93826df commit 5d51d37
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,14 @@ module.exports = cls => class IdealTreeBuilder extends cls {
// Load on a new Arborist object, so the Nodes aren't the same,
// or else it'll get super confusing when we change them!
.then(async root => {
if (!this[_updateAll] && !this[_global] && !root.meta.loadedFromDisk)
if (!this[_updateAll] && !this[_global] && !root.meta.loadedFromDisk) {
await new this.constructor(this.options).loadActual({ root })
// even though we didn't load it from a package-lock.json FILE,
// we still loaded it "from disk", meaning we have to reset
// dep flags before assuming that any mutations were reflected.
if (root.children.size)
root.meta.loadedFromDisk = true
}
return root
})

Expand Down
17 changes: 17 additions & 0 deletions test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2317,3 +2317,20 @@ t.test('peer dep override with dep sets being replaced', async t => {
await t.rejects(printIdeal(path), { code: 'ERESOLVE' })
t.matchSnapshot(await printIdeal(path, { force: true }))
})

t.test('remove deps when initializing tree from actual tree', async t => {
const path = t.testdir({
node_modules: {
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.2.3',
}),
},
},
})

const arb = new Arborist({ path, ...OPT })
const tree = await arb.buildIdealTree({ rm: ['foo'] })
t.equal(tree.children.get('foo'), undefined, 'removed foo child')
})

0 comments on commit 5d51d37

Please sign in to comment.