Skip to content

CLI finds and uses 1st available port when none specified.#685

Merged
SpaceK33z merged 2 commits into
webpack:masterfrom
benwiley4000:find-available-path
Nov 3, 2016
Merged

CLI finds and uses 1st available port when none specified.#685
SpaceK33z merged 2 commits into
webpack:masterfrom
benwiley4000:find-available-path

Conversation

@benwiley4000
Copy link
Copy Markdown
Contributor

@benwiley4000 benwiley4000 commented Nov 3, 2016

Addresses #683.

Please check if the PR fulfills these requirements

  • An example has been added or updated in 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?

  • Docs have been added / updated (for bug fixes / features)

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?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)

Because portfinder is async, startDevServer had to be spun out into a new function.

  • Build related changes
  • CI related changes
  • Other... Please describe:

For details see #683

Does this PR introduce a breaking change?

  • Yes
  • No

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.

@jsf-clabot
Copy link
Copy Markdown

jsf-clabot commented Nov 3, 2016

CLA assistant check
All committers have signed the CLA.

Comment thread bin/webpack-dev-server.js Outdated
// 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;
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

@benwiley4000 benwiley4000 Nov 3, 2016

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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 :).

Copy link
Copy Markdown
Contributor Author

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.

@benwiley4000
Copy link
Copy Markdown
Contributor Author

I'm sorry in my last update I briefly made a horrible typo. 😭 It is fixed now!

@SpaceK33z SpaceK33z merged commit 5bee6bb into webpack:master Nov 3, 2016
@SpaceK33z
Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants