Skip to content

feat(client): add clientMode option #1977

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
merged 8 commits into from
Jun 27, 2019

Conversation

knagaitsev
Copy link
Collaborator

  • 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?

Yes

Motivation / Use-Case

This option makes it possible to provide a custom client socket implementation.

This mimics the serverMode implementation with one exception: clientMode does not accept a function (specifically, a class, as serverMode does). The reason for this is that it is not possible (or just pointlessly complex and impractical) to make a class within an executing server-side script, then pass it along to the client. There must be a path to the file that module.exports the client implementation.

Since the only thing we really need to pass to the client is the path to the implementation, I made the helper getSocketClientPath. There is no reason for a helper to be returning the whole ClientImplementation class, since it is not actually used server-side.

Breaking Changes

None

Additional Info

One consideration:
Should more error handling be added to confirm that the serverMode/clientMode are implemented correctly? For example, there could be some functionality in the Dev Server that tests the contents of ClientImplementation.protoype, to see if all the required functions are implemented.

@codecov
Copy link

codecov bot commented Jun 6, 2019

Codecov Report

Merging #1977 into master will increase coverage by 0.03%.
The diff coverage is 90.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1977      +/-   ##
==========================================
+ Coverage   92.71%   92.75%   +0.03%     
==========================================
  Files          31       32       +1     
  Lines        1181     1201      +20     
  Branches      329      335       +6     
==========================================
+ Hits         1095     1114      +19     
- Misses         82       83       +1     
  Partials        4        4
Impacted Files Coverage Δ
lib/Server.js 92.77% <100%> (+0.26%) ⬆️
lib/utils/updateCompiler.js 100% <100%> (ø) ⬆️
lib/utils/getSocketClientPath.js 87.5% <87.5%> (ø)

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 1437625...c4453fd. Read the comment docs.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good work, one note.
/cc @hiroppy

lib/options.json Outdated
@@ -390,6 +393,7 @@
"ca": "should be {String|Buffer}",
"cert": "should be {String|Buffer}",
"clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
"clientMode": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverclientmode-)",
Copy link
Member

Choose a reason for hiding this comment

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

extra - at end of line

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to modify this? L437 was fixed it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we need to modify this? L437 was fixed it.

Yes, I mistakenly did not remove that -, but they should be removed in both places.

hiroppy
hiroppy previously approved these changes Jun 6, 2019
@hiroppy
Copy link
Member

hiroppy commented Jun 6, 2019

CI fails.

options validation clientMode

Error: expect(received).toBeInstanceOf(expected)

Expected constructor: ValidationError
Received constructor: JestAssertionError

@knagaitsev
Copy link
Collaborator Author

getSocketClientPath(options) is only called if inline is enabled, so the clientMode option is only validated by it when inline is enabled. Should I keep it as is, move it outside the inline check so that the clientMode option gets validated anyway, or throw an error when clientMode is provided without inline mode enabled?

@knagaitsev
Copy link
Collaborator Author

I'm now wondering why this empty string is passing this test: https://github.com/webpack/webpack-dev-server/blob/master/test/options.test.js#L350. Because that should not be throwing a ValidationError, it should be throwing an error later on. Problem with options.test.js?

@alexander-akait
Copy link
Member

/cc @Loonride need rebase

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

One note

);
}

updateCompiler(this.compiler, this.options);
Copy link
Member

Choose a reason for hiding this comment

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

Why we move this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@evilebottnawi I reorganized it to have the default setting for serverMode and clientMode together above that. updateCompiler uses this.options.clientMode, so the default setting for it must be set before updateCompiler is called. It can be switched back, I just thought it would be nice to have default setting for serverMode and clientMode right next to one another

@knagaitsev knagaitsev force-pushed the clientMode-option branch from db1067c to ee8a4b2 Compare June 8, 2019 20:04
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

/cc @hiroppy

describe('sockjs', () => {
beforeAll((done) => {
const options = {
port: 9000,
Copy link
Member

Choose a reason for hiding this comment

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

Sorry but I change tests system. See #2005.
And I'll merge #2007 asap. Please change 🙏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hiroppy done

"liveReload",
"[WDS] Live Reloading enabled.",
"hash",
"ok",
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't onClose called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hiroppy testServer.close happens after the snapshot is tested, so the client is not closed before that. I could maybe rearrange that to test onClose as well.

hiroppy
hiroppy previously approved these changes Jun 11, 2019
@alexander-akait
Copy link
Member

/cc @Loonride need rebase, great job!

@knagaitsev knagaitsev force-pushed the clientMode-option branch 3 times, most recently from 302b26a to bdbe023 Compare June 20, 2019 02:02
@knagaitsev
Copy link
Collaborator Author

knagaitsev commented Jun 26, 2019

@evilebottnawi @hiroppy Can I get a final review for this?

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

/cc @hiroppy

@knagaitsev
Copy link
Collaborator Author

/cc @evilebottnawi

@alexander-akait alexander-akait merged commit 6141018 into webpack:master Jun 27, 2019
knagaitsev added a commit to knagaitsev/webpack-dev-server that referenced this pull request Jul 31, 2019
@knagaitsev knagaitsev added gsoc Google Summer of Code scope: ws(s) labels Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc Google Summer of Code scope: ws(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants