Skip to content

Instantly share code, notes, and snippets.

@darcyclarke
Created March 9, 2022 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darcyclarke/48f55608aeb0b496122769242afad48b to your computer and use it in GitHub Desktop.
Save darcyclarke/48f55608aeb0b496122769242afad48b to your computer and use it in GitHub Desktop.
Get All Contributors From Dependencies
const{ promisify } = require('util')
const Arborist = require('@npmcli/arborist')
const read = promisify(require('read-package-json'))
const arb = new Arborist({ path: '.' })
arb.loadActual().then(async tree => {
const authors = {}
const deps = []
function store (author) {
if (author.email && !authors[author.email]) {
authors[author.email] = author
}
}
async function walk(node) {
if (!deps[node.path]) {
deps.push(node.path)
const pkg = await read(node.path + '/package.json')
if (pkg.author) store(pkg.author)
if (pkg.contributors) pkg.contributors.map(store)
if (pkg.maintainers) pkg.maintainers.map(store)
}
if (node.children) {
for (let [key, value] of node.children) {
await walk(value)
}
}
}
await walk(tree)
console.log(authors)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment