Skip to content

fix #752: allow --port 0 again#918

Merged
shellscape merged 3 commits into
webpack:masterfrom
also:port-zero
Jun 14, 2017
Merged

fix #752: allow --port 0 again#918
shellscape merged 3 commits into
webpack:masterfrom
also:port-zero

Conversation

@also
Copy link
Copy Markdown
Contributor

@also also commented May 23, 2017

What kind of change does this PR introduce?

Bugfix for #752

Did you add or update the examples/?

Summary

Fixes the check for options.port and argv.port to allow 0. I rely on the operating system to assign a port so that it is guaranteed to be available and doesn't ever bind to the default 8080. I can't update beyond v2.1.0-beta.10, because after #685 0 is treated the same as not passing the option and triggers portfinder.

Does this PR introduce a breaking change?

It should only change behavior when 0 is passed as the port option.

Other information

The behavior when using port 0 could still be improved. This simply brings back the ability to specify port 0 which existed prior to v2.1.0-beta.11.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2017

Codecov Report

Merging #918 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #918   +/-   ##
======================================
  Coverage    71.3%   71.3%           
======================================
  Files           4       4           
  Lines         453     453           
  Branches      133     133           
======================================
  Hits          323     323           
  Misses        130     130

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a7693c...c9fddf7. Read the comment docs.

Comment thread bin/webpack-dev-server.js
options.port = argv.port === DEFAULT_PORT ? (options.port || argv.port) : (argv.port || options.port);
if(options.port) {
options.port = argv.port === DEFAULT_PORT ? defaultTo(options.port, argv.port) : defaultTo(argv.port, options.port);
if(options.port != null) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not add !=null here because it's not consistant with the current code style.
Should keep if(options.port)

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.

if(options.port) is the source of the bug, because it excludes 0 by relying on "truthiness".

if(options.port != null) ensures that any options.port value except null or undefined is respected.

Would a more explicit check with triple-equals like if(options.port !== null && options.port !== undefined) be in line with the code style?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if(options.port || options.port === 0) ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me that if you're doing a truthy check, you do it as per your code style...but in this case, you specifically want "if not null and not undefined", for which the most idiomatic way is != null.

Why obfuscate the code? This isn't about stylistic (I'm all about style consistency), it's essentially about correctness in this very particular scenario.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in agreement with @Phoenixmatrix and @also

Comment thread bin/webpack-dev-server.js Outdated
return msg;
}

const defaultTo = (v, def) => v == null ? def : v;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no sense in obfuscating parameters here and one-letter variables make me stabby. please do change v to value.

@shellscape shellscape merged commit 1a26ab4 into webpack:master Jun 14, 2017
@also also deleted the port-zero branch June 14, 2017 16:48
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.

4 participants