-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install-test: fix shrinkwrap handling of package-lock.json (#20358)
For a simple project with .npmrc containing 'package-lock=false', `npm install-test` command will generate package-lock.json.*. If there is an existing package-lock.json, npm install-test triggers lifecycle actions twice for both install and test. PR-URL: npm/npm#20358 Credit: @raymondfeng Reviewed-By: @zkat
- Loading branch information
1 parent
385fdd4
commit 9d5d0a1
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
|
||
var mkdirp = require('mkdirp') | ||
var osenv = require('osenv') | ||
var rimraf = require('rimraf') | ||
var test = require('tap').test | ||
|
||
var common = require('../common-tap.js') | ||
|
||
var pkg = path.join(__dirname, path.basename(__filename, '.js')) | ||
|
||
var EXEC_OPTS = { cwd: pkg } | ||
|
||
var json = { | ||
name: 'install-test-cli-without-package-lock', | ||
description: 'fixture', | ||
version: '0.0.0', | ||
dependencies: { | ||
dependency: 'file:./dependency' | ||
} | ||
} | ||
|
||
var dependency = { | ||
name: 'dependency', | ||
description: 'fixture', | ||
version: '0.0.0' | ||
} | ||
|
||
test('setup', function (t) { | ||
setup() | ||
t.pass('setup ran') | ||
t.end() | ||
}) | ||
|
||
test('\'npm install-test\' should not generate package-lock.json.*', function (t) { | ||
common.npm(['install-test'], EXEC_OPTS, function (err, code, stderr, stdout) { | ||
if (err) throw err | ||
t.comment(stdout.trim()) | ||
t.comment(stderr.trim()) | ||
t.is(code, 0, 'npm install did not raise error code') | ||
var files = fs.readdirSync(pkg).filter(function (f) { | ||
return f.indexOf('package-lock.json.') === 0 | ||
}) | ||
t.notOk( | ||
files.length > 0, | ||
'package-lock.json.* should not be generated: ' + files | ||
) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('cleanup', function (t) { | ||
cleanup() | ||
t.pass('cleaned up') | ||
t.end() | ||
}) | ||
|
||
function setup () { | ||
mkdirp.sync(path.join(pkg, 'dependency')) | ||
fs.writeFileSync( | ||
path.join(pkg, 'dependency', 'package.json'), | ||
JSON.stringify(dependency, null, 2) | ||
) | ||
|
||
mkdirp.sync(path.join(pkg, 'node_modules')) | ||
fs.writeFileSync( | ||
path.join(pkg, 'package.json'), | ||
JSON.stringify(json, null, 2) | ||
) | ||
|
||
// Disable package-lock | ||
fs.writeFileSync( | ||
path.join(pkg, '.npmrc'), | ||
'package-lock=false\n' | ||
) | ||
process.chdir(pkg) | ||
} | ||
|
||
function cleanup () { | ||
process.chdir(osenv.tmpdir()) | ||
rimraf.sync(pkg) | ||
} |