From 085813ead2f1b90ea7e555b33e5fb81cb6ac372e Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Tue, 28 Apr 2020 16:49:27 +0900 Subject: [PATCH] fix: remove lazy and filename options --- bin/cli-flags.js | 5 -- bin/options.js | 4 - examples/cli/lazy/README.md | 19 ----- examples/cli/lazy/app.js | 12 --- examples/cli/lazy/webpack.config.js | 10 --- lib/Server.js | 9 +-- lib/options.json | 18 ----- lib/utils/createConfig.js | 8 -- test/Validation.test.js | 20 ----- test/__snapshots__/Validation.test.js.snap | 2 +- .../schema/webpack.config.no-dev-stats.js | 2 - test/options.test.js | 18 ----- test/ports-map.js | 1 - test/server/lazy-option.test.js | 30 -------- test/server/open-option.test.js | 2 +- .../WebsocketServer.test.js.snap | 2 +- .../__snapshots__/createConfig.test.js.snap | 74 ------------------- test/server/utils/createConfig.test.js | 58 --------------- 18 files changed, 4 insertions(+), 290 deletions(-) delete mode 100644 examples/cli/lazy/README.md delete mode 100644 examples/cli/lazy/app.js delete mode 100644 examples/cli/lazy/webpack.config.js delete mode 100644 test/server/lazy-option.test.js diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 973cee7ae0..4448e2b7f8 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -14,11 +14,6 @@ module.exports = { type: Boolean, describe: 'Broadcasts the server via ZeroConf networking on start', }, - { - name: 'lazy', - type: Boolean, - describe: 'Lazy', - }, { name: 'liveReload', type: Boolean, diff --git a/bin/options.js b/bin/options.js index 276468c2c3..a5669cabab 100644 --- a/bin/options.js +++ b/bin/options.js @@ -16,10 +16,6 @@ const options = { type: 'boolean', describe: 'Broadcasts the server via ZeroConf networking on start', }, - lazy: { - type: 'boolean', - describe: 'Lazy', - }, liveReload: { type: 'boolean', describe: 'Enables/Disables live reloading on changing files', diff --git a/examples/cli/lazy/README.md b/examples/cli/lazy/README.md deleted file mode 100644 index 2547ffab4f..0000000000 --- a/examples/cli/lazy/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# CLI: Lazy Option - -With the `lazy` option enabled, `webpack-dev-server` does **not** watch the -bundle files, nor does it automatically recompile them or refresh the browser. -Instead, it only compiles after you manually refresh the page. - -```shell -npm run webpack-dev-server -- --open --lazy --no-inline -``` - -## What should happen - -1. The script should open `http://localhost:8080/` in your default browser. -2. You should see the text on the page itself change to read `Success!`. -3. Change something in `app.js` and save. -4. You should not see any changes in the console/terminal output. -5. You should not see any changes in the browser. -6. Refresh the page. -7. You should see compilation in the console/terminal and changes in the browser. diff --git a/examples/cli/lazy/app.js b/examples/cli/lazy/app.js deleted file mode 100644 index bc127811c7..0000000000 --- a/examples/cli/lazy/app.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -const target = document.querySelector('#target'); - -target.classList.add('pass'); -target.innerHTML = 'Success!'; - -// This results in a warning: -// if(!window) require("./" + window + "parseable.js"); - -// This results in an error: -// if(!window) require("test"); diff --git a/examples/cli/lazy/webpack.config.js b/examples/cli/lazy/webpack.config.js deleted file mode 100644 index e0e5363925..0000000000 --- a/examples/cli/lazy/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -// our setup function adds behind-the-scenes bits to the config that all of our -// examples need -const { setup } = require('../../util'); - -module.exports = setup({ - context: __dirname, - entry: './app.js', -}); diff --git a/lib/Server.js b/lib/Server.js index 37cdd61f17..41beaae026 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -50,10 +50,6 @@ if (!process.env.WEBPACK_DEV_SERVER) { class Server { constructor(compiler, options = {}, _log) { - if (options.lazy && !options.filename) { - throw new Error("'filename' option must be set in lazy mode."); - } - validateOptions(schema, options, 'webpack Dev Server'); this.compiler = compiler; @@ -763,10 +759,7 @@ class Server { } showStatus() { - const suffix = - this.options.inline !== false || this.options.lazy === true - ? '/' - : '/webpack-dev-server/'; + const suffix = this.options.inline !== false ? '/' : '/webpack-dev-server/'; const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`; status( diff --git a/lib/options.json b/lib/options.json index 3e7d05214c..c21e362b14 100644 --- a/lib/options.json +++ b/lib/options.json @@ -94,19 +94,6 @@ "type": "string" } }, - "filename": { - "anyOf": [ - { - "type": "string" - }, - { - "instanceof": "RegExp" - }, - { - "instanceof": "Function" - } - ] - }, "fs": { "type": "object" }, @@ -192,9 +179,6 @@ } ] }, - "lazy": { - "type": "boolean" - }, "liveReload": { "type": "boolean" }, @@ -445,7 +429,6 @@ "contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)", "disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)", "features": "should be {Array}", - "filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserverfilename-)", "fs": "should be {Object} (https://github.com/webpack/webpack-dev-middleware#fs)", "headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverheaders-)", "historyApiFallback": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback)", @@ -458,7 +441,6 @@ "injectHot": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverinjecthot)", "inline": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverinline)", "key": "should be {String|Buffer}", - "lazy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlazy-)", "liveReload": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlivereload-)", "log": "should be {Function}", "logLevel": "should be {String} and equal to one of the allowed values\n\n [ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]\n\n (https://github.com/webpack/webpack-dev-middleware#loglevel)", diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index e3a06b767e..888fbfd9a1 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -72,10 +72,6 @@ function createConfig(config, argv, { port }) { } } - if (!options.filename && firstWpOpt.output && firstWpOpt.output.filename) { - options.filename = firstWpOpt.output && firstWpOpt.output.filename; - } - if (!options.watchOptions && firstWpOpt.watchOptions) { options.watchOptions = firstWpOpt.watchOptions; } @@ -137,10 +133,6 @@ function createConfig(config, argv, { port }) { options.stats = Object.assign({}, options.stats, { colors: argv.color }); } - if (argv.lazy) { - options.lazy = true; - } - // TODO remove in `v4` if (!argv.info) { options.noInfo = true; diff --git a/test/Validation.test.js b/test/Validation.test.js index 8ff86693ab..8a62b47044 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -76,26 +76,6 @@ describe('Validation', () => { }); }); - describe('filename', () => { - afterEach((done) => { - server.close(() => { - done(); - }); - }); - - it('should allow filename to be a function', () => { - try { - server = new Server(compiler, { filename: () => {} }); - } catch (err) { - if (err === 'ValidationError') { - throw err; - } - - throw new Error("Validation failed and it shouldn't"); - } - }); - }); - describe('checkHost', () => { afterEach((done) => { server.close(() => { diff --git a/test/__snapshots__/Validation.test.js.snap b/test/__snapshots__/Validation.test.js.snap index 374cb086a9..44b622b88f 100644 --- a/test/__snapshots__/Validation.test.js.snap +++ b/test/__snapshots__/Validation.test.js.snap @@ -37,5 +37,5 @@ exports[`Validation validation should fail validation for invalid \`writeToDisk\ 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 { after?, allowedHosts?, before?, bonjour?, ca?, cert?, clientLogLevel?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, features?, filename?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, inline?, key?, lazy?, liveReload?, log?, logLevel?, logTime?, mimeTypes?, noInfo?, onListening?, open?, openPage?, overlay?, pfx?, pfxPassphrase?, port?, profile?, progress?, proxy?, public?, publicPath?, quiet?, reporter?, requestCert?, serveIndex?, serverSideRender?, setup?, sockHost?, sockPath?, sockPort?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, warn?, watchContentBase?, watchOptions?, writeToDisk? }" + object { after?, allowedHosts?, before?, bonjour?, ca?, cert?, clientLogLevel?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, features?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, inline?, key?, liveReload?, log?, logLevel?, logTime?, mimeTypes?, noInfo?, onListening?, open?, openPage?, overlay?, pfx?, pfxPassphrase?, port?, profile?, progress?, proxy?, public?, publicPath?, quiet?, reporter?, requestCert?, serveIndex?, serverSideRender?, setup?, sockHost?, sockPath?, sockPort?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, warn?, watchContentBase?, watchOptions?, writeToDisk? }" `; diff --git a/test/fixtures/schema/webpack.config.no-dev-stats.js b/test/fixtures/schema/webpack.config.no-dev-stats.js index 553607cbe9..5573935934 100644 --- a/test/fixtures/schema/webpack.config.no-dev-stats.js +++ b/test/fixtures/schema/webpack.config.no-dev-stats.js @@ -11,12 +11,10 @@ module.exports = { socket: '_socket', progress: '_progress', publicPath: '_publicPath', - filename: '_filename', hot: '_hot', clientLogLevel: '_clientLogLevel', contentBase: '_contentBase', watchContentBase: '_watchContentBase', - lazy: '_lazy', noInfo: '_noInfo', quiet: '_quiet', https: '_https', diff --git a/test/options.test.js b/test/options.test.js index ce899f8dd4..e0a19e4bfd 100644 --- a/test/options.test.js +++ b/test/options.test.js @@ -163,10 +163,6 @@ describe('options', () => { success: [['before'], []], failure: [false], }, - filename: { - success: ['', new RegExp(''), () => {}], - failure: [false], - }, fs: { success: [ { @@ -219,20 +215,6 @@ describe('options', () => { success: ['', Buffer.from('')], failure: [false], }, - lazy: { - success: [ - { - lazy: true, - filename: '.', - }, - ], - failure: [ - { - lazy: '', - filename: '.', - }, - ], - }, log: { success: [() => {}], failure: [''], diff --git a/test/ports-map.js b/test/ports-map.js index 0917c02e88..00b7676713 100644 --- a/test/ports-map.js +++ b/test/ports-map.js @@ -24,7 +24,6 @@ const portsList = { 'http2-option': 1, 'https-option': 1, 'inline-option': 1, - 'lazy-option': 1, 'liveReload-option': 1, 'mineTypes-option': 1, 'onListening-option': 1, diff --git a/test/server/lazy-option.test.js b/test/server/lazy-option.test.js deleted file mode 100644 index 1d2a660aaf..0000000000 --- a/test/server/lazy-option.test.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const testServer = require('../helpers/test-server'); -const config = require('../fixtures/simple-config/webpack.config'); -const port = require('../ports-map')['lazy-option']; - -describe('lazy option', () => { - afterEach(testServer.close); - - it('without filename option it should throw an error', () => { - expect(() => { - testServer.start(config, { - lazy: true, - port, - }); - }).toThrow(/'filename' option must be set/); - }); - - it('with filename option should not throw an error', (done) => { - testServer.startBeforeCompilation( - config, - { - lazy: true, - filename: 'bundle.js', - port, - }, - done - ); - }); -}); diff --git a/test/server/open-option.test.js b/test/server/open-option.test.js index 76658eb35c..9112521ea1 100644 --- a/test/server/open-option.test.js +++ b/test/server/open-option.test.js @@ -27,7 +27,7 @@ describe('open option', () => { server.close(() => { expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ - "http://localhost:8119/", + "http://localhost:8118/", Object { "wait": false, }, diff --git a/test/server/servers/__snapshots__/WebsocketServer.test.js.snap b/test/server/servers/__snapshots__/WebsocketServer.test.js.snap index 16b78745af..888e58e672 100644 --- a/test/server/servers/__snapshots__/WebsocketServer.test.js.snap +++ b/test/server/servers/__snapshots__/WebsocketServer.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`WebsocketServer should receive connection, send message, and close client 1`] = `"localhost:8130"`; +exports[`WebsocketServer should receive connection, send message, and close client 1`] = `"localhost:8129"`; exports[`WebsocketServer should receive connection, send message, and close client 2`] = ` Array [ diff --git a/test/server/utils/__snapshots__/createConfig.test.js.snap b/test/server/utils/__snapshots__/createConfig.test.js.snap index 9c7daf4ae5..9ddb8fac11 100644 --- a/test/server/utils/__snapshots__/createConfig.test.js.snap +++ b/test/server/utils/__snapshots__/createConfig.test.js.snap @@ -265,48 +265,6 @@ Object { } `; -exports[`createConfig filename option (in devServer config) 1`] = ` -Object { - "filename": "[name]-dev-server-bundle.js", - "hot": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - -exports[`createConfig filename option (in output config) 1`] = ` -Object { - "filename": "[name]-output-bundle.js", - "hot": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - -exports[`createConfig filename option (in webpack config) 1`] = ` -Object { - "filename": "[name]-bundle.js", - "hot": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - exports[`createConfig historyApiFallback option (in devServer config) 1`] = ` Object { "historyApiFallback": true, @@ -599,34 +557,6 @@ Object { } `; -exports[`createConfig lazy option (in devServer config) 1`] = ` -Object { - "hot": true, - "lazy": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - -exports[`createConfig lazy option 1`] = ` -Object { - "hot": true, - "lazy": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - exports[`createConfig liveReload option 1`] = ` Object { "hot": true, @@ -1234,13 +1164,11 @@ Object { "compress": "_compress", "contentBase": "_contentBase", "disableHostCheck": "_disableHostCheck", - "filename": "_filename", "historyApiFallback": "_historyApiFallback", "host": "_foo", "hot": "_hot", "https": "_https", "inline": "_inline", - "lazy": "_lazy", "noInfo": true, "open": "_open", "openPage": "_openPage", @@ -1266,13 +1194,11 @@ Object { "compress": "_compress", "contentBase": "_contentBase", "disableHostCheck": "_disableHostCheck", - "filename": "_filename", "historyApiFallback": "_historyApiFallback", "host": "_foo", "hot": "_hot", "https": "_https", "inline": "_inline", - "lazy": "_lazy", "noInfo": true, "open": "_open", "openPage": "_openPage", diff --git a/test/server/utils/createConfig.test.js b/test/server/utils/createConfig.test.js index 0b519c2bfc..cd8580c76b 100644 --- a/test/server/utils/createConfig.test.js +++ b/test/server/utils/createConfig.test.js @@ -274,42 +274,6 @@ describe('createConfig', () => { expect(config).toMatchSnapshot(); }); - it('filename option (in webpack config)', () => { - const config = createConfig( - Object.assign({}, webpackConfig, { - output: { filename: '[name]-bundle.js' }, - }), - argv, - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - - it('filename option (in output config)', () => { - const config = createConfig( - Object.assign({}, webpackConfig, { - output: { filename: '[name]-output-bundle.js' }, - }), - argv, - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - - it('filename option (in devServer config)', () => { - const config = createConfig( - Object.assign({}, webpackConfig, { - devServer: { filename: '[name]-dev-server-bundle.js' }, - }), - argv, - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - it('watchOptions option (in output config)', () => { const config = createConfig( Object.assign({}, webpackConfig, { @@ -474,28 +438,6 @@ describe('createConfig', () => { expect(config).toMatchSnapshot(); }); - it('lazy option', () => { - const config = createConfig( - webpackConfig, - Object.assign({}, argv, { lazy: true }), - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - - it('lazy option (in devServer config)', () => { - const config = createConfig( - Object.assign({}, webpackConfig, { - devServer: { lazy: true }, - }), - argv, - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - it('info option', () => { const config = createConfig( webpackConfig,