README
npm-shrinkwrap-mirror
Purpose
To allow application authors to create their own http caches of npm modules that they depend on - thus protecting themselves against unscrupulous 3rd party authors unpublishing their modules and causing our own applications to fail installing.
Method
npm-shrinkwrap-mirror accepts a pre-existing npm-shrinkwrap.json file as input, and will download all dependencies listed therein. It will modify the npm-shrinkwrap.json URLs to replace the https://registry.npmjs.org host with a user-supplied host instead. Thus the user is left with a new npm-shrinkwrap.json pointing to their own HTTP server, and a directory structure which they can then host on their own server.
Usage
Assuming www.myhost.com is hosted on the same server under /var/www, executed from the root of your application:
npm shrinkwrap
npm-shrinkwrap-mirror --url http://www.myhost.com/my-npm-cache --outdir /var/www/my-npm-cache
And the contents of the npm-shrinkwrap.json will now contain something similar to:
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"jquery": {
"version": "2.1.4",
"from": "jquery@*",
"resolved": "http://www.myhost.com/my-npm-cache/jquery/-/jquery-2.1.4.tgz"
}
}
}
So any future users of your application will automagically install dependencies from your own HTTP server instead of the npmjs registry.
Options
Usage: npm-shrinkwrap-mirror [options]
Options:
--shrinkwrap Input shrinkwrap file generated by npm [default: "npm-shrinkwrap.json"]
--outdir Output directory to put web server contents [default: "www"]
--outshrinkwrap Outputs modified shrinkwrap file to another file (defaults to modifying input file)
--url URL to write into the new shrinkwrap json that will hold the mirrored npm dependencies [required]
--downloadLimit Total number of concurrent downloads to process [default: 4]
--force, -f Force downloading dependencies that already exist on the file system [default: false]
--quiet Do not output console messages [default: false]
--help Show help [boolean]
API
npm-shrinkwrap-mirror can be require()'d like most other npm modules. It takes a single options object as a parameter, using the same names accepted on the command line. This allows you to integrate it into your build process if desired.
For example:
var mirror = require( 'npm-shrinkwrap-mirror' );
mirror(
{
shrinkwrap: "/home/user/my-application/npm-shrinkwrap.json",
url: "http://www.myhost.com/my-npm-cache",
outdir: "/var/www/my-npm-cache"
},
function( err ) {
console.log( "Complete!" );
}
);