-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow Node arguments to be configured #2272
Conversation
ec5304d
to
1f81b2f
Compare
Hey @maximelkin sorry about the delay in reviewing. At first glance this looks great, though I'd like to play with it a little first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice @maximelkin! I kept writing comments and then looking at other code and realizing I got things wrong… by which I mean to say you really did think through all the angles here.
I've pushed some small tweaks, and left some other comments as well. Let me know what you think.
15d1e19
to
5998865
Compare
5998865
to
8e51406
Compare
Not sure, why tests getting SIGKILL on local machine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your continuing work on this @maximelkin. I think it's nearly there.
Hopefully I've figured out how to make the CI run on pull requests as well.
lib/api.js
Outdated
@@ -15,6 +16,8 @@ const makeDir = require('make-dir'); | |||
const ms = require('ms'); | |||
const chunkd = require('chunkd'); | |||
const Emittery = require('emittery'); | |||
const minimist = require('minimist'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use https://www.npmjs.com/package/yargs-parser instead? It's already in our dependency tree as part of meow
.
(Though it looks like so is minimist
, because Node.js modules, but for less apparent reasons.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I choose minimist, because it has reverse package, maybe there is another package for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon dargs
may work with yargs-parser
too, assuming it also outputs straight-forward objects.
lib/api.js
Outdated
const hasInspect = args.inspect || args['inspect-brk']; | ||
if (hasInspect) { | ||
if (args.inspect && args['inspect-brk']) { | ||
throw new Error('Flags inspect and inspect-brk provided simultaneously'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: check how this ends up being reported.
lib/cli.js
Outdated
@@ -115,6 +116,10 @@ exports.run = async () => { // eslint-disable-line complexity | |||
type: 'boolean', | |||
default: false | |||
}, | |||
'node-arguments': { | |||
type: 'string', | |||
default: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this default? See my comment for normalizeNodeArguments()
.
lib/node-arguments.js
Outdated
* @param {string} cliParams | ||
* @return {object} | ||
*/ | ||
function normalizeNodeArguments(confParams, cliParams) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can assume the arguments may be undefined
, we can use default parameter values:
function normalizeNodeArguments(confParams, cliParams) { | |
function normalizeNodeArguments(confParams = [], cliParams = '') { |
And we can get rid of the JSDoc comment too.
We do need to enforce confParams
is an array.
lib/node-arguments.js
Outdated
function normalizeNodeArguments(confParams, cliParams) { | ||
return omit({ | ||
...minimist(confParams || []), | ||
...minimist(cliParams.split(' ')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there Node.js arguments that take strings? Cause then splitting on the empty string won't work.
lib/node-arguments.js
Outdated
return omit({ | ||
...minimist(confParams || []), | ||
...minimist(cliParams.split(' ')) | ||
}, '_'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the _
returned by minimist
? I'd prefer rest-spread for this:
const { _, ...normalized } = { ...minimist(), ...minimist() };
return normalized;
lib/api.js
Outdated
if (inspectArgIndex === -1) { | ||
return Promise.resolve(execArgv); | ||
} | ||
const mainProcessArgs = minimist(process.execArgv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we cache this? This function runs for every test file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, what I correctly understand you, check please
Great work! Will be so nice to have since Node v12 changed TLS min version and we need |
Hi @maximelkin, I did not have time to look at your changes yet, sorry. |
About passing arguments via cli |
@maximelkin what do you mean by this? I spotted the change of This then led me to think about how we're combining the arguments. I think we should simplify it a little:
This without parsing into objects, though we do need to parse the value to the I guess what may complicate this is the dynamic port assignment when we see |
@maximelkin I've been making a lot of changes over the past few weeks which has caused a lot of merge conflicts here. Sorry about that. I can try and resolve them when I get some time. With regards to parsing |
* Combine values without overwriting duplicates * Use Node.js to parse the argv string Also add a bit more context in the documentation.
@maximelkin I've fixed the merge conflicts and simplified the implementation as per #2272 (comment). Please let me know what you think! |
f1d24ad
to
037cc33
Compare
I was afraid this wouldn't work on Windows though 😢 |
Hello, sorry for long inactivity |
So adding |
I found https://github.com/astur/arrgv which claims to work just like Node.js does. Looking at the implementation in Node.js itself it also does a bunch of validation, which could lead to unexpected errors. So a simple parser is better. And this one gives us arrays which is what we want. Plus, it's tested using AVA 😄 Let's see if CI passes and then let's ship this! |
Fixes #2090
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
--node-arguments
flagsIssueHunt has been backed by the following sponsors. Become a sponsor