-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
refactor(options): Move options from createConfig to normalizeOptions #2174
refactor(options): Move options from createConfig to normalizeOptions #2174
Conversation
|
Codecov Report
@@ Coverage Diff @@
## next #2174 +/- ##
==========================================
- Coverage 93.57% 93.23% -0.35%
==========================================
Files 33 33
Lines 1245 1256 +11
Branches 363 372 +9
==========================================
+ Hits 1165 1171 +6
- Misses 71 79 +8
+ Partials 9 6 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## next #2174 +/- ##
==========================================
+ Coverage 93.88% 94.02% +0.14%
==========================================
Files 34 36 +2
Lines 1276 1323 +47
Branches 363 379 +16
==========================================
+ Hits 1198 1244 +46
+ Misses 71 70 -1
- Partials 7 9 +2
Continue to review full report at Codecov.
|
0965fbc
to
eaf36fe
Compare
/cc @evilebottnawi @hiroppy This is ready for review. I've moved many things from |
|
||
if (options.open && !options.openPage) { | ||
options.openPage = ''; | ||
// eslint-disable-next-line no-undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems unnecessary. Or if we need it, We'll be able move this rule to .eslintrc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is necessary, but I moved to the top of the createConfig
file for convenience in this file. Let's remove the no-undefined
requirement in another PR.
lib/utils/normalizeOptions.js
Outdated
}); | ||
|
||
if (!options.publicPath) { | ||
// eslint-disable-next-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was there originally, but I don't know why. eslint is fine without it.
lib/utils/normalizeOptions.js
Outdated
options.inline = true; | ||
} | ||
|
||
// ---- The options below were already here, they are not breaking changes ---- // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, these comments were just helping me stay organized while working on this
@@ -210,131 +209,11 @@ describe('createConfig', () => { | |||
expect(config).toMatchSnapshot(); | |||
}); | |||
|
|||
it('publicPath option (not specify)', () => { | |||
const config = createConfig(webpackConfig, argv, { port: 8080 }); | |||
// removed: publicPath tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
||
expect(config).toMatchSnapshot(); | ||
}); | ||
// removed: watchOptions tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
||
expect(config).toMatchSnapshot(); | ||
}); | ||
// removed: contentBase tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
/cc @evilebottnawi @hiroppy Can you review this? I've moved most options from I've realized that one difficulty with the approach of merging the compiler's |
I wanna wait for #2202 because this pr is related is-absolute-url. |
Agree. I hope so. |
lib/utils/createConfig.js
Outdated
const isAbsoluteUrl = require('is-absolute-url'); | ||
/* eslint-disable | ||
no-undefined | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid this in favor eslint-disable-next-line
if (argv.bonjour) { | ||
options.bonjour = true; | ||
} | ||
|
||
if (argv.host && (argv.host !== 'localhost' || !options.host)) { | ||
if (argv.host) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we remove && (argv.host !== 'localhost' || !options.host)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not have to make this change now, but we need to carefully rethink how we handle the options: host
, port
, and socket
, since these are relevant for the listen
method.
The logic in && (argv.host !== 'localhost' || !options.host)
is made difficult by the fact that localhost
is the CLI default, so we can't tell if the user explicitly asked for localhost
or if it was set by default:
webpack-dev-server/bin/options.js
Line 175 in eab6acd
default: 'localhost', |
My proposal is:
Don't set default values for the CLI options host or port. I have done this in webpack-cli serve
:
https://github.com/webpack/webpack-cli/blob/44d0fb01f47852b4dfc7423b8e1dfa6c51872e55/packages/serve/flags.js
Have a clear hierarchy for which value gets used. The order of precedence should be:
- CLI value
- webpackConfig.devServer value
- default value
You can see I have implemented this order of precedence in these lines:
https://github.com/webpack/webpack-cli/pull/1011/files#diff-24921f08fe12bbbb2c25f5ed41d757b4R19-R23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, i think we should keep https://github.com/webpack/webpack-cli/blob/44d0fb01f47852b4dfc7423b8e1dfa6c51872e55/packages/serve/flags.js on our side, because when we want add cli option it is require change something on webpack-cli side, it is not good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, i think we should keep https://github.com/webpack/webpack-cli/blob/44d0fb01f47852b4dfc7423b8e1dfa6c51872e55/packages/serve/flags.js on our side, because when we want add cli option it is require change something on webpack-cli side, it is not good
I agree, but I don't think we should move it yet because it will be easier to finish implementing webpack-cli serve
with the flags at webpack-cli
, then we move it just before release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. webpack-cli will work with webpack-dev-server@3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that webpack-cli serve
could just install the latest webpack-dev-server
as a dependency (https://github.com/webpack/webpack-cli/pull/1011/files#diff-e630bd2ce7c76bdd3674ca4624f13b7fR18). Is that not what we want? I think it could be difficult to make refactored webpack-cli serve
work with webpack-dev-server@3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Loonride webpack-cli
should not have webpack-dev-server
in deps, they should use peerDependenciesMeta
with optional: true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes
Because opn was renamed to open.
* feat(server): add stdin for api * test(stdin): switch to async await tests for stdin * test(cli): use await timer
105fdf9
to
c674e87
Compare
c54ae99
to
edfcfd6
Compare
4408469
to
dc1c72f
Compare
d14892a
to
5f1ad3b
Compare
For Bugs and Features; did you add new tests?
Not yet
Motivation / Use-Case
Currently conceptualizing how options handling should be moved into the API. There will be many minor breaking changes, but I think they will all ultimately be for the better.
Breaking Changes
Read the comments in
normalizeOptions
.Additional Info