Skip to content

Instantly share code, notes, and snippets.

@DiogoDoreto
Last active April 18, 2022 03:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiogoDoreto/ec3bde4889b2f587024ca6c6a0970f9a to your computer and use it in GitHub Desktop.
Save DiogoDoreto/ec3bde4889b2f587024ca6c6a0970f9a to your computer and use it in GitHub Desktop.
Log dependencies that are potentially duplicated in yarn.lock
const readline = require('readline');
const fs = require('fs');
const file = fs.createReadStream('yarn.lock');
const rl = readline.createInterface(file);
let lastPkg, lastVer, lastLine, currPkg, currVer, currLine;
const re = /^"?(@?[^@]+)/;
rl.on('line', (line) => {
if (currPkg && !currVer) {
currVer = line.split(' ').pop();
if (lastPkg === currPkg && lastVer[1] === currVer[1]) {
console.log(currPkg);
console.log(` ${lastVer} ${lastLine}`);
console.log(` ${currVer} ${currLine}`);
}
return;
}
if (!line[0] || line[0] === ' ') return;
lastLine = currLine;
lastPkg = currPkg;
lastVer = currVer;
currVer = null;
currLine = line;
currPkg = re.exec(line)[1];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment