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

special-case parsing of "require" in unparseNodeArgs(); closes #4035 #4063

Merged
merged 1 commit into from Oct 13, 2019
Merged
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
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 @@ -132,5 +132,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'
]);
});
});
});