alexanderGugel / ied

:package: Like npm, but faster - an alternative package manager for Node
http://alexandergugel.github.io/ied
MIT License
1.99k stars 53 forks source link

Support offline / no-index installs #51

Open lrowe opened 8 years ago

lrowe commented 8 years ago

We occasionally see build failures due to problems accessing the npm server. While we could run a local npm server instance ourselves, doing so adds unwanted complexity.

The Python world has a simple solution: save a copy of the used packages to a local directory or web accessible directory listing, then install using:

$ pip --no-index --find-links=/path/or/url ...

The package manager will then simply fetch the desired packages from the local directory or from the links extracted from the returned html directory listing. See: https://pip.pypa.io/en/stable/reference/pip_wheel/?highlight=find-links#cmdoption-f

This also provides a simple way to publish private packages within your organisation.

patrickheeney commented 8 years ago

+1 for this, but its actually a lot more simple. Just need to tie in with npm's cache instead of installing to node_modules/.tmp. When installing a second time, it just checks npm cache for the tarball. This way your compatible with npm, supports offline installs, and really speeds up the install process.

function getUserHome() {
  return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}

function getTarball(pkg) {
  return path.join(getUserHome(), '.npm', pkg.name, pkg.version, 'package.tgz');
}

if (pathExists(getTarball(pkg)) {
  // -> alreaded downloaded -> gunzip 
} else {
 // -> download
}

You could later expand this to use a custom path instead of npm's cache, but then it wouldn't work alongside npm.