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

Reset flags when initializing ideal from actual #194

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})