Created
December 6, 2018 20:02
-
-
Save dgieselaar/dd6de31ca967af29267b8ea4ef3a18ad to your computer and use it in GitHub Desktop.
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 fs = require('fs'); | |
const path = require('path'); | |
const { uniq, groupBy, pickBy } = require('lodash'); | |
const beautifiedJsFile = fs.readFileSync(path.join(__dirname, './build.js'), 'utf-8'); | |
const nodeModulesRegex = /"(.*?\/node_modules\/.*?)"/; | |
const findNodeModules = ( str ) => { | |
const lines = str.split('\n'); | |
const modules = []; | |
lines.forEach(line => { | |
if (line.includes(`/node_modules/`)) { | |
const match = line.match(nodeModulesRegex); | |
modules.push(match[1]); | |
} | |
}) | |
return uniq(modules); | |
}; | |
const getRealModuleName = ( str ) => { | |
return str.substr(str.lastIndexOf('/node_modules/')); | |
}; | |
const findDupes = ( str ) => { | |
const modules = findNodeModules(str); | |
return pickBy( | |
groupBy(modules, getRealModuleName), | |
( val, key ) => val.length > 1 | |
); | |
}; | |
console.log(findDupes(beautifiedJsFile)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment