Skip to content

Commit

Permalink
install: throw error when using --package-lock-only with `package-l…
Browse files Browse the repository at this point in the history
…ock: false`
  • Loading branch information
Audrey Eschright committed Jan 23, 2019
1 parent 7a2f6b0 commit be9f550
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ function install (where, args, cb) {
log.warn('install', 'Usage of the `--dev` option is deprecated. Use `--only=dev` instead.')
}

if (npm.config.get('package-lock-only') && !npm.config.get('package-lock')) {
return cb(Object.assign(new Error('--package-lock-only conflicts with config setting `package-lock: false`.'), { code: 'ENEEDPACKAGELOCK' }))
}

if (where === globalTop && !args.length) {
args = ['.']
}
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ function errorMessage (er) {
].join('\n')
])
break
case 'ENEEDPACKAGELOCK':
short.push(['eneedpackagelock', er.message])
detail.push([
'eneedpackagelock',
'Package lock must be enabled in order to use --package-lock-only.'
])
break

default:
short.push(['', er.message || er])
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/tap/install-package-lock-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ var conf = {
})
}

const confPkgLockFalse = {
cwd: testdir,
env: Object.assign({}, process.env, {
npm_config_cache: cachedir,
npm_config_tmp: tmpdir,
npm_config_prefix: globaldir,
npm_config_registry: common.registry,
npm_config_loglevel: 'warn',
npm_config_package_lock: false
})
}

var server
var fixture = new Tacks(Dir({
cache: Dir(),
Expand Down Expand Up @@ -78,6 +90,19 @@ test('package-lock-only', function (t) {
})
})

test('package-lock-only errors when package-lock=false', function (t) {
return common.npm(['install', '--package-lock-only', '--json'], confPkgLockFalse).spread((code, stdout, stderr) => {
t.isNot(code, 0, 'error')
t.comment(stdout.trim())
t.comment(stderr.trim())
let error = JSON.parse(stdout).error
t.equal(error.code, "ENEEDPACKAGELOCK")
t.equal(error.summary, "--package-lock-only conflicts with config setting `package-lock: false`.")
t.equal(error.detail, "Package lock must be enabled in order to use --package-lock-only.")
t.end()
})
})

test('cleanup', function (t) {
server.close()
cleanup()
Expand Down

0 comments on commit be9f550

Please sign in to comment.