Last active
April 18, 2022 03:39
-
-
Save DiogoDoreto/ec3bde4889b2f587024ca6c6a0970f9a to your computer and use it in GitHub Desktop.
Log dependencies that are potentially duplicated in yarn.lock
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
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