Skip to content

Commit 684bccf

Browse files
aeschrightzkat
authored andcommitted
install: always save package_lock.json when using --package-lock-only (#146)
PR-URL: #146 Credit: @aeschright Reviewed-By: @zkat
1 parent ee6b674 commit 684bccf

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Diff for: lib/install/save.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exports.saveShrinkwrap = saveShrinkwrap
4444

4545
function saveShrinkwrap (tree, next) {
4646
validate('OF', arguments)
47-
if (!npm.config.get('shrinkwrap') || !npm.config.get('package-lock')) {
47+
if (!npm.config.get('package-lock-only') && (!npm.config.get('shrinkwrap') || !npm.config.get('package-lock'))) {
4848
return next()
4949
}
5050
require('../shrinkwrap.js').createShrinkwrap(tree, {silent: false}, next)

Diff for: test/tap/install-package-lock-only.js

+39-1
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(),
@@ -54,7 +66,6 @@ function cleanup () {
5466
}
5567

5668
test('setup', function (t) {
57-
setup()
5869
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
5970
if (err) throw err
6071
server = s
@@ -63,6 +74,7 @@ test('setup', function (t) {
6374
})
6475

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

93+
test('--package-lock-only with --package-lock negates `package_lock: false`', function (t) {
94+
setup()
95+
return common.npm(['install', '--package-lock', '--package-lock-only'], confPkgLockFalse).spread((code, stdout, stderr) => {
96+
t.is(code, 0, 'ok')
97+
t.comment(stdout.trim())
98+
t.comment(stderr.trim())
99+
100+
// Verify that package-lock.json exists.
101+
t.ok(fs.existsSync(pkgLockPath), 'ensure that package-lock.json was created')
102+
t.end()
103+
})
104+
})
105+
106+
test('package-lock-only creates package_lock.json when config has `package_lock: false`', function (t) {
107+
setup()
108+
return common.npm(['install', '--package-lock-only'], confPkgLockFalse).spread((code, stdout, stderr) => {
109+
t.is(code, 0, 'ok')
110+
t.comment(stdout.trim())
111+
t.comment(stderr.trim())
112+
113+
// Verify that package-lock.json exists.
114+
t.ok(fs.existsSync(pkgLockPath), 'ensure that package-lock.json was created')
115+
t.end()
116+
})
117+
})
118+
81119
test('cleanup', function (t) {
82120
server.close()
83121
cleanup()

0 commit comments

Comments
 (0)