Skip to content

Instantly share code, notes, and snippets.

@chengjianhua
Created April 9, 2021 09:36
Show Gist options
  • Save chengjianhua/a4ac382db8982244745959badafa49fb to your computer and use it in GitHub Desktop.
Save chengjianhua/a4ac382db8982244745959badafa49fb to your computer and use it in GitHub Desktop.
[Analyze prefixes of all dependencies]
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