Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"npm ls --include-extraneous-dep" to output the complete dependency tree #583

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/content/cli-commands/npm-ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ Display only dependencies which are linked
Whether to represent the tree structure using unicode characters.
Set it to false in order to use all-ansi output.

#### include-extraneous-dep

* Type: Boolean
* Default: false

Display the complete dependency tree, including the nested dependencies
brought in by extraneous packages.

### See Also

* [npm config](/cli-commands/npm-config)
Expand Down
8 changes: 8 additions & 0 deletions docs/content/using-npm/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,14 @@ If true, npm will not run `prepublish` scripts.

If true, npm does not run scripts specified in package.json files.

#### include-extraneous-dep

* Default: false
* Type: Boolean

If true, `npm ls` outputs the complete dependency tree,
including the nested dependencies brought in by extraneous packages.

#### init-module

* Default: ~/.npm-init.js
Expand Down
2 changes: 2 additions & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'if-present': false,
'ignore-prepublish': false,
'ignore-scripts': false,
'include-extraneous-dep': false,
'init-module': path.resolve(home, '.npm-init.js'),
'init-author-name': '',
'init-author-email': '',
Expand Down Expand Up @@ -306,6 +307,7 @@ exports.types = {
'if-present': Boolean,
'ignore-prepublish': Boolean,
'ignore-scripts': Boolean,
'include-extraneous-dep': Boolean,
'init-module': path,
'init-author-name': String,
'init-author-email': String,
Expand Down
4 changes: 4 additions & 0 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ var lsFromTree = ls.fromTree = function (dir, physicalTree, args, silent, cb) {
}

function pruneNestedExtraneous (data, visited) {
if (npm.config.get('include-extraneous-dep')) {
return
}

visited = visited || []
visited.push(data)
for (var i in data.dependencies) {
Expand Down
24 changes: 20 additions & 4 deletions test/tap/nested-extraneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var pj = {
version: '1.2.3'
}

var dep = path.resolve(pkg, 'node_modules', 'dep')
var dep = path.resolve(pkg, 'node_modules', 'nested-extraneous-dep')
var deppj = {
name: 'nested-extraneous-dep',
version: '1.2.3',
Expand All @@ -20,10 +20,10 @@ var deppj = {
}
}

var depdep = path.resolve(dep, 'node_modules', 'depdep')
var depdep = path.resolve(dep, 'node_modules', 'nested-extra-depdep')
var depdeppj = {
name: 'nested-extra-depdep',
version: '1.2.3'
version: '2.3.4'
}

test('setup', function (t) {
Expand All @@ -40,13 +40,29 @@ test('test', function (t) {
cwd: pkg
}, function (er, code, sto, ste) {
if (er) throw er
t.notEqual(code, 0)
t.strictEqual(code, 1)
t.similar(ste, /dep@1\.2\.3/)
t.notSimilar(ste, /depdep/)
t.similar(sto, /dep@1\.2\.3/)
t.notSimilar(sto, /depdep/)
t.end()
})
})

test('test include-extraneous-dep', function (t) {
common.npm(['ls', '--include-extraneous-dep'], {
cwd: pkg
}, function (er, code, sto, ste) {
if (er) throw er
t.strictEqual(code, 1)
t.similar(ste, /dep@1\.2\.3/)
t.similar(ste, /depdep/)
t.similar(sto, /dep@1\.2\.3/)
t.similar(sto, /depdep/)
t.end()
})
})

test('clean', function (t) {
rimraf.sync(pkg)
t.end()
Expand Down