-
-
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, tested that and it appears to work in all cases :).
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.
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
portfinder
on the wiki I can do so as soon as the PR is merged.What kind of change does this PR introduce?
Because
portfinder
is async,startDevServer
had 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.