-
-
Notifications
You must be signed in to change notification settings - Fork 628
fix(serve): set client port when using default port #2147
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
Conversation
We need to fix CI here 😞 |
a950158
to
043e5c9
Compare
Hmm the tests didn't fail for me locally, but the CI logs indicate it's likely related to my code changes to the types. I have pushed a new commit that (hopefully) fixes the tests in CI - they all work locally for me. |
Codecov Report
@@ Coverage Diff @@
## master #2147 +/- ##
==========================================
- Coverage 68.41% 68.34% -0.08%
==========================================
Files 72 72
Lines 2340 2344 +4
Branches 516 518 +2
==========================================
+ Hits 1601 1602 +1
- Misses 739 742 +3
Continue to review full report at Codecov.
|
The tests now passed! The coverage checks failed because I didn't add tests, since the tests only run on webpack-dev-server@3 and my code changes only apply to webpack-dev-server@4 |
Yes we are enabling tests for v4 in #2155 |
What kind of change does this PR introduce?
Resolves webpack/webpack-dev-server#2873. This fixes a regression where
webpack serve
is not equivalent to the olderwebpack-dev-server
command.Did you add tests for your changes?
No, since the serve plugin's tests only run on webpack-dev-server@3 and my changes only apply to webpack-dev-server@4. If there is a way to run certain tests against different versions of webpack-dev-server, I'm happy to add tests.
If relevant, did you update the documentation?
N/A
Summary
webpack-dev-server adds a new entry point which loads the webpack-dev-server webpack client. The entry has a resource query which determines the host, port, and protocol of the websocket connection. That resource query must be created synchronously, since modifying the entry points must be done synchronously before webpack starts compilation. The problem is that
findPort()
(used within webpack-dev-server to find a default server port) is asynchronous.webpack-dev-server@3 worked around this issue by having the webpack-dev-server CLI delay starting webpack until
findPort()
finishes. The following code shows where this used to happen:https://github.com/webpack/webpack-dev-server/blob/4ab1f21bc85cc1695255c739160ad00dc14375f1/bin/webpack-dev-server.js#L165-L167
https://github.com/webpack/webpack-dev-server/blob/4ab1f21bc85cc1695255c739160ad00dc14375f1/lib/utils/processOptions.js#L30-L34
When the webpack-dev-server CLI was abandoned in favor of
webpack serve
, this behavior was lost. As a result, the webpack-dev-server socket client attempts to connect to the wrong port when you let webpack-dev-server find a default port for you.I made the code change here in webpack-cli because it is the equivalent to the previous webpack-dev-server CLI code. I do not believe that any code change to webpack-dev-server could solve this issue, since the entries must be modified synchronously but findPort() is asynchronous.
Does this PR introduce a breaking change?
I don't think so. The
startDevServer
function within@webpack-cli/serve
has changed to return a promise, but its use seems to be entirely internal to webpack-cli and so I don't consider it part of the package's public API.Other information