Skip to content
Open
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: 4 additions & 0 deletions lib/utils/validate-lockfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function validateLockfile (virtualTree, idealTree) {
// for each package compares the versions with the version stored in the
// package-lock and adds an error to the list in case of mismatches
for (const [key, entry] of idealTree.entries()) {
if (entry.inert) {
continue
}

const lock = virtualTree.get(key)

if (!lock) {
Expand Down
39 changes: 39 additions & 0 deletions test/lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,45 @@ t.test('should throw error when ideal inventory mismatches virtual', async t =>
t.equal(fs.existsSync(nmTestFile), true, 'does not remove node_modules')
})

t.test('accepts a lock file with an unavailable optional dependency', async t => {
const missingOptional = 'missing-optional'
const { npm, registry } = await loadMockNpm(t, {
config: {
audit: false,
'dry-run': true,
'ignore-scripts': true,
},
prefixDir: {
'package.json': JSON.stringify({
name: 'test-package',
version: '1.0.0',
dependencies: { 'optional-parent': '1.0.0' },
}),
'package-lock.json': JSON.stringify({
name: 'test-package',
version: '1.0.0',
lockfileVersion: 3,
requires: true,
packages: {
'': {
name: 'test-package',
version: '1.0.0',
dependencies: { 'optional-parent': '1.0.0' },
},
'node_modules/optional-parent': {
version: '1.0.0',
resolved: 'https://registry.npmjs.org/optional-parent/-/optional-parent-1.0.0.tgz',
optionalDependencies: { [missingOptional]: '1.0.0' },
},
},
}),
},
})
registry.nock.get(`/${missingOptional}`).reply(404, { error: 'Not found' })

await npm.exec('ci', [])
})

t.test('should remove dirty node_modules with unhoisted workspace module', async t => {
const { npm, registry, assert } = await loadMockNpm(t, {
prefixDir: workspaceMock(t, {
Expand Down
18 changes: 18 additions & 0 deletions test/lib/utils/validate-lockfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ t.test('extra inventory items on idealTree', async t => {
)
})

t.test('inert inventory items on idealTree', async t => {
t.strictSame(
validateLockfile(
new Map(),
new Map([
['missing-optional', {
name: 'missing-optional',
version: '',
optional: true,
inert: true,
}],
])
),
[],
'does not require lock file entries for inert optional dependencies'
)
})

t.test('extra inventory items on virtualTree', async t => {
t.matchSnapshot(
validateLockfile(
Expand Down