Skip to content

Commit

Permalink
fix(ci): should not use package-lock config
Browse files Browse the repository at this point in the history
`npm ci` should never be affected by the `package-lock` config.

Fixes: #4185
  • Loading branch information
ruyadorno committed Feb 3, 2022
1 parent 5a84e65 commit 7ddec04
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/content/using-npm/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,8 @@ When package package-locks are disabled, automatic pruning of extraneous
modules will also be disabled. To remove extraneous modules with
package-locks disabled use `npm prune`.

This configuration does not affect `npm ci`.

<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->

Expand Down
1 change: 1 addition & 0 deletions lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CI extends ArboristWorkspaceCmd {
const where = this.npm.prefix
const opts = {
...this.npm.flatOptions,
packageLock: true, // npm ci should never skip lock files
path: where,
log,
save: false, // npm ci should never modify the lockfile or package.json
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,8 @@ define('package-lock', {
When package package-locks are disabled, automatic pruning of extraneous
modules will also be disabled. To remove extraneous modules with
package-locks disabled use \`npm prune\`.
This configuration does not affect \`npm ci\`.
`,
flatten: (key, obj, flatOptions) => {
flatten(key, obj, flatOptions)
Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/utils/config/definitions.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,8 @@ will also prevent _writing_ \`package-lock.json\` if \`save\` is true.
When package package-locks are disabled, automatic pruning of extraneous
modules will also be disabled. To remove extraneous modules with
package-locks disabled use \`npm prune\`.
This configuration does not affect \`npm ci\`.
`

exports[`test/lib/utils/config/definitions.js TAP > config description for package-lock-only 1`] = `
Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,8 @@ When package package-locks are disabled, automatic pruning of extraneous
modules will also be disabled. To remove extraneous modules with
package-locks disabled use \`npm prune\`.
This configuration does not affect \`npm ci\`.
<!-- automatically generated, do not edit manually -->
<!-- see lib/utils/config/definitions.js -->
Expand Down
3 changes: 2 additions & 1 deletion test/lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ t.test('should throw ECIGLOBAL', async t => {
})

t.test('should remove existing node_modules before installing', async t => {
t.plan(2)
t.plan(3)
const testDir = t.testdir({
node_modules: {
'some-file': 'some contents',
Expand All @@ -212,6 +212,7 @@ t.test('should remove existing node_modules before installing', async t => {
'@npmcli/arborist': function () {
this.loadVirtual = () => Promise.resolve(true)
this.reify = async (options) => {
t.equal(options.packageLock, true, 'npm ci should never ignore lock')
t.equal(options.save, false, 'npm ci should never save')
// check if node_modules was removed before reifying
const contents = await readdir(testDir)
Expand Down

0 comments on commit 7ddec04

Please sign in to comment.