Created
March 16, 2018 07:00
-
-
Save Meir017/7b59bacc4473ca093cf6bc01bf1b20f4 to your computer and use it in GitHub Desktop.
find-duplicates in a node_module directory
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 glob = require("glob"); | |
const fs = require('fs'); | |
const mainDir = 'angular-cli-demo'; | |
const dups = {}; | |
const packageJsons = glob.sync(`${mainDir}/node_modules/**/package.json`); | |
for (const packageJson of packageJsons) { | |
try { | |
const json = require(packageJson); | |
if(!json.name || !json.version) { | |
throw 'invalid package.json'; | |
} | |
if (!dups[json.name]) { | |
dups[json.name] = {}; | |
} | |
if (!dups[json.name][json.version]) { | |
dups[json.name][json.version] = 1; | |
} else { | |
dups[json.name][json.version]++; | |
} | |
} catch (error) { | |
console.error(`invalid package.json`, packageJson); | |
} | |
} | |
for (const key in dups) { | |
const versions = Object.keys(dups[key]); | |
if(versions.length === 1 && dups[key][versions[0]] === 1) { | |
delete dups[key]; | |
} | |
} | |
fs.writeFileSync(`${mainDir}/dups.json`, JSON.stringify(dups, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the duplicates found for
@angular/[email protected]
are: