Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit 2cbe412

Browse files
bengliarna
authored andcommitted
ls: Add support for --only={prod[uction]|dev[elopment]}
PR-URL: #9024
1 parent 3428611 commit 2cbe412

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lib/ls.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ function pruneNestedExtraneous (data, visited) {
113113
}
114114

115115
function filterByEnv (data) {
116-
var dev = npm.config.get('dev')
117-
var production = npm.config.get('production')
116+
var dev = npm.config.get('dev') || /^dev(elopment)?$/.test(npm.config.get('only'))
117+
var production = npm.config.get('production') || /^prod(uction)?$/.test(npm.config.get('only'))
118118
var dependencies = {}
119119
var devDependencies = data.devDependencies || []
120120
Object.keys(data.dependencies).forEach(function (name) {

test/tap/ls-env.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ test('npm ls --dev', function (t) {
5454
})
5555
})
5656

57+
test('npm ls --only=development', function (t) {
58+
common.npm(['ls', '--only=development'], EXEC_OPTS, function (er, code, stdout) {
59+
t.ifError(er, 'ls --only=development ran without issue')
60+
t.equal(code, 0)
61+
t.has(stdout, /(empty)/, 'output contains (empty)')
62+
t.end()
63+
})
64+
})
65+
66+
test('npm ls --only=dev', function (t) {
67+
common.npm(['ls', '--only=dev'], EXEC_OPTS, function (er, code, stdout) {
68+
t.ifError(er, 'ls --only=dev ran without issue')
69+
t.equal(code, 0)
70+
t.has(stdout, /(empty)/, 'output contains (empty)')
71+
t.end()
72+
})
73+
})
74+
5775
test('npm ls --production', function (t) {
5876
common.npm(['ls', '--production'], EXEC_OPTS, function (er, code, stdout) {
5977
t.ifError(er, 'ls --production ran without issue')
@@ -80,6 +98,32 @@ test('npm ls --prod', function (t) {
8098
})
8199
})
82100

101+
test('npm ls --only=production', function (t) {
102+
common.npm(['ls', '--only=production'], EXEC_OPTS, function (er, code, stdout) {
103+
t.ifError(er, 'ls --only=production ran without issue')
104+
t.notOk(code, 'npm exited ok')
105+
t.has(
106+
stdout,
107+
/test-package-with-one-dep@0\.0\.0/,
108+
'output contains [email protected]'
109+
)
110+
t.end()
111+
})
112+
})
113+
114+
test('npm ls --only=prod', function (t) {
115+
common.npm(['ls', '--only=prod'], EXEC_OPTS, function (er, code, stdout) {
116+
t.ifError(er, 'ls --only=prod ran without issue')
117+
t.notOk(code, 'npm exited ok')
118+
t.has(
119+
stdout,
120+
/test-package-with-one-dep@0\.0\.0/,
121+
'output contains [email protected]'
122+
)
123+
t.end()
124+
})
125+
})
126+
83127
test('cleanup', function (t) {
84128
cleanup()
85129
t.end()

0 commit comments

Comments
 (0)