Skip to content

refactor: transportMode and client URL options #3260

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

Merged

Conversation

alexander-akait
Copy link
Member

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

WIP

Motivation / Use-Case

I want to split #3181 on multiple PRs/commits

  1. We will implement (this PR) { options.transportMode: { server: { type: 'ws', options: { path: '/ws' } } } } and { options.transportMode: { client: { type: 'ws', options: { path: '/ws' } } } }, now we can pass options to websocket server, also should fix devServer.sockPath #2535, so you can pass
  2. Move client.host/client.port to options.transportMode.client.options
  3. Union transportMode and client options we need discussion here how better name this option, we have server (i.e. all top level options like host, port and etc), websocket server (i.e. ws/sockjs packages and options, for example options.transportMode.server.options.path) and client (i.e. websocket API/sockjs client and options for client like client.overlay/client.logging/etc), and here we have problems our options mixed between options.transportMode.client and top level client (step 2 partial fix it, but I think we can simplify it and do it better)

/cc @webpack/cli-team

Breaking Changes

Yes

Additional Info

  • Need fix CLI args
  • Need fix examples and docs

evenstensberg
evenstensberg previously approved these changes May 6, 2021
Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

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

Lgtm. Nice comments on new code as well👏🏽

Copy link
Member

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

Looks great! Let's fix CI 🚀

@alexander-akait
Copy link
Member Author

I found better way without big changes

@alexander-akait
Copy link
Member Author

Hard...

Now we have more clearly options:

  • webSocketServer allow to set host/port/path (host and port is not supported by sockjs), it allow to run socket server even on other host and port, not only change path, by default we use noServer mode, but if you provide host or port it will be separate server, it is really very flexible
  • Also we have client.host/client.port/client.path, it change only URL to socket server, it is not change websocket server options, i.e. if you set webSocketServer.options.path: '/custom' it will create web socket server and will accept connection on by this path, if you set client.path: '/custom' it just change URL to websocket server i.e. new WebSocket(url) in browser. DO we really need this (maybe we have cases with proxy?)?

It's all pretty flexible but may be slightly misleading. Maybe somebody have ideas how to improve this (renaming/clear description/etc).

@alexander-akait
Copy link
Member Author

/cc @snitin315 maybe you have ideas too

@snitin315
Copy link
Member

The change looks good to me. I think we can roll it in next beta release for more feedback and see if developers files any complaints or finds it confusing.

@alexander-akait
Copy link
Member Author

Maybe we don't need client.host/client.port/client.path, I tried to find case where it can be useful...

@alexander-akait
Copy link
Member Author

@snitin315 Found cases, I think we need better name, maybe client.webSocketHost/etc, but still misleading, we need to find an explicit name that indicates that this does not change the web socket server host/port/path, but used only for creating URL to websocket server, i.e. https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket

@alexander-akait
Copy link
Member Author

I'll try to figure it out by tomorrow, I will be glad for any help, we need to finish the release as soon as possible...

@snitin315
Copy link
Member

snitin315 commented May 14, 2021

@snitin315 Found cases, I think we need better name, maybe client.webSocketHost/etc, but still misleading, we need to find an explicit name that indicates that this does not change the web socket server host/port/path, but used only for creating URL to websocket server, i.e. https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket

Maybe webSocketURLHost or webSocketURLExclusiveHost etc and we can add in the description it's only for URL. Anyway let's do it separate I can create PR for the same. Let me know.

In the meantime, I will fix the tests here.

@snitin315 snitin315 force-pushed the refactor-client-and-server-transport-mode-options branch from b8ba623 to b1bb5c1 Compare May 14, 2021 10:13
@snitin315 snitin315 force-pushed the refactor-client-and-server-transport-mode-options branch 2 times, most recently from e08f597 to d6f9a30 Compare May 14, 2021 12:09
@alexander-akait
Copy link
Member Author

alexander-akait commented May 14, 2021

Yep, let's solve separately, also we need refactor our logic to inject and remove public in favor webSocketURLHost/etc

@snitin315 snitin315 force-pushed the refactor-client-and-server-transport-mode-options branch from d6f9a30 to b4e38a0 Compare May 14, 2021 12:14
snitin315 and others added 2 commits May 14, 2021 15:16
…port-mode-options' into refactor-client-and-server-transport-mode-options

# Conflicts:
#	test/server/__snapshots__/transportMode-option.test.js.snap.webpack5
@snitin315 snitin315 force-pushed the refactor-client-and-server-transport-mode-options branch from b4e38a0 to 4d5307b Compare May 14, 2021 12:17
@alexander-akait
Copy link
Member Author

I will finish PR, we need rewrite some tests + add more them, give me 30-40 minutes

@@ -9,12 +9,9 @@ module.exports = {
entry: resolve(__dirname, './foo.js'),
devServer: {
client: {
transport: 'sockjs',
Copy link
Member Author

Choose a reason for hiding this comment

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

@snitin315 Again, here you do the same problem as do other developers, client.transport for only client, it is not create sockjs server, we need search better name for this, you should not set sockjs/ws server using this options, it is only if you want create custom web socket client

Copy link
Member

Choose a reason for hiding this comment

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

I see we need configure webSocketServer here.

Copy link
Member Author

@alexander-akait alexander-akait May 14, 2021

Choose a reason for hiding this comment

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

Yep, I am working on it, most of tests are good, anyway we need refactor many tests, I will create roadmap for rc for tests and how we need rewrite them

@alexander-akait alexander-akait force-pushed the refactor-client-and-server-transport-mode-options branch from 4d5307b to 7405bb6 Compare May 14, 2021 14:45
@codecov
Copy link

codecov bot commented May 14, 2021

Codecov Report

Merging #3260 (8e62861) into master (8283a97) will decrease coverage by 0.01%.
The diff coverage is 98.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3260      +/-   ##
==========================================
- Coverage   95.56%   95.54%   -0.02%     
==========================================
  Files          34       34              
  Lines        1241     1258      +17     
  Branches      354      356       +2     
==========================================
+ Hits         1186     1202      +16     
- Misses         51       52       +1     
  Partials        4        4              
Impacted Files Coverage Δ
lib/Server.js 95.62% <ø> (-0.20%) ⬇️
lib/servers/WebsocketServer.js 94.11% <ø> (ø)
lib/utils/getSocketServerImplementation.js 90.47% <88.88%> (ø)
lib/servers/SockJSServer.js 94.73% <100.00%> (+0.61%) ⬆️
lib/utils/DevServerPlugin.js 98.82% <100.00%> (+0.07%) ⬆️
lib/utils/getSocketClientPath.js 100.00% <100.00%> (ø)
lib/utils/normalizeOptions.js 100.00% <100.00%> (ø)

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 8283a97...8e62861. Read the comment docs.

@alexander-akait
Copy link
Member Author

@snitin315 @anshumanv let's finish this firstly before merge other, each rebase is harder and harder

@anshumanv
Copy link
Member

Yep lets focus to get this in first 👍

Copy link
Member

@anshumanv anshumanv left a comment

Choose a reason for hiding this comment

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

👍

@alexander-akait alexander-akait merged commit 7632956 into master May 15, 2021
@alexander-akait alexander-akait deleted the refactor-client-and-server-transport-mode-options branch May 15, 2021 14:37
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.

devServer.sockPath
4 participants