Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #877, adds ability to pass execution args on Windows platform #891

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,17 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
if (isExplicitJS) {
args.unshift(bin);
// add executable arguments to spawn
args = (process.execArgv || []).concat(args);
args = this.getExecutableArguments().concat(args);

proc = spawn(process.argv[0], args, { stdio: 'inherit', customFds: [0, 1, 2] });
} else {
proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] });
}
} else {
args.unshift(bin);
// add executable arguments to spawn
args = this.getExecutableArguments().concat(args);

proc = spawn(process.execPath, args, { stdio: 'inherit' });
}

Expand All @@ -591,6 +594,24 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
this.runningCommand = proc;
};

/**
* Get executable arguments for sub-command process.
* If COMMANDER_NODE_OPTIONS Environment Variable is set,
* it combines current execArgv and COMMANDER_NODE_OPTIONS.
*
* @return {Array}
* @api private
*/

Command.prototype.getExecutableArguments = function() {
var commanderNodeOptions = process.env['COMMANDER_NODE_OPTIONS'];
var execArgv = process.execArgv || [];
if (commanderNodeOptions && commanderNodeOptions !== null && commanderNodeOptions.length > 0) {
execArgv = execArgv.concat(commanderNodeOptions.split(' '));
}
return execArgv;
};

/**
* Normalize `args`, splitting joined short flags. For example
* the arg "-abc" is equivalent to "-a -b -c".
Expand Down
20 changes: 20 additions & 0 deletions test/test.command.getExecutableArguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var program = require('../')
, should = require('should');

program.command('foo');

// empty current execArgv
process.execArgv = [];
// in order to run this test properly, COMMANDER_NODE_OPTIONS Environment Variable have to be not defined.

program.getExecutableArguments().should.deepEqual([]);

// lets add some execution arguments to execArgv
process.execArgv = ["--harmony"];
// it should be equal to process.execArgv because of our COMMANDER_NODE_OPTIONS haven't been set yet.
program.getExecutableArguments().should.deepEqual(["--harmony"]);

// set COMMANDER_NODE_OPTIONS environment variable
process.env["COMMANDER_NODE_OPTIONS"] = "--max-old-space-size=8192";
// it should be equal to execArgv and COMMANDER_NODE_OPTIONS combined.
program.getExecutableArguments().should.deepEqual(["--harmony", "--max-old-space-size=8192"]);