Skip to content

Instantly share code, notes, and snippets.

@marcogrcr
Created March 10, 2025 14:12
Show Gist options
  • Save marcogrcr/4843a43c09eb365a0ed5a791e114aaa8 to your computer and use it in GitHub Desktop.
Save marcogrcr/4843a43c09eb365a0ed5a791e114aaa8 to your computer and use it in GitHub Desktop.
Gets duplicate packages in a yarn.lock file
import("node:fs")
.then(({ readFileSync, writeFileSync }) => {
const packages = new Map();
const output = [];
readFileSync("yarn.lock")
.toString()
.split("\n")
.forEach((l) => {
if (l[0] === '"') {
const [pkg] = l.split("@npm:");
if (packages.has(pkg)) {
if (packages.get(pkg)) {
output.push(packages.get(pkg));
packages.set(pkg, false);
}
output.push(l);
} else {
packages.set(pkg, l);
}
}
});
writeFileSync("yarn.lock.dup", output.join("\n"));
})
.catch((e) => console.error(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment