Skip to content

Instantly share code, notes, and snippets.

@Meir017
Created March 16, 2018 07:00
Show Gist options
  • Save Meir017/7b59bacc4473ca093cf6bc01bf1b20f4 to your computer and use it in GitHub Desktop.
Save Meir017/7b59bacc4473ca093cf6bc01bf1b20f4 to your computer and use it in GitHub Desktop.
find-duplicates in a node_module directory
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));
@Meir017
Copy link
Author

Meir017 commented Mar 16, 2018

the duplicates found for @angular/[email protected] are:

{
  "ajv": { "5.5.2": 5, "6.2.1": 1, "4.11.8": 2 },
  "abbrev": { "1.1.1": 1, "1.1.0": 1 },
  "acorn": { "4.0.13": 1, "5.5.3": 1 },
  "ansi-regex": { "2.1.1": 2, "3.0.0": 1 },
  "ansi-styles": { "3.2.1": 1, "2.2.1": 2 },
  "anymatch": { "1.3.2": 1, "2.0.0": 2 },
  "aproba": { "1.2.0": 1, "1.1.1": 1 },
  "are-we-there-yet": { "1.1.4": 2 },
  "arr-diff": { "2.0.0": 1, "4.0.0": 3 },
  "array-flatten": { "2.1.1": 1, "1.1.1": 1 },
  "array-unique": { "0.2.1": 1, "0.3.2": 3 },
  "asn1": { "0.2.3": 2 },
  "assert-plus": { "0.2.0": 2, "1.0.0": 9 },
  "async": { "2.6.0": 1, "1.5.2": 1 },
  "asynckit": { "0.4.0": 2 },
  "aws-sign2": { "0.6.0": 2 },
  "aws4": { "1.6.0": 2 },
  "chalk": { "1.1.3": 2, "2.2.2": 1, "2.3.2": 1 },
  "supports-color": { "2.0.0": 2, "5.3.0": 2, "4.5.0": 1 },
  "balanced-match": { "1.0.0": 1, "0.4.2": 1 },
  "define-property": { "1.0.0": 6, "0.2.5": 6, "2.0.2": 1 },
  "isobject": { "3.0.1": 12, "2.1.0": 2 },
  "bcrypt-pbkdf": { "1.0.1": 2 },
  "block-stream": { "0.0.9": 2 },
  "qs": { "6.5.1": 2, "6.4.0": 2, "6.3.2": 1 },
  "boom": { "2.10.1": 2 },
  "brace-expansion": { "1.1.11": 1, "1.1.7": 1 },
  "braces": { "1.8.5": 1, "2.3.1": 2 },
  "camelcase": { "2.1.1": 1, "3.0.0": 3, "1.2.1": 1, "4.1.0": 2 },
  "caseless": { "0.12.0": 2, "0.11.0": 1 },
  "chokidar": { "1.7.0": 1, "2.0.2": 2 },
  "kind-of": { "3.2.2": 15, "5.1.0": 7, "6.0.2": 8, "4.0.0": 2 },
  "is-accessor-descriptor": { "0.1.6": 6, "1.0.0": 1 },
  "is-data-descriptor": { "0.1.4": 6, "1.0.0": 1 },
  "is-descriptor": { "0.1.6": 6, "1.0.2": 1 },
  "cliui": { "3.2.0": 2, "2.1.0": 1 },
  "for-own": { "1.0.0": 1, "0.1.5": 1 },
  "co": { "4.6.0": 2 },
  "code-point-at": { "1.1.0": 2 },
  "combined-stream": { "1.0.6": 1, "1.0.5": 1 },
  "commander": { "2.15.0": 1, "2.13.0": 1 },
  "concat-map": { "0.0.1": 2 },
  "console-control-strings": { "1.1.0": 2 },
  "is-extglob": { "2.1.1": 4, "1.0.0": 1 },
  "is-glob": { "4.0.0": 3, "3.1.0": 3, "2.0.1": 1 },
  "core-util-is": { "1.0.2": 2 },
  "minimist": { "1.2.0": 3, "0.0.8": 2 },
  "cross-spawn": { "3.0.1": 1, "5.1.0": 1 },
  "cryptiles": { "2.0.5": 2 },
  "dashdash": { "1.14.1": 2 },
  "debug": { "2.6.9": 2, "2.6.8": 1, "3.1.0": 1 },
  "pify": { "2.3.0": 5, "3.0.0": 1 },
  "globby": { "6.1.0": 1, "7.1.1": 1 },
  "delayed-stream": { "1.0.0": 2 },
  "delegates": { "1.0.0": 2 },
  "depd": { "1.1.2": 1, "1.1.1": 1 },
  "utila": { "0.3.3": 2, "0.4.0": 1 },
  "domelementtype": { "1.1.3": 1, "1.3.0": 1 },
  "domutils": { "1.5.1": 1, "1.1.6": 1 },
  "ecc-jsbn": { "0.1.1": 2 },
  "expand-brackets": { "0.1.5": 1, "2.1.4": 2 },
  "is-extendable": { "1.0.1": 2, "0.1.1": 1 },
  "extend-shallow": { "3.0.2": 1, "2.0.1": 11 },
  "extend": { "3.0.1": 2 },
  "extglob": { "0.3.2": 1, "2.0.4": 2 },
  "schema-utils": { "0.3.0": 4, "0.4.5": 1 },
  "extsprintf": { "1.3.0": 1, "1.0.2": 1 },
  "faye-websocket": { "0.10.0": 1, "0.11.1": 1 },
  "fill-range": { "2.2.3": 1, "4.0.0": 2 },
  "find-up": { "2.1.0": 1, "1.1.2": 1 },
  "for-in": { "1.0.2": 1, "0.1.8": 1 },
  "forever-agent": { "0.6.1": 2 },
  "form-data": { "2.1.4": 2 },
  "fs.realpath": { "1.0.0": 2 },
  "fstream": { "1.0.11": 2 },
  "gauge": { "2.7.4": 2 },
  "getpass": { "0.1.7": 2 },
  "glob": { "7.1.2": 2, "7.0.6": 1, "6.0.4": 1 },
  "graceful-fs": { "4.1.11": 2 },
  "har-schema": { "1.0.5": 2 },
  "har-validator": { "4.2.1": 2, "2.0.6": 1 },
  "has-unicode": { "2.0.1": 2 },
  "hawk": { "3.1.3": 2 },
  "hoek": { "2.16.3": 2 },
  "http-signature": { "1.1.1": 2 },
  "inflight": { "1.0.6": 2 },
  "inherits": { "2.0.3": 2, "2.0.1": 1 },
  "is-fullwidth-code-point": { "1.0.0": 2, "2.0.0": 1 },
  "is-typedarray": { "1.0.0": 2 },
  "isarray": { "1.0.0": 2, "0.0.1": 1 },
  "isstream": { "0.1.2": 2 },
  "jsbn": { "0.1.1": 2 },
  "json-schema": { "0.2.3": 2 },
  "json-stable-stringify": { "1.0.1": 2 },
  "json-stringify-safe": { "5.0.1": 2 },
  "jsonify": { "0.0.0": 2 },
  "jsprim": { "1.4.0": 1, "1.4.1": 1 },
  "mime-db": { "1.27.0": 1, "1.33.0": 1 },
  "mime-types": { "2.1.15": 1, "2.1.18": 1 },
  "minimatch": { "3.0.4": 2 },
  "mkdirp": { "0.5.1": 2 },
  "ms": { "2.0.0": 2 },
  "nopt": { "4.0.1": 2, "3.0.6": 1 },
  "npmlog": { "4.1.0": 1, "4.1.2": 1 },
  "number-is-nan": { "1.0.1": 2 },
  "oauth-sign": { "0.8.2": 2 },
  "object-assign": { "4.1.1": 2 },
  "once": { "1.4.0": 2 },
  "os-homedir": { "1.0.2": 2 },
  "os-tmpdir": { "1.0.2": 2 },
  "osenv": { "0.1.4": 1, "0.1.5": 1 },
  "path-is-absolute": { "1.0.1": 2 },
  "performance-now": { "0.2.0": 2 },
  "process-nextick-args": { "1.0.7": 1, "2.0.0": 1 },
  "punycode": { "1.4.1": 2, "1.3.2": 1 },
  "readable-stream": { "2.2.9": 1, "1.0.34": 1, "2.3.5": 1 },
  "request": { "2.81.0": 2, "2.79.0": 1 },
  "rimraf": { "2.6.1": 1, "2.6.2": 1 },
  "safe-buffer": { "5.0.1": 1, "5.1.1": 1 },
  "semver": { "5.3.0": 2, "5.5.0": 1 },
  "set-blocking": { "2.0.0": 2 },
  "signal-exit": { "3.0.2": 2 },
  "sntp": { "1.0.9": 2 },
  "sshpk": { "1.13.0": 1, "1.14.1": 1 },
  "string_decoder": { "1.0.1": 1, "0.10.31": 1, "1.0.3": 1 },
  "string-width": { "1.0.2": 3, "2.1.1": 1 },
  "stringstream": { "0.0.5": 2 },
  "strip-ansi": { "3.0.1": 2, "4.0.0": 1 },
  "tar": { "2.2.1": 2 },
  "tough-cookie": { "2.3.2": 1, "2.3.4": 1 },
  "tunnel-agent": { "0.6.0": 2, "0.4.3": 1 },
  "tweetnacl": { "0.14.5": 2 },
  "util-deprecate": { "1.0.2": 2 },
  "uuid": { "3.0.1": 1, "3.2.1": 1 },
  "verror": { "1.3.6": 1, "1.10.0": 1 },
  "wide-align": { "1.1.2": 2 },
  "wrappy": { "1.0.2": 2 },
  "glob-parent": { "2.0.0": 1, "3.1.0": 2 },
  "has-flag": { "2.0.0": 1, "3.0.0": 2 },
  "has-value": { "1.0.0": 1, "0.3.1": 1 },
  "is-number": { "3.0.0": 5, "2.1.0": 1, "4.0.0": 1 },
  "has-values": { "1.0.0": 1, "0.1.4": 1 },
  "hash-base": { "2.0.2": 1, "3.0.4": 1 },
  "loader-utils": { "0.2.17": 1, "1.1.0": 1 },
  "setprototypeof": { "1.0.3": 1, "1.1.0": 1 },
  "load-json-file": { "1.1.0": 1, "2.0.0": 1 },
  "micromatch": { "2.3.11": 1, "3.1.9": 2 },
  "mime": { "1.6.0": 1, "1.4.1": 1 },
  "url-parse": { "1.0.5": 1, "1.2.0": 1 },
  "os-locale": { "1.4.0": 1, "2.1.0": 1 },
  "path-exists": { "3.0.0": 1, "2.1.0": 1 },
  "path-type": { "3.0.0": 1, "1.1.0": 1, "2.0.0": 1 },
  "source-map": { "0.6.1": 4, "0.4.4": 2, "0.5.7": 1, "0.1.43": 1 },
  "querystringify": { "0.0.4": 1, "1.0.0": 1 },
  "read-pkg-up": { "1.0.1": 1, "2.0.0": 1 },
  "read-pkg": { "1.1.0": 1, "2.0.0": 1 },
  "set-value": { "2.0.0": 1, "0.4.3": 1 },
  "sockjs-express": { "0.0.0-unreleasable": 2 },
  "source-list-map": { "2.0.0": 1, "0.1.8": 1 },
  "strip-bom": { "2.0.0": 1, "3.0.0": 1 },
  "uglify-js": { "3.3.15": 1, "2.8.29": 1 },
  "uglifyjs-webpack-plugin": { "1.2.3": 1, "0.4.6": 1 },
  "y18n": { "3.2.1": 3, "4.0.0": 1 },
  "yargs-parser": { "4.2.1": 1, "7.0.0": 1, "5.0.0": 1 },
  "yargs": { "6.6.0": 1, "3.10.0": 1, "8.0.2": 1, "7.1.0": 1 },
  "which-module": { "2.0.0": 1, "1.0.0": 1 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment