Skip to content

feat(client): add clientMode option - #1977

Merged
alexander-akait merged 8 commits into
webpack:masterfrom
knagaitsev:clientMode-option
Jun 27, 2019
Merged

feat(client): add clientMode option#1977
alexander-akait merged 8 commits into
webpack:masterfrom
knagaitsev:clientMode-option

Conversation

@knagaitsev

Copy link
Copy Markdown
Contributor
  • 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

codecovBot commented Jun 6, 2019

Copy link
Copy Markdown

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 FilesCoverage Δ
lib/Server.js92.77% <100%> (+0.26%)⬆️
lib/utils/updateCompiler.js100% <100%> (ø)⬆️
lib/utils/getSocketClientPath.js87.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.

@alexander-akaitalexander-akait left a comment

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.

Good work, one note.
/cc @hiroppy

Comment threadlib/options.json Outdated
"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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

CI fails.

options validation clientMode

Error: expect(received).toBeInstanceOf(expected)
Expected constructor: ValidationError
Received constructor: JestAssertionError

@knagaitsev

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

/cc @Loonride need rebase

@alexander-akaitalexander-akait left a comment

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.

One note

Comment threadlib/Server.js
);
}

updateCompiler(this.compiler, this.options);

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.

Why we move this?

Copy link
Copy Markdown
ContributorAuthor

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

alexander-akait
alexander-akait previously approved these changes Jun 10, 2019

@alexander-akaitalexander-akait left a comment

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.

Comment threadtest/e2e/ClientMode.test.js Outdated
describe('sockjs', () => {
beforeAll((done) => {
const options = {
port: 9000,

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.

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

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

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

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.

Why isn't onClose called?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@hiroppytestServer.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
wizardofhogwarts
wizardofhogwarts previously approved these changes Jun 13, 2019
alexander-akait
alexander-akait previously approved these changes Jun 13, 2019
@alexander-akait

Copy link
Copy Markdown
Member

/cc @Loonride need rebase, great job!

@knagaitsev
knagaitsevforce-pushed the clientMode-option branch 3 times, most recently from 302b26a to bdbe023CompareJune 20, 2019 02:02
@knagaitsev

knagaitsev commented Jun 26, 2019

Copy link
Copy Markdown
ContributorAuthor

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

alexander-akait
alexander-akait previously approved these changes Jun 26, 2019

@alexander-akaitalexander-akait left a comment

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.

@knagaitsev

Copy link
Copy Markdown
ContributorAuthor

/cc @evilebottnawi

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

Labels

gsocGoogle Summer of Codescope: ws(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@knagaitsev@hiroppy@alexander-akait@wizardofhogwarts