Skip to content

Instantly share code, notes, and snippets.

@kristianmandrup
Created September 18, 2014 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristianmandrup/c424528345f9393a364b to your computer and use it in GitHub Desktop.
Save kristianmandrup/c424528345f9393a364b to your computer and use it in GitHub Desktop.
Optimize local node_modules to symlink to global repo
Idea for a small *optimize* util to speedup project creation time and keep app footprint low
var emberDevDeps = ['body-parser', 'broccoli-asset-rev',
'broccoli-ember-hbs-template-compiler', 'ember-cli-ember-data',
'ember-cli-ic-ajax', 'ember-cli-ic-ajax',
'ember-cli-inject-live-reload', 'ember-cli-qunit express glob'
];
$ optimize link --all
go through each module dependency in `package.json` via `npm list --depth=0`
get list of globally installed modules for those dependencies `npm list <modules referenced> --depth=0`
for each one returned, extract name and version in `Repo` object /(.*)@(.*)/
`<name>: [<list of versions>]`
for each module dependency
get name and version (of exact release versions only, thh like `/(\d{1,2}\.\w+)` - ignore version prefixes for now
see if this version (exactly?) matches a globally installed module (lookup in `Repo` object)
if so, make a symlink to global module in local /node_modules (via `npm link <module>`)
else ignore and continue
run `npm install` (it will ignore any local module already symlinked)
To remove symlinks, run:
$ optimize unlink
This should not conflict with the normal npm workflow with respect to updating dependencies...
But then again, perhaps too much trouble to implement all this infrastructure to circumvent a basic/standard npm mechanism. I wonder if npm 2.0 dedupe will resolve some of this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment