Open lrowe opened 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.
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:
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.