CLI finds and uses 1st available port when none specified.#685
Conversation
| // that wouldn't throw errors. E.g. both argv port and options port | ||
| // were specified, but since argv port is 8080, options port will be | ||
| // used instead. | ||
| options.port = argv.port === DEFAULT_PORT ? options.port || argv.port : argv.port; |
There was a problem hiding this comment.
There seems to be an error here. If I set the port via options, after this line it results in options.port being undefined.
There was a problem hiding this comment.
Aha, thanks for catching that. I didn't account for the case where options.port is defined but argv.port is not (I forgot since argv used to have a default).
What do you think of just changing it to:
options.port = argv.port === DEFAULT ? (options.port || argv.port) : (argv.port || options.port);? This should account for all cases I believe.
There was a problem hiding this comment.
It's a bit strange semantically when argv.port is not DEFAULT and therefore favored because it's undefined, but we'll still land on options.port in the end.
There was a problem hiding this comment.
Okay, tested that and it appears to work in all cases :).
There was a problem hiding this comment.
My branch has been updated.
9a7535d to
335aa9e
Compare
|
I'm sorry in my last update I briefly made a horrible typo. 😭 It is fixed now! |
|
Thanks! |
Addresses #683.
Please check if the PR fulfills these requirements
examples/(for features)I'm not sure about a new example - is there an easy way to verify that two webpack dev servers are running simultaneously at expected ports? ETA: I imagine this could be tested via a SharedWorker or the localStorage polyfill that does the same thing - allowing two browser tabs to talk to one another. But a system-level test maybe would be better?
As for docs, if it's important to document the use of
portfinderon the wiki I can do so as soon as the PR is merged.What kind of change does this PR introduce?
Because
portfinderis async,startDevServerhad to be spun out into a new function.For details see #683
Does this PR introduce a breaking change?
Only in the sense that if two dev servers are run with no port config, one of them will now use a different port (and work). If someone wanted their server not to work before, now they might be out of luck! Probably not serious enough for a major version number, you know?
Note: There was one situation where a real breaking change could take place but it was mitigated.