Created
April 9, 2021 09:36
-
-
Save chengjianhua/a4ac382db8982244745959badafa49fb to your computer and use it in GitHub Desktop.
[Analyze prefixes of all dependencies]
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 glob = require("glob"); | |
const fs = require("fs-extra"); | |
async function main() { | |
const pkgFilePaths = glob.sync("./packages/*/package.json"); | |
console.log(pkgFilePaths); | |
const prefixes = new Set(); | |
const pkgJsons = await Promise.all(pkgFilePaths.map((p) => fs.readJson(p))); | |
for (let pkgJson of pkgJsons) { | |
// console.log(pkgJson); | |
const allDependencies = [ | |
...Object.keys(pkgJson.dependencies ?? {}), | |
...Object.keys(pkgJson.devDependencies ?? {}), | |
]; | |
const dependenciesWithPrefix = allDependencies.filter((d) => | |
d.startsWith("@") | |
); | |
dependenciesWithPrefix.forEach((d) => { | |
const [,prefix] = /^(@.*)\//.exec(d); | |
prefixes.add(prefix) | |
}); | |
} | |
console.log(prefixes); | |
} | |
main().catch((e) => { | |
console.error(e); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment