forked from npm/cli
-
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.
shrinkwrap: Record if dep is dev-only and honor the annotation
Credit: @bengl Reviewed-By: @iarna PR-URL: npm/npm#10073
- Loading branch information
Showing
5 changed files
with
147 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
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,139 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var existsSync = fs.existsSync || path.existsSync | ||
|
||
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-cli-only-shrinkwrap', | ||
description: 'fixture', | ||
version: '0.0.0', | ||
dependencies: { | ||
dependency: 'file:./dependency' | ||
}, | ||
devDependencies: { | ||
'dev-dependency': 'file:./dev-dependency' | ||
} | ||
} | ||
|
||
var shrinkwrap = { | ||
name: 'install-cli-only-shrinkwrap', | ||
description: 'fixture', | ||
version: '0.0.0', | ||
dependencies: { | ||
dependency: { | ||
version: '0.0.0', | ||
from: 'file:./dependency' | ||
}, | ||
'dev-dependency': { | ||
version: '0.0.0', | ||
from: 'file:./dev-dependency', | ||
dev: true | ||
} | ||
} | ||
} | ||
|
||
var dependency = { | ||
name: 'dependency', | ||
description: 'fixture', | ||
version: '0.0.0' | ||
} | ||
|
||
var devDependency = { | ||
name: 'dev-dependency', | ||
description: 'fixture', | ||
version: '0.0.0' | ||
} | ||
|
||
test('setup', function (t) { | ||
setup() | ||
t.pass('setup ran') | ||
t.end() | ||
}) | ||
|
||
test('\'npm install --only=development\' should only install devDependencies', function (t) { | ||
common.npm(['install', '--only=development'], 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') | ||
t.ok( | ||
existsSync( | ||
path.resolve(pkg, 'node_modules/dev-dependency/package.json') | ||
), | ||
'devDependency was installed' | ||
) | ||
t.notOk( | ||
existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')), | ||
'dependency was NOT installed' | ||
) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('\'npm install --only=production\' should only install dependencies', function (t) { | ||
cleanup() | ||
setup() | ||
common.npm(['install', '--only=production'], EXEC_OPTS, function (err, code, stdout, stderr) { | ||
if (err) throw err | ||
t.comment(stdout.trim()) | ||
t.comment(stderr.trim()) | ||
t.is(code, 0, 'npm install did not raise error code') | ||
t.ok( | ||
existsSync( | ||
path.resolve(pkg, 'node_modules/dependency/package.json') | ||
), | ||
'dependency was installed' | ||
) | ||
t.notOk( | ||
existsSync(path.resolve(pkg, 'node_modules/dev-dependency/package.json')), | ||
'devDependency was NOT installed' | ||
) | ||
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, 'dev-dependency')) | ||
fs.writeFileSync( | ||
path.join(pkg, 'dev-dependency', 'package.json'), | ||
JSON.stringify(devDependency, null, 2) | ||
) | ||
|
||
mkdirp.sync(path.join(pkg, 'node_modules')) | ||
fs.writeFileSync( | ||
path.join(pkg, 'package.json'), | ||
JSON.stringify(json, null, 2) | ||
) | ||
fs.writeFileSync( | ||
path.join(pkg, 'npm-shrinkwrap.json'), | ||
JSON.stringify(shrinkwrap, null, 2) | ||
) | ||
process.chdir(pkg) | ||
} | ||
|
||
function cleanup () { | ||
process.chdir(osenv.tmpdir()) | ||
rimraf.sync(pkg) | ||
} |
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 |
---|---|---|
|
@@ -70,6 +70,7 @@ var desired = { | |
resolved: common.registry + '/request/-/request-0.9.0.tgz' | ||
}, | ||
underscore: { | ||
dev: true, | ||
version: '1.5.1', | ||
from: '[email protected]', | ||
resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz' | ||
|
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 |
---|---|---|
|
@@ -50,6 +50,7 @@ var desired = { | |
resolved: common.registry + '/request/-/request-0.9.0.tgz' | ||
}, | ||
underscore: { | ||
dev: true, | ||
version: '1.5.1', | ||
from: '[email protected]', | ||
resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz' | ||
|