Last active
May 22, 2017 15:30
-
-
Save ramasilveyra/088f9aeddc7149f699672a12179bf76f to your computer and use it in GitHub Desktop.
List duplicated deps on the npm-shrinkwrap.json
This file contains hidden or 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
'use strict'; | |
const shrinkwrap = require('./npm-shrinkwrap.json'); | |
const modules = {}; | |
const duplicatedModules = {}; | |
walk(shrinkwrap, (key, body) => { | |
if (!modules[key]) { | |
modules[key] = [body.version]; | |
return; | |
} | |
modules[key].push(body.version); | |
duplicatedModules[key] = modules[key]; | |
}); | |
console.log(duplicatedModules); | |
function walk(obj, cb) { | |
if (!obj) return; | |
const deps = obj.dependencies; | |
if (!deps) return; | |
const keys = Object.keys(deps); | |
keys.forEach(key => { | |
cb(key, deps[key]); | |
walk(deps[key], cb); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment