Skip to content

Commit

Permalink
Implement --proxy and --https-proxy as pass-throughs to npm.
Browse files Browse the repository at this point in the history
This fixes issue #80.
  • Loading branch information
Dan Bornstein committed Dec 23, 2016
1 parent a4eddca commit a539bff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -24,6 +24,10 @@ UPDATE for v.next.
`cd path/to/my/package; npmunbox --install=. path/to/box.npmbox`
* New unbox option `--scripts` to enable running of scripts. (By default,
npmbox acts like `--ignore-scripts` was specified.)
* New options `--proxy` and `--https-proxy` which pass through to the
underlying `npm` invocation. Works on both `npmbox` and `npmunbox`. In the
latter case, this can help prevent unboxing from inadvertently hitting the
network (by specifying nonexistent proxies).

UPDATE December 21, 2016: v4.1.0 of npmbox is out.
* Support for running npmbox on a top-level local package, e.g.
Expand Down Expand Up @@ -59,6 +63,8 @@ Given some package, like `express` this command will create a archive file of th
-v, --verbose Shows npm output which is normally hidden.
-s, --silent Shows no output whatsoever.
-t, --target Specify the .npmbox file to write.
--proxy=<url> npm --proxy switch.
--https-proxy=<url> npm --https-proxy switch.

You must specify at least one package. Packages can be anything accepted as
an argument to `npm install`, and can also be a local path to a `.json` file,
Expand Down Expand Up @@ -98,6 +104,8 @@ Given some .npmbox file (must end with the .npmbox extension), installs the cont
-O, --save-optional npm --save-optional switch.
-B, --save-bundle npm --save-bundle switch.
-E, --save-exact npm --save-exact switch.
--proxy=<url> npm --proxy switch.
--https-proxy=<url> npm --https-proxy switch.

You must specify at least one file.

Expand Down
10 changes: 9 additions & 1 deletion npmbox.js
Expand Up @@ -8,6 +8,10 @@
var boxxer = require("./npmboxxer.js");

var argv = require("optimist")
.string([
"proxy",
"https-proxy"
])
.boolean(["v","verbose","s","silent"])
.options("t", {
alias: "target",
Expand All @@ -29,14 +33,18 @@ if (args.length<1 || argv.help) {
console.log(" -v, --verbose Shows additional output which is normally hidden.");
console.log(" -s, --silent Hide all output.");
console.log(" -t, --target Specify the target .npmbox file to write.");
console.log(" --proxy=<url> npm --proxy switch.");
console.log(" --https-proxy=<url> npm --https-proxy switch.");
console.log("");
process.exit(0);
}

var options = {
verbose: argv.v || argv.verbose || false,
silent: argv.s || argv.silent || false,
target: argv.t || argv.target || null
target: argv.t || argv.target || null,
proxy: argv.proxy || null,
"https-proxy": argv["https-proxy"] || null
};

var sources = args;
Expand Down
2 changes: 2 additions & 0 deletions npmboxxer.js
Expand Up @@ -357,6 +357,8 @@
"ignore-scripts": true,
loglevel: options && options.verbose ? "http" : "silent"
};
if (options.proxy) npmoptions.proxy = options.proxy;
if (options["https-proxy"]) npmoptions["https-proxy"] = options["https-proxy"];

npmInit(npmoptions,function(err){
if (err) return done(err);
Expand Down
8 changes: 7 additions & 1 deletion npmunbox.js
Expand Up @@ -10,7 +10,9 @@ var utils = require("./utils");

var argv = require("optimist")
.string([
"C","prefix"
"C","prefix",
"proxy",
"https-proxy"
])
.boolean([
"v","verbose",
Expand Down Expand Up @@ -55,6 +57,8 @@ if (args.length<1 || argv.help) {
console.log(" -O, --save-optional npm --save-optional switch.");
console.log(" -B, --save-bundle npm --save-bundle switch.");
console.log(" -E, --save-exact npm --save-exact switch.");
console.log(" --proxy=<url> npm --proxy switch.");
console.log(" --https-proxy=<url> npm --https-proxy switch.");
console.log("");
process.exit(0);
}
Expand All @@ -72,6 +76,8 @@ var options = {
path: argv.p || argv.path || false
};
if (argv.C || argv.prefix) options.prefix = argv.C || argv.prefix;
if (argv.proxy) options.proxy = argv.proxy;
if (argv["https-proxy"]) options["https-proxy"] = argv["https-proxy"];

var errorCount = 0;
var sources = args.filter(function(source){
Expand Down

0 comments on commit a539bff

Please sign in to comment.