Skip to content

Commit be9f550

Browse files
author
Audrey Eschright
committed
install: throw error when using --package-lock-only with package-lock: false
1 parent 7a2f6b0 commit be9f550

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

lib/install.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ function install (where, args, cb) {
195195
log.warn('install', 'Usage of the `--dev` option is deprecated. Use `--only=dev` instead.')
196196
}
197197

198+
if (npm.config.get('package-lock-only') && !npm.config.get('package-lock')) {
199+
return cb(Object.assign(new Error('--package-lock-only conflicts with config setting `package-lock: false`.'), { code: 'ENEEDPACKAGELOCK' }))
200+
}
201+
198202
if (where === globalTop && !args.length) {
199203
args = ['.']
200204
}

lib/utils/error-message.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ function errorMessage (er) {
351351
].join('\n')
352352
])
353353
break
354+
case 'ENEEDPACKAGELOCK':
355+
short.push(['eneedpackagelock', er.message])
356+
detail.push([
357+
'eneedpackagelock',
358+
'Package lock must be enabled in order to use --package-lock-only.'
359+
])
360+
break
354361

355362
default:
356363
short.push(['', er.message || er])

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/tap/install-package-lock-only.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ var conf = {
2828
})
2929
}
3030

31+
const confPkgLockFalse = {
32+
cwd: testdir,
33+
env: Object.assign({}, process.env, {
34+
npm_config_cache: cachedir,
35+
npm_config_tmp: tmpdir,
36+
npm_config_prefix: globaldir,
37+
npm_config_registry: common.registry,
38+
npm_config_loglevel: 'warn',
39+
npm_config_package_lock: false
40+
})
41+
}
42+
3143
var server
3244
var fixture = new Tacks(Dir({
3345
cache: Dir(),
@@ -78,6 +90,19 @@ test('package-lock-only', function (t) {
7890
})
7991
})
8092

93+
test('package-lock-only errors when package-lock=false', function (t) {
94+
return common.npm(['install', '--package-lock-only', '--json'], confPkgLockFalse).spread((code, stdout, stderr) => {
95+
t.isNot(code, 0, 'error')
96+
t.comment(stdout.trim())
97+
t.comment(stderr.trim())
98+
let error = JSON.parse(stdout).error
99+
t.equal(error.code, "ENEEDPACKAGELOCK")
100+
t.equal(error.summary, "--package-lock-only conflicts with config setting `package-lock: false`.")
101+
t.equal(error.detail, "Package lock must be enabled in order to use --package-lock-only.")
102+
t.end()
103+
})
104+
})
105+
81106
test('cleanup', function (t) {
82107
server.close()
83108
cleanup()

0 commit comments

Comments
 (0)