Created
October 10, 2019 18:23
-
-
Save julien-f/04496613440b339d07207c658eefc07d to your computer and use it in GitHub Desktop.
Dependencies usage
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 { readFileSync } = require("fs"); | |
const depsCount = {}; | |
function processDeps(deps) { | |
deps !== undefined && | |
Object.keys(deps).forEach(dep => { | |
depsCount[dep] = 1 + (depsCount[dep] || 0); | |
}); | |
} | |
process.argv.slice(2).forEach(pkgFile => { | |
try { | |
const pkg = JSON.parse(readFileSync(pkgFile)); | |
processDeps(pkg.dependencies); | |
// processDeps(pkg.devDependencies); | |
processDeps(pkg.optionalDependencies); | |
} catch (_) {} | |
}); | |
Object.entries(depsCount) | |
.sort((a, b) => b[1] - a[1]) | |
// .filter(dep => dep[1] > 1) | |
// .slice(0, 50) | |
.forEach(([name, count]) => { | |
console.log("%s (%d)", name, count); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment