Skip to content

Commit

Permalink
special-case parsing of "require" in unparseNodeArgs(); closes #4035 (#…
Browse files Browse the repository at this point in the history
…4063)

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Oct 18, 2019
1 parent 954cf0b commit e9c036c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/cli/node-flags.js
Expand Up @@ -68,6 +68,7 @@ exports.impliesNoTimeouts = flag => debugFlags.has(flag);
/**
* All non-strictly-boolean arguments to node--those with values--must specify those values using `=`, e.g., `--inspect=0.0.0.0`.
* Unparse these arguments using `yargs-unparser` (which would result in `--inspect 0.0.0.0`), then supply `=` where we have values.
* Apparently --require in Node.js v8 does NOT want `=`.
* There's probably an easier or more robust way to do this; fixes welcome
* @param {Object} opts - Arguments object
* @returns {string[]} Unparsed arguments using `=` to specify values
Expand All @@ -79,7 +80,9 @@ exports.unparseNodeFlags = opts => {
? args
.join(' ')
.split(/\b/)
.map(arg => (arg === ' ' ? '=' : arg))
.map((arg, index, args) =>
arg === ' ' && args[index - 1] !== 'require' ? '=' : arg
)
.join('')
.split(' ')
: [];
Expand Down
9 changes: 9 additions & 0 deletions test/node-unit/cli/node-flags.spec.js
Expand Up @@ -134,5 +134,14 @@ describe('node-flags', function() {
['--v8-numeric-one=1', '--v8-boolean-one', '--v8-numeric-two=2']
);
});

it('should special-case "--require"', function() {
// note the only way for this to happen IN REAL LIFE is if you use "--require esm";
// mocha eats all --require args otherwise.
expect(unparseNodeFlags({require: 'mcrib'}), 'to equal', [
'--require',
'mcrib'
]);
});
});
});

0 comments on commit e9c036c

Please sign in to comment.