diff --git a/lib/ls.js b/lib/ls.js index 5cdb8b39af416..8d5cd80873913 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -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 30039b5b30819..29058d9245836 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()