Created
March 10, 2025 14:12
-
-
Save marcogrcr/4843a43c09eb365a0ed5a791e114aaa8 to your computer and use it in GitHub Desktop.
Gets duplicate packages in a yarn.lock file
This file contains hidden or 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
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