Skip to content

Commit e9c036c

Browse files
committed
special-case parsing of "require" in unparseNodeArgs(); closes #4035 (#4063)
Signed-off-by: Christopher Hiller <[email protected]>
1 parent 954cf0b commit e9c036c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: lib/cli/node-flags.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ exports.impliesNoTimeouts = flag => debugFlags.has(flag);
6868
/**
6969
* All non-strictly-boolean arguments to node--those with values--must specify those values using `=`, e.g., `--inspect=0.0.0.0`.
7070
* Unparse these arguments using `yargs-unparser` (which would result in `--inspect 0.0.0.0`), then supply `=` where we have values.
71+
* Apparently --require in Node.js v8 does NOT want `=`.
7172
* There's probably an easier or more robust way to do this; fixes welcome
7273
* @param {Object} opts - Arguments object
7374
* @returns {string[]} Unparsed arguments using `=` to specify values
@@ -79,7 +80,9 @@ exports.unparseNodeFlags = opts => {
7980
? args
8081
.join(' ')
8182
.split(/\b/)
82-
.map(arg => (arg === ' ' ? '=' : arg))
83+
.map((arg, index, args) =>
84+
arg === ' ' && args[index - 1] !== 'require' ? '=' : arg
85+
)
8386
.join('')
8487
.split(' ')
8588
: [];

Diff for: test/node-unit/cli/node-flags.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,14 @@ describe('node-flags', function() {
134134
['--v8-numeric-one=1', '--v8-boolean-one', '--v8-numeric-two=2']
135135
);
136136
});
137+
138+
it('should special-case "--require"', function() {
139+
// note the only way for this to happen IN REAL LIFE is if you use "--require esm";
140+
// mocha eats all --require args otherwise.
141+
expect(unparseNodeFlags({require: 'mcrib'}), 'to equal', [
142+
'--require',
143+
'mcrib'
144+
]);
145+
});
137146
});
138147
});

0 commit comments

Comments
 (0)