Skip to content
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
4 changes: 3 additions & 1 deletion workspaces/arborist/lib/arborist/isolated-reifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ module.exports = cls => class IsolatedReifier extends cls {
}
this.counter = 0

this.idealGraph.workspaces = await Promise.all(Array.from(idealTree.fsChildren.values(), w => this.#workspaceProxy(w)))
// Skip extraneous fsChildren: workspaces removed from the root manifest can linger in fsChildren via the lockfile, and re-materializing them here would re-create a directory the user just deleted.
const fsChildren = Array.from(idealTree.fsChildren.values()).filter(w => !w.extraneous)
this.idealGraph.workspaces = await Promise.all(fsChildren.map(w => this.#workspaceProxy(w)))
const processed = new Set()
const queue = [idealTree, ...idealTree.fsChildren]
while (queue.length !== 0) {
Expand Down
33 changes: 33 additions & 0 deletions workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3930,6 +3930,39 @@ t.test('install strategy linked', async (t) => {
t.ok(store.isDirectory(), 'abbrev got installed')
t.ok(abbrev.isSymbolicLink(), 'abbrev got installed')
})

t.test('does not re-create a workspace dir removed from manifest', async t => {
// Regression test for https://github.com/npm/cli/issues/9331
const path = t.testdir({
'package.json': JSON.stringify({
name: 'host',
version: '1.0.0',
workspaces: ['packages/a', 'packages/b'],
}),
packages: {
a: { 'package.json': JSON.stringify({ name: 'a', version: '1.0.0' }) },
b: { 'package.json': JSON.stringify({ name: 'b', version: '1.0.0' }) },
},
})

createRegistry(t, false)
await reify(path, { installStrategy: 'linked' })

// Drop workspace b: remove its directory and its entry from package.json.
fs.rmSync(resolve(path, 'packages/b'), { recursive: true, force: true })
fs.writeFileSync(resolve(path, 'package.json'), JSON.stringify({
name: 'host',
version: '1.0.0',
workspaces: ['packages/a'],
}))

await reify(path, { installStrategy: 'linked' })

t.notOk(
fs.existsSync(resolve(path, 'packages/b')),
'packages/b should remain absent after reinstall'
)
})
})

t.test('workspace installs retain existing versions with newer package specs', async t => {
Expand Down
Loading