diff options
author | Bryan English <bryan@bryanenglish.com> | 2015-07-18 02:04:27 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-08-12 09:27:03 +0300 |
commit | 3ab1eea260f0fa61a9c6a444036211f82c97c671 (patch) | |
tree | d7ee274006ea723888fbeb9be4d6ff6da48fa77d | |
parent | 915ed50f90557a97e098d40427dc0dc1e4f6ee66 (diff) |
install: Add support for --only={prod[uction]|dev[elopment]}
PR-URL: https://github.com/npm/npm/pull/9024
-rw-r--r-- | lib/install.js | 9 | ||||
-rw-r--r-- | test/tap/install-cli-only-development.js | 85 | ||||
-rw-r--r-- | test/tap/install-cli-only-production.js | 88 |
3 files changed, 179 insertions, 3 deletions
diff --git a/lib/install.js b/lib/install.js index a1b48b290..d3b782c45 100644 --- a/lib/install.js +++ b/lib/install.js @@ -197,7 +197,8 @@ function Installer (where, dryrun, args) { this.noPackageJsonOk = !!args.length this.topLevelLifecycles = !args.length this.npat = npm.config.get('npat') - this.dev = npm.config.get('dev') || !npm.config.get('production') + this.dev = npm.config.get('dev') || (!/^prod(uction)?$/.test(npm.config.get('only')) && !npm.config.get('production')) + this.prod = !/^dev(elopment)?$/.test(npm.config.get('only')) this.rollback = npm.config.get('rollback') this.link = npm.config.get('link') this.global = this.where === path.resolve(npm.globalDir, '..') @@ -363,8 +364,10 @@ Installer.prototype.loadAllDepsIntoIdealTree = function (cb) { steps.push([validateArgs, this.idealTree, this.args]) steps.push([loadRequestedDeps, this.args, this.idealTree, saveDeps, cg.newGroup('loadRequestedDeps')]) } else { - steps.push( - [loadDeps, this.idealTree, cg.newGroup('loadDeps')]) + if (this.prod) { + steps.push( + [loadDeps, this.idealTree, cg.newGroup('loadDeps')]) + } if (this.dev) { steps.push( [loadDevDeps, this.idealTree, cg.newGroup('loadDevDeps')]) diff --git a/test/tap/install-cli-only-development.js b/test/tap/install-cli-only-development.js new file mode 100644 index 000000000..21c30378e --- /dev/null +++ b/test/tap/install-cli-only-development.js @@ -0,0 +1,85 @@ +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, 'install-cli-development') + +var EXEC_OPTS = { cwd: pkg } + +var json = { + name: 'install-cli-development', + description: 'fixture', + version: '0.0.0', + dependencies: { + dependency: 'file:./dependency' + }, + devDependencies: { + 'dev-dependency': 'file:./dev-dependency' + } +} + +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) { + 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) + ) + + process.chdir(pkg) + t.end() +}) + +test('\'npm install --only=development\' should only install devDependencies', function (t) { + common.npm(['install', '--only=development'], EXEC_OPTS, function (err, code) { + t.ifError(err, 'install development successful') + t.equal(code, 0, 'npm install did not raise error code') + t.ok( + JSON.parse(fs.readFileSync( + path.resolve(pkg, 'node_modules/dev-dependency/package.json'), 'utf8') + ), + 'devDependency was installed' + ) + t.notOk( + existsSync(path.resolve(pkg, 'node_modules/dependency/package.json')), + 'dependency was NOT installed' + ) + t.end() + }) +}) + +test('cleanup', function (t) { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) + t.end() +}) diff --git a/test/tap/install-cli-only-production.js b/test/tap/install-cli-only-production.js new file mode 100644 index 000000000..7f46a23e1 --- /dev/null +++ b/test/tap/install-cli-only-production.js @@ -0,0 +1,88 @@ +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, 'install-cli-only-production') + +var EXEC_OPTS = { cwd: pkg } + +var json = { + name: 'install-cli-only-production', + description: 'fixture', + version: '0.0.0', + scripts: { + prepublish: 'exit 123' + }, + dependencies: { + dependency: 'file:./dependency' + }, + devDependencies: { + 'dev-dependency': 'file:./dev-dependency' + } +} + +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) { + mkdirp.sync(path.join(pkg, 'dependency')) + fs.writeFileSync( + path.join(pkg, 'dependency', 'package.json'), + JSON.stringify(dependency, null, 2) + ) + + mkdirp.sync(path.join(pkg, 'devDependency')) + fs.writeFileSync( + path.join(pkg, 'devDependency', '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) + ) + + process.chdir(pkg) + t.end() +}) + +test('\'npm install --only=production\' should only install dependencies', function (t) { + common.npm(['install', '--only=production'], EXEC_OPTS, function (err, code) { + t.ifError(err, 'install production successful') + t.equal(code, 0, 'npm install did not raise error code') + t.ok( + JSON.parse(fs.readFileSync( + path.resolve(pkg, 'node_modules/dependency/package.json'), 'utf8') + ), + '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) { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) + t.end() +}) |