Skip to content

Commit

Permalink
ls: Add support for --only={prod[uction]|dev[elopment]}
Browse files Browse the repository at this point in the history
PR-URL: npm/npm#9024
  • Loading branch information
bengl authored and iarna committed Aug 12, 2015
1 parent 3428611 commit 2cbe412
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions test/tap/ls-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 [email protected]'
)
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 [email protected]'
)
t.end()
})
})

test('cleanup', function (t) {
cleanup()
t.end()
Expand Down

0 comments on commit 2cbe412

Please sign in to comment.