Last active
December 24, 2015 19:49
-
-
Save jakobmattsson/6853504 to your computer and use it in GitHub Desktop.
Run this is a node-project to get a list of all repeated dependencies
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
fs = require 'fs' | |
_ = require 'underscore' | |
{exec} = require 'child_process' | |
exec 'npm ls', (err, output) -> | |
return console.log(err) if err? | |
lines = output.split('\n').slice(1, -2) | |
packages = lines.map (x) -> | |
[all, name, version] = x.match(/\s([^@\s]*)@(.*)$/) | |
{name, version} | |
groups = _.groupBy(packages, 'name') | |
versionGroups = _.pairs(groups).map ([name, data]) -> | |
{ name, versions: data.map (x) -> x.version } | |
sortedVersionGroups = _.sortBy(versionGroups, (x) -> x.versions.length) | |
console.log "Installed deps: " + lines.length | |
console.log "Packages: " + sortedVersionGroups.length | |
console.log sortedVersionGroups |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment