Skip to content

Commit

Permalink
install: always save package_lock.json when using `--package-lock-onl…
Browse files Browse the repository at this point in the history
…y` (#146)

PR-URL: #146
Credit: @aeschright
Reviewed-By: @zkat
  • Loading branch information
aeschright authored and zkat committed Feb 18, 2019
1 parent ee6b674 commit 684bccf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/install/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports.saveShrinkwrap = saveShrinkwrap

function saveShrinkwrap (tree, next) {
validate('OF', arguments)
if (!npm.config.get('shrinkwrap') || !npm.config.get('package-lock')) {
if (!npm.config.get('package-lock-only') && (!npm.config.get('shrinkwrap') || !npm.config.get('package-lock'))) {
return next()
}
require('../shrinkwrap.js').createShrinkwrap(tree, {silent: false}, next)
Expand Down
40 changes: 39 additions & 1 deletion 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 All @@ -54,7 +66,6 @@ function cleanup () {
}

test('setup', function (t) {
setup()
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
if (err) throw err
server = s
Expand All @@ -63,6 +74,7 @@ test('setup', function (t) {
})

test('package-lock-only', function (t) {
setup()
return common.npm(['install', '--package-lock-only'], conf).spread((code, stdout, stderr) => {
t.is(code, 0, 'command ran ok')
t.comment(stdout.trim())
Expand All @@ -78,6 +90,32 @@ test('package-lock-only', function (t) {
})
})

test('--package-lock-only with --package-lock negates `package_lock: false`', function (t) {
setup()
return common.npm(['install', '--package-lock', '--package-lock-only'], confPkgLockFalse).spread((code, stdout, stderr) => {
t.is(code, 0, 'ok')
t.comment(stdout.trim())
t.comment(stderr.trim())

// Verify that package-lock.json exists.
t.ok(fs.existsSync(pkgLockPath), 'ensure that package-lock.json was created')
t.end()
})
})

test('package-lock-only creates package_lock.json when config has `package_lock: false`', function (t) {
setup()
return common.npm(['install', '--package-lock-only'], confPkgLockFalse).spread((code, stdout, stderr) => {
t.is(code, 0, 'ok')
t.comment(stdout.trim())
t.comment(stderr.trim())

// Verify that package-lock.json exists.
t.ok(fs.existsSync(pkgLockPath), 'ensure that package-lock.json was created')
t.end()
})
})

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

0 comments on commit 684bccf

Please sign in to comment.