fix(ci): don't error on optional deps in the lockfile (#9083) · npm/cli@76c76e5 · GitHub
Skip to content

Commit 76c76e5

Browse files
authored
fix(ci): don't error on optional deps in the lockfile (#9083)
We build a virtual tree from the lockfile before we build the ideal tree so that we can compare the two and error if package.json differs from what was used to build the lockfile. The virtual tree includes optional deps in it that would otherwise be ignored when building the ideal tree. In order not to have `npm ci` fail in this situation we need to build the virtual tree separately, and start clean when building the ideal tree. This also brings in a few linting fixups.
1 parent 1a744b5 commit 76c76e5

4 files changed

Lines changed: 30 additions & 45 deletions

File tree

lib/commands/ci.js

Lines changed: 16 additions & 18 deletions

lib/utils/audit-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { redactLog: replaceInfo } = require('@npmcli/redact')
77
// returns 'true' if there was an error, false otherwise
88

99
const auditError = (npm, report) => {
10-
if (!report || !report.error) {
10+
if (!report?.error) {
1111
return false
1212
}
1313

@@ -34,6 +34,7 @@ const auditError = (npm, report) => {
3434
output.standard(body)
3535
}
3636

37+
// XXX we should throw a real error here
3738
throw 'audit endpoint returned an error'
3839
}
3940

lib/utils/reify-finish.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,18 @@ const { writeFile } = require('node:fs/promises')
44
const { resolve } = require('node:path')
55

66
const reifyFinish = async (npm, arb) => {
7-
await saveBuiltinConfig(npm, arb)
8-
reifyOutput(npm, arb)
9-
}
10-
11-
const saveBuiltinConfig = async (npm, arb) => {
12-
const { options: { global }, actualTree } = arb
13-
if (!global) {
14-
return
15-
}
16-
17-
// if we are using a builtin config, and just installed npm as
18-
// a top-level global package, we have to preserve that config.
19-
const npmNode = actualTree.inventory.get('node_modules/npm')
20-
if (!npmNode) {
21-
return
7+
// if we are using a builtin config, and just installed npm as a top-level global package, we have to preserve that config.
8+
if (arb.options.global) {
9+
const npmNode = arb.actualTree.inventory.get('node_modules/npm')
10+
if (npmNode) {
11+
const builtinConf = npm.config.data.get('builtin')
12+
if (!builtinConf.loadError) {
13+
const content = ini.stringify(builtinConf.raw).trim() + '\n'
14+
await writeFile(resolve(npmNode.path, 'npmrc'), content)
15+
}
16+
}
2217
}
23-
24-
const builtinConf = npm.config.data.get('builtin')
25-
if (builtinConf.loadError) {
26-
return
27-
}
28-
29-
const content = ini.stringify(builtinConf.raw).trim() + '\n'
30-
await writeFile(resolve(npmNode.path, 'npmrc'), content)
18+
reifyOutput(npm, arb)
3119
}
3220

3321
module.exports = reifyFinish

lib/utils/reify-output.js

Lines changed: 1 addition & 3 deletions

0 commit comments

Comments
 (0)