diff options
author | Bryan English <bryan@bryanenglish.com> | 2015-08-01 01:47:34 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-08-12 09:28:38 +0300 |
commit | 2cbe412bbe920f6927ca45a8f842d4cbd3525eaf (patch) | |
tree | ec4d20293db8c08bc5a4f80a113ac4cd44585265 | |
parent | 3428611e3b4735fc6d34915a9e86d7bfbd29fd56 (diff) |
ls: Add support for --only={prod[uction]|dev[elopment]}
PR-URL: https://github.com/npm/npm/pull/9024
-rw-r--r-- | lib/ls.js | 4 | ||||
-rw-r--r-- | test/tap/ls-env.js | 44 |
2 files changed, 46 insertions, 2 deletions
@@ -113,8 +113,8 @@ function pruneNestedExtraneous (data, visited) { } function filterByEnv (data) { - var dev = npm.config.get('dev') - var production = npm.config.get('production') + var dev = npm.config.get('dev') || /^dev(elopment)?$/.test(npm.config.get('only')) + var production = npm.config.get('production') || /^prod(uction)?$/.test(npm.config.get('only')) var dependencies = {} var devDependencies = data.devDependencies || [] Object.keys(data.dependencies).forEach(function (name) { diff --git a/test/tap/ls-env.js b/test/tap/ls-env.js index 30039b5b3..29058d924 100644 --- a/test/tap/ls-env.js +++ b/test/tap/ls-env.js @@ -54,6 +54,24 @@ test('npm ls --dev', function (t) { }) }) +test('npm ls --only=development', function (t) { + common.npm(['ls', '--only=development'], EXEC_OPTS, function (er, code, stdout) { + t.ifError(er, 'ls --only=development ran without issue') + t.equal(code, 0) + t.has(stdout, /(empty)/, 'output contains (empty)') + t.end() + }) +}) + +test('npm ls --only=dev', function (t) { + common.npm(['ls', '--only=dev'], EXEC_OPTS, function (er, code, stdout) { + t.ifError(er, 'ls --only=dev ran without issue') + t.equal(code, 0) + t.has(stdout, /(empty)/, 'output contains (empty)') + t.end() + }) +}) + test('npm ls --production', function (t) { common.npm(['ls', '--production'], EXEC_OPTS, function (er, code, stdout) { t.ifError(er, 'ls --production ran without issue') @@ -80,6 +98,32 @@ test('npm ls --prod', function (t) { }) }) +test('npm ls --only=production', function (t) { + common.npm(['ls', '--only=production'], EXEC_OPTS, function (er, code, stdout) { + t.ifError(er, 'ls --only=production ran without issue') + t.notOk(code, 'npm exited ok') + t.has( + stdout, + /test-package-with-one-dep@0\.0\.0/, + 'output contains test-package-with-one-dep@0.0.0' + ) + t.end() + }) +}) + +test('npm ls --only=prod', function (t) { + common.npm(['ls', '--only=prod'], EXEC_OPTS, function (er, code, stdout) { + t.ifError(er, 'ls --only=prod ran without issue') + t.notOk(code, 'npm exited ok') + t.has( + stdout, + /test-package-with-one-dep@0\.0\.0/, + 'output contains test-package-with-one-dep@0.0.0' + ) + t.end() + }) +}) + test('cleanup', function (t) { cleanup() t.end() |