Created
November 17, 2023 02:02
-
-
Save hyrious/f2db2d8b30374356bc0cddcd7c582614 to your computer and use it in GitHub Desktop.
Find duplicate dependencies in Node.js project
This file contains 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
$("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