Skip to content

Instantly share code, notes, and snippets.

@elidrissidev
Last active February 22, 2023 21:22
Show Gist options
  • Save elidrissidev/36e17a5f1206a656848eff086a3519e4 to your computer and use it in GitHub Desktop.
Save elidrissidev/36e17a5f1206a656848eff086a3519e4 to your computer and use it in GitHub Desktop.
A Deno script that fetches the mostly commonly used folder names in popular NPM packages. Read the blog post: https://www.elidrissi.dev/posts/2023/02/most-used-folder-names-npm-packages/
import packages from "./packages.json" assert { type: "json" };
const NPM_REGISTRY_API_URL = "https://registry.npmjs.com";
const GITHUB_API_URL = "https://api.github.com";
const fallbackRepoURL = {
yarn: 'https://github.com/yarnpkg/yarn'
};
const directories = new Map();
console.log('Fetching packages information...');
const pkgs = await Promise.all(
packages.map(name =>
fetch(`${NPM_REGISTRY_API_URL}/${name}`)
.then(res => res.json())
.catch(console.error)
)
);
console.log('Fetching repositories information...');
const repos = await Promise.all(
pkgs.map(pkg => {
// Parse the repo URL for every package, fallback to a predefined
// map when a URL is unavailable
const githubUrl = new URL(pkg.repository.url ?? fallbackRepoURL[pkg.name]);
const repoNamespace = githubUrl.pathname.replace(/\.git$/i, "");
return fetch(`${GITHUB_API_URL}/repos${repoNamespace}/contents`)
.then(res => res.json())
.catch(console.error);
})
);
repos.flat()
.filter(file => file.type === 'dir')
.map(dir => dir.name)
.forEach(dir => {
let count = directories.get(dir);
directories.set(dir, count ? ++count : 1);
});
const dirs = Array.from(directories.entries())
// Filter out the directories that appear only once
.filter(v => v[1] > 1)
// Sort desc by their count
.sort((a, b) => b[1] - a[1]);
// Print out the result
for (let [dir, count] of dirs) {
console.log(dir, ':', count);
}
[
"acorn",
"async",
"axios",
"@babel/cli",
"bluebird",
"bootstrap",
"chalk",
"classnames",
"colors",
"commander",
"core-js",
"cors",
"d3",
"debug",
"dotenv",
"ejs",
"enzyme",
"escape-html",
"eslint",
"express",
"formik",
"fs-extra",
"glob",
"graphql",
"gulp",
"helmet",
"history",
"husky",
"i18next",
"ioredis",
"jest",
"jquery",
"jsonwebtoken",
"jws",
"karma",
"koa",
"lodash",
"mkdirp",
"mocha",
"moment",
"mongodb",
"msw",
"nanoid",
"next",
"node-fetch",
"passport",
"postcss",
"prisma",
"prop-types",
"react-dom",
"react-hook-form",
"react",
"redux",
"request",
"rxjs",
"sass",
"styled-components",
"swr",
"tailwindcss",
"tslib",
"underscore",
"uuid",
"vite",
"vue",
"webpack",
"winston",
"yaml",
"yarn",
"yargs",
"zod"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment