Skip to content
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

feat(server): add serverMode option #1937

Merged
merged 7 commits into from
Jun 1, 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

The goal of this option is to allow the user to choose the current server implementation, or provide their own implementation as a path/class.

It is a GSoC Refactor goal: #1860

Breaking Changes

None

Additional Info

@codecov
Copy link

codecov bot commented May 30, 2019

Codecov Report

Merging #1937 into master will decrease coverage by <.01%.
The diff coverage is 92.3%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1937      +/-   ##
=========================================
- Coverage    91.8%   91.8%   -0.01%     
=========================================
  Files          22      23       +1     
  Lines         879     903      +24     
  Branches      276     283       +7     
=========================================
+ Hits          807     829      +22     
- Misses         69      71       +2     
  Partials        3       3
Impacted Files Coverage Δ
lib/Server.js 92.3% <100%> (+0.08%) ⬆️
lib/utils/getSocketServerImplementation.js 89.47% <89.47%> (ø)

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 def98d8...54a8067. 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 job, need some fixes

lib/Server.js Outdated
'via require.resolve(...), or the class itself which extends BaseServer'
);
}
this.ServerImplementation = ServerImplementation;
Copy link
Member

Choose a reason for hiding this comment

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

  1. Let's move this to util getSocketServerImplementation
  2. Don't think we need function
  3. Let's rewrite this on switch

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 function option is good if the user wants to supply an implementation, but their file is exporting multiple things, for example. So like if they want to do:

serverMode: require('./my-implementation').Server

Copy link
Member

Choose a reason for hiding this comment

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

I think better use require.resolve('./my-implementation/Server')
/cc @hiroppy

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine either way:) Currently, it was fixed as require.resolve.

@@ -340,6 +341,15 @@ describe('options', () => {
success: [true],
failure: [''],
},
serverMode: {
success: [
'',
Copy link
Member

Choose a reason for hiding this comment

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

'' should be failure

config,
{
sockPath: '/foo/test/bar/',
serverMode: class MySockJSServer extends BaseServer {
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 being able to pass in class also makes testing easier

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 job, wait @hiroppy review

hiroppy
hiroppy previously approved these changes May 30, 2019
Copy link
Member

@hiroppy hiroppy left a comment

Choose a reason for hiding this comment

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

LGTM with nits. And need to create documentation to webpack.js.org repo.


if (!serverImplFound) {
throw new Error(
"serverMode must be a string denoting a default implementation (eg. 'sockjs'), a full path to " +
Copy link
Member

Choose a reason for hiding this comment

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

nit

- eg
+ e.g.

lib/Server.js Outdated
);
}

this.ServerImplementation = getSocketServerImplementation(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.

I think we should rename variable to this.socketServerImplementation to avoid misleading, we already store value in this.socketServer so let's use socket prefix too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to capitalize first letter to clarify that it is a class.

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 too

lib/Server.js Outdated
}

// this.SocketServerImplementation is a class, so it must be instantiated before use
this.SocketServerImplementation = getSocketServerImplementation(
Copy link
Member

Choose a reason for hiding this comment

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

this.SocketServerImplementation -> this.socketServerImplementation

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.

nit pick 😄

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

Copy link
Member

@hiroppy hiroppy left a comment

Choose a reason for hiding this comment

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

💯

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