-
-
Save osde8info/554e89b0d4474a9290cfa8ada3ed1976 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