Created
August 4, 2017 16:10
-
-
Save json2d/2cf1aec242417662632c937685983455 to your computer and use it in GitHub Desktop.
Walk through dependency tree of installed packages via `npm ls`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const spawn = require('cross-spawn'); | |
const path = require('path') | |
const ls = spawn.sync('npm', ['ls','--json']); | |
const tree = JSON.parse(ls.stdout) | |
const walkDepTree = (tree,cb) => { | |
const deps = tree.dependencies | |
if(deps) { | |
Object.keys(deps).forEach(name => { | |
const dep = deps[name]; | |
cb(name,dep) | |
walkDepTree(dep,cb); | |
}) | |
} | |
} | |
walkDepTree( | |
tree, | |
(name,data)=> { | |
if(data.resolved.startsWith('https://registry.npmjs.org/')) | |
console.log(`${name} @ ${data.resolved}`) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment