Skip to content

Commit

Permalink
refactor: remove CLI progress and move progress option into client (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ylemkimon authored Nov 26, 2020
1 parent 98c68bf commit ecf2fe1
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 301 deletions.
24 changes: 16 additions & 8 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ module.exports = {
negative: true,
},
{
name: 'profile',
name: 'client-progress',
type: Boolean,
describe: 'Print compilation profile data for progress steps',
},
{
name: 'progress',
type: Boolean,
describe: 'Print compilation progress in percentage',
describe: 'Print compilation progress in percentage in the browser',
group: BASIC_GROUP,
processor(opts) {
opts.client = opts.client || {};
opts.client.progress = opts.clientProgress;
delete opts.clientProgress;
},
},
{
name: 'hot-only',
type: Boolean,
describe: 'Do not refresh page if HMR fails',
group: ADVANCED_GROUP,
processor(opts) {
opts.hot = 'only';
delete opts.hotOnly;
},
},
{
name: 'setup-exit-signals',
Expand Down Expand Up @@ -73,6 +77,11 @@ module.exports = {
group: DISPLAY_GROUP,
describe:
'Log level in the browser (none, error, warn, info, log, verbose)',
processor(opts) {
opts.client = opts.client || {};
opts.client.logging = opts.clientLogging;
delete opts.clientLogging;
},
},
{
name: 'https',
Expand Down Expand Up @@ -106,7 +115,6 @@ module.exports = {
describe: 'Enable gzip compression',
group: RESPONSE_GROUP,
},
// findPort is currently not set up
{
name: 'port',
type: Number,
Expand Down
114 changes: 0 additions & 114 deletions bin/options.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/cli/progress/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { setup } = require('../../util');
module.exports = setup({
context: __dirname,
entry: './app.js',
devServer: {
client: {
progress: true,
},
});
12 changes: 3 additions & 9 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Server {
this.options
);

if (this.options.progress) {
if (this.options.client.progress) {
this.setupProgressPlugin();
}
this.setupHooks();
Expand All @@ -83,12 +83,6 @@ class Server {
}

setupProgressPlugin() {
// for CLI output
new webpack.ProgressPlugin({
profile: !!this.options.profile,
}).apply(this.compiler);

// for browser console output
new webpack.ProgressPlugin((percent, msg, addInfo) => {
percent = Math.floor(percent * 100);

Expand Down Expand Up @@ -569,8 +563,8 @@ class Server {
this.sockWrite([connection], 'liveReload');
}

if (this.options.progress) {
this.sockWrite([connection], 'progress', this.options.progress);
if (this.options.client.progress) {
this.sockWrite([connection], 'progress', this.options.client.progress);
}

if (this.options.clientOverlay) {
Expand Down
11 changes: 3 additions & 8 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
},
"logging": {
"enum": ["none", "error", "warn", "info", "log", "verbose"]
},
"progress": {
"type": "boolean"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -292,12 +295,6 @@
}
]
},
"profile": {
"type": "boolean"
},
"progress": {
"type": "boolean"
},
"proxy": {
"anyOf": [
{
Expand Down Expand Up @@ -408,8 +405,6 @@
"openPage": "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devserveropenpage)",
"overlay": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserveroverlay)",
"port": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserverport)",
"profile": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverprofile)",
"progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverprogress---cli-only)",
"proxy": "should be {Object|Array} (https://webpack.js.org/configuration/dev-server/#devserverproxy)",
"public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublic)",
"setupExitSignals": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserversetupexitsignals)",
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/Validation.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ exports[`Validation validation should fail validation for invalid \`static\` con
exports[`Validation validation should fail validation for no additional properties 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property 'additional'. These properties are valid:
object { bonjour?, client?, compress?, dev?, firewall?, headers?, historyApiFallback?, host?, hot?, http2?, https?, injectClient?, injectHot?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, setupExitSignals?, static?, stdin?, transportMode?, useLocalIp? }"
object { bonjour?, client?, compress?, dev?, firewall?, headers?, historyApiFallback?, host?, hot?, http2?, https?, injectClient?, injectHot?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, proxy?, public?, setupExitSignals?, static?, stdin?, transportMode?, useLocalIp? }"
`;
25 changes: 0 additions & 25 deletions test/cli/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,6 @@ runCLITest('CLI', () => {
.catch(done);
});

it('--progress', (done) => {
testBin('--progress')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('100%');
// should not profile
expect(output.stderr).not.toContain(
'ms after chunk modules optimization'
);
done();
})
.catch(done);
});

it('--progress --profile', (done) => {
testBin('--progress --profile')
.then((output) => {
expect(output.exitCode).toEqual(0);
// should profile
expect(output.stderr).toContain('after chunk modules optimization');
done();
})
.catch(done);
});

it('--bonjour', (done) => {
testBin('--bonjour')
.then((output) => {
Expand Down
4 changes: 4 additions & 0 deletions test/client/utils/__snapshots__/createSocketUrl.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`createSocketUrl should return the url when __resourceQuery is ?test 1`] = `"/ws"`;

exports[`createSocketUrl should return the url when __resourceQuery is file://filename 1`] = `"file://filename/ws"`;

exports[`createSocketUrl should return the url when __resourceQuery is http://0.0.0.0 1`] = `"http://localhost/ws"`;

exports[`createSocketUrl should return the url when __resourceQuery is http://127.0.0.1 1`] = `"http://127.0.0.1/ws"`;
Expand All @@ -22,6 +24,8 @@ exports[`createSocketUrl should return the url when __resourceQuery is undefined

exports[`createSocketUrl should return the url when the current script source is ?test 1`] = `"/ws"`;

exports[`createSocketUrl should return the url when the current script source is file://filename 1`] = `"file://filename/ws"`;

exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http://localhost/ws"`;

exports[`createSocketUrl should return the url when the current script source is http://127.0.0.1 1`] = `"http://127.0.0.1/ws"`;
Expand Down
4 changes: 1 addition & 3 deletions test/client/utils/createSocketUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ describe('createSocketUrl', () => {
'https://localhost:123',
'http://user:pass@[::]:8080',
'http://127.0.0.1',
// TODO: comment out after the major release
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
// 'file://filename',
'file://filename',
// eslint-disable-next-line no-undefined
undefined,
];
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/Progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ describe('client progress', () => {
port,
host: '0.0.0.0',
hot: true,
progress: true,
client: {
progress: true,
},
};

// we need a delay between file writing and the start
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/schema/webpack.config.no-dev-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
devServer: {
host: '_foo',
public: '_public',
progress: '_progress',
publicPath: '_publicPath',
hot: '_hot',
clientLogging: '_clientLogging',
Expand Down
18 changes: 10 additions & 8 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ describe('options', () => {
port: null,
},
},
{
client: {
progress: false,
},
},
],
failure: [
'whoops!',
Expand All @@ -227,6 +232,11 @@ describe('options', () => {
logging: 'silent',
},
},
{
client: {
progress: '',
},
},
],
},
compress: {
Expand Down Expand Up @@ -355,14 +365,6 @@ describe('options', () => {
success: ['', 0, null],
failure: [false],
},
profile: {
success: [false],
failure: [''],
},
progress: {
success: [false],
failure: [''],
},
proxy: {
success: [
{
Expand Down
2 changes: 0 additions & 2 deletions test/ports-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const portsList = {
WebsocketServer: 1,
TransportMode: 1,
Progress: 1,
'progress-option': 1,
'profile-option': 1,
Iframe: 1,
SocketInjection: 1,
'static-publicPath-option': 1,
Expand Down
Loading

0 comments on commit ecf2fe1

Please sign in to comment.