Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created November 17, 2023 02:02
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 hyrious/f2db2d8b30374356bc0cddcd7c582614 to your computer and use it in GitHub Desktop.
Save hyrious/f2db2d8b30374356bc0cddcd7c582614 to your computer and use it in GitHub Desktop.
Find duplicate dependencies in Node.js project
$("dup", async () => {
if (fs.existsSync("pnpm-lock.yaml")) {
const { packages } = yaml.load(fs.readFileSync("pnpm-lock.yaml", "utf8"));
let last = ["", ""];
let seen = new Set();
const log = (s) => seen.has(s) || (seen.add(s), console.log(s));
for (const path in packages) {
const i = path.lastIndexOf("@");
const pkg = path.slice(1, i);
const ver = path.slice(i + 1);
if (last[0] == pkg) {
log(last.join("@"));
log(pkg + "@" + ver);
}
last = [pkg, ver];
}
return;
}
console.log("don't know how to handle this project");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment