Skip to content
Closed
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
36 changes: 36 additions & 0 deletions test/lib/commands/install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const t = require('tap')
const { join } = require('path')
const { rmSync } = require('fs')

const { load: _loadMockNpm } = require('../../fixtures/mock-npm')

Expand Down Expand Up @@ -327,3 +329,37 @@ t.test('completion', async t => {
t.strictSame(res, [])
})
})

t.test('workspace', async it => {
const cwd = process.cwd()

t.afterEach(() => {
process.chdir(cwd)
})

t.test('remove non-exist workspace node and its dependency', async t => {
const localPrefix = join(t.testdir(), 'prefix')
const { npm } = await loadMockNpm(t)

process.chdir(localPrefix)
// init and install root package and its workspaces
npm.config.set('yes', true)
await npm.exec('init', [])
npm.config.set('workspace', ['packages/a', 'packages/b'])
await npm.exec('init', [])
await npm.exec('install', [])

// remove one workspace node and reinstall
rmSync(join(localPrefix, 'packages/b'), { recursive: true, force: true })
await npm.exec('install', [])
const lockJson = require(join(localPrefix, 'package-lock.json'))

t.strictSame(lockJson.packages[''].workspaces, ['packages/a'], 'remove non-exist ws node')
t.equal(lockJson.packages['packages/b'], undefined, 'remove non-exist ws package')
t.equal(lockJson.packages['node_modules/b'],
undefined,
'remove non-exist ws node_modules package'
)
t.equal(lockJson.dependencies.b, undefined, 'remove non-exist ws dependency')
})
})
11 changes: 11 additions & 0 deletions workspaces/arborist/lib/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,18 @@ class Shrinkwrap {
if (node === this.tree || node.isRoot || node.location === '') {
continue
}

const loc = relpath(this.path, node.path)

// extraneous ws node should not commit
if (node.extraneous && root.workspaces && root.workspaces.length) {
const wsIndex = root.workspaces.findIndex(ws => ws === loc)
if (wsIndex > -1) {
root.workspaces.splice(wsIndex, 1)
continue
}
}

this.data.packages[loc] = Shrinkwrap.metaFromNode(
node,
this.path,
Expand Down