From a91f6c1889bdb6897f824f0a6f7c84bcc1092a99 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 12:58:22 -0400 Subject: [PATCH 01/10] reorganzing package.json --- package.json | 68 +++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 9255aeaf35..d45383b11e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,43 @@ { "name": "webpack-dev-server", "version": "2.7.1", - "author": "Tobias Koppers @sokra", "description": "Serves a webpack app. Updates the browser on changes.", + "license": "MIT", + "repository": "webpack/webpack-dev-server", + "author": "Tobias Koppers @sokra", + "homepage": "http://github.com/webpack/webpack-dev-server", + "maintainers": [ + { + "name": "Andrew Powell", + "email": "andrew@shellscape.org", + "url": "shellscape.org" + } + ], + "main": "lib/Server.js", + "bin": "bin/webpack-dev-server.js", + "engines": { + "node": ">=4.7" + }, + "scripts": { + "beautify": "npm run lint -- --fix", + "ci": "npm run cover -- --report lcovonly && npm run test", + "cover": "istanbul cover node_modules/mocha/bin/_mocha", + "lint": "eslint bin lib test examples client/{index,live,socket,sockjs,overlay,webpack.config}.js", + "mocha": "mocha --full-trace --check-leaks", + "posttest": "npm run -s lint", + "prepublish": "npm run -s client-live && npm run -s client-index && npm run -s client-sockjs", + "test": "npm run lint && npm run mocha", + + "client-live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p", + "client-index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p", + "client-sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p" + }, + "files": [ + "lib/", + "bin", + "client/", + "ssl/" + ], "peerDependencies": { "webpack": "^2.2.0 || ^3.0.0" }, @@ -35,6 +70,8 @@ "codecov.io": "^0.1.6", "css-loader": "~0.26.1", "eslint": "^3.4.0", + "eslint-config-webpack": "^1.2.5", + "eslint-plugin-import": "^2.7.0", "file-loader": "~0.10.0", "istanbul": "^0.4.5", "jquery": "^2.2.0", @@ -51,34 +88,5 @@ "url-loader": "~0.5.6", "webpack": "^3.0.0", "ws": "^1.1.1" - }, - "license": "MIT", - "repository": { - "type": "git", - "url": "git://github.com/webpack/webpack-dev-server.git" - }, - "homepage": "http://github.com/webpack/webpack-dev-server", - "main": "lib/Server.js", - "bin": "bin/webpack-dev-server.js", - "engines": { - "node": ">=4.7" - }, - "files": [ - "lib/", - "bin", - "client/", - "ssl/" - ], - "scripts": { - "prepublish": "npm run -s client-live && npm run -s client-index && npm run -s client-sockjs", - "client-live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p", - "client-index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p", - "client-sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p", - "lint": "eslint bin lib test examples client/{index,live,socket,sockjs,overlay,webpack.config}.js", - "beautify": "npm run lint -- --fix", - "test": "mocha --full-trace --check-leaks", - "posttest": "npm run -s lint", - "cover": "istanbul cover node_modules/mocha/bin/_mocha", - "travis": "npm run cover -- --report lcovonly && npm run lint" } } From a9b8b58ae2e42f2aa546ee1319aa7e1e035e36e6 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 12:58:35 -0400 Subject: [PATCH 02/10] reorganzing travis config --- .travis.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b8ae2b1747..a92770c711 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,18 @@ sudo: false branches: only: - master -language: node_js + +language: + node_js + node_js: - - "6" - - "4" -script: npm run travis + - '8' + - '6' + - '4' + +script: + npm run ci + after_success: - cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js - rm -rf ./coverage From 8961bf3289e7961ad56caf0caef8f87375d1a540 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 12:58:54 -0400 Subject: [PATCH 03/10] adding eslint-config-webpack --- .editorconfig | 15 ++++++--------- .eslintrc | 49 +------------------------------------------------ 2 files changed, 7 insertions(+), 57 deletions(-) diff --git a/.editorconfig b/.editorconfig index 60a0bc444e..28e1806f34 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,16 +1,13 @@ -root = true +# editorconfig.org [*] -indent_style = tab -indent_size = 4 charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true -max_line_length = 233 - -[*.json] indent_style = space indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true -[*.md] +[.md] +insert_final_newline = false trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc index a6afa62ce1..78879dd8ca 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,50 +1,3 @@ { - "root": true, - "extends": [ - "eslint:recommended" - ], - "env": { - "node": true, - "mocha": true, - "browser": true, - "es6": true - }, - "rules": { - "quotes": ["error", "double"], - "no-undef": "error", - "brace-style": "error", - "eol-last": "error", - "indent": ["error", "tab", { "SwitchCase": 1 }], - "no-extra-bind": "warn", - "no-empty": "off", - "no-multiple-empty-lines": "error", - "no-multi-spaces": "error", - "no-process-exit": "warn", - "space-in-parens": "error", - "no-trailing-spaces": "error", - "no-unused-vars": "error", - "key-spacing": "error", - "space-infix-ops": "error", - "no-unsafe-negation": "error", - "no-loop-func": "warn", - "space-before-function-paren": ["error", "never"], - "space-before-blocks": "error", - "object-curly-spacing": ["error", "always"], - "keyword-spacing": ["error", { - "after": false, - "overrides": { - "try": {"after": true}, - "else": {"after": true}, - "throw": {"after": true}, - "case": {"after": true}, - "return": {"after": true}, - "finally": {"after": true}, - "do": {"after": true} - } - }], - "no-console": "off", - "valid-jsdoc": "error", - "no-useless-computed-key": "error", - "prefer-const": "error" - } + "extends": "webpack" } From 767b40b8e42747e28d88fcad54493d091025dea7 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 17:17:35 -0400 Subject: [PATCH 04/10] add eslint ignore --- .eslintignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..f30eb6505d --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +examples +test From 5cd8b713ce68ce6407e5ac279bfaf4f23a0094e2 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 17:17:45 -0400 Subject: [PATCH 05/10] linting cleanup --- .eslintrc | 12 +- bin/webpack-dev-server.js | 842 ++++++------ client/index.js | 340 +++-- client/live.js | 221 +-- client/overlay.js | 189 +-- client/socket.js | 69 +- client/sockjs.js | 2 +- client/webpack.config.js | 34 +- client/webpack.sockjs.config.js | 10 +- examples/bonjour/webpack.config.js | 6 +- examples/cli-open-page/app.js | 4 +- examples/cli-open-page/webpack.config.js | 6 +- examples/cli-public/webpack.config.js | 6 +- examples/cli-stdin/webpack.config.js | 6 +- examples/compression/webpack.config.js | 6 +- examples/history-api-fallback/app.js | 54 +- .../history-api-fallback/webpack.config.js | 16 +- examples/hmr/app.js | 2 +- examples/hmr/example.js | 4 +- examples/hmr/hmr.js | 14 +- examples/hmr/webpack.config.js | 16 +- examples/host-port/webpack.config.js | 6 +- examples/https/webpack.config.js | 6 +- examples/listen-socket/check-socket.js | 10 +- examples/listen-socket/webpack.config.js | 6 +- examples/modus-iframe/webpack.config.js | 6 +- examples/modus-inline/app.js | 2 +- examples/modus-inline/webpack.config.js | 40 +- examples/modus-lazy/webpack.config.js | 6 +- .../modus-manual-script/webpack.config.js | 6 +- examples/node-api-middleware/app.js | 2 +- examples/node-api-middleware/server.js | 30 +- .../node-api-middleware/webpack.config.js | 12 +- examples/node-api-simple/app.js | 2 +- examples/node-api-simple/server.js | 18 +- examples/node-api-simple/webpack.config.js | 12 +- examples/overlay-warnings/caseSensitive.js | 2 +- examples/overlay-warnings/webpack.config.js | 18 +- examples/overlay/webpack.config.js | 12 +- examples/proxy-advanced/webpack.config.js | 38 +- examples/proxy-hot-reload/proxy-config.js | 8 +- examples/proxy-hot-reload/webpack.config.js | 61 +- examples/proxy-simple/webpack.config.js | 16 +- examples/watch-content-base/app.js | 4 +- examples/watch-content-base/webpack.config.js | 18 +- examples/webpack-config-array/app.js | 2 +- .../webpack-config-array/webpack.config.js | 103 +- examples/webworker/web.js | 10 +- examples/webworker/webpack.config.js | 38 +- examples/webworker/worker.js | 12 +- lib/OptionsValidationError.js | 269 ++-- lib/Server.js | 1179 ++++++++--------- lib/util/addDevServerEntrypoints.js | 40 +- lib/util/createDomain.js | 23 +- package.json | 42 +- test/Compress.test.js | 38 +- test/ContentBase.test.js | 246 ++-- test/HistoryApiFallback.test.js | 304 ++--- test/Lazy.test.js | 38 +- test/Proxy.test.js | 440 +++--- test/Routes.test.js | 104 +- test/Validation.test.js | 345 +++-- test/fixtures/contentbase-config/foo.js | 4 +- .../contentbase-config/webpack.config.js | 12 +- .../historyapifallback-2-config/foo.js | 2 +- .../webpack.config.js | 12 +- .../historyapifallback-3-config/foo.js | 5 +- .../webpack.config.js | 30 +- .../fixtures/historyapifallback-config/foo.js | 7 +- .../webpack.config.js | 30 +- test/fixtures/proxy-config/foo.js | 2 +- test/fixtures/proxy-config/webpack.config.js | 12 +- test/fixtures/simple-config/foo.js | 2 +- test/fixtures/simple-config/webpack.config.js | 12 +- test/helper.js | 50 +- 75 files changed, 2790 insertions(+), 2823 deletions(-) diff --git a/.eslintrc b/.eslintrc index 78879dd8ca..deb9f30449 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,13 @@ { - "extends": "webpack" + "extends": "webpack", + "globals": { + "document": true, + "window": true + }, + "rules": { + "consistent-return": "off", + "no-param-reassign": "off", + "no-underscore-dangle": "off", + "prefer-rest-params": "off" + } } diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index 314495c70b..73c815ab6c 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -1,62 +1,67 @@ #!/usr/bin/env node -"use strict"; -const path = require("path"); -const open = require("opn"); -const fs = require("fs"); -const net = require("net"); -const portfinder = require("portfinder"); -const addDevServerEntrypoints = require("../lib/util/addDevServerEntrypoints"); -const createDomain = require("../lib/util/createDomain"); +/* eslint global-require: off, import/order: off, no-console: off */ + +const fs = require('fs'); +const net = require('net'); +const path = require('path'); +const open = require('opn'); +const portfinder = require('portfinder'); +const addDevServerEntrypoints = require('../lib/util/addDevServerEntrypoints'); +const createDomain = require('../lib/util/createDomain'); // eslint-disable-line // Local version replaces global one try { - const localWebpackDevServer = require.resolve(path.join(process.cwd(), "node_modules", "webpack-dev-server", "bin", "webpack-dev-server.js")); - if(__filename !== localWebpackDevServer) { - return require(localWebpackDevServer); - } -} catch(e) {} + const localWebpackDevServer = require.resolve(path.join(process.cwd(), 'node_modules', 'webpack-dev-server', 'bin', 'webpack-dev-server.js')); + if (__filename !== localWebpackDevServer) { + require(localWebpackDevServer); // eslint-disable-line + } +} catch (e) { + // eslint-disable-line +} -const Server = require("../lib/Server"); -const webpack = require("webpack"); +const Server = require('../lib/Server'); +const webpack = require('webpack'); // eslint-disable-line function versionInfo() { - return `webpack-dev-server ${require("../package.json").version}\n` + - `webpack ${require("webpack/package.json").version}`; + return `webpack-dev-server ${require('../package.json').version}\n` + + `webpack ${require('webpack/package.json').version}`; } function colorInfo(useColor, msg) { - if(useColor) - // Make text blue and bold, so it *pops* - return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`; - return msg; + if (useColor) { + // Make text blue and bold, so it *pops* + return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`; + } + return msg; } function colorError(useColor, msg) { - if(useColor) - // Make text red and bold, so it *pops* - return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`; - return msg; + if (useColor) { + // Make text red and bold, so it *pops* + return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`; + } + return msg; } +// eslint-disable-next-line const defaultTo = (value, def) => value == null ? def : value; -const yargs = require("yargs") - .usage(`${versionInfo() - }\nUsage: https://webpack.js.org/configuration/dev-server/`); +const yargs = require('yargs') + .usage(`${versionInfo()}\nUsage: https://webpack.js.org/configuration/dev-server/`); -require("webpack/bin/config-yargs")(yargs); +require('webpack/bin/config-yargs')(yargs); // It is important that this is done after the webpack yargs config, // so it overrides webpack's version info. yargs.version(versionInfo); -const ADVANCED_GROUP = "Advanced options:"; -const DISPLAY_GROUP = "Stats options:"; -const SSL_GROUP = "SSL options:"; -const CONNECTION_GROUP = "Connection options:"; -const RESPONSE_GROUP = "Response options:"; -const BASIC_GROUP = "Basic options:"; +const ADVANCED_GROUP = 'Advanced options:'; +const DISPLAY_GROUP = 'Stats options:'; +const SSL_GROUP = 'SSL options:'; +const CONNECTION_GROUP = 'Connection options:'; +const RESPONSE_GROUP = 'Response options:'; +const BASIC_GROUP = 'Basic options:'; // Taken out of yargs because we must know if // it wasn't given by the user, in which case @@ -64,433 +69,402 @@ const BASIC_GROUP = "Basic options:"; const DEFAULT_PORT = 8080; yargs.options({ - "bonjour": { - type: "boolean", - describe: "Broadcasts the server via ZeroConf networking on start" - }, - "lazy": { - type: "boolean", - describe: "Lazy" - }, - "inline": { - type: "boolean", - default: true, - describe: "Inline mode (set to false to disable including client scripts like livereload)" - }, - "progress": { - type: "boolean", - describe: "Print compilation progress in percentage", - group: BASIC_GROUP - }, - "hot-only": { - type: "boolean", - describe: "Do not refresh page if HMR fails", - group: ADVANCED_GROUP - }, - "stdin": { - type: "boolean", - describe: "close when stdin ends" - }, - "open": { - type: "boolean", - describe: "Open default browser" - }, - "useLocalIp": { - type: "boolean", - describe: "Open default browser with local IP" - }, - "open-page": { - type: "string", - describe: "Open default browser with the specified page", - requiresArg: true, - }, - "color": { - type: "boolean", - alias: "colors", - default: function supportsColor() { - return require("supports-color"); - }, - group: DISPLAY_GROUP, - describe: "Enables/Disables colors on the console" - }, - "info": { - type: "boolean", - group: DISPLAY_GROUP, - default: true, - describe: "Info" - }, - "quiet": { - type: "boolean", - group: DISPLAY_GROUP, - describe: "Quiet" - }, - "client-log-level": { - type: "string", - group: DISPLAY_GROUP, - default: "info", - describe: "Log level in the browser (info, warning, error or none)" - }, - "https": { - type: "boolean", - group: SSL_GROUP, - describe: "HTTPS" - }, - "key": { - type: "string", - describe: "Path to a SSL key.", - group: SSL_GROUP - }, - "cert": { - type: "string", - describe: "Path to a SSL certificate.", - group: SSL_GROUP - }, - "cacert": { - type: "string", - describe: "Path to a SSL CA certificate.", - group: SSL_GROUP - }, - "pfx": { - type: "string", - describe: "Path to a SSL pfx file.", - group: SSL_GROUP - }, - "pfx-passphrase": { - type: "string", - describe: "Passphrase for pfx file.", - group: SSL_GROUP - }, - "content-base": { - type: "string", - describe: "A directory or URL to serve HTML content from.", - group: RESPONSE_GROUP - }, - "watch-content-base": { - type: "boolean", - describe: "Enable live-reloading of the content-base.", - group: RESPONSE_GROUP - }, - "history-api-fallback": { - type: "boolean", - describe: "Fallback to /index.html for Single Page Applications.", - group: RESPONSE_GROUP - }, - "compress": { - type: "boolean", - describe: "Enable gzip compression", - group: RESPONSE_GROUP - }, - "port": { - describe: "The port", - group: CONNECTION_GROUP - }, - "disable-host-check": { - type: "boolean", - describe: "Will not check the host", - group: CONNECTION_GROUP - }, - "socket": { - type: "String", - describe: "Socket to listen", - group: CONNECTION_GROUP - }, - "public": { - type: "string", - describe: "The public hostname/ip address of the server", - group: CONNECTION_GROUP - }, - "host": { - type: "string", - default: "localhost", - describe: "The hostname/ip address the server will bind to", - group: CONNECTION_GROUP - }, - "allowed-hosts": { - type: "string", - describe: "A comma-delimited string of hosts that are allowed to access the dev server", - group: CONNECTION_GROUP - } + bonjour: { + type: 'boolean', + describe: 'Broadcasts the server via ZeroConf networking on start', + }, + lazy: { + type: 'boolean', + describe: 'Lazy', + }, + inline: { + type: 'boolean', + default: true, + describe: 'Inline mode (set to false to disable including client scripts like livereload)', + }, + progress: { + type: 'boolean', + describe: 'Print compilation progress in percentage', + group: BASIC_GROUP, + }, + 'hot-only': { + type: 'boolean', + describe: 'Do not refresh page if HMR fails', + group: ADVANCED_GROUP, + }, + stdin: { + type: 'boolean', + describe: 'close when stdin ends', + }, + open: { + type: 'boolean', + describe: 'Open default browser', + }, + useLocalIp: { + type: 'boolean', + describe: 'Open default browser with local IP', + }, + 'open-page': { + type: 'string', + describe: 'Open default browser with the specified page', + requiresArg: true, + }, + color: { + type: 'boolean', + alias: 'colors', + default: function supportsColor() { + return require('supports-color'); + }, + group: DISPLAY_GROUP, + describe: 'Enables/Disables colors on the console', + }, + info: { + type: 'boolean', + group: DISPLAY_GROUP, + default: true, + describe: 'Info', + }, + quiet: { + type: 'boolean', + group: DISPLAY_GROUP, + describe: 'Quiet', + }, + 'client-log-level': { + type: 'string', + group: DISPLAY_GROUP, + default: 'info', + describe: 'Log level in the browser (info, warning, error or none)', + }, + https: { + type: 'boolean', + group: SSL_GROUP, + describe: 'HTTPS', + }, + key: { + type: 'string', + describe: 'Path to a SSL key.', + group: SSL_GROUP, + }, + cert: { + type: 'string', + describe: 'Path to a SSL certificate.', + group: SSL_GROUP, + }, + cacert: { + type: 'string', + describe: 'Path to a SSL CA certificate.', + group: SSL_GROUP, + }, + pfx: { + type: 'string', + describe: 'Path to a SSL pfx file.', + group: SSL_GROUP, + }, + 'pfx-passphrase': { + type: 'string', + describe: 'Passphrase for pfx file.', + group: SSL_GROUP, + }, + 'content-base': { + type: 'string', + describe: 'A directory or URL to serve HTML content from.', + group: RESPONSE_GROUP, + }, + 'watch-content-base': { + type: 'boolean', + describe: 'Enable live-reloading of the content-base.', + group: RESPONSE_GROUP, + }, + 'history-api-fallback': { + type: 'boolean', + describe: 'Fallback to /index.html for Single Page Applications.', + group: RESPONSE_GROUP, + }, + compress: { + type: 'boolean', + describe: 'Enable gzip compression', + group: RESPONSE_GROUP, + }, + port: { + describe: 'The port', + group: CONNECTION_GROUP, + }, + 'disable-host-check': { + type: 'boolean', + describe: 'Will not check the host', + group: CONNECTION_GROUP, + }, + socket: { + type: 'String', + describe: 'Socket to listen', + group: CONNECTION_GROUP, + }, + public: { + type: 'string', + describe: 'The public hostname/ip address of the server', + group: CONNECTION_GROUP, + }, + host: { + type: 'string', + default: 'localhost', + describe: 'The hostname/ip address the server will bind to', + group: CONNECTION_GROUP, + }, + 'allowed-hosts': { + type: 'string', + describe: 'A comma-delimited string of hosts that are allowed to access the dev server', + group: CONNECTION_GROUP, + }, }); -const argv = yargs.argv; +const { argv } = yargs; -const wpOpt = require("webpack/bin/convert-argv")(yargs, argv, { - outputFilename: "/bundle.js" +const wpOpt = require('webpack/bin/convert-argv')(yargs, argv, { + outputFilename: '/bundle.js', }); function processOptions(wpOpt) { - // process Promise - if(typeof wpOpt.then === "function") { - wpOpt.then(processOptions).catch(function(err) { - console.error(err.stack || err); - process.exit(); // eslint-disable-line - }); - return; - } - - const firstWpOpt = Array.isArray(wpOpt) ? wpOpt[0] : wpOpt; + // process Promise + if (typeof wpOpt.then === 'function') { + wpOpt.then(processOptions).catch((err) => { + console.error(err.stack || err); + process.exit(); // eslint-disable-line + }); + return; + } + + const firstWpOpt = Array.isArray(wpOpt) ? wpOpt[0] : wpOpt; + + const options = wpOpt.devServer || firstWpOpt.devServer || {}; + + if (argv.bonjour) { options.bonjour = true; } + + if (argv.host !== 'localhost' || !options.host) { options.host = argv.host; } + + if (argv['allowed-hosts']) { options.allowedHosts = argv['allowed-hosts'].split(','); } + + if (argv.public) { options.public = argv.public; } + + if (argv.socket) { options.socket = argv.socket; } + + if (!options.publicPath) { + // eslint-disable-next-line + options.publicPath = firstWpOpt.output && firstWpOpt.output.publicPath || ''; + if (!/^(https?:)?\/\//.test(options.publicPath) && options.publicPath[0] !== '/') { + options.publicPath = `/${options.publicPath}`; + } + } + + if (!options.filename) { options.filename = firstWpOpt.output && firstWpOpt.output.filename; } + + if (!options.watchOptions) { options.watchOptions = firstWpOpt.watchOptions; } + + if (argv.stdin) { + process.stdin.on('end', () => { + process.exit(0); // eslint-disable-line no-process-exit + }); + process.stdin.resume(); + } + + if (!options.hot) { options.hot = argv.hot; } + + if (!options.hotOnly) { options.hotOnly = argv['hot-only']; } - const options = wpOpt.devServer || firstWpOpt.devServer || {}; + if (!options.clientLogLevel) { options.clientLogLevel = argv['client-log-level']; } - if(argv.bonjour) - options.bonjour = true; + // eslint-disable-next-line + if (options.contentBase === undefined) { + if (argv['content-base']) { + options.contentBase = argv['content-base']; + if (Array.isArray(options.contentBase)) { + options.contentBase = options.contentBase.map(val => path.resolve(val)); + } else if (/^[0-9]$/.test(options.contentBase)) { options.contentBase = +options.contentBase; } else if (!/^(https?:)?\/\//.test(options.contentBase)) { options.contentBase = path.resolve(options.contentBase); } + // It is possible to disable the contentBase by using `--no-content-base`, which results in arg["content-base"] = false + } else if (argv['content-base'] === false) { + options.contentBase = false; + } + } - if(argv.host !== "localhost" || !options.host) - options.host = argv.host; + if (argv['watch-content-base']) { options.watchContentBase = true; } - if(argv["allowed-hosts"]) - options.allowedHosts = argv["allowed-hosts"].split(","); + if (!options.stats) { + options.stats = { + cached: false, + cachedAssets: false, + }; + } - if(argv.public) - options.public = argv.public; + if (typeof options.stats === 'object' && typeof options.stats.colors === 'undefined') { options.stats.colors = argv.color; } - if(argv.socket) - options.socket = argv.socket; + if (argv.lazy) { options.lazy = true; } - if(!options.publicPath) { - options.publicPath = firstWpOpt.output && firstWpOpt.output.publicPath || ""; - if(!/^(https?:)?\/\//.test(options.publicPath) && options.publicPath[0] !== "/") - options.publicPath = `/${options.publicPath}`; - } + if (!argv.info) { options.noInfo = true; } - if(!options.filename) - options.filename = firstWpOpt.output && firstWpOpt.output.filename; + if (argv.quiet) { options.quiet = true; } - if(!options.watchOptions) - options.watchOptions = firstWpOpt.watchOptions; + if (argv.https) { options.https = true; } - if(argv["stdin"]) { - process.stdin.on("end", function() { - process.exit(0); // eslint-disable-line no-process-exit - }); - process.stdin.resume(); - } + if (argv.cert) { options.cert = fs.readFileSync(path.resolve(argv.cert)); } - if(!options.hot) - options.hot = argv["hot"]; - - if(!options.hotOnly) - options.hotOnly = argv["hot-only"]; - - if(!options.clientLogLevel) - options.clientLogLevel = argv["client-log-level"]; - - if(options.contentBase === undefined) { - if(argv["content-base"]) { - options.contentBase = argv["content-base"]; - if(Array.isArray(options.contentBase)) { - options.contentBase = options.contentBase.map(function(val) { - return path.resolve(val); - }); - } else if(/^[0-9]$/.test(options.contentBase)) - options.contentBase = +options.contentBase; - else if(!/^(https?:)?\/\//.test(options.contentBase)) - options.contentBase = path.resolve(options.contentBase); - // It is possible to disable the contentBase by using `--no-content-base`, which results in arg["content-base"] = false - } else if(argv["content-base"] === false) { - options.contentBase = false; - } - } - - if(argv["watch-content-base"]) - options.watchContentBase = true; - - if(!options.stats) { - options.stats = { - cached: false, - cachedAssets: false - }; - } - - if(typeof options.stats === "object" && typeof options.stats.colors === "undefined") - options.stats.colors = argv.color; - - if(argv["lazy"]) - options.lazy = true; - - if(!argv["info"]) - options.noInfo = true; - - if(argv["quiet"]) - options.quiet = true; - - if(argv["https"]) - options.https = true; - - if(argv["cert"]) - options.cert = fs.readFileSync(path.resolve(argv["cert"])); - - if(argv["key"]) - options.key = fs.readFileSync(path.resolve(argv["key"])); - - if(argv["cacert"]) - options.ca = fs.readFileSync(path.resolve(argv["cacert"])); + if (argv.key) { options.key = fs.readFileSync(path.resolve(argv.key)); } - if(argv["pfx"]) - options.pfx = fs.readFileSync(path.resolve(argv["pfx"])); + if (argv.cacert) { options.ca = fs.readFileSync(path.resolve(argv.cacert)); } - if(argv["pfx-passphrase"]) - options.pfxPassphrase = argv["pfx-passphrase"]; - - if(argv["inline"] === false) - options.inline = false; - - if(argv["history-api-fallback"]) - options.historyApiFallback = true; - - if(argv["compress"]) - options.compress = true; - - if(argv["disable-host-check"]) - options.disableHostCheck = true; - - if(argv["open"] || argv["open-page"]) { - options.open = true; - options.openPage = argv["open-page"]; - } - - if(options.open && !options.openPage) - options.openPage = ""; - - if(argv["useLocalIp"]) - options.useLocalIp = true; - - // Kind of weird, but ensures prior behavior isn't broken in cases - // that wouldn't throw errors. E.g. both argv.port and options.port - // were specified, but since argv.port is 8080, options.port will be - // tried first instead. - options.port = argv.port === DEFAULT_PORT ? defaultTo(options.port, argv.port) : defaultTo(argv.port, options.port); - if(options.port != null) { - startDevServer(wpOpt, options); - return; - } - - portfinder.basePort = DEFAULT_PORT; - portfinder.getPort(function(err, port) { - if(err) throw err; - options.port = port; - startDevServer(wpOpt, options); - }); + if (argv.pfx) { options.pfx = fs.readFileSync(path.resolve(argv.pfx)); } + + if (argv['pfx-passphrase']) { options.pfxPassphrase = argv['pfx-passphrase']; } + + if (argv.inline === false) { options.inline = false; } + + if (argv['history-api-fallback']) { options.historyApiFallback = true; } + + if (argv.compress) { options.compress = true; } + + if (argv['disable-host-check']) { options.disableHostCheck = true; } + + if (argv.open || argv['open-page']) { + options.open = true; + options.openPage = argv['open-page']; + } + + if (options.open && !options.openPage) { options.openPage = ''; } + + if (argv.useLocalIp) { options.useLocalIp = true; } + + // Kind of weird, but ensures prior behavior isn't broken in cases + // that wouldn't throw errors. E.g. both argv.port and options.port + // were specified, but since argv.port is 8080, options.port will be + // tried first instead. + options.port = argv.port === DEFAULT_PORT ? defaultTo(options.port, argv.port) : defaultTo(argv.port, options.port); + if (options.port != null) { + startDevServer(wpOpt, options); + return; + } + + portfinder.basePort = DEFAULT_PORT; + portfinder.getPort((err, port) => { + if (err) throw err; + options.port = port; + startDevServer(wpOpt, options); + }); } function startDevServer(wpOpt, options) { - addDevServerEntrypoints(wpOpt, options); - - let compiler; - try { - compiler = webpack(wpOpt); - } catch(e) { - if(e instanceof webpack.WebpackOptionsValidationError) { - console.error(colorError(options.stats.colors, e.message)); - process.exit(1); // eslint-disable-line - } - throw e; - } - - if(argv["progress"]) { - compiler.apply(new webpack.ProgressPlugin({ - profile: argv["profile"] - })); - } - - const uri = createDomain(options) + (options.inline !== false || options.lazy === true ? "/" : "/webpack-dev-server/"); - - let server; - try { - server = new Server(compiler, options); - } catch(e) { - const OptionsValidationError = require("../lib/OptionsValidationError"); - if(e instanceof OptionsValidationError) { - console.error(colorError(options.stats.colors, e.message)); - process.exit(1); // eslint-disable-line - } - throw e; - } - - ["SIGINT", "SIGTERM"].forEach(function(sig) { - process.on(sig, function() { - server.close(); - process.exit(); // eslint-disable-line no-process-exit - }); - }); - - if(options.socket) { - server.listeningApp.on("error", function(e) { - if(e.code === "EADDRINUSE") { - const clientSocket = new net.Socket(); - clientSocket.on("error", function(e) { - if(e.code === "ECONNREFUSED") { - // No other server listening on this socket so it can be safely removed - fs.unlinkSync(options.socket); - server.listen(options.socket, options.host, function(err) { - if(err) throw err; - }); - } - }); - clientSocket.connect({ path: options.socket }, function() { - throw new Error("This socket is already used"); - }); - } - }); - server.listen(options.socket, options.host, function(err) { - if(err) throw err; - const READ_WRITE = 438; // chmod 666 (rw rw rw) - fs.chmod(options.socket, READ_WRITE, function(err) { - if(err) throw err; - reportReadiness(uri, options); - }); - }); - } else { - server.listen(options.port, options.host, function(err) { - if(err) throw err; - if(options.bonjour) broadcastZeroconf(options); - reportReadiness(uri, options); - }); - } + addDevServerEntrypoints(wpOpt, options); + + let compiler; + try { + compiler = webpack(wpOpt); + } catch (e) { + if (e instanceof webpack.WebpackOptionsValidationError) { + console.error(colorError(options.stats.colors, e.message)); + process.exit(1); // eslint-disable-line + } + throw e; + } + + if (argv.progress) { + compiler.apply(new webpack.ProgressPlugin({ + profile: argv.profile, + })); + } + + const uri = createDomain(options) + (options.inline !== false || options.lazy === true ? '/' : '/webpack-dev-server/'); + + let server; + try { + server = new Server(compiler, options); + } catch (e) { + const OptionsValidationError = require('../lib/OptionsValidationError'); + if (e instanceof OptionsValidationError) { + console.error(colorError(options.stats.colors, e.message)); + process.exit(1); // eslint-disable-line + } + throw e; + } + + ['SIGINT', 'SIGTERM'].forEach((sig) => { + process.on(sig, () => { + server.close(); + process.exit(); // eslint-disable-line no-process-exit + }); + }); + + if (options.socket) { + server.listeningApp.on('error', (e) => { + if (e.code === 'EADDRINUSE') { + const clientSocket = new net.Socket(); + clientSocket.on('error', (e) => { + if (e.code === 'ECONNREFUSED') { + // No other server listening on this socket so it can be safely removed + fs.unlinkSync(options.socket); + server.listen(options.socket, options.host, (err) => { + if (err) throw err; + }); + } + }); + clientSocket.connect({ path: options.socket }, () => { + throw new Error('This socket is already used'); + }); + } + }); + server.listen(options.socket, options.host, (err) => { + if (err) throw err; + // chmod 666 (rw rw rw) + const READ_WRITE = 438; + fs.chmod(options.socket, READ_WRITE, (err) => { + if (err) throw err; + reportReadiness(uri, options); + }); + }); + } else { + server.listen(options.port, options.host, (err) => { + if (err) throw err; + if (options.bonjour) broadcastZeroconf(options); + reportReadiness(uri, options); + }); + } } function reportReadiness(uri, options) { - const useColor = argv.color; - const contentBase = Array.isArray(options.contentBase) ? options.contentBase.join(", ") : options.contentBase; - - if(!options.quiet) { - let startSentence = `Project is running at ${colorInfo(useColor, uri)}` - if(options.socket) { - startSentence = `Listening to socket at ${colorInfo(useColor, options.socket)}`; - } - console.log((argv["progress"] ? "\n" : "") + startSentence); - - console.log(`webpack output is served from ${colorInfo(useColor, options.publicPath)}`); - - if(contentBase) - console.log(`Content not from webpack is served from ${colorInfo(useColor, contentBase)}`); - - if(options.historyApiFallback) - console.log(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || "/index.html")}`); - - if(options.bonjour) - console.log("Broadcasting \"http\" with subtype of \"webpack\" via ZeroConf DNS (Bonjour)"); - } - if(options.open) { - open(uri + options.openPage).catch(function() { - console.log("Unable to open browser. If you are running in a headless environment, please do not use the open flag."); - }); - } + const useColor = argv.color; + const contentBase = Array.isArray(options.contentBase) ? options.contentBase.join(', ') : options.contentBase; + + if (!options.quiet) { + let startSentence = `Project is running at ${colorInfo(useColor, uri)}`; + if (options.socket) { + startSentence = `Listening to socket at ${colorInfo(useColor, options.socket)}`; + } + console.log((argv.progress ? '\n' : '') + startSentence); + + console.log(`webpack output is served from ${colorInfo(useColor, options.publicPath)}`); + + if (contentBase) { console.log(`Content not from webpack is served from ${colorInfo(useColor, contentBase)}`); } + + if (options.historyApiFallback) { console.log(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || '/index.html')}`); } + + if (options.bonjour) { console.log('Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'); } + } + if (options.open) { + open(uri + options.openPage).catch(() => { + console.log('Unable to open browser. If you are running in a headless environment, please do not use the open flag.'); + }); + } } function broadcastZeroconf(options) { - const bonjour = require("bonjour")(); - bonjour.publish({ - name: "Webpack Dev Server", - port: options.port, - type: "http", - subtypes: ["webpack"] - }); - process.on("exit", function() { - bonjour.unpublishAll(function() { - bonjour.destroy(); - }); - }); + const bonjour = require('bonjour')(); + bonjour.publish({ + name: 'Webpack Dev Server', + port: options.port, + type: 'http', + subtypes: ['webpack'], + }); + process.on('exit', () => { + bonjour.unpublishAll(() => { + bonjour.destroy(); + }); + }); } processOptions(wpOpt); diff --git a/client/index.js b/client/index.js index 1eb8ff1643..11ecbd5101 100644 --- a/client/index.js +++ b/client/index.js @@ -1,207 +1,205 @@ -/* global __resourceQuery WorkerGlobalScope */ -var url = require("url"); -var stripAnsi = require("strip-ansi"); -var log = require("loglevel") -var socket = require("./socket"); -var overlay = require("./overlay"); +/* global __resourceQuery WorkerGlobalScope self */ +/* eslint prefer-destructuring: off */ + +const url = require('url'); +const stripAnsi = require('strip-ansi'); +const log = require('loglevel'); +const socket = require('./socket'); +const overlay = require('./overlay'); function getCurrentScriptSource() { - // `document.currentScript` is the most accurate way to find the current script, - // but is not supported in all browsers. - if(document.currentScript) - return document.currentScript.getAttribute("src"); - // Fall back to getting all scripts in the document. - var scriptElements = document.scripts || []; - var currentScript = scriptElements[scriptElements.length - 1]; - if(currentScript) - return currentScript.getAttribute("src"); - // Fail as there was no script to use. - throw new Error("[WDS] Failed to get current script source"); + // `document.currentScript` is the most accurate way to find the current script, + // but is not supported in all browsers. + if (document.currentScript) { return document.currentScript.getAttribute('src'); } + // Fall back to getting all scripts in the document. + const scriptElements = document.scripts || []; + const currentScript = scriptElements[scriptElements.length - 1]; + if (currentScript) { return currentScript.getAttribute('src'); } + // Fail as there was no script to use. + throw new Error('[WDS] Failed to get current script source'); } -var urlParts; -if(typeof __resourceQuery === "string" && __resourceQuery) { - // If this bundle is inlined, use the resource query to get the correct url. - urlParts = url.parse(__resourceQuery.substr(1)); +let urlParts; +if (typeof __resourceQuery === 'string' && __resourceQuery) { + // If this bundle is inlined, use the resource query to get the correct url. + urlParts = url.parse(__resourceQuery.substr(1)); } else { - // Else, get the url from the '); - /* eslint-enable quotes */ - } catch(e) { - return next(); - } -} +Server.prototype.listen = function (port, hostname) { + this.listenHostname = hostname; + // eslint-disable-next-line + const returnValue = this.listeningApp.listen.apply(this.listeningApp, arguments); + const sockServer = sockjs.createServer({ + // Use provided up-to-date sockjs-client + sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js', + // Limit useless logs + log(severity, line) { + if (severity === 'error') { + console.log(line); + } + }, + }); + sockServer.on('connection', (conn) => { + if (!conn) return; + if (!this.checkHost(conn.headers)) { + this.sockWrite([conn], 'error', 'Invalid Host header'); + conn.close(); + return; + } + this.sockets.push(conn); + + conn.on('close', () => { + const connIndex = this.sockets.indexOf(conn); + if (connIndex >= 0) { + this.sockets.splice(connIndex, 1); + } + }); + + if (this.clientLogLevel) { this.sockWrite([conn], 'log-level', this.clientLogLevel); } + + if (this.clientOverlay) { this.sockWrite([conn], 'overlay', this.clientOverlay); } + + if (this.hot) this.sockWrite([conn], 'hot'); + + if (!this._stats) return; + this._sendStats([conn], this._stats.toJson(clientStats), true); + }); + + sockServer.installHandlers(this.listeningApp, { + prefix: '/sockjs-node', + }); + return returnValue; +}; + +Server.prototype.close = function (callback) { + this.sockets.forEach((sock) => { + sock.close(); + }); + this.sockets = []; + this.listeningApp.close(() => { + this.middleware.close(callback); + }); + + this.contentBaseWatchers.forEach((watcher) => { + watcher.close(); + }); + this.contentBaseWatchers = []; +}; + +Server.prototype.sockWrite = function (sockets, type, data) { + sockets.forEach((sock) => { + sock.write(JSON.stringify({ + type, + data, + })); + }); +}; + +Server.prototype.serveMagicHtml = function (req, res, next) { + const _path = req.path; + try { + if (!this.middleware.fileSystem.statSync(this.middleware.getFilenameFromUrl(`${_path}.js`)).isFile()) { return next(); } + // Serve a page that executes the javascript + /* eslint-disable quotes */ + res.write(''); + /* eslint-enable quotes */ + } catch (e) { + return next(); + } +}; // send stats to a socket or multiple sockets -Server.prototype._sendStats = function(sockets, stats, force) { - if(!force && - stats && - (!stats.errors || stats.errors.length === 0) && - stats.assets && - stats.assets.every((asset) => !asset.emitted) - ) - return this.sockWrite(sockets, "still-ok"); - this.sockWrite(sockets, "hash", stats.hash); - if(stats.errors.length > 0) - this.sockWrite(sockets, "errors", stats.errors); - else if(stats.warnings.length > 0) - this.sockWrite(sockets, "warnings", stats.warnings); - else - this.sockWrite(sockets, "ok"); -} - -Server.prototype._watch = function(path) { - const watcher = chokidar.watch(path).on("change", () => { - this.sockWrite(this.sockets, "content-changed"); - }); - - this.contentBaseWatchers.push(watcher); -} - -Server.prototype.invalidate = function() { - if(this.middleware) this.middleware.invalidate(); -} +Server.prototype._sendStats = function (sockets, stats, force) { + if (!force && + stats && + (!stats.errors || stats.errors.length === 0) && + stats.assets && + stats.assets.every(asset => !asset.emitted) + ) { return this.sockWrite(sockets, 'still-ok'); } + this.sockWrite(sockets, 'hash', stats.hash); + if (stats.errors.length > 0) { this.sockWrite(sockets, 'errors', stats.errors); } else if (stats.warnings.length > 0) { this.sockWrite(sockets, 'warnings', stats.warnings); } else { this.sockWrite(sockets, 'ok'); } +}; + +Server.prototype._watch = function (path) { + const watcher = chokidar.watch(path).on('change', () => { + this.sockWrite(this.sockets, 'content-changed'); + }); + + this.contentBaseWatchers.push(watcher); +}; + +Server.prototype.invalidate = function () { + if (this.middleware) this.middleware.invalidate(); +}; // Export this logic, so that other implementations, like task-runners can use it -Server.addDevServerEntrypoints = require("./util/addDevServerEntrypoints"); +Server.addDevServerEntrypoints = require('./util/addDevServerEntrypoints'); module.exports = Server; diff --git a/lib/util/addDevServerEntrypoints.js b/lib/util/addDevServerEntrypoints.js index 0a22d47a66..015181a353 100644 --- a/lib/util/addDevServerEntrypoints.js +++ b/lib/util/addDevServerEntrypoints.js @@ -1,26 +1,24 @@ -"use strict"; -const createDomain = require("./createDomain"); +/* eslint no-param-reassign: 'off' */ + +const createDomain = require('./createDomain'); module.exports = function addDevServerEntrypoints(webpackOptions, devServerOptions) { - if(devServerOptions.inline !== false) { - const domain = createDomain(devServerOptions); - const devClient = [`${require.resolve("../../client/")}?${domain}`]; + if (devServerOptions.inline !== false) { + const domain = createDomain(devServerOptions); + const devClient = [`${require.resolve('../../client/')}?${domain}`]; - if(devServerOptions.hotOnly) - devClient.push("webpack/hot/only-dev-server"); - else if(devServerOptions.hot) - devClient.push("webpack/hot/dev-server"); + if (devServerOptions.hotOnly) { devClient.push('webpack/hot/only-dev-server'); } else if (devServerOptions.hot) { devClient.push('webpack/hot/dev-server'); } - [].concat(webpackOptions).forEach((wpOpt) => { - if(typeof wpOpt.entry === "object" && !Array.isArray(wpOpt.entry)) { - Object.keys(wpOpt.entry).forEach((key) => { - wpOpt.entry[key] = devClient.concat(wpOpt.entry[key]); - }); - } else if(typeof wpOpt.entry === "function") { - wpOpt.entry = wpOpt.entry(devClient); - } else { - wpOpt.entry = devClient.concat(wpOpt.entry); - } - }); - } + [].concat(webpackOptions).forEach((wpOpt) => { + if (typeof wpOpt.entry === 'object' && !Array.isArray(wpOpt.entry)) { + Object.keys(wpOpt.entry).forEach((key) => { + wpOpt.entry[key] = devClient.concat(wpOpt.entry[key]); + }); + } else if (typeof wpOpt.entry === 'function') { + wpOpt.entry = wpOpt.entry(devClient); + } else { + wpOpt.entry = devClient.concat(wpOpt.entry); + } + }); + } }; diff --git a/lib/util/createDomain.js b/lib/util/createDomain.js index 00a9c762d1..4bdf1eda35 100644 --- a/lib/util/createDomain.js +++ b/lib/util/createDomain.js @@ -1,14 +1,15 @@ -"use strict"; -const url = require("url"); -const internalIp = require("internal-ip"); + + +const url = require('url'); +const internalIp = require('internal-ip'); module.exports = function createDomain(options) { - const protocol = options.https ? "https" : "http"; - - // the formatted domain (url without path) of the webpack server - return options.public ? `${protocol}://${options.public}` : url.format({ - protocol: protocol, - hostname: options.useLocalIp ? internalIp.v4() : options.host, - port: options.socket ? 0 : options.port.toString() - }); + const protocol = options.https ? 'https' : 'http'; + + // the formatted domain (url without path) of the webpack server + return options.public ? `${protocol}://${options.public}` : url.format({ + protocol, + hostname: options.useLocalIp ? internalIp.v4() : options.host, + port: options.socket ? 0 : options.port.toString(), + }); }; diff --git a/package.json b/package.json index d45383b11e..8cfeebeda0 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,11 @@ "cover": "istanbul cover node_modules/mocha/bin/_mocha", "lint": "eslint bin lib test examples client/{index,live,socket,sockjs,overlay,webpack.config}.js", "mocha": "mocha --full-trace --check-leaks", - "posttest": "npm run -s lint", - "prepublish": "npm run -s client-live && npm run -s client-index && npm run -s client-sockjs", + "prepublish": "npm run -s build:live && npm run -s build:index && npm run -s build:sockjs", "test": "npm run lint && npm run mocha", - - "client-live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p", - "client-index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p", - "client-sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p" + "build:live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p", + "build:index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p", + "build:sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p" }, "files": [ "lib/", @@ -51,42 +49,42 @@ "express": "^4.13.3", "html-entities": "^1.2.0", "http-proxy-middleware": "~0.17.4", - "internal-ip": "^1.2.0", + "internal-ip": "^2.0.2", "ip": "^1.1.5", "loglevel": "^1.4.1", - "opn": "4.0.2", + "opn": "^5.1.0", "portfinder": "^1.0.9", "selfsigned": "^1.9.1", "serve-index": "^1.7.2", "sockjs": "0.3.18", "sockjs-client": "1.1.4", "spdy": "^3.4.1", - "strip-ansi": "^3.0.0", - "supports-color": "^3.1.1", + "strip-ansi": "^4.0.0", + "supports-color": "^4.2.1", "webpack-dev-middleware": "^1.11.0", - "yargs": "^6.0.0" + "yargs": "^8.0.2" }, "devDependencies": { "codecov.io": "^0.1.6", - "css-loader": "~0.26.1", - "eslint": "^3.4.0", + "css-loader": "^0.28.5", + "eslint": "^4.5.0", "eslint-config-webpack": "^1.2.5", "eslint-plugin-import": "^2.7.0", - "file-loader": "~0.10.0", + "file-loader": "^0.11.2", "istanbul": "^0.4.5", - "jquery": "^2.2.0", + "jquery": "^3.2.1", "less": "^2.5.1", - "less-loader": "~2.2.0", + "less-loader": "^4.0.5", "mocha": "^3.0.2", - "mocha-sinon": "^1.1.6", + "mocha-sinon": "^2.0.0", "pug": "^2.0.0-beta5", "pug-loader": "^2.3.0", - "should": "^11.1.0", - "sinon": "^1.17.6", - "style-loader": "~0.13.0", - "supertest": "^2.0.1", + "should": "^12.0.0", + "sinon": "^3.2.1", + "style-loader": "^0.18.2", + "supertest": "^3.0.0", "url-loader": "~0.5.6", "webpack": "^3.0.0", - "ws": "^1.1.1" + "ws": "^3.1.0" } } diff --git a/test/Compress.test.js b/test/Compress.test.js index 15eb90e69b..3337631c72 100644 --- a/test/Compress.test.js +++ b/test/Compress.test.js @@ -1,25 +1,25 @@ -"use strict"; -const request = require("supertest"); -const helper = require("./helper"); -const config = require("./fixtures/simple-config/webpack.config"); -describe("Compress", function() { - let server; - let req; +const request = require('supertest'); +const helper = require('./helper'); +const config = require('./fixtures/simple-config/webpack.config'); - before(function(done) { - server = helper.start(config, { - compress: true - }, done); - req = request(server.app); - }); +describe('Compress', () => { + let server; + let req; - after(helper.close); + before((done) => { + server = helper.start(config, { + compress: true, + }, done); + req = request(server.app); + }); - it("request to bundle file", function(done) { - req.get("/bundle.js") - .expect("Content-Encoding", "gzip") - .expect(200, done); - }); + after(helper.close); + + it('request to bundle file', (done) => { + req.get('/bundle.js') + .expect('Content-Encoding', 'gzip') + .expect(200, done); + }); }); diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index b4273979a4..e39c19b7f7 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -1,124 +1,124 @@ -"use strict"; - -const request = require("supertest"); -const path = require("path"); -const helper = require("./helper"); -const config = require("./fixtures/contentbase-config/webpack.config"); -require("mocha-sinon"); - -const contentBasePublic = path.join(__dirname, "fixtures/contentbase-config/public"); -const contentBaseOther = path.join(__dirname, "fixtures/contentbase-config/other"); - -describe("ContentBase", function() { - let server; - let req; - afterEach(helper.close); - - describe("to directory", function() { - before(function(done) { - server = helper.start(config, { - contentBase: contentBasePublic, - }, done); - req = request(server.app); - }); - - it("Request to index", function(done) { - req.get("/") - .expect(200, /Heyo/, done); - }); - - it("Request to other file", function(done) { - req.get("/other.html") - .expect(200, /Other html/, done); - }); - }); - - describe("to directories", function() { - before(function(done) { - server = helper.start(config, { - contentBase: [contentBasePublic, contentBaseOther], - }, done); - req = request(server.app); - }); - - it("Request to first directory", function(done) { - req.get("/") - .expect(200, /Heyo/, done); - }); - - it("Request to second directory", function(done) { - req.get("/foo.html") - .expect(200, /Foo!/, done); - }); - }); - - describe("to port", function() { - before(function(done) { - server = helper.start(config, { - contentBase: 9099999, - }, done); - req = request(server.app); - }); - - it("Request to page", function(done) { - req.get("/other.html") - .expect("Location", "//localhost:9099999/other.html") - .expect(302, done); - }); - }); - - describe("to external url", function() { - before(function(done) { - server = helper.start(config, { - contentBase: "http://example.com/", - }, done); - req = request(server.app); - }); - - it("Request to page", function(done) { - req.get("/foo.html") - // TODO: hmm, two slashes seems to be a bug? - .expect("Location", "http://example.com//foo.html") - .expect(302, done); - }); - - it("Request to page with search params", function(done) { - req.get("/foo.html?space=ship") - // TODO: hmm, two slashes seems to be a bug? - .expect("Location", "http://example.com//foo.html?space=ship") - .expect(302, done); - }); - }); - - describe("default to PWD", function() { - before(function(done) { - this.sinon.stub(process, "cwd"); - process.cwd.returns(contentBasePublic); - server = helper.start(config, {}, done); - req = request(server.app); - }); - - it("Request to page", function(done) { - req.get("/other.html") - .expect(200, done); - }); - }); - - describe("disable", function() { - before(function(done) { - // This is a somewhat weird test, but it is important that we mock - // the PWD here, and test if /other.html in our "fake" PWD really is not requested. - this.sinon.stub(process, "cwd"); - process.cwd.returns(contentBasePublic); - server = helper.start(config, { - contentBase: false - }, done); - req = request(server.app); - }); - - it("Request to page", function(done) { - req.get("/other.html") - .expect(404, done); - }); - }); + + +const request = require('supertest'); +const path = require('path'); +const helper = require('./helper'); +const config = require('./fixtures/contentbase-config/webpack.config'); +require('mocha-sinon'); + +const contentBasePublic = path.join(__dirname, 'fixtures/contentbase-config/public'); +const contentBaseOther = path.join(__dirname, 'fixtures/contentbase-config/other'); + +describe('ContentBase', () => { + let server; + let req; + afterEach(helper.close); + + describe('to directory', () => { + before((done) => { + server = helper.start(config, { + contentBase: contentBasePublic, + }, done); + req = request(server.app); + }); + + it('Request to index', (done) => { + req.get('/') + .expect(200, /Heyo/, done); + }); + + it('Request to other file', (done) => { + req.get('/other.html') + .expect(200, /Other html/, done); + }); + }); + + describe('to directories', () => { + before((done) => { + server = helper.start(config, { + contentBase: [contentBasePublic, contentBaseOther], + }, done); + req = request(server.app); + }); + + it('Request to first directory', (done) => { + req.get('/') + .expect(200, /Heyo/, done); + }); + + it('Request to second directory', (done) => { + req.get('/foo.html') + .expect(200, /Foo!/, done); + }); + }); + + describe('to port', () => { + before((done) => { + server = helper.start(config, { + contentBase: 9099999, + }, done); + req = request(server.app); + }); + + it('Request to page', (done) => { + req.get('/other.html') + .expect('Location', '//localhost:9099999/other.html') + .expect(302, done); + }); + }); + + describe('to external url', () => { + before((done) => { + server = helper.start(config, { + contentBase: 'http://example.com/', + }, done); + req = request(server.app); + }); + + it('Request to page', (done) => { + req.get('/foo.html') + // TODO: hmm, two slashes seems to be a bug? + .expect('Location', 'http://example.com//foo.html') + .expect(302, done); + }); + + it('Request to page with search params', (done) => { + req.get('/foo.html?space=ship') + // TODO: hmm, two slashes seems to be a bug? + .expect('Location', 'http://example.com//foo.html?space=ship') + .expect(302, done); + }); + }); + + describe('default to PWD', () => { + before(function (done) { + this.sinon.stub(process, 'cwd'); + process.cwd.returns(contentBasePublic); + server = helper.start(config, {}, done); + req = request(server.app); + }); + + it('Request to page', (done) => { + req.get('/other.html') + .expect(200, done); + }); + }); + + describe('disable', () => { + before(function (done) { + // This is a somewhat weird test, but it is important that we mock + // the PWD here, and test if /other.html in our "fake" PWD really is not requested. + this.sinon.stub(process, 'cwd'); + process.cwd.returns(contentBasePublic); + server = helper.start(config, { + contentBase: false, + }, done); + req = request(server.app); + }); + + it('Request to page', (done) => { + req.get('/other.html') + .expect(404, done); + }); + }); }); diff --git a/test/HistoryApiFallback.test.js b/test/HistoryApiFallback.test.js index 4d44807aee..e3f4a9f765 100644 --- a/test/HistoryApiFallback.test.js +++ b/test/HistoryApiFallback.test.js @@ -1,150 +1,156 @@ -"use strict"; - -const path = require("path"); -const request = require("supertest"); -const helper = require("./helper"); -const config = require("./fixtures/historyapifallback-config/webpack.config"); -const config2 = require("./fixtures/historyapifallback-2-config/webpack.config"); -const config3 = require("./fixtures/historyapifallback-3-config/webpack.config"); - -describe("HistoryApiFallback", function() { - let server; - let req; - - afterEach(helper.close); - - describe("as boolean", function() { - before(function(done) { - server = helper.start(config, { - historyApiFallback: true - }, done); - req = request(server.app); - }); - - it("request to directory", function(done) { - req.get("/foo") - .accept("html") - .expect(200, /Heyyy/, done); - }); - }); - - describe("as object", function() { - before(function(done) { - server = helper.start(config, { - historyApiFallback: { - index: "/bar.html" - } - }, done); - req = request(server.app); - }); - - it("request to directory", function(done) { - req.get("/foo") - .accept("html") - .expect(200, /Foobar/, done); - }); - }); - - describe("as object with contentBase", function() { - before(function(done) { - server = helper.start(config2, { - contentBase: path.join(__dirname, "fixtures/historyapifallback-2-config"), - historyApiFallback: { - index: "/bar.html" - } - }, done); - req = request(server.app); - }); - - it("historyApiFallback should take preference above directory index", function(done) { - req.get("/") - .accept("html") - .expect(200, /Foobar/, done); - }); - - it("request to directory", function(done) { - req.get("/foo") - .accept("html") - .expect(200, /Foobar/, done); - }); - - it("contentBase file should take preference above historyApiFallback", function(done) { - req.get("/random-file") - .accept("html") - .expect(200, /Random file/, done); - }); - }); - - describe("as object with contentBase set to false", function() { - before(function(done) { - server = helper.start(config3, { - contentBase: false, - historyApiFallback: { - index: "/bar.html" - } - }, done); - req = request(server.app); - }); - - it("historyApiFallback should work and ignore static content", function(done) { - req.get("/index.html") - .accept("html") - .expect(200, /In-memory file/, done); - }); - }); - - describe("as object with contentBase and rewrites", function() { - before(function(done) { - server = helper.start(config2, { - contentBase: path.join(__dirname, "fixtures/historyapifallback-2-config"), - historyApiFallback: { - rewrites: [ - { - from: /other/, - to: "/other.html" - }, - { - from: /.*/, - to: "/bar.html" - } - ] - } - }, done); - req = request(server.app); - }); - - it("historyApiFallback respect rewrites for index", function(done) { - req.get("/") - .accept("html") - .expect(200, /Foobar/, done); - }); - - it("historyApiFallback respect rewrites and shows index for unknown urls", function(done) { - req.get("/acme") - .accept("html") - .expect(200, /Foobar/, done); - }); - - it("historyApiFallback respect any other specified rewrites", function(done) { - req.get("/other") - .accept("html") - .expect(200, /Other file/, done); - }); - }); - - describe("in-memory files", function() { - before(function(done) { - server = helper.start(config3, { - contentBase: path.join(__dirname, "fixtures/historyapifallback-3-config"), - historyApiFallback: true - }, done); - req = request(server.app); - }); - - it("should take precedence over contentBase files", function(done) { - req.get("/foo") - .accept("html") - .expect(200, /In-memory file/, done); - }); - }); + +const assert = require('assert'); +const path = require('path'); +const request = require('supertest'); +const helper = require('./helper'); +const config = require('./fixtures/historyapifallback-config/webpack.config'); +const config2 = require('./fixtures/historyapifallback-2-config/webpack.config'); +const config3 = require('./fixtures/historyapifallback-3-config/webpack.config'); + +describe('HistoryApiFallback', () => { + let server; + let req; + + afterEach(helper.close); + + describe('as boolean', () => { + before((done) => { + server = helper.start(config, { + historyApiFallback: true, + }, done); + req = request(server.app); + }); + + it('request to directory', (done) => { + req.get('/foo') + .accept('html') + .expect(200, /Heyyy/, done); + }); + }); + + describe('as object', () => { + before((done) => { + server = helper.start(config, { + historyApiFallback: { + index: '/bar.html', + }, + }, done); + req = request(server.app); + }); + + it('request to directory', (done) => { + req.get('/foo') + .accept('html') + .expect(200, /Foobar/, done); + }); + }); + + describe('as object with contentBase', () => { + before((done) => { + server = helper.start(config2, { + contentBase: path.join(__dirname, 'fixtures/historyapifallback-2-config'), + historyApiFallback: { + index: '/bar.html', + }, + }, done); + req = request(server.app); + }); + + it('historyApiFallback should take preference above directory index', (done) => { + req.get('/') + .accept('html') + .expect(200, /Foobar/, done); + }); + + it('request to directory', (done) => { + req.get('/foo') + .accept('html') + .expect(200, /Foobar/, done); + }); + + it('contentBase file should take preference above historyApiFallback', (done) => { + req.get('/random-file') + .accept('html') + .end((err, res) => { // eslint-disable-line + if (err) { + done(err); + } + assert(res.body.toString(), 'Random file'); + done(); + }); + }); + }); + + describe('as object with contentBase set to false', () => { + before((done) => { + server = helper.start(config3, { + contentBase: false, + historyApiFallback: { + index: '/bar.html', + }, + }, done); + req = request(server.app); + }); + + it('historyApiFallback should work and ignore static content', (done) => { + req.get('/index.html') + .accept('html') + .expect(200, /In-memory file/, done); + }); + }); + + describe('as object with contentBase and rewrites', () => { + before((done) => { + server = helper.start(config2, { + contentBase: path.join(__dirname, 'fixtures/historyapifallback-2-config'), + historyApiFallback: { + rewrites: [ + { + from: /other/, + to: '/other.html', + }, + { + from: /.*/, + to: '/bar.html', + }, + ], + }, + }, done); + req = request(server.app); + }); + + it('historyApiFallback respect rewrites for index', (done) => { + req.get('/') + .accept('html') + .expect(200, /Foobar/, done); + }); + + it('historyApiFallback respect rewrites and shows index for unknown urls', (done) => { + req.get('/acme') + .accept('html') + .expect(200, /Foobar/, done); + }); + + it('historyApiFallback respect any other specified rewrites', (done) => { + req.get('/other') + .accept('html') + .expect(200, /Other file/, done); + }); + }); + + describe('in-memory files', () => { + before((done) => { + server = helper.start(config3, { + contentBase: path.join(__dirname, 'fixtures/historyapifallback-3-config'), + historyApiFallback: true, + }, done); + req = request(server.app); + }); + + it('should take precedence over contentBase files', (done) => { + req.get('/foo') + .accept('html') + .expect(200, /In-memory file/, done); + }); + }); }); diff --git a/test/Lazy.test.js b/test/Lazy.test.js index e8c031c768..9d225cbdf8 100644 --- a/test/Lazy.test.js +++ b/test/Lazy.test.js @@ -1,24 +1,24 @@ -"use strict"; -const should = require("should"); -const helper = require("./helper"); -const config = require("./fixtures/simple-config/webpack.config"); -describe("Lazy", function() { - afterEach(helper.close); +const should = require('should'); +const helper = require('./helper'); +const config = require('./fixtures/simple-config/webpack.config'); - it("without filename option it should throw an error", function() { - should.throws(function() { - helper.start(config, { - lazy: true - }); - }, /'filename' option must be set/); - }); +describe('Lazy', () => { + afterEach(helper.close); - it("with filename option should not throw an error", function(done) { - helper.start(config, { - lazy: true, - filename: "bundle.js" - }, done); - }); + it('without filename option it should throw an error', () => { + should.throws(() => { + helper.start(config, { + lazy: true, + }); + }, /'filename' option must be set/); + }); + + it('with filename option should not throw an error', (done) => { + helper.start(config, { + lazy: true, + filename: 'bundle.js', + }, done); + }); }); diff --git a/test/Proxy.test.js b/test/Proxy.test.js index ba6c75936f..3b509f0658 100644 --- a/test/Proxy.test.js +++ b/test/Proxy.test.js @@ -1,234 +1,234 @@ -"use strict"; -const request = require("supertest"); -const path = require("path"); -const express = require("express"); -const WebSocket = require("ws"); -const helper = require("./helper"); -const should = require("should"); -const config = require("./fixtures/proxy-config/webpack.config"); + +const request = require('supertest'); +const path = require('path'); +const express = require('express'); +const WebSocket = require('ws'); +const helper = require('./helper'); +const should = require('should'); +const config = require('./fixtures/proxy-config/webpack.config'); const WebSocketServer = WebSocket.Server; -const contentBase = path.join(__dirname, "fixtures/proxy-config"); +const contentBase = path.join(__dirname, 'fixtures/proxy-config'); const proxyOption = { - "/proxy1": { - target: "http://localhost:9000", - }, - "/api/proxy2": { - target: "http://localhost:9001", - pathRewrite: { "^/api": "" }, - }, - "/foo": { - bypass: function(req) { - if(/\.html$/.test(req.path)) { - return "/index.html"; - } - }, - }, + '/proxy1': { + target: 'http://localhost:9000', + }, + '/api/proxy2': { + target: 'http://localhost:9001', + pathRewrite: { '^/api': '' }, + }, + '/foo': { + bypass(req) { + if (/\.html$/.test(req.path)) { + return '/index.html'; + } + }, + }, }; const proxyOptionOfArray = [ - { context: "/proxy1", target: proxyOption["/proxy1"].target }, - function() { - return { - context: "/api/proxy2", - target: "http://localhost:9001", - pathRewrite: { "^/api": "" }, - }; - }, + { context: '/proxy1', target: proxyOption['/proxy1'].target }, + function () { + return { + context: '/api/proxy2', + target: 'http://localhost:9001', + pathRewrite: { '^/api': '' }, + }; + }, ]; function startProxyServers() { - const listeners = []; - const proxy1 = express(); - const proxy2 = express(); - proxy1.get("/proxy1", function(req, res) { - res.send("from proxy1"); - }); - proxy1.get("/api", function(req, res) { - res.send("api response from proxy1"); - }); - proxy2.get("/proxy2", function(req, res) { - res.send("from proxy2"); - }); - listeners.push(proxy1.listen(9000)); - listeners.push(proxy2.listen(9001)); - // return a function to shutdown proxy servers - return function() { - listeners.forEach(function(listener) { - listener.close(); - }); - }; + const listeners = []; + const proxy1 = express(); + const proxy2 = express(); + proxy1.get('/proxy1', (req, res) => { + res.send('from proxy1'); + }); + proxy1.get('/api', (req, res) => { + res.send('api response from proxy1'); + }); + proxy2.get('/proxy2', (req, res) => { + res.send('from proxy2'); + }); + listeners.push(proxy1.listen(9000)); + listeners.push(proxy2.listen(9001)); + // return a function to shutdown proxy servers + return function () { + listeners.forEach((listener) => { + listener.close(); + }); + }; } -describe("Proxy", function() { - context("proxy options is a object", function() { - let server; - let req; - let closeProxyServers; - - before(function(done) { - closeProxyServers = startProxyServers(); - server = helper.start(config, { - contentBase, - proxy: proxyOption, - }, done); - req = request(server.app); - }); - - after(function(done) { - helper.close(function() { - closeProxyServers(); - done(); - }); - }); - - describe("target", function() { - it("respects a proxy option when a request path is matched", function(done) { - req.get("/proxy1") - .expect(200, "from proxy1", done); - }); - }); - - describe("pathRewrite", function() { - it("respects a pathRewrite option", function(done) { - req.get("/api/proxy2") - .expect(200, "from proxy2", done); - }); - }); - - describe("bypass", function() { - it("can rewrite a request path", function(done) { - req.get("/foo/bar.html") - .expect(200, /Hello/, done); - }); - - it("can rewrite a request path regardless of the target defined a bypass option", function(done) { - req.get("/baz/hoge.html") - .expect(200, /Hello/, done); - }); - - it("should pass through a proxy when a bypass function returns null", function(done) { - req.get("/foo.js") - .expect(200, /Hey/, done); - }); - }); - }); - - context("proxy option is an array", function() { - let server; - let req; - let closeProxyServers; - - before(function(done) { - closeProxyServers = startProxyServers(); - server = helper.start(config, { - contentBase, - proxy: proxyOptionOfArray, - }, done); - req = request(server.app); - }); - - after(function(done) { - helper.close(function() { - closeProxyServers(); - done(); - }); - }); - - it("respects a proxy option", function(done) { - req.get("/proxy1") - .expect(200, "from proxy1", done); - }); - - it("respects a proxy option of function", function(done) { - req.get("/api/proxy2") - .expect(200, "from proxy2", done); - }); - }); - - context("sharing a proxy option", function() { - let server; - let req; - let listener; - const proxyTarget = { - target: "http://localhost:9000" - }; - - before(function(done) { - const proxy = express(); - proxy.get("*", function(req, res) { - res.send("from proxy"); - }); - listener = proxy.listen(9000); - server = helper.start(config, { - contentBase, - proxy: { - "/proxy1": proxyTarget, - "/proxy2": proxyTarget, - } - }, done); - req = request(server.app); - }); - - after(function(done) { - helper.close(function() { - listener.close(); - done(); - }); - }); - - it("respects proxy1 option", function(done) { - req.get("/proxy1").expect(200, "from proxy", done); - }); - - it("respects proxy2 option", function(done) { - req.get("/proxy2").expect(200, "from proxy", done); - }); - }); - - context("External websocket upgrade", function() { - let ws; - let wsServer; - let responseMessage; - - before(function(done) { - helper.start(config, { - contentBase, - proxy: [{ - context: "/", - target: "http://localhost:9003", - ws: true - }] - }, done); - - wsServer = new WebSocketServer({ port: 9003 }); - wsServer.on("connection", function connection(ws) { - ws.on("message", function incoming(message) { - ws.send(message); - }); - }); - }); - - beforeEach(function(done) { - ws = new WebSocket("ws://localhost:8080/proxy3/socket"); - ws.on("message", function(message) { - responseMessage = message; - done() - }); - ws.on("open", function open() { - ws.send("foo"); - }); - }) - - it("Should receive response", function() { - should(responseMessage).equal("foo"); - }); - - after(function(done) { - wsServer.close(); - helper.close(done); - }); - }); +describe('Proxy', () => { + context('proxy options is a object', () => { + let server; + let req; + let closeProxyServers; + + before((done) => { + closeProxyServers = startProxyServers(); + server = helper.start(config, { + contentBase, + proxy: proxyOption, + }, done); + req = request(server.app); + }); + + after((done) => { + helper.close(() => { + closeProxyServers(); + done(); + }); + }); + + describe('target', () => { + it('respects a proxy option when a request path is matched', (done) => { + req.get('/proxy1') + .expect(200, 'from proxy1', done); + }); + }); + + describe('pathRewrite', () => { + it('respects a pathRewrite option', (done) => { + req.get('/api/proxy2') + .expect(200, 'from proxy2', done); + }); + }); + + describe('bypass', () => { + it('can rewrite a request path', (done) => { + req.get('/foo/bar.html') + .expect(200, /Hello/, done); + }); + + it('can rewrite a request path regardless of the target defined a bypass option', (done) => { + req.get('/baz/hoge.html') + .expect(200, /Hello/, done); + }); + + it('should pass through a proxy when a bypass function returns null', (done) => { + req.get('/foo.js') + .expect(200, /Hey/, done); + }); + }); + }); + + context('proxy option is an array', () => { + let server; + let req; + let closeProxyServers; + + before((done) => { + closeProxyServers = startProxyServers(); + server = helper.start(config, { + contentBase, + proxy: proxyOptionOfArray, + }, done); + req = request(server.app); + }); + + after((done) => { + helper.close(() => { + closeProxyServers(); + done(); + }); + }); + + it('respects a proxy option', (done) => { + req.get('/proxy1') + .expect(200, 'from proxy1', done); + }); + + it('respects a proxy option of function', (done) => { + req.get('/api/proxy2') + .expect(200, 'from proxy2', done); + }); + }); + + context('sharing a proxy option', () => { + let server; + let req; + let listener; + const proxyTarget = { + target: 'http://localhost:9000', + }; + + before((done) => { + const proxy = express(); + proxy.get('*', (req, res) => { + res.send('from proxy'); + }); + listener = proxy.listen(9000); + server = helper.start(config, { + contentBase, + proxy: { + '/proxy1': proxyTarget, + '/proxy2': proxyTarget, + }, + }, done); + req = request(server.app); + }); + + after((done) => { + helper.close(() => { + listener.close(); + done(); + }); + }); + + it('respects proxy1 option', (done) => { + req.get('/proxy1').expect(200, 'from proxy', done); + }); + + it('respects proxy2 option', (done) => { + req.get('/proxy2').expect(200, 'from proxy', done); + }); + }); + + context('External websocket upgrade', () => { + let ws; + let wsServer; + let responseMessage; + + before((done) => { + helper.start(config, { + contentBase, + proxy: [{ + context: '/', + target: 'http://localhost:9003', + ws: true, + }], + }, done); + + wsServer = new WebSocketServer({ port: 9003 }); + wsServer.on('connection', (ws) => { + ws.on('message', (message) => { + ws.send(message); + }); + }); + }); + + beforeEach((done) => { + ws = new WebSocket('ws://localhost:8080/proxy3/socket'); + ws.on('message', (message) => { + responseMessage = message; + done(); + }); + ws.on('open', () => { + ws.send('foo'); + }); + }); + + it('Should receive response', () => { + should(responseMessage).equal('foo'); + }); + + after((done) => { + wsServer.close(); + helper.close(done); + }); + }); }); diff --git a/test/Routes.test.js b/test/Routes.test.js index a86b7ac538..36d03c2e28 100644 --- a/test/Routes.test.js +++ b/test/Routes.test.js @@ -1,65 +1,65 @@ -"use strict"; -const request = require("supertest"); -const fs = require("fs"); -const path = require("path"); -const helper = require("./helper"); -const config = require("./fixtures/simple-config/webpack.config"); -const directoryIndex = fs.readFileSync(path.join(__dirname, "fixtures/directory-index.txt"), "utf-8"); -const magicHtml = fs.readFileSync(path.join(__dirname, "fixtures/magic-html.txt"), "utf-8"); +const request = require('supertest'); +const fs = require('fs'); +const path = require('path'); +const helper = require('./helper'); +const config = require('./fixtures/simple-config/webpack.config'); -describe("Routes", function() { - let server; - let req; +const directoryIndex = fs.readFileSync(path.join(__dirname, 'fixtures/directory-index.txt'), 'utf-8'); +const magicHtml = fs.readFileSync(path.join(__dirname, 'fixtures/magic-html.txt'), 'utf-8'); - before(function(done) { - server = helper.start(config, { - headers: { "X-Foo": "1" } - }, done); - req = request(server.app); - }); +describe('Routes', () => { + let server; + let req; - after(helper.close); + before((done) => { + server = helper.start(config, { + headers: { 'X-Foo': '1' }, + }, done); + req = request(server.app); + }); - it("GET request to inline bundle", function(done) { - req.get("/webpack-dev-server.js") - .expect("Content-Type", "application/javascript") - .expect(200, done); - }); + after(helper.close); - it("GET request to live bundle", function(done) { - req.get("/__webpack_dev_server__/live.bundle.js") - .expect("Content-Type", "application/javascript") - .expect(200, done); - }); + it('GET request to inline bundle', (done) => { + req.get('/webpack-dev-server.js') + .expect('Content-Type', 'application/javascript') + .expect(200, done); + }); - it("GET request to sockjs bundle", function(done) { - req.get("/__webpack_dev_server__/sockjs.bundle.js") - .expect("Content-Type", "application/javascript") - .expect(200, done); - }); + it('GET request to live bundle', (done) => { + req.get('/__webpack_dev_server__/live.bundle.js') + .expect('Content-Type', 'application/javascript') + .expect(200, done); + }); - it("GET request to live html", function(done) { - req.get("/webpack-dev-server/") - .expect("Content-Type", "text/html") - .expect(200, /__webpack_dev_server__/, done); - }); + it('GET request to sockjs bundle', (done) => { + req.get('/__webpack_dev_server__/sockjs.bundle.js') + .expect('Content-Type', 'application/javascript') + .expect(200, done); + }); - it("GET request to directory index", function(done) { - req.get("/webpack-dev-server") - .expect("Content-Type", "text/html") - .expect(200, directoryIndex.trim(), done); - }); + it('GET request to live html', (done) => { + req.get('/webpack-dev-server/') + .expect('Content-Type', 'text/html') + .expect(200, /__webpack_dev_server__/, done); + }); - it("GET request to magic html", function(done) { - req.get("/bundle") - .expect(200, magicHtml.trim(), done); - }); + it('GET request to directory index', (done) => { + req.get('/webpack-dev-server') + .expect('Content-Type', 'text/html') + .expect(200, directoryIndex.trim(), done); + }); - it("GET request with headers", function(done) { - req.get("/bundle") - .expect("X-Foo", "1") - .expect(200, done); - }); + it('GET request to magic html', (done) => { + req.get('/bundle') + .expect(200, magicHtml.trim(), done); + }); + + it('GET request with headers', (done) => { + req.get('/bundle') + .expect('X-Foo', '1') + .expect(200, done); + }); }); diff --git a/test/Validation.test.js b/test/Validation.test.js index 6ccc0809fc..2c8ddc11cf 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -1,185 +1,184 @@ -"use strict"; -const config = require("./fixtures/simple-config/webpack.config"); -const OptionsValidationError = require("../lib/OptionsValidationError"); -const Server = require("../lib/Server"); -const webpack = require("webpack"); -describe("Validation", function() { - let compiler; - before(function() { - compiler = webpack(config); - }); - const testCases = [{ - name: "invalid `hot` configuration", - config: { hot: "asdf" }, - message: [ - " - configuration.hot should be a boolean." - ] - }, { - name: "invalid `public` configuration", - config: { public: 1 }, - message: [ - " - configuration.public should be a string." - ] - }, { - name: "invalid `allowedHosts` configuration", - config: { allowedHosts: 1 }, - message: [ - " - configuration.allowedHosts should be an array:", - " [string]", - " Specifies which hosts are allowed to access the dev server." - ] - }, { - name: "invalid `contentBase` configuration", - config: { contentBase: [0] }, - message: [ - " - configuration.contentBase should be one of these:", - " [string] | false | number | string", - " A directory to serve files non-webpack files from.", - " Details:", - " * configuration.contentBase[0] should be a string.", - " * configuration.contentBase should be false", - " * configuration.contentBase should be a number.", - " * configuration.contentBase should be a string." - ] - }, { - name: "non-existing key configuration", - config: { asdf: true }, - message: [ - " - configuration has an unknown property 'asdf'. These properties are valid:", - " object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, " + - "watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, " + - "inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, " + - "compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " + - "noInfo?, quiet?, serverSideRender?, index?, log?, warn? }" - ] - }]; - testCases.forEach(function(testCase) { - it(`should fail validation for ${testCase.name}`, function() { - try { - new Server(compiler, testCase.config); - } catch(e) { - if(!(e instanceof OptionsValidationError)) - throw e; - e.message.should.startWith("Invalid configuration object."); - e.message.split("\n").slice(1).should.be.eql(testCase.message); - return; - } - throw new Error("Validation didn't fail"); - }) - }); +const config = require('./fixtures/simple-config/webpack.config'); +const OptionsValidationError = require('../lib/OptionsValidationError'); +const Server = require('../lib/Server'); +const webpack = require('webpack'); - describe("checkHost", function() { - it("should always allow any host if options.disableHostCheck is set", function() { - const options = { - public: "test.host:80", - disableHostCheck: true - }; - const headers = { - host: "bad.host" - }; - const server = new Server(compiler, options); - if(!server.checkHost(headers)) { - throw new Error("Validation didn't fail"); - } - }); +describe('Validation', () => { + let compiler; + before(() => { + compiler = webpack(config); + }); + const testCases = [{ + name: 'invalid `hot` configuration', + config: { hot: 'asdf' }, + message: [ + ' - configuration.hot should be a boolean.', + ], + }, { + name: 'invalid `public` configuration', + config: { public: 1 }, + message: [ + ' - configuration.public should be a string.', + ], + }, { + name: 'invalid `allowedHosts` configuration', + config: { allowedHosts: 1 }, + message: [ + ' - configuration.allowedHosts should be an array:', + ' [string]', + ' Specifies which hosts are allowed to access the dev server.', + ], + }, { + name: 'invalid `contentBase` configuration', + config: { contentBase: [0] }, + message: [ + ' - configuration.contentBase should be one of these:', + ' [string] | false | number | string', + ' A directory to serve files non-webpack files from.', + ' Details:', + ' * configuration.contentBase[0] should be a string.', + ' * configuration.contentBase should be false', + ' * configuration.contentBase should be a number.', + ' * configuration.contentBase should be a string.', + ], + }, { + name: 'non-existing key configuration', + config: { asdf: true }, + message: [ + " - configuration has an unknown property 'asdf'. These properties are valid:", + ' object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, ' + + 'watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, ' + + 'inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, ' + + 'compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, ' + + 'noInfo?, quiet?, serverSideRender?, index?, log?, warn? }', + ], + }]; + testCases.forEach((testCase) => { + it(`should fail validation for ${testCase.name}`, () => { + try { + new Server(compiler, testCase.config); + } catch (e) { + if (!(e instanceof OptionsValidationError)) { throw e; } + e.message.should.startWith('Invalid configuration object.'); + e.message.split('\n').slice(1).should.be.eql(testCase.message); + return; + } + throw new Error("Validation didn't fail"); + }); + }); - it("should allow any valid options.public when host is localhost", function() { - const options = { - public: "test.host:80" - }; - const headers = { - host: "localhost" - }; - const server = new Server(compiler, options); - if(!server.checkHost(headers)) { - throw new Error("Validation didn't fail"); - } - }); + describe('checkHost', () => { + it('should always allow any host if options.disableHostCheck is set', () => { + const options = { + public: 'test.host:80', + disableHostCheck: true, + }; + const headers = { + host: 'bad.host', + }; + const server = new Server(compiler, options); + if (!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); - it("should allow any valid options.public when host is 127.0.0.1", function() { - const options = { - public: "test.host:80" - }; - const headers = { - host: "127.0.0.1" - }; - const server = new Server(compiler, options); - if(!server.checkHost(headers)) { - throw new Error("Validation didn't fail"); - } - }); + it('should allow any valid options.public when host is localhost', () => { + const options = { + public: 'test.host:80', + }; + const headers = { + host: 'localhost', + }; + const server = new Server(compiler, options); + if (!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); - it("should allow access for every requests using an IP", function() { - const options = {}; - const testHosts = [ - "192.168.1.123", - "192.168.1.2:8080", - "[::1]", - "[::1]:8080", - "[ad42::1de2:54c2:c2fa:1234]", - "[ad42::1de2:54c2:c2fa:1234]:8080" - ]; + it('should allow any valid options.public when host is 127.0.0.1', () => { + const options = { + public: 'test.host:80', + }; + const headers = { + host: '127.0.0.1', + }; + const server = new Server(compiler, options); + if (!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); - const server = new Server(compiler, options); - testHosts.forEach(function(testHost) { - const headers = { host: testHost }; - if(!server.checkHost(headers)) { - throw new Error("Validation didn't pass"); - } - }); - }); + it('should allow access for every requests using an IP', () => { + const options = {}; + const testHosts = [ + '192.168.1.123', + '192.168.1.2:8080', + '[::1]', + '[::1]:8080', + '[ad42::1de2:54c2:c2fa:1234]', + '[ad42::1de2:54c2:c2fa:1234]:8080', + ]; - it("should not allow hostnames that don't match options.public", function() { - const options = { - public: "test.host:80", - }; - const headers = { - host: "test.hostname:80" - }; - const server = new Server(compiler, options); - if(server.checkHost(headers)) { - throw new Error("Validation didn't fail"); - } - }); + const server = new Server(compiler, options); + testHosts.forEach((testHost) => { + const headers = { host: testHost }; + if (!server.checkHost(headers)) { + throw new Error("Validation didn't pass"); + } + }); + }); - describe("allowedHosts", function() { - it("should allow hosts in allowedHosts", function() { - const testHosts = [ - "test.host", - "test2.host", - "test3.host" - ]; - const options = { allowedHosts: testHosts }; - const server = new Server(compiler, options); + it("should not allow hostnames that don't match options.public", () => { + const options = { + public: 'test.host:80', + }; + const headers = { + host: 'test.hostname:80', + }; + const server = new Server(compiler, options); + if (server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); - testHosts.forEach(function(testHost) { - const headers = { host: testHost }; - if(!server.checkHost(headers)) { - throw new Error("Validation didn't fail"); - } - }); - }); - it("should allow hosts that pass a wildcard in allowedHosts", function() { - const options = { allowedHosts: [".example.com"] }; - const server = new Server(compiler, options); - const testHosts = [ - "www.example.com", - "subdomain.example.com", - "example.com", - "subsubcomain.subdomain.example.com", - "example.com:80", - "subdomain.example.com:80" - ]; + describe('allowedHosts', () => { + it('should allow hosts in allowedHosts', () => { + const testHosts = [ + 'test.host', + 'test2.host', + 'test3.host', + ]; + const options = { allowedHosts: testHosts }; + const server = new Server(compiler, options); - testHosts.forEach(function(testHost) { - const headers = { host: testHost }; - if(!server.checkHost(headers)) { - throw new Error("Validation didn't fail"); - } - }); - }); - }); - }) + testHosts.forEach((testHost) => { + const headers = { host: testHost }; + if (!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); + }); + it('should allow hosts that pass a wildcard in allowedHosts', () => { + const options = { allowedHosts: ['.example.com'] }; + const server = new Server(compiler, options); + const testHosts = [ + 'www.example.com', + 'subdomain.example.com', + 'example.com', + 'subsubcomain.subdomain.example.com', + 'example.com:80', + 'subdomain.example.com:80', + ]; + + testHosts.forEach((testHost) => { + const headers = { host: testHost }; + if (!server.checkHost(headers)) { + throw new Error("Validation didn't fail"); + } + }); + }); + }); + }); }); diff --git a/test/fixtures/contentbase-config/foo.js b/test/fixtures/contentbase-config/foo.js index 01a3a05c17..e0b66dfbfa 100644 --- a/test/fixtures/contentbase-config/foo.js +++ b/test/fixtures/contentbase-config/foo.js @@ -1,3 +1,3 @@ -require("./index.html"); +require('./index.html'); -console.log("Hey."); +console.log('Hey.'); diff --git a/test/fixtures/contentbase-config/webpack.config.js b/test/fixtures/contentbase-config/webpack.config.js index 8ec01d9183..218f332217 100644 --- a/test/fixtures/contentbase-config/webpack.config.js +++ b/test/fixtures/contentbase-config/webpack.config.js @@ -1,8 +1,8 @@ module.exports = { - context: __dirname, - entry: "./foo.js", - output: { - filename: "bundle.js", - publicPath: "/" - } + context: __dirname, + entry: './foo.js', + output: { + filename: 'bundle.js', + publicPath: '/', + }, }; diff --git a/test/fixtures/historyapifallback-2-config/foo.js b/test/fixtures/historyapifallback-2-config/foo.js index 3dea82f991..fd3d63ff92 100644 --- a/test/fixtures/historyapifallback-2-config/foo.js +++ b/test/fixtures/historyapifallback-2-config/foo.js @@ -1 +1 @@ -console.log("Hey."); +console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-2-config/webpack.config.js b/test/fixtures/historyapifallback-2-config/webpack.config.js index 42acc2c118..9f103c72c8 100644 --- a/test/fixtures/historyapifallback-2-config/webpack.config.js +++ b/test/fixtures/historyapifallback-2-config/webpack.config.js @@ -1,8 +1,8 @@ module.exports = { - context: __dirname, - entry: "./foo.js", - output: { - filename: "bundle.js", - path: "/" - } + context: __dirname, + entry: './foo.js', + output: { + filename: 'bundle.js', + path: '/', + }, }; diff --git a/test/fixtures/historyapifallback-3-config/foo.js b/test/fixtures/historyapifallback-3-config/foo.js index 5f6793297e..6236950572 100644 --- a/test/fixtures/historyapifallback-3-config/foo.js +++ b/test/fixtures/historyapifallback-3-config/foo.js @@ -1,2 +1,3 @@ -require("./bar.html"); -console.log("Hey."); +require('./bar.html'); + +console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-3-config/webpack.config.js b/test/fixtures/historyapifallback-3-config/webpack.config.js index f179e4cf17..a39c9ee63e 100644 --- a/test/fixtures/historyapifallback-3-config/webpack.config.js +++ b/test/fixtures/historyapifallback-3-config/webpack.config.js @@ -1,17 +1,17 @@ module.exports = { - context: __dirname, - entry: "./foo.js", - output: { - filename: "bundle.js", - path: "/" - }, - module: { - loaders: [ - { - test: /\.html$/, - loader: "file-loader", - query: { name: "index.html" } - } - ] - } + context: __dirname, + entry: './foo.js', + output: { + filename: 'bundle.js', + path: '/', + }, + module: { + loaders: [ + { + test: /\.html$/, + loader: 'file-loader', + query: { name: 'index.html' }, + }, + ], + }, }; diff --git a/test/fixtures/historyapifallback-config/foo.js b/test/fixtures/historyapifallback-config/foo.js index 63be220b2f..b8cb52c592 100644 --- a/test/fixtures/historyapifallback-config/foo.js +++ b/test/fixtures/historyapifallback-config/foo.js @@ -1,3 +1,4 @@ -require("./index.html"); -require("./bar.html"); -console.log("Hey."); +require('./index.html'); +require('./bar.html'); + +console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-config/webpack.config.js b/test/fixtures/historyapifallback-config/webpack.config.js index 11aeca1d97..726afac5e0 100644 --- a/test/fixtures/historyapifallback-config/webpack.config.js +++ b/test/fixtures/historyapifallback-config/webpack.config.js @@ -1,17 +1,17 @@ module.exports = { - context: __dirname, - entry: "./foo.js", - output: { - filename: "bundle.js", - path: "/" - }, - module: { - loaders: [ - { - test: /\.html$/, - loader: "file-loader", - query: { name: "[name].[ext]" } - } - ] - } + context: __dirname, + entry: './foo.js', + output: { + filename: 'bundle.js', + path: '/', + }, + module: { + loaders: [ + { + test: /\.html$/, + loader: 'file-loader', + query: { name: '[name].[ext]' }, + }, + ], + }, }; diff --git a/test/fixtures/proxy-config/foo.js b/test/fixtures/proxy-config/foo.js index 3dea82f991..cd23a458ba 100644 --- a/test/fixtures/proxy-config/foo.js +++ b/test/fixtures/proxy-config/foo.js @@ -1 +1 @@ -console.log("Hey."); +console.log('Hey.'); diff --git a/test/fixtures/proxy-config/webpack.config.js b/test/fixtures/proxy-config/webpack.config.js index 42acc2c118..9f103c72c8 100644 --- a/test/fixtures/proxy-config/webpack.config.js +++ b/test/fixtures/proxy-config/webpack.config.js @@ -1,8 +1,8 @@ module.exports = { - context: __dirname, - entry: "./foo.js", - output: { - filename: "bundle.js", - path: "/" - } + context: __dirname, + entry: './foo.js', + output: { + filename: 'bundle.js', + path: '/', + }, }; diff --git a/test/fixtures/simple-config/foo.js b/test/fixtures/simple-config/foo.js index 3dea82f991..cd23a458ba 100644 --- a/test/fixtures/simple-config/foo.js +++ b/test/fixtures/simple-config/foo.js @@ -1 +1 @@ -console.log("Hey."); +console.log('Hey.'); diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index 42acc2c118..9f103c72c8 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -1,8 +1,8 @@ module.exports = { - context: __dirname, - entry: "./foo.js", - output: { - filename: "bundle.js", - path: "/" - } + context: __dirname, + entry: './foo.js', + output: { + filename: 'bundle.js', + path: '/', + }, }; diff --git a/test/helper.js b/test/helper.js index c25a4e1dfa..165118c354 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,33 +1,33 @@ -"use strict"; -const Server = require("../lib/Server"); -const webpack = require("webpack"); + +const Server = require('../lib/Server'); +const webpack = require('webpack'); let server; module.exports = { - start: function(config, options, done) { - if(options.quiet === undefined) { - options.quiet = true; - } - const compiler = webpack(config); - server = new Server(compiler, options); + start(config, options, done) { + if (options.quiet === undefined) { + options.quiet = true; + } + const compiler = webpack(config); + server = new Server(compiler, options); - server.listen(8080, "localhost", function(err) { - if(err) return done(err); - done(); - }); + server.listen(8080, 'localhost', (err) => { + if (err) return done(err); + done(); + }); - return server; - }, - close: function(done) { - if(server) { - server.close(function() { - server = null; - done(); - }); - } else { - done(); - } - } + return server; + }, + close(done) { + if (server) { + server.close(() => { + server = null; + done(); + }); + } else { + done(); + } + }, }; From c3a2f69f240429956eb4e06a3f1eefe5a22bb27c Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 17:21:53 -0400 Subject: [PATCH 06/10] cleanup test linting --- .eslintignore | 1 - test/ContentBase.test.js | 3 +-- test/Lazy.test.js | 1 - test/Proxy.test.js | 5 ++--- test/Routes.test.js | 3 +-- test/Validation.test.js | 6 +++--- test/fixtures/contentbase-config/foo.js | 2 +- test/helper.js | 4 ++-- 8 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.eslintignore b/.eslintignore index f30eb6505d..1e107f52e4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1 @@ examples -test diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index e39c19b7f7..392eb1d24c 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -1,7 +1,6 @@ - -const request = require('supertest'); const path = require('path'); +const request = require('supertest'); const helper = require('./helper'); const config = require('./fixtures/contentbase-config/webpack.config'); require('mocha-sinon'); diff --git a/test/Lazy.test.js b/test/Lazy.test.js index 9d225cbdf8..d0555bc026 100644 --- a/test/Lazy.test.js +++ b/test/Lazy.test.js @@ -1,5 +1,4 @@ - const should = require('should'); const helper = require('./helper'); const config = require('./fixtures/simple-config/webpack.config'); diff --git a/test/Proxy.test.js b/test/Proxy.test.js index 3b509f0658..b1600d33b7 100644 --- a/test/Proxy.test.js +++ b/test/Proxy.test.js @@ -1,11 +1,10 @@ - -const request = require('supertest'); const path = require('path'); +const request = require('supertest'); const express = require('express'); const WebSocket = require('ws'); -const helper = require('./helper'); const should = require('should'); +const helper = require('./helper'); const config = require('./fixtures/proxy-config/webpack.config'); const WebSocketServer = WebSocket.Server; diff --git a/test/Routes.test.js b/test/Routes.test.js index 36d03c2e28..fcc9a0437f 100644 --- a/test/Routes.test.js +++ b/test/Routes.test.js @@ -1,8 +1,7 @@ - -const request = require('supertest'); const fs = require('fs'); const path = require('path'); +const request = require('supertest'); const helper = require('./helper'); const config = require('./fixtures/simple-config/webpack.config'); diff --git a/test/Validation.test.js b/test/Validation.test.js index 2c8ddc11cf..2407e6a585 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -1,9 +1,8 @@ - -const config = require('./fixtures/simple-config/webpack.config'); +const webpack = require('webpack'); const OptionsValidationError = require('../lib/OptionsValidationError'); const Server = require('../lib/Server'); -const webpack = require('webpack'); +const config = require('./fixtures/simple-config/webpack.config'); describe('Validation', () => { let compiler; @@ -58,6 +57,7 @@ describe('Validation', () => { testCases.forEach((testCase) => { it(`should fail validation for ${testCase.name}`, () => { try { + // eslint-disable-next-line no-new new Server(compiler, testCase.config); } catch (e) { if (!(e instanceof OptionsValidationError)) { throw e; } diff --git a/test/fixtures/contentbase-config/foo.js b/test/fixtures/contentbase-config/foo.js index e0b66dfbfa..c45a498241 100644 --- a/test/fixtures/contentbase-config/foo.js +++ b/test/fixtures/contentbase-config/foo.js @@ -1,3 +1,3 @@ -require('./index.html'); +require('./index.html'); // eslint-disable-line console.log('Hey.'); diff --git a/test/helper.js b/test/helper.js index 165118c354..0a45ad6d0a 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,12 +1,12 @@ - -const Server = require('../lib/Server'); const webpack = require('webpack'); +const Server = require('../lib/Server'); let server; module.exports = { start(config, options, done) { + // eslint-disable-next-line no-undefined if (options.quiet === undefined) { options.quiet = true; } From 16cb162fa55b10848df8c598904025a973fc9b26 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 17:31:55 -0400 Subject: [PATCH 07/10] cleanup example linting --- .eslintignore | 1 - examples/history-api-fallback/app.js | 1 + examples/node-api-middleware/app.js | 5 ++++- examples/node-api-simple/app.js | 5 ++++- examples/proxy-hot-reload/proxy-config.js | 2 +- examples/proxy-hot-reload/webpack.config.js | 7 ++++--- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.eslintignore b/.eslintignore index 1e107f52e4..e69de29bb2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +0,0 @@ -examples diff --git a/examples/history-api-fallback/app.js b/examples/history-api-fallback/app.js index fd50bbdb25..c902a7c514 100644 --- a/examples/history-api-fallback/app.js +++ b/examples/history-api-fallback/app.js @@ -1,3 +1,4 @@ +/* global XMLHttpRequest */ const path = document.location.pathname; document.write(`It's working from path ${path}`); diff --git a/examples/node-api-middleware/app.js b/examples/node-api-middleware/app.js index f9caaf8b35..707e792acb 100644 --- a/examples/node-api-middleware/app.js +++ b/examples/node-api-middleware/app.js @@ -1,7 +1,10 @@ document.write("It's working."); // This results in a warning: -if (!window) require(`./${window}parseable.js`); +if (!window) { + // eslint-disable-next-line + require(`./${window}parseable.js`); +} // This results in an error: // if(!window) require("test"); diff --git a/examples/node-api-simple/app.js b/examples/node-api-simple/app.js index f9caaf8b35..707e792acb 100644 --- a/examples/node-api-simple/app.js +++ b/examples/node-api-simple/app.js @@ -1,7 +1,10 @@ document.write("It's working."); // This results in a warning: -if (!window) require(`./${window}parseable.js`); +if (!window) { + // eslint-disable-next-line + require(`./${window}parseable.js`); +} // This results in an error: // if(!window) require("test"); diff --git a/examples/proxy-hot-reload/proxy-config.js b/examples/proxy-hot-reload/proxy-config.js index 6ec5ad445a..ff1fa6bae0 100644 --- a/examples/proxy-hot-reload/proxy-config.js +++ b/examples/proxy-hot-reload/proxy-config.js @@ -13,6 +13,6 @@ module.exports = { /** / module.exports = { - target: 'http://reqres.in/' + target: 'http://reqres.in/' }; /**/ diff --git a/examples/proxy-hot-reload/webpack.config.js b/examples/proxy-hot-reload/webpack.config.js index 3bb03cfac6..6e788dff24 100644 --- a/examples/proxy-hot-reload/webpack.config.js +++ b/examples/proxy-hot-reload/webpack.config.js @@ -1,7 +1,6 @@ - +/* eslint global-require: off */ const fs = require('fs'); - const proxyConfig = require('./proxy-config'); let proxyOptions = { @@ -24,7 +23,9 @@ fs.watch('./proxy-config.js', () => { changeOrigin: true, }; } - } catch (e) {} + } catch (e) { + // eslint-disable-line + } }); module.exports = { From e5fcd06d91e818f209c1237e4021c4bf1f4b885a Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 19:35:50 -0400 Subject: [PATCH 08/10] adding comma dangle, fixing prepublish --- .eslintrc | 1 + bin/webpack-dev-server.js | 68 +++++++++---------- client/index.js | 6 +- client/live.js | 16 ++--- client/overlay.js | 6 +- client/webpack.config.js | 18 +++-- client/webpack.sockjs.config.js | 9 ++- examples/bonjour/webpack.config.js | 2 +- examples/cli-open-page/webpack.config.js | 2 +- examples/cli-public/webpack.config.js | 2 +- examples/cli-stdin/webpack.config.js | 2 +- examples/compression/webpack.config.js | 2 +- examples/history-api-fallback/app.js | 2 +- .../history-api-fallback/webpack.config.js | 6 +- examples/hmr/webpack.config.js | 4 +- examples/host-port/webpack.config.js | 2 +- examples/https/webpack.config.js | 2 +- examples/listen-socket/webpack.config.js | 2 +- examples/modus-iframe/webpack.config.js | 2 +- examples/modus-inline/webpack.config.js | 12 ++-- examples/modus-lazy/webpack.config.js | 2 +- .../modus-manual-script/webpack.config.js | 2 +- examples/node-api-middleware/server.js | 4 +- .../node-api-middleware/webpack.config.js | 4 +- examples/node-api-simple/server.js | 4 +- examples/node-api-simple/webpack.config.js | 4 +- examples/overlay-warnings/webpack.config.js | 6 +- examples/overlay/webpack.config.js | 4 +- examples/proxy-advanced/webpack.config.js | 10 +-- examples/proxy-hot-reload/proxy-config.js | 4 +- examples/proxy-hot-reload/webpack.config.js | 10 +-- examples/proxy-simple/webpack.config.js | 6 +- examples/watch-content-base/webpack.config.js | 6 +- .../webpack-config-array/webpack.config.js | 30 ++++---- examples/webworker/web.js | 2 +- examples/webworker/webpack.config.js | 10 +-- examples/webworker/worker.js | 2 +- lib/Server.js | 20 +++--- lib/util/createDomain.js | 2 +- package.json | 7 +- test/Compress.test.js | 2 +- test/ContentBase.test.js | 10 +-- test/HistoryApiFallback.test.js | 26 +++---- test/Lazy.test.js | 4 +- test/Proxy.test.js | 26 +++---- test/Routes.test.js | 2 +- test/Validation.test.js | 42 ++++++------ .../contentbase-config/webpack.config.js | 4 +- .../webpack.config.js | 4 +- .../webpack.config.js | 10 +-- .../webpack.config.js | 10 +-- test/fixtures/proxy-config/webpack.config.js | 4 +- test/fixtures/simple-config/webpack.config.js | 4 +- test/helper.js | 2 +- 54 files changed, 235 insertions(+), 220 deletions(-) diff --git a/.eslintrc b/.eslintrc index deb9f30449..20dec83382 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,7 @@ "window": true }, "rules": { + "comma-dangle": ["error", "never"], "consistent-return": "off", "no-param-reassign": "off", "no-underscore-dangle": "off", diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index 73c815ab6c..bd78010822 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -71,43 +71,43 @@ const DEFAULT_PORT = 8080; yargs.options({ bonjour: { type: 'boolean', - describe: 'Broadcasts the server via ZeroConf networking on start', + describe: 'Broadcasts the server via ZeroConf networking on start' }, lazy: { type: 'boolean', - describe: 'Lazy', + describe: 'Lazy' }, inline: { type: 'boolean', default: true, - describe: 'Inline mode (set to false to disable including client scripts like livereload)', + describe: 'Inline mode (set to false to disable including client scripts like livereload)' }, progress: { type: 'boolean', describe: 'Print compilation progress in percentage', - group: BASIC_GROUP, + group: BASIC_GROUP }, 'hot-only': { type: 'boolean', describe: 'Do not refresh page if HMR fails', - group: ADVANCED_GROUP, + group: ADVANCED_GROUP }, stdin: { type: 'boolean', - describe: 'close when stdin ends', + describe: 'close when stdin ends' }, open: { type: 'boolean', - describe: 'Open default browser', + describe: 'Open default browser' }, useLocalIp: { type: 'boolean', - describe: 'Open default browser with local IP', + describe: 'Open default browser with local IP' }, 'open-page': { type: 'string', describe: 'Open default browser with the specified page', - requiresArg: true, + requiresArg: true }, color: { type: 'boolean', @@ -116,111 +116,111 @@ yargs.options({ return require('supports-color'); }, group: DISPLAY_GROUP, - describe: 'Enables/Disables colors on the console', + describe: 'Enables/Disables colors on the console' }, info: { type: 'boolean', group: DISPLAY_GROUP, default: true, - describe: 'Info', + describe: 'Info' }, quiet: { type: 'boolean', group: DISPLAY_GROUP, - describe: 'Quiet', + describe: 'Quiet' }, 'client-log-level': { type: 'string', group: DISPLAY_GROUP, default: 'info', - describe: 'Log level in the browser (info, warning, error or none)', + describe: 'Log level in the browser (info, warning, error or none)' }, https: { type: 'boolean', group: SSL_GROUP, - describe: 'HTTPS', + describe: 'HTTPS' }, key: { type: 'string', describe: 'Path to a SSL key.', - group: SSL_GROUP, + group: SSL_GROUP }, cert: { type: 'string', describe: 'Path to a SSL certificate.', - group: SSL_GROUP, + group: SSL_GROUP }, cacert: { type: 'string', describe: 'Path to a SSL CA certificate.', - group: SSL_GROUP, + group: SSL_GROUP }, pfx: { type: 'string', describe: 'Path to a SSL pfx file.', - group: SSL_GROUP, + group: SSL_GROUP }, 'pfx-passphrase': { type: 'string', describe: 'Passphrase for pfx file.', - group: SSL_GROUP, + group: SSL_GROUP }, 'content-base': { type: 'string', describe: 'A directory or URL to serve HTML content from.', - group: RESPONSE_GROUP, + group: RESPONSE_GROUP }, 'watch-content-base': { type: 'boolean', describe: 'Enable live-reloading of the content-base.', - group: RESPONSE_GROUP, + group: RESPONSE_GROUP }, 'history-api-fallback': { type: 'boolean', describe: 'Fallback to /index.html for Single Page Applications.', - group: RESPONSE_GROUP, + group: RESPONSE_GROUP }, compress: { type: 'boolean', describe: 'Enable gzip compression', - group: RESPONSE_GROUP, + group: RESPONSE_GROUP }, port: { describe: 'The port', - group: CONNECTION_GROUP, + group: CONNECTION_GROUP }, 'disable-host-check': { type: 'boolean', describe: 'Will not check the host', - group: CONNECTION_GROUP, + group: CONNECTION_GROUP }, socket: { type: 'String', describe: 'Socket to listen', - group: CONNECTION_GROUP, + group: CONNECTION_GROUP }, public: { type: 'string', describe: 'The public hostname/ip address of the server', - group: CONNECTION_GROUP, + group: CONNECTION_GROUP }, host: { type: 'string', default: 'localhost', describe: 'The hostname/ip address the server will bind to', - group: CONNECTION_GROUP, + group: CONNECTION_GROUP }, 'allowed-hosts': { type: 'string', describe: 'A comma-delimited string of hosts that are allowed to access the dev server', - group: CONNECTION_GROUP, - }, + group: CONNECTION_GROUP + } }); const { argv } = yargs; const wpOpt = require('webpack/bin/convert-argv')(yargs, argv, { - outputFilename: '/bundle.js', + outputFilename: '/bundle.js' }); function processOptions(wpOpt) { @@ -290,7 +290,7 @@ function processOptions(wpOpt) { if (!options.stats) { options.stats = { cached: false, - cachedAssets: false, + cachedAssets: false }; } @@ -365,7 +365,7 @@ function startDevServer(wpOpt, options) { if (argv.progress) { compiler.apply(new webpack.ProgressPlugin({ - profile: argv.profile, + profile: argv.profile })); } @@ -458,7 +458,7 @@ function broadcastZeroconf(options) { name: 'Webpack Dev Server', port: options.port, type: 'http', - subtypes: ['webpack'], + subtypes: ['webpack'] }); process.on('exit', () => { bonjour.unpublishAll(() => { diff --git a/client/index.js b/client/index.js index 11ecbd5101..f771ddf279 100644 --- a/client/index.js +++ b/client/index.js @@ -54,7 +54,7 @@ function sendMsg(type, data) { ) { self.postMessage({ type: `webpack${type}`, - data, + data }, '*'); } } @@ -144,7 +144,7 @@ const onSocketMsg = { close() { log.error('[WDS] Disconnected!'); sendMsg('Close'); - }, + } }; let hostname = urlParts.hostname; @@ -175,7 +175,7 @@ const socketUrl = url.format({ auth: urlParts.auth, hostname, port: (urlParts.port === '0') ? self.location.port : urlParts.port, - pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : urlParts.path, + pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : urlParts.path }); socket(socketUrl, onSocketMsg); diff --git a/client/live.js b/client/live.js index 20d337144f..e0201362db 100644 --- a/client/live.js +++ b/client/live.js @@ -22,7 +22,7 @@ $(() => { $errors.hide(); iframe.hide(); header.css({ - borderColor: '#96b5b4', + borderColor: '#96b5b4' }); const onSocketMsg = { @@ -34,7 +34,7 @@ $(() => { okness.text(''); status.text('App updated. Recompiling...'); header.css({ - borderColor: '#96b5b4', + borderColor: '#96b5b4' }); $errors.hide(); if (!hot) iframe.hide(); @@ -46,7 +46,7 @@ $(() => { okness.text(''); status.text('App ready.'); header.css({ - borderColor: '', + borderColor: '' }); $errors.hide(); if (!hot) iframe.show(); @@ -66,7 +66,7 @@ $(() => { okness.text('Errors while compiling.'); $errors.text(`\n${stripAnsi(errors.join('\n\n\n'))}\n\n`); header.css({ - borderColor: '#ebcb8b', + borderColor: '#ebcb8b' }); $errors.show(); iframe.hide(); @@ -76,11 +76,11 @@ $(() => { okness.text('Disconnected.'); $errors.text('\n\n\n Lost connection to webpack-dev-server.\n Please restart the server to reestablish connection...\n\n\n\n'); header.css({ - borderColor: '#ebcb8b', + borderColor: '#ebcb8b' }); $errors.show(); iframe.hide(); - }, + } }; socket('/sockjs-node', onSocketMsg); @@ -88,7 +88,7 @@ $(() => { iframe.load(() => { status.text('App ready.'); header.css({ - borderColor: '', + borderColor: '' }); iframe.show(); }); @@ -105,7 +105,7 @@ $(() => { } else { status.text('App updated. Reloading app...'); header.css({ - borderColor: '#96b5b4', + borderColor: '#96b5b4' }); try { let old = `${iframe[0].contentWindow.location}`; diff --git a/client/overlay.js b/client/overlay.js index 35b13ee3d9..90196598c0 100644 --- a/client/overlay.js +++ b/client/overlay.js @@ -15,7 +15,7 @@ const colors = { magenta: '7FACCA', cyan: 'C3C2EF', lightgrey: 'EBE7E3', - darkgrey: '6D7891', + darkgrey: '6D7891' }; ansiHTML.setColors(colors); @@ -93,9 +93,9 @@ function ensureOverlayDivExists(onOverlayDivReady) { } function showMessageOverlay(message) { - ensureOverlayDivExists((overlayDiv) => { + ensureOverlayDivExists((div) => { // Make it look similar to our terminal. - overlayDiv.innerHTML = + div.innerHTML = `Failed to compile.

${ diff --git a/client/webpack.config.js b/client/webpack.config.js index b00b28c9d0..ce6469b4a6 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -1,19 +1,25 @@ + +const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); + module.exports = { module: { rules: [ { test: /\.pug$/, use: [ - 'pug-loader?self', - ], + 'pug-loader?self' + ] }, { test: /\.css$/, use: [ 'style-loader', - 'css-loader', - ], - }, - ], + 'css-loader' + ] + } + ] }, + plugins: [ + new UglifyJSPlugin() + ] }; diff --git a/client/webpack.sockjs.config.js b/client/webpack.sockjs.config.js index c1fe1117dd..7d7964213a 100644 --- a/client/webpack.sockjs.config.js +++ b/client/webpack.sockjs.config.js @@ -1,6 +1,13 @@ + +// eslint-disable-next-line +const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); + module.exports = { output: { library: 'SockJS', - libraryTarget: 'umd', + libraryTarget: 'umd' }, + plugins: [ + new UglifyJSPlugin() + ] }; diff --git a/examples/bonjour/webpack.config.js b/examples/bonjour/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/bonjour/webpack.config.js +++ b/examples/bonjour/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/cli-open-page/webpack.config.js b/examples/cli-open-page/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/cli-open-page/webpack.config.js +++ b/examples/cli-open-page/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/cli-public/webpack.config.js b/examples/cli-public/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/cli-public/webpack.config.js +++ b/examples/cli-public/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/cli-stdin/webpack.config.js b/examples/cli-stdin/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/cli-stdin/webpack.config.js +++ b/examples/cli-stdin/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/compression/webpack.config.js b/examples/compression/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/compression/webpack.config.js +++ b/examples/compression/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/history-api-fallback/app.js b/examples/history-api-fallback/app.js index c902a7c514..aa9da65c2e 100644 --- a/examples/history-api-fallback/app.js +++ b/examples/history-api-fallback/app.js @@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', () => { const tests = [ { url: '/', name: 'index', re: /^/ }, { url: '/test', name: 'unexisting path', re: /^/ }, - { url: '/file.txt', name: 'existing path', re: /^file/ }, + { url: '/file.txt', name: 'existing path', re: /^file/ } ]; const table = document.createElement('table'); diff --git a/examples/history-api-fallback/webpack.config.js b/examples/history-api-fallback/webpack.config.js index db348ef618..98969d24b0 100644 --- a/examples/history-api-fallback/webpack.config.js +++ b/examples/history-api-fallback/webpack.config.js @@ -3,7 +3,7 @@ module.exports = { entry: './app.js', devServer: { historyApiFallback: { - disableDotRule: true, - }, - }, + disableDotRule: true + } + } }; diff --git a/examples/hmr/webpack.config.js b/examples/hmr/webpack.config.js index 20c53854b6..37c27ee2ec 100644 --- a/examples/hmr/webpack.config.js +++ b/examples/hmr/webpack.config.js @@ -6,6 +6,6 @@ module.exports = { context: __dirname, entry: './app.js', plugins: [ - new webpack.NamedModulesPlugin(), - ], + new webpack.NamedModulesPlugin() + ] }; diff --git a/examples/host-port/webpack.config.js b/examples/host-port/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/host-port/webpack.config.js +++ b/examples/host-port/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/https/webpack.config.js b/examples/https/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/https/webpack.config.js +++ b/examples/https/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/listen-socket/webpack.config.js b/examples/listen-socket/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/listen-socket/webpack.config.js +++ b/examples/listen-socket/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/modus-iframe/webpack.config.js b/examples/modus-iframe/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/modus-iframe/webpack.config.js +++ b/examples/modus-iframe/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/modus-inline/webpack.config.js b/examples/modus-inline/webpack.config.js index da350877c5..871b314b7e 100644 --- a/examples/modus-inline/webpack.config.js +++ b/examples/modus-inline/webpack.config.js @@ -8,14 +8,14 @@ module.exports = { use: [ 'style-loader', 'css-loader', - 'less-loader', - ], + 'less-loader' + ] }, { test: /\.png$/, loader: 'file-loader', - options: { prefix: 'img/' }, - }, - ], - }, + options: { prefix: 'img/' } + } + ] + } }; diff --git a/examples/modus-lazy/webpack.config.js b/examples/modus-lazy/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/modus-lazy/webpack.config.js +++ b/examples/modus-lazy/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/modus-manual-script/webpack.config.js b/examples/modus-manual-script/webpack.config.js index 5b42517f8c..f19bd324bf 100644 --- a/examples/modus-manual-script/webpack.config.js +++ b/examples/modus-manual-script/webpack.config.js @@ -1,4 +1,4 @@ module.exports = { context: __dirname, - entry: './app.js', + entry: './app.js' }; diff --git a/examples/node-api-middleware/server.js b/examples/node-api-middleware/server.js index 175cdc2c0f..5f6ec4b40d 100644 --- a/examples/node-api-middleware/server.js +++ b/examples/node-api-middleware/server.js @@ -7,14 +7,14 @@ const webpackConfig = require('./webpack.config'); const compiler = Webpack(webpackConfig); const server = new WebpackDevServer(compiler, { stats: { - colors: true, + colors: true }, setup(app) { app.use((req, res, next) => { console.log(`Using middleware for ${req.url}`); next(); }); - }, + } }); server.listen(8080, '127.0.0.1', () => { diff --git a/examples/node-api-middleware/webpack.config.js b/examples/node-api-middleware/webpack.config.js index 9890cef473..afcd3b765e 100644 --- a/examples/node-api-middleware/webpack.config.js +++ b/examples/node-api-middleware/webpack.config.js @@ -2,6 +2,6 @@ module.exports = { context: __dirname, entry: ['./app.js', '../../client/index.js?http://localhost:8080/'], output: { - filename: 'bundle.js', - }, + filename: 'bundle.js' + } }; diff --git a/examples/node-api-simple/server.js b/examples/node-api-simple/server.js index 921a089a34..1e5e570475 100644 --- a/examples/node-api-simple/server.js +++ b/examples/node-api-simple/server.js @@ -7,8 +7,8 @@ const webpackConfig = require('./webpack.config'); const compiler = Webpack(webpackConfig); const server = new WebpackDevServer(compiler, { stats: { - colors: true, - }, + colors: true + } }); server.listen(8080, '127.0.0.1', () => { diff --git a/examples/node-api-simple/webpack.config.js b/examples/node-api-simple/webpack.config.js index 9890cef473..afcd3b765e 100644 --- a/examples/node-api-simple/webpack.config.js +++ b/examples/node-api-simple/webpack.config.js @@ -2,6 +2,6 @@ module.exports = { context: __dirname, entry: ['./app.js', '../../client/index.js?http://localhost:8080/'], output: { - filename: 'bundle.js', - }, + filename: 'bundle.js' + } }; diff --git a/examples/overlay-warnings/webpack.config.js b/examples/overlay-warnings/webpack.config.js index 9f1f7a8142..8c0ef559a8 100644 --- a/examples/overlay-warnings/webpack.config.js +++ b/examples/overlay-warnings/webpack.config.js @@ -4,7 +4,7 @@ module.exports = { devServer: { overlay: { errors: true, - warnings: true, - }, - }, + warnings: true + } + } }; diff --git a/examples/overlay/webpack.config.js b/examples/overlay/webpack.config.js index cf889cd9a0..d4c70bb380 100644 --- a/examples/overlay/webpack.config.js +++ b/examples/overlay/webpack.config.js @@ -2,6 +2,6 @@ module.exports = { context: __dirname, entry: './app.js', devServer: { - overlay: true, - }, + overlay: true + } }; diff --git a/examples/proxy-advanced/webpack.config.js b/examples/proxy-advanced/webpack.config.js index a93b6f4d8e..665779277e 100644 --- a/examples/proxy-advanced/webpack.config.js +++ b/examples/proxy-advanced/webpack.config.js @@ -7,14 +7,14 @@ module.exports = { target: 'http://jsonplaceholder.typicode.com/', changeOrigin: true, pathRewrite: { - '^/api': '', + '^/api': '' }, bypass(req) { if (req.url === '/api/nope') { return '/bypass.html'; } - }, - }, - }, - }, + } + } + } + } }; diff --git a/examples/proxy-hot-reload/proxy-config.js b/examples/proxy-hot-reload/proxy-config.js index ff1fa6bae0..0f4079d247 100644 --- a/examples/proxy-hot-reload/proxy-config.js +++ b/examples/proxy-hot-reload/proxy-config.js @@ -2,8 +2,8 @@ module.exports = { target: 'http://jsonplaceholder.typicode.com/', pathRewrite: { - '^/api': '', - }, + '^/api': '' + } }; /**/ diff --git a/examples/proxy-hot-reload/webpack.config.js b/examples/proxy-hot-reload/webpack.config.js index 6e788dff24..9394c177c6 100644 --- a/examples/proxy-hot-reload/webpack.config.js +++ b/examples/proxy-hot-reload/webpack.config.js @@ -7,7 +7,7 @@ let proxyOptions = { context: '/api', target: proxyConfig.target, pathRewrite: proxyConfig.pathRewrite, - changeOrigin: true, + changeOrigin: true }; fs.watch('./proxy-config.js', () => { @@ -20,7 +20,7 @@ fs.watch('./proxy-config.js', () => { context: '/api', target: newProxyConfig.target, pathRewrite: newProxyConfig.pathRewrite, - changeOrigin: true, + changeOrigin: true }; } } catch (e) { @@ -35,7 +35,7 @@ module.exports = { proxy: [ function () { return proxyOptions; - }, - ], - }, + } + ] + } }; diff --git a/examples/proxy-simple/webpack.config.js b/examples/proxy-simple/webpack.config.js index 6403da2eca..b1882b65f9 100644 --- a/examples/proxy-simple/webpack.config.js +++ b/examples/proxy-simple/webpack.config.js @@ -3,7 +3,7 @@ module.exports = { entry: './app.js', devServer: { proxy: { - '/api': 'http://127.0.0.1:50545', - }, - }, + '/api': 'http://127.0.0.1:50545' + } + } }; diff --git a/examples/watch-content-base/webpack.config.js b/examples/watch-content-base/webpack.config.js index 2f6a59f12e..e6366a2065 100644 --- a/examples/watch-content-base/webpack.config.js +++ b/examples/watch-content-base/webpack.config.js @@ -4,7 +4,7 @@ module.exports = { devServer: { contentBase: [ 'assets', - 'css', - ], - }, + 'css' + ] + } }; diff --git a/examples/webpack-config-array/webpack.config.js b/examples/webpack-config-array/webpack.config.js index 0db790abfe..d0f12b7253 100644 --- a/examples/webpack-config-array/webpack.config.js +++ b/examples/webpack-config-array/webpack.config.js @@ -13,22 +13,22 @@ module.exports = [ use: [ 'style-loader', 'css-loader', - 'less-loader', - ], + 'less-loader' + ] }, { test: /\.png$/, loader: 'file-loader', - options: { prefix: 'img/' }, - }, - ], - }, + options: { prefix: 'img/' } + } + ] + } }, { context: __dirname, entry: './app.js', output: { - filename: 'bundle2.js', + filename: 'bundle2.js' }, module: { rules: [ @@ -37,18 +37,18 @@ module.exports = [ use: [ 'style-loader', 'css-loader', - 'less-loader', - ], + 'less-loader' + ] }, { test: /\.png$/, loader: 'url-loader', - options: { limit: 100000 }, - }, - ], + options: { limit: 100000 } + } + ] }, plugins: [ - new webpack.optimize.UglifyJsPlugin(), - ], - }, + new webpack.optimize.UglifyJsPlugin() + ] + } ]; diff --git a/examples/webworker/web.js b/examples/webworker/web.js index 3357481e42..0684aa5b09 100644 --- a/examples/webworker/web.js +++ b/examples/webworker/web.js @@ -6,5 +6,5 @@ worker.onmessage = function (e) { console.log('[MAIN]', e); }; worker.postMessage({ - hello: 111, + hello: 111 }); diff --git a/examples/webworker/webpack.config.js b/examples/webworker/webpack.config.js index 3bd0e2200e..a382ee9014 100644 --- a/examples/webworker/webpack.config.js +++ b/examples/webworker/webpack.config.js @@ -7,8 +7,8 @@ module.exports = [ entry: './web.js', output: { filename: 'web.bundle.js', - path: __dirname, - }, + path: __dirname + } }, { devtool: 'source-map', @@ -16,7 +16,7 @@ module.exports = [ entry: './worker.js', output: { filename: 'worker.bundle.js', - path: __dirname, - }, - }, + path: __dirname + } + } ]; diff --git a/examples/webworker/worker.js b/examples/webworker/worker.js index 04dfc84f70..075dce718e 100644 --- a/examples/webworker/worker.js +++ b/examples/webworker/worker.js @@ -4,6 +4,6 @@ self.onmessage = function (e) { console.log('[WORKER]', e); self.postMessage({ - hello: 222, + hello: 222 }); }; diff --git a/lib/Server.js b/lib/Server.js index 9fb8d1e601..f53c9e2a5c 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -171,7 +171,7 @@ function Server(compiler, options) { if (typeof options.proxy[context] === 'string') { proxyOptions = { context: correctedContext, - target: options.proxy[context], + target: options.proxy[context] }; } else { proxyOptions = Object.assign({}, options.proxy[context]); @@ -267,7 +267,7 @@ function Server(compiler, options) { // Redirect every request to contentBase app.get('*', (req, res) => { res.writeHead(302, { - Location: contentBase + req.path + (req._parsedUrl.search || ''), + Location: contentBase + req.path + (req._parsedUrl.search || '') }); res.end(); }); @@ -277,7 +277,7 @@ function Server(compiler, options) { // Redirect every request to the port contentBase app.get('*', (req, res) => { res.writeHead(302, { - Location: `//localhost:${contentBase}${req.path}${req._parsedUrl.search || ''}`, + Location: `//localhost:${contentBase}${req.path}${req._parsedUrl.search || ''}` }); res.end(); }); @@ -324,7 +324,7 @@ function Server(compiler, options) { setup: () => { if (typeof options.setup === 'function') { options.setup(app, this); } - }, + } }; const defaultFeatures = ['setup', 'headers', 'middleware']; @@ -352,7 +352,7 @@ function Server(compiler, options) { cert: options.cert, ca: options.ca, pfx: options.pfx, - passphrase: options.pfxPassphrase, + passphrase: options.pfxPassphrase }; } @@ -382,7 +382,7 @@ function Server(compiler, options) { const pems = selfsigned.generate(attrs, { algorithm: 'sha256', days: 30, - keySize: 2048, + keySize: 2048 }); fs.writeFileSync(certPath, pems.private + pems.cert, { encoding: 'utf-8' }); @@ -395,7 +395,7 @@ function Server(compiler, options) { if (!options.https.spdy) { options.https.spdy = { - protocols: ['h2', 'http/1.1'], + protocols: ['h2', 'http/1.1'] }; } @@ -491,7 +491,7 @@ Server.prototype.listen = function (port, hostname) { if (severity === 'error') { console.log(line); } - }, + } }); sockServer.on('connection', (conn) => { if (!conn) return; @@ -520,7 +520,7 @@ Server.prototype.listen = function (port, hostname) { }); sockServer.installHandlers(this.listeningApp, { - prefix: '/sockjs-node', + prefix: '/sockjs-node' }); return returnValue; }; @@ -544,7 +544,7 @@ Server.prototype.sockWrite = function (sockets, type, data) { sockets.forEach((sock) => { sock.write(JSON.stringify({ type, - data, + data })); }); }; diff --git a/lib/util/createDomain.js b/lib/util/createDomain.js index 4bdf1eda35..30c591baa3 100644 --- a/lib/util/createDomain.js +++ b/lib/util/createDomain.js @@ -10,6 +10,6 @@ module.exports = function createDomain(options) { return options.public ? `${protocol}://${options.public}` : url.format({ protocol, hostname: options.useLocalIp ? internalIp.v4() : options.host, - port: options.socket ? 0 : options.port.toString(), + port: options.socket ? 0 : options.port.toString() }); }; diff --git a/package.json b/package.json index 8cfeebeda0..14cbc33e58 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "mocha": "mocha --full-trace --check-leaks", "prepublish": "npm run -s build:live && npm run -s build:index && npm run -s build:sockjs", "test": "npm run lint && npm run mocha", - "build:live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js -p", - "build:index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js -p", - "build:sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js -p" + "build:live": "webpack ./client/live.js client/live.bundle.js --color --config client/webpack.config.js", + "build:index": "webpack ./client/index.js client/index.bundle.js --color --config client/webpack.config.js", + "build:sockjs": "webpack ./client/sockjs.js client/sockjs.bundle.js --color --config client/webpack.sockjs.config.js" }, "files": [ "lib/", @@ -83,6 +83,7 @@ "sinon": "^3.2.1", "style-loader": "^0.18.2", "supertest": "^3.0.0", + "uglifyjs-webpack-plugin": "^1.0.0-beta.2", "url-loader": "~0.5.6", "webpack": "^3.0.0", "ws": "^3.1.0" diff --git a/test/Compress.test.js b/test/Compress.test.js index 3337631c72..26cf17d4b7 100644 --- a/test/Compress.test.js +++ b/test/Compress.test.js @@ -10,7 +10,7 @@ describe('Compress', () => { before((done) => { server = helper.start(config, { - compress: true, + compress: true }, done); req = request(server.app); }); diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index 392eb1d24c..2a851e4ffe 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -16,7 +16,7 @@ describe('ContentBase', () => { describe('to directory', () => { before((done) => { server = helper.start(config, { - contentBase: contentBasePublic, + contentBase: contentBasePublic }, done); req = request(server.app); }); @@ -35,7 +35,7 @@ describe('ContentBase', () => { describe('to directories', () => { before((done) => { server = helper.start(config, { - contentBase: [contentBasePublic, contentBaseOther], + contentBase: [contentBasePublic, contentBaseOther] }, done); req = request(server.app); }); @@ -54,7 +54,7 @@ describe('ContentBase', () => { describe('to port', () => { before((done) => { server = helper.start(config, { - contentBase: 9099999, + contentBase: 9099999 }, done); req = request(server.app); }); @@ -69,7 +69,7 @@ describe('ContentBase', () => { describe('to external url', () => { before((done) => { server = helper.start(config, { - contentBase: 'http://example.com/', + contentBase: 'http://example.com/' }, done); req = request(server.app); }); @@ -110,7 +110,7 @@ describe('ContentBase', () => { this.sinon.stub(process, 'cwd'); process.cwd.returns(contentBasePublic); server = helper.start(config, { - contentBase: false, + contentBase: false }, done); req = request(server.app); }); diff --git a/test/HistoryApiFallback.test.js b/test/HistoryApiFallback.test.js index e3f4a9f765..5c94a831d5 100644 --- a/test/HistoryApiFallback.test.js +++ b/test/HistoryApiFallback.test.js @@ -16,7 +16,7 @@ describe('HistoryApiFallback', () => { describe('as boolean', () => { before((done) => { server = helper.start(config, { - historyApiFallback: true, + historyApiFallback: true }, done); req = request(server.app); }); @@ -32,8 +32,8 @@ describe('HistoryApiFallback', () => { before((done) => { server = helper.start(config, { historyApiFallback: { - index: '/bar.html', - }, + index: '/bar.html' + } }, done); req = request(server.app); }); @@ -50,8 +50,8 @@ describe('HistoryApiFallback', () => { server = helper.start(config2, { contentBase: path.join(__dirname, 'fixtures/historyapifallback-2-config'), historyApiFallback: { - index: '/bar.html', - }, + index: '/bar.html' + } }, done); req = request(server.app); }); @@ -86,8 +86,8 @@ describe('HistoryApiFallback', () => { server = helper.start(config3, { contentBase: false, historyApiFallback: { - index: '/bar.html', - }, + index: '/bar.html' + } }, done); req = request(server.app); }); @@ -107,14 +107,14 @@ describe('HistoryApiFallback', () => { rewrites: [ { from: /other/, - to: '/other.html', + to: '/other.html' }, { from: /.*/, - to: '/bar.html', - }, - ], - }, + to: '/bar.html' + } + ] + } }, done); req = request(server.app); }); @@ -142,7 +142,7 @@ describe('HistoryApiFallback', () => { before((done) => { server = helper.start(config3, { contentBase: path.join(__dirname, 'fixtures/historyapifallback-3-config'), - historyApiFallback: true, + historyApiFallback: true }, done); req = request(server.app); }); diff --git a/test/Lazy.test.js b/test/Lazy.test.js index d0555bc026..a62d1b9f24 100644 --- a/test/Lazy.test.js +++ b/test/Lazy.test.js @@ -9,7 +9,7 @@ describe('Lazy', () => { it('without filename option it should throw an error', () => { should.throws(() => { helper.start(config, { - lazy: true, + lazy: true }); }, /'filename' option must be set/); }); @@ -17,7 +17,7 @@ describe('Lazy', () => { it('with filename option should not throw an error', (done) => { helper.start(config, { lazy: true, - filename: 'bundle.js', + filename: 'bundle.js' }, done); }); }); diff --git a/test/Proxy.test.js b/test/Proxy.test.js index b1600d33b7..1af07776fb 100644 --- a/test/Proxy.test.js +++ b/test/Proxy.test.js @@ -12,19 +12,19 @@ const contentBase = path.join(__dirname, 'fixtures/proxy-config'); const proxyOption = { '/proxy1': { - target: 'http://localhost:9000', + target: 'http://localhost:9000' }, '/api/proxy2': { target: 'http://localhost:9001', - pathRewrite: { '^/api': '' }, + pathRewrite: { '^/api': '' } }, '/foo': { bypass(req) { if (/\.html$/.test(req.path)) { return '/index.html'; } - }, - }, + } + } }; const proxyOptionOfArray = [ @@ -33,9 +33,9 @@ const proxyOptionOfArray = [ return { context: '/api/proxy2', target: 'http://localhost:9001', - pathRewrite: { '^/api': '' }, + pathRewrite: { '^/api': '' } }; - }, + } ]; function startProxyServers() { @@ -71,7 +71,7 @@ describe('Proxy', () => { closeProxyServers = startProxyServers(); server = helper.start(config, { contentBase, - proxy: proxyOption, + proxy: proxyOption }, done); req = request(server.app); }); @@ -124,7 +124,7 @@ describe('Proxy', () => { closeProxyServers = startProxyServers(); server = helper.start(config, { contentBase, - proxy: proxyOptionOfArray, + proxy: proxyOptionOfArray }, done); req = request(server.app); }); @@ -152,7 +152,7 @@ describe('Proxy', () => { let req; let listener; const proxyTarget = { - target: 'http://localhost:9000', + target: 'http://localhost:9000' }; before((done) => { @@ -165,8 +165,8 @@ describe('Proxy', () => { contentBase, proxy: { '/proxy1': proxyTarget, - '/proxy2': proxyTarget, - }, + '/proxy2': proxyTarget + } }, done); req = request(server.app); }); @@ -198,8 +198,8 @@ describe('Proxy', () => { proxy: [{ context: '/', target: 'http://localhost:9003', - ws: true, - }], + ws: true + }] }, done); wsServer = new WebSocketServer({ port: 9003 }); diff --git a/test/Routes.test.js b/test/Routes.test.js index fcc9a0437f..8733a2f790 100644 --- a/test/Routes.test.js +++ b/test/Routes.test.js @@ -14,7 +14,7 @@ describe('Routes', () => { before((done) => { server = helper.start(config, { - headers: { 'X-Foo': '1' }, + headers: { 'X-Foo': '1' } }, done); req = request(server.app); }); diff --git a/test/Validation.test.js b/test/Validation.test.js index 2407e6a585..8d8e75f6e9 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -13,22 +13,22 @@ describe('Validation', () => { name: 'invalid `hot` configuration', config: { hot: 'asdf' }, message: [ - ' - configuration.hot should be a boolean.', - ], + ' - configuration.hot should be a boolean.' + ] }, { name: 'invalid `public` configuration', config: { public: 1 }, message: [ - ' - configuration.public should be a string.', - ], + ' - configuration.public should be a string.' + ] }, { name: 'invalid `allowedHosts` configuration', config: { allowedHosts: 1 }, message: [ ' - configuration.allowedHosts should be an array:', ' [string]', - ' Specifies which hosts are allowed to access the dev server.', - ], + ' Specifies which hosts are allowed to access the dev server.' + ] }, { name: 'invalid `contentBase` configuration', config: { contentBase: [0] }, @@ -40,8 +40,8 @@ describe('Validation', () => { ' * configuration.contentBase[0] should be a string.', ' * configuration.contentBase should be false', ' * configuration.contentBase should be a number.', - ' * configuration.contentBase should be a string.', - ], + ' * configuration.contentBase should be a string.' + ] }, { name: 'non-existing key configuration', config: { asdf: true }, @@ -51,8 +51,8 @@ describe('Validation', () => { 'watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, ' + 'inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, ' + 'compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, ' + - 'noInfo?, quiet?, serverSideRender?, index?, log?, warn? }', - ], + 'noInfo?, quiet?, serverSideRender?, index?, log?, warn? }' + ] }]; testCases.forEach((testCase) => { it(`should fail validation for ${testCase.name}`, () => { @@ -73,10 +73,10 @@ describe('Validation', () => { it('should always allow any host if options.disableHostCheck is set', () => { const options = { public: 'test.host:80', - disableHostCheck: true, + disableHostCheck: true }; const headers = { - host: 'bad.host', + host: 'bad.host' }; const server = new Server(compiler, options); if (!server.checkHost(headers)) { @@ -86,10 +86,10 @@ describe('Validation', () => { it('should allow any valid options.public when host is localhost', () => { const options = { - public: 'test.host:80', + public: 'test.host:80' }; const headers = { - host: 'localhost', + host: 'localhost' }; const server = new Server(compiler, options); if (!server.checkHost(headers)) { @@ -99,10 +99,10 @@ describe('Validation', () => { it('should allow any valid options.public when host is 127.0.0.1', () => { const options = { - public: 'test.host:80', + public: 'test.host:80' }; const headers = { - host: '127.0.0.1', + host: '127.0.0.1' }; const server = new Server(compiler, options); if (!server.checkHost(headers)) { @@ -118,7 +118,7 @@ describe('Validation', () => { '[::1]', '[::1]:8080', '[ad42::1de2:54c2:c2fa:1234]', - '[ad42::1de2:54c2:c2fa:1234]:8080', + '[ad42::1de2:54c2:c2fa:1234]:8080' ]; const server = new Server(compiler, options); @@ -132,10 +132,10 @@ describe('Validation', () => { it("should not allow hostnames that don't match options.public", () => { const options = { - public: 'test.host:80', + public: 'test.host:80' }; const headers = { - host: 'test.hostname:80', + host: 'test.hostname:80' }; const server = new Server(compiler, options); if (server.checkHost(headers)) { @@ -148,7 +148,7 @@ describe('Validation', () => { const testHosts = [ 'test.host', 'test2.host', - 'test3.host', + 'test3.host' ]; const options = { allowedHosts: testHosts }; const server = new Server(compiler, options); @@ -169,7 +169,7 @@ describe('Validation', () => { 'example.com', 'subsubcomain.subdomain.example.com', 'example.com:80', - 'subdomain.example.com:80', + 'subdomain.example.com:80' ]; testHosts.forEach((testHost) => { diff --git a/test/fixtures/contentbase-config/webpack.config.js b/test/fixtures/contentbase-config/webpack.config.js index 218f332217..49df998a77 100644 --- a/test/fixtures/contentbase-config/webpack.config.js +++ b/test/fixtures/contentbase-config/webpack.config.js @@ -3,6 +3,6 @@ module.exports = { entry: './foo.js', output: { filename: 'bundle.js', - publicPath: '/', - }, + publicPath: '/' + } }; diff --git a/test/fixtures/historyapifallback-2-config/webpack.config.js b/test/fixtures/historyapifallback-2-config/webpack.config.js index 9f103c72c8..c18f7e157d 100644 --- a/test/fixtures/historyapifallback-2-config/webpack.config.js +++ b/test/fixtures/historyapifallback-2-config/webpack.config.js @@ -3,6 +3,6 @@ module.exports = { entry: './foo.js', output: { filename: 'bundle.js', - path: '/', - }, + path: '/' + } }; diff --git a/test/fixtures/historyapifallback-3-config/webpack.config.js b/test/fixtures/historyapifallback-3-config/webpack.config.js index a39c9ee63e..5592f88b58 100644 --- a/test/fixtures/historyapifallback-3-config/webpack.config.js +++ b/test/fixtures/historyapifallback-3-config/webpack.config.js @@ -3,15 +3,15 @@ module.exports = { entry: './foo.js', output: { filename: 'bundle.js', - path: '/', + path: '/' }, module: { loaders: [ { test: /\.html$/, loader: 'file-loader', - query: { name: 'index.html' }, - }, - ], - }, + query: { name: 'index.html' } + } + ] + } }; diff --git a/test/fixtures/historyapifallback-config/webpack.config.js b/test/fixtures/historyapifallback-config/webpack.config.js index 726afac5e0..fd3d45a45a 100644 --- a/test/fixtures/historyapifallback-config/webpack.config.js +++ b/test/fixtures/historyapifallback-config/webpack.config.js @@ -3,15 +3,15 @@ module.exports = { entry: './foo.js', output: { filename: 'bundle.js', - path: '/', + path: '/' }, module: { loaders: [ { test: /\.html$/, loader: 'file-loader', - query: { name: '[name].[ext]' }, - }, - ], - }, + query: { name: '[name].[ext]' } + } + ] + } }; diff --git a/test/fixtures/proxy-config/webpack.config.js b/test/fixtures/proxy-config/webpack.config.js index 9f103c72c8..c18f7e157d 100644 --- a/test/fixtures/proxy-config/webpack.config.js +++ b/test/fixtures/proxy-config/webpack.config.js @@ -3,6 +3,6 @@ module.exports = { entry: './foo.js', output: { filename: 'bundle.js', - path: '/', - }, + path: '/' + } }; diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index 9f103c72c8..c18f7e157d 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -3,6 +3,6 @@ module.exports = { entry: './foo.js', output: { filename: 'bundle.js', - path: '/', - }, + path: '/' + } }; diff --git a/test/helper.js b/test/helper.js index 0a45ad6d0a..499fe1ea1b 100644 --- a/test/helper.js +++ b/test/helper.js @@ -29,5 +29,5 @@ module.exports = { } else { done(); } - }, + } }; From 28f32836807fc71eb72cec7fb52b2d06211e3042 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 19:53:11 -0400 Subject: [PATCH 09/10] fixing linting warnings --- bin/webpack-dev-server.js | 26 ++++++++++----------- client/index.js | 18 +++++++------- client/live.js | 4 ++-- client/socket.js | 6 ++--- examples/.eslintrc | 5 ++++ examples/proxy-hot-reload/webpack.config.js | 2 +- examples/webworker/web.js | 2 +- examples/webworker/worker.js | 2 +- lib/OptionsValidationError.js | 2 +- lib/Server.js | 14 +++++------ test/.eslintrc | 5 ++++ test/ContentBase.test.js | 4 ++-- test/Proxy.test.js | 12 +++++----- 13 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 examples/.eslintrc create mode 100644 test/.eslintrc diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index bd78010822..6dc9acf66b 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -223,19 +223,19 @@ const wpOpt = require('webpack/bin/convert-argv')(yargs, argv, { outputFilename: '/bundle.js' }); -function processOptions(wpOpt) { +function processOptions(webpackOptions) { // process Promise - if (typeof wpOpt.then === 'function') { - wpOpt.then(processOptions).catch((err) => { + if (typeof webpackOptions.then === 'function') { + webpackOptions.then(processOptions).catch((err) => { console.error(err.stack || err); process.exit(); // eslint-disable-line }); return; } - const firstWpOpt = Array.isArray(wpOpt) ? wpOpt[0] : wpOpt; + const firstWpOpt = Array.isArray(webpackOptions) ? webpackOptions[0] : webpackOptions; - const options = wpOpt.devServer || firstWpOpt.devServer || {}; + const options = webpackOptions.devServer || firstWpOpt.devServer || {}; if (argv.bonjour) { options.bonjour = true; } @@ -349,16 +349,16 @@ function processOptions(wpOpt) { }); } -function startDevServer(wpOpt, options) { - addDevServerEntrypoints(wpOpt, options); +function startDevServer(webpackOptions, options) { + addDevServerEntrypoints(webpackOptions, options); let compiler; try { - compiler = webpack(wpOpt); + compiler = webpack(webpackOptions); } catch (e) { if (e instanceof webpack.WebpackOptionsValidationError) { console.error(colorError(options.stats.colors, e.message)); - process.exit(1); // eslint-disable-line + process.exit(1); // eslint-disable-line } throw e; } @@ -394,8 +394,8 @@ function startDevServer(wpOpt, options) { server.listeningApp.on('error', (e) => { if (e.code === 'EADDRINUSE') { const clientSocket = new net.Socket(); - clientSocket.on('error', (e) => { - if (e.code === 'ECONNREFUSED') { + clientSocket.on('error', (clientError) => { + if (clientError.code === 'ECONNREFUSED') { // No other server listening on this socket so it can be safely removed fs.unlinkSync(options.socket); server.listen(options.socket, options.host, (err) => { @@ -412,8 +412,8 @@ function startDevServer(wpOpt, options) { if (err) throw err; // chmod 666 (rw rw rw) const READ_WRITE = 438; - fs.chmod(options.socket, READ_WRITE, (err) => { - if (err) throw err; + fs.chmod(options.socket, READ_WRITE, (fsError) => { + if (fsError) throw fsError; reportReadiness(uri, options); }); }); diff --git a/client/index.js b/client/index.js index f771ddf279..f17a970d60 100644 --- a/client/index.js +++ b/client/index.js @@ -73,12 +73,12 @@ const onSocketMsg = { hash(hash) { currentHash = hash; }, - 'still-ok': function () { + 'still-ok': function stillOk() { log.info('[WDS] Nothing changed.'); if (useWarningOverlay || useErrorOverlay) overlay.clear(); sendMsg('StillOk'); }, - 'log-level': function (level) { + 'log-level': function logLevel(level) { const hotCtx = require.context('webpack/hot', false, /^\.\/log$/); const contextKeys = hotCtx.keys(); if (contextKeys.length && contextKeys['./log']) { @@ -100,14 +100,14 @@ const onSocketMsg = { log.error(`[WDS] Unknown clientLogLevel '${level}'`); } }, - overlay(overlay) { + overlay(value) { if (typeof document !== 'undefined') { - if (typeof (overlay) === 'boolean') { + if (typeof (value) === 'boolean') { useWarningOverlay = false; - useErrorOverlay = overlay; - } else if (overlay) { - useWarningOverlay = overlay.warnings; - useErrorOverlay = overlay.errors; + useErrorOverlay = value; + } else if (value) { + useWarningOverlay = value.warnings; + useErrorOverlay = value.errors; } } }, @@ -117,7 +117,7 @@ const onSocketMsg = { if (initial) return initial = false; // eslint-disable-line no-return-assign reloadApp(); }, - 'content-changed': function () { + 'content-changed': function contentChanged() { log.info('[WDS] Content base changed. Reloading...'); self.location.reload(); }, diff --git a/client/live.js b/client/live.js index e0201362db..0a16f8ad4c 100644 --- a/client/live.js +++ b/client/live.js @@ -42,7 +42,7 @@ $(() => { hash(hash) { currentHash = hash; }, - 'still-ok': function () { + 'still-ok': function stillOk() { okness.text(''); status.text('App ready.'); header.css({ @@ -99,7 +99,7 @@ $(() => { try { iframe[0].contentWindow.postMessage(`webpackHotUpdate${currentHash}`, '*'); } catch (e) { - console.warn(e); + console.warn(e); // eslint-disable-line } iframe.show(); } else { diff --git a/client/socket.js b/client/socket.js index ca7e09bd4a..ba020eff6e 100644 --- a/client/socket.js +++ b/client/socket.js @@ -6,11 +6,11 @@ let sock = null; function socket(url, handlers) { sock = new SockJS(url); - sock.onopen = function () { + sock.onopen = function onopen() { retries = 0; }; - sock.onclose = function () { + sock.onclose = function onclose() { if (retries === 0) { handlers.close(); } // Try to reconnect. @@ -30,7 +30,7 @@ function socket(url, handlers) { } }; - sock.onmessage = function (e) { + sock.onmessage = function onmessage(e) { // This assumes that all data sent via the websocket is JSON. const msg = JSON.parse(e.data); if (handlers[msg.type]) { handlers[msg.type](msg.data); } diff --git a/examples/.eslintrc b/examples/.eslintrc new file mode 100644 index 0000000000..d5ba8f9d9c --- /dev/null +++ b/examples/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "no-console": "off" + } +} diff --git a/examples/proxy-hot-reload/webpack.config.js b/examples/proxy-hot-reload/webpack.config.js index 9394c177c6..a2312e61d3 100644 --- a/examples/proxy-hot-reload/webpack.config.js +++ b/examples/proxy-hot-reload/webpack.config.js @@ -33,7 +33,7 @@ module.exports = { entry: './app.js', devServer: { proxy: [ - function () { + function proxy() { return proxyOptions; } ] diff --git a/examples/webworker/web.js b/examples/webworker/web.js index 0684aa5b09..8b365d3ed9 100644 --- a/examples/webworker/web.js +++ b/examples/webworker/web.js @@ -2,7 +2,7 @@ const worker = new Worker('worker.bundle.js'); -worker.onmessage = function (e) { +worker.onmessage = function onMessage(e) { console.log('[MAIN]', e); }; worker.postMessage({ diff --git a/examples/webworker/worker.js b/examples/webworker/worker.js index 075dce718e..24ceef1b78 100644 --- a/examples/webworker/worker.js +++ b/examples/webworker/worker.js @@ -1,7 +1,7 @@ /* eslint-env worker */ -self.onmessage = function (e) { +self.onmessage = function onMessage(e) { console.log('[WORKER]', e); self.postMessage({ hello: 222 diff --git a/lib/OptionsValidationError.js b/lib/OptionsValidationError.js index 4a29ac382c..c52ecbf918 100644 --- a/lib/OptionsValidationError.js +++ b/lib/OptionsValidationError.js @@ -108,7 +108,7 @@ class OptionsValidationError extends Error { } else if (err.keyword === 'oneOf' || err.keyword === 'anyOf') { if (err.children && err.children.length > 0) { return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` + - `Details:\n${err.children.map(err => ` * ${indent(OptionsValidationError.formatValidationError(err), ' ', false)}`).join('\n')}`; + `Details:\n${err.children.map(e => ` * ${indent(OptionsValidationError.formatValidationError(e), ' ', false)}`).join('\n')}`; } return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`; } else if (err.keyword === 'enum') { diff --git a/lib/Server.js b/lib/Server.js index f53c9e2a5c..478190b125 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -91,15 +91,15 @@ function Server(compiler, options) { res.setHeader('Content-Type', 'text/html'); /* eslint-disable quotes */ res.write(''); - const path = this.middleware.getFilenameFromUrl(options.publicPath || "/"); - const fs = this.middleware.fileSystem; + const outputPath = this.middleware.getFilenameFromUrl(options.publicPath || "/"); + const filesystem = this.middleware.fileSystem; function writeDirectory(baseUrl, basePath) { - const content = fs.readdirSync(basePath); + const content = filesystem.readdirSync(basePath); res.write(""); } /* eslint-enable quotes */ - writeDirectory(options.publicPath || '/', path); + writeDirectory(options.publicPath || '/', outputPath); res.end(''); }); @@ -578,8 +578,8 @@ Server.prototype._sendStats = function (sockets, stats, force) { if (stats.errors.length > 0) { this.sockWrite(sockets, 'errors', stats.errors); } else if (stats.warnings.length > 0) { this.sockWrite(sockets, 'warnings', stats.warnings); } else { this.sockWrite(sockets, 'ok'); } }; -Server.prototype._watch = function (path) { - const watcher = chokidar.watch(path).on('change', () => { +Server.prototype._watch = function (watchPath) { + const watcher = chokidar.watch(watchPath).on('change', () => { this.sockWrite(this.sockets, 'content-changed'); }); diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000000..d5ba8f9d9c --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "no-console": "off" + } +} diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index 2a851e4ffe..d69610d66e 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -90,7 +90,7 @@ describe('ContentBase', () => { }); describe('default to PWD', () => { - before(function (done) { + before(function before(done) { this.sinon.stub(process, 'cwd'); process.cwd.returns(contentBasePublic); server = helper.start(config, {}, done); @@ -104,7 +104,7 @@ describe('ContentBase', () => { }); describe('disable', () => { - before(function (done) { + before(function before(done) { // This is a somewhat weird test, but it is important that we mock // the PWD here, and test if /other.html in our "fake" PWD really is not requested. this.sinon.stub(process, 'cwd'); diff --git a/test/Proxy.test.js b/test/Proxy.test.js index 1af07776fb..9262f5fcdf 100644 --- a/test/Proxy.test.js +++ b/test/Proxy.test.js @@ -29,7 +29,7 @@ const proxyOption = { const proxyOptionOfArray = [ { context: '/proxy1', target: proxyOption['/proxy1'].target }, - function () { + function proxy() { return { context: '/api/proxy2', target: 'http://localhost:9001', @@ -54,7 +54,7 @@ function startProxyServers() { listeners.push(proxy1.listen(9000)); listeners.push(proxy2.listen(9001)); // return a function to shutdown proxy servers - return function () { + return function proxy() { listeners.forEach((listener) => { listener.close(); }); @@ -157,7 +157,7 @@ describe('Proxy', () => { before((done) => { const proxy = express(); - proxy.get('*', (req, res) => { + proxy.get('*', (proxyReq, res) => { res.send('from proxy'); }); listener = proxy.listen(9000); @@ -203,9 +203,9 @@ describe('Proxy', () => { }, done); wsServer = new WebSocketServer({ port: 9003 }); - wsServer.on('connection', (ws) => { - ws.on('message', (message) => { - ws.send(message); + wsServer.on('connection', (server) => { + server.on('message', (message) => { + server.send(message); }); }); }); From a968d706e347c4ec76dc82ad6be17153b3822342 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 28 Aug 2017 20:46:00 -0400 Subject: [PATCH 10/10] use strict and es6 fixes for node 4.x --- .eslintrc | 7 ++++++- .gitignore | 1 + bin/webpack-dev-server.js | 5 +++-- client/index.js | 2 ++ client/live.js | 2 ++ client/overlay.js | 3 +++ client/socket.js | 2 ++ client/sockjs.js | 2 ++ client/webpack.config.js | 1 + client/webpack.sockjs.config.js | 1 + examples/bonjour/app.js | 2 ++ examples/bonjour/webpack.config.js | 2 ++ examples/cli-open-page/app.js | 2 ++ examples/cli-open-page/webpack.config.js | 2 ++ examples/cli-public/app.js | 2 ++ examples/cli-public/webpack.config.js | 2 ++ examples/cli-stdin/app.js | 2 ++ examples/cli-stdin/webpack.config.js | 2 ++ examples/compression/app.js | 2 ++ examples/compression/webpack.config.js | 2 ++ examples/history-api-fallback/app.js | 2 ++ examples/history-api-fallback/webpack.config.js | 2 ++ examples/hmr/app.js | 2 ++ examples/hmr/example.js | 2 ++ examples/hmr/hmr.js | 2 ++ examples/hmr/webpack.config.js | 2 +- examples/host-port/app.js | 2 ++ examples/host-port/webpack.config.js | 2 ++ examples/https/app.js | 2 ++ examples/https/webpack.config.js | 2 ++ examples/listen-socket/app.js | 2 ++ examples/listen-socket/check-socket.js | 2 +- examples/listen-socket/webpack.config.js | 2 ++ examples/modus-iframe/app.js | 2 ++ examples/modus-iframe/webpack.config.js | 2 ++ examples/modus-inline/app.js | 2 ++ examples/modus-inline/webpack.config.js | 2 ++ examples/modus-lazy/app.js | 2 ++ examples/modus-lazy/webpack.config.js | 2 ++ examples/modus-manual-script/app.js | 2 ++ examples/modus-manual-script/webpack.config.js | 2 ++ examples/node-api-middleware/app.js | 2 ++ examples/node-api-middleware/server.js | 2 +- examples/node-api-middleware/webpack.config.js | 2 ++ examples/node-api-simple/app.js | 2 ++ examples/node-api-simple/server.js | 2 +- examples/node-api-simple/webpack.config.js | 2 ++ examples/overlay-warnings/app.js | 2 ++ examples/overlay-warnings/caseSensitive.js | 3 ++- examples/overlay-warnings/webpack.config.js | 2 ++ examples/overlay/app.js | 2 ++ examples/overlay/webpack.config.js | 2 ++ examples/proxy-advanced/app.js | 2 ++ examples/proxy-advanced/webpack.config.js | 2 ++ examples/proxy-hot-reload/app.js | 2 ++ examples/proxy-hot-reload/proxy-config.js | 2 ++ examples/proxy-hot-reload/webpack.config.js | 2 ++ examples/proxy-simple/app.js | 2 ++ examples/proxy-simple/webpack.config.js | 2 ++ examples/watch-content-base/app.js | 2 ++ examples/watch-content-base/webpack.config.js | 2 ++ examples/webpack-config-array/app.js | 2 ++ examples/webpack-config-array/webpack.config.js | 2 +- examples/webworker/web.js | 3 ++- examples/webworker/webpack.config.js | 2 +- examples/webworker/worker.js | 3 ++- lib/OptionsValidationError.js | 2 ++ lib/Server.js | 6 +++++- lib/polyfills.js | 9 +++++++++ lib/util/addDevServerEntrypoints.js | 2 ++ lib/util/createDomain.js | 2 +- package.json | 1 + test/Compress.test.js | 2 +- test/ContentBase.test.js | 1 + test/HistoryApiFallback.test.js | 1 + test/Lazy.test.js | 1 + test/Proxy.test.js | 1 + test/Routes.test.js | 1 + test/Validation.test.js | 1 + test/fixtures/contentbase-config/foo.js | 2 ++ test/fixtures/contentbase-config/webpack.config.js | 2 ++ test/fixtures/historyapifallback-2-config/foo.js | 2 ++ .../historyapifallback-2-config/webpack.config.js | 2 ++ test/fixtures/historyapifallback-3-config/foo.js | 2 ++ .../historyapifallback-3-config/webpack.config.js | 2 ++ test/fixtures/historyapifallback-config/foo.js | 2 ++ .../fixtures/historyapifallback-config/webpack.config.js | 2 ++ test/fixtures/proxy-config/foo.js | 2 ++ test/fixtures/proxy-config/webpack.config.js | 2 ++ test/fixtures/simple-config/foo.js | 2 ++ test/fixtures/simple-config/webpack.config.js | 2 ++ test/helper.js | 1 + 92 files changed, 181 insertions(+), 15 deletions(-) create mode 100644 lib/polyfills.js diff --git a/.eslintrc b/.eslintrc index 20dec83382..a7f05e00fb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,11 +4,16 @@ "document": true, "window": true }, + "parserOptions": { + "sourceType": "script" + }, "rules": { "comma-dangle": ["error", "never"], "consistent-return": "off", "no-param-reassign": "off", "no-underscore-dangle": "off", - "prefer-rest-params": "off" + "prefer-destructuring": ["error", {"object": false, "array": false}], + "prefer-rest-params": "off", + "strict": ["error", "safe"] } } diff --git a/.gitignore b/.gitignore index 7058d9d22f..e4503a17c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +npm-debug.log node_modules /client/live.bundle.js /client/index.bundle.js diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index 6dc9acf66b..5bf1a24d21 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +'use strict'; + /* eslint global-require: off, import/order: off, no-console: off */ const fs = require('fs'); @@ -217,8 +219,7 @@ yargs.options({ } }); -const { argv } = yargs; - +const argv = yargs.argv; const wpOpt = require('webpack/bin/convert-argv')(yargs, argv, { outputFilename: '/bundle.js' }); diff --git a/client/index.js b/client/index.js index f17a970d60..a9780e258a 100644 --- a/client/index.js +++ b/client/index.js @@ -1,3 +1,5 @@ +'use strict'; + /* global __resourceQuery WorkerGlobalScope self */ /* eslint prefer-destructuring: off */ diff --git a/client/live.js b/client/live.js index 0a16f8ad4c..24f6881aa7 100644 --- a/client/live.js +++ b/client/live.js @@ -1,3 +1,5 @@ +'use strict'; + /* eslint import/no-extraneous-dependencies: off, global-require: off */ const $ = require('jquery'); diff --git a/client/overlay.js b/client/overlay.js index 90196598c0..76330570bb 100644 --- a/client/overlay.js +++ b/client/overlay.js @@ -1,5 +1,8 @@ +'use strict'; + // The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app) // They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware). + const ansiHTML = require('ansi-html'); const Entities = require('html-entities').AllHtmlEntities; diff --git a/client/socket.js b/client/socket.js index ba020eff6e..f1a3bf7a83 100644 --- a/client/socket.js +++ b/client/socket.js @@ -1,3 +1,5 @@ +'use strict'; + const SockJS = require('sockjs-client'); let retries = 0; diff --git a/client/sockjs.js b/client/sockjs.js index 6bcc717efc..a7db01b9d3 100644 --- a/client/sockjs.js +++ b/client/sockjs.js @@ -1 +1,3 @@ +'use strict'; + module.exports = require('sockjs-client'); diff --git a/client/webpack.config.js b/client/webpack.config.js index ce6469b4a6..8d26d1e417 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -1,3 +1,4 @@ +'use strict'; const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); diff --git a/client/webpack.sockjs.config.js b/client/webpack.sockjs.config.js index 7d7964213a..581beb4847 100644 --- a/client/webpack.sockjs.config.js +++ b/client/webpack.sockjs.config.js @@ -1,3 +1,4 @@ +'use strict'; // eslint-disable-next-line const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); diff --git a/examples/bonjour/app.js b/examples/bonjour/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/bonjour/app.js +++ b/examples/bonjour/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/bonjour/webpack.config.js b/examples/bonjour/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/bonjour/webpack.config.js +++ b/examples/bonjour/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/cli-open-page/app.js b/examples/cli-open-page/app.js index 9e69a3017f..85f5ab6624 100644 --- a/examples/cli-open-page/app.js +++ b/examples/cli-open-page/app.js @@ -1,3 +1,5 @@ +'use strict'; + if (window.location.href.endsWith('example.html#page1')) { document.write("It's working."); } diff --git a/examples/cli-open-page/webpack.config.js b/examples/cli-open-page/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/cli-open-page/webpack.config.js +++ b/examples/cli-open-page/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/cli-public/app.js b/examples/cli-public/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/cli-public/app.js +++ b/examples/cli-public/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/cli-public/webpack.config.js b/examples/cli-public/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/cli-public/webpack.config.js +++ b/examples/cli-public/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/cli-stdin/app.js b/examples/cli-stdin/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/cli-stdin/app.js +++ b/examples/cli-stdin/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/cli-stdin/webpack.config.js b/examples/cli-stdin/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/cli-stdin/webpack.config.js +++ b/examples/cli-stdin/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/compression/app.js b/examples/compression/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/compression/app.js +++ b/examples/compression/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/compression/webpack.config.js b/examples/compression/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/compression/webpack.config.js +++ b/examples/compression/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/history-api-fallback/app.js b/examples/history-api-fallback/app.js index aa9da65c2e..46ba7b2463 100644 --- a/examples/history-api-fallback/app.js +++ b/examples/history-api-fallback/app.js @@ -1,3 +1,5 @@ +'use strict'; + /* global XMLHttpRequest */ const path = document.location.pathname; document.write(`It's working from path ${path}`); diff --git a/examples/history-api-fallback/webpack.config.js b/examples/history-api-fallback/webpack.config.js index 98969d24b0..39550c30ac 100644 --- a/examples/history-api-fallback/webpack.config.js +++ b/examples/history-api-fallback/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/hmr/app.js b/examples/hmr/app.js index 29555cc3ca..265a7d582a 100644 --- a/examples/hmr/app.js +++ b/examples/hmr/app.js @@ -1 +1,3 @@ +'use strict'; + require('./hmr'); diff --git a/examples/hmr/example.js b/examples/hmr/example.js index 7de2bacf46..b863dfaaf2 100644 --- a/examples/hmr/example.js +++ b/examples/hmr/example.js @@ -1,3 +1,5 @@ +'use strict'; + const myText = document.getElementById('mytext'); myText.textContent = 'Does it work? yes'; diff --git a/examples/hmr/hmr.js b/examples/hmr/hmr.js index 0e1181fe0b..dc9068a482 100644 --- a/examples/hmr/hmr.js +++ b/examples/hmr/hmr.js @@ -1,3 +1,5 @@ +'use strict'; + require('./example'); if (module.hot) { diff --git a/examples/hmr/webpack.config.js b/examples/hmr/webpack.config.js index 37c27ee2ec..d6057861cb 100644 --- a/examples/hmr/webpack.config.js +++ b/examples/hmr/webpack.config.js @@ -1,4 +1,4 @@ - +'use strict'; const webpack = require('webpack'); diff --git a/examples/host-port/app.js b/examples/host-port/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/host-port/app.js +++ b/examples/host-port/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/host-port/webpack.config.js b/examples/host-port/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/host-port/webpack.config.js +++ b/examples/host-port/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/https/app.js b/examples/https/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/https/app.js +++ b/examples/https/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/https/webpack.config.js b/examples/https/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/https/webpack.config.js +++ b/examples/https/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/listen-socket/app.js b/examples/listen-socket/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/listen-socket/app.js +++ b/examples/listen-socket/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/listen-socket/check-socket.js b/examples/listen-socket/check-socket.js index ca2cca6476..660e360747 100644 --- a/examples/listen-socket/check-socket.js +++ b/examples/listen-socket/check-socket.js @@ -1,4 +1,4 @@ - +'use strict'; const net = require('net'); diff --git a/examples/listen-socket/webpack.config.js b/examples/listen-socket/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/listen-socket/webpack.config.js +++ b/examples/listen-socket/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/modus-iframe/app.js b/examples/modus-iframe/app.js index 6b799b3705..0c6feed6c2 100644 --- a/examples/modus-iframe/app.js +++ b/examples/modus-iframe/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in a warning: diff --git a/examples/modus-iframe/webpack.config.js b/examples/modus-iframe/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/modus-iframe/webpack.config.js +++ b/examples/modus-iframe/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/modus-inline/app.js b/examples/modus-inline/app.js index e262ee52e9..1f541b00d1 100644 --- a/examples/modus-inline/app.js +++ b/examples/modus-inline/app.js @@ -1,3 +1,5 @@ +'use strict'; + require('./style.less'); document.write("It's working."); diff --git a/examples/modus-inline/webpack.config.js b/examples/modus-inline/webpack.config.js index 871b314b7e..85a1dca10a 100644 --- a/examples/modus-inline/webpack.config.js +++ b/examples/modus-inline/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/modus-lazy/app.js b/examples/modus-lazy/app.js index 6b799b3705..0c6feed6c2 100644 --- a/examples/modus-lazy/app.js +++ b/examples/modus-lazy/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in a warning: diff --git a/examples/modus-lazy/webpack.config.js b/examples/modus-lazy/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/modus-lazy/webpack.config.js +++ b/examples/modus-lazy/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/modus-manual-script/app.js b/examples/modus-manual-script/app.js index 6b799b3705..0c6feed6c2 100644 --- a/examples/modus-manual-script/app.js +++ b/examples/modus-manual-script/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in a warning: diff --git a/examples/modus-manual-script/webpack.config.js b/examples/modus-manual-script/webpack.config.js index f19bd324bf..7316e8848c 100644 --- a/examples/modus-manual-script/webpack.config.js +++ b/examples/modus-manual-script/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js' diff --git a/examples/node-api-middleware/app.js b/examples/node-api-middleware/app.js index 707e792acb..e45e577a65 100644 --- a/examples/node-api-middleware/app.js +++ b/examples/node-api-middleware/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in a warning: diff --git a/examples/node-api-middleware/server.js b/examples/node-api-middleware/server.js index 5f6ec4b40d..5b9253e886 100644 --- a/examples/node-api-middleware/server.js +++ b/examples/node-api-middleware/server.js @@ -1,4 +1,4 @@ - +'use strict'; const Webpack = require('webpack'); const WebpackDevServer = require('../../lib/Server'); diff --git a/examples/node-api-middleware/webpack.config.js b/examples/node-api-middleware/webpack.config.js index afcd3b765e..93e493cd8a 100644 --- a/examples/node-api-middleware/webpack.config.js +++ b/examples/node-api-middleware/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: ['./app.js', '../../client/index.js?http://localhost:8080/'], diff --git a/examples/node-api-simple/app.js b/examples/node-api-simple/app.js index 707e792acb..e45e577a65 100644 --- a/examples/node-api-simple/app.js +++ b/examples/node-api-simple/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in a warning: diff --git a/examples/node-api-simple/server.js b/examples/node-api-simple/server.js index 1e5e570475..b73257eeb0 100644 --- a/examples/node-api-simple/server.js +++ b/examples/node-api-simple/server.js @@ -1,4 +1,4 @@ - +'use strict'; const Webpack = require('webpack'); const WebpackDevServer = require('../../lib/Server'); diff --git a/examples/node-api-simple/webpack.config.js b/examples/node-api-simple/webpack.config.js index afcd3b765e..93e493cd8a 100644 --- a/examples/node-api-simple/webpack.config.js +++ b/examples/node-api-simple/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: ['./app.js', '../../client/index.js?http://localhost:8080/'], diff --git a/examples/overlay-warnings/app.js b/examples/overlay-warnings/app.js index 6477d0c3f3..7bcebebed5 100644 --- a/examples/overlay-warnings/app.js +++ b/examples/overlay-warnings/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in a warning: diff --git a/examples/overlay-warnings/caseSensitive.js b/examples/overlay-warnings/caseSensitive.js index 3265341271..d5329d30bd 100644 --- a/examples/overlay-warnings/caseSensitive.js +++ b/examples/overlay-warnings/caseSensitive.js @@ -1,2 +1,3 @@ -console.log('case sensitive'); +'use strict'; +console.log('case sensitive'); diff --git a/examples/overlay-warnings/webpack.config.js b/examples/overlay-warnings/webpack.config.js index 8c0ef559a8..478c6290df 100644 --- a/examples/overlay-warnings/webpack.config.js +++ b/examples/overlay-warnings/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/overlay/app.js b/examples/overlay/app.js index 23a4d2a01c..25efd99a02 100644 --- a/examples/overlay/app.js +++ b/examples/overlay/app.js @@ -1,3 +1,5 @@ +'use strict'; + document.write("It's working."); // This results in an error: diff --git a/examples/overlay/webpack.config.js b/examples/overlay/webpack.config.js index d4c70bb380..e690ecb913 100644 --- a/examples/overlay/webpack.config.js +++ b/examples/overlay/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/proxy-advanced/app.js b/examples/proxy-advanced/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/proxy-advanced/app.js +++ b/examples/proxy-advanced/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/proxy-advanced/webpack.config.js b/examples/proxy-advanced/webpack.config.js index 665779277e..569be583f2 100644 --- a/examples/proxy-advanced/webpack.config.js +++ b/examples/proxy-advanced/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/proxy-hot-reload/app.js b/examples/proxy-hot-reload/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/proxy-hot-reload/app.js +++ b/examples/proxy-hot-reload/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/proxy-hot-reload/proxy-config.js b/examples/proxy-hot-reload/proxy-config.js index 0f4079d247..5d6765a517 100644 --- a/examples/proxy-hot-reload/proxy-config.js +++ b/examples/proxy-hot-reload/proxy-config.js @@ -1,3 +1,5 @@ +'use strict'; + /**/ module.exports = { target: 'http://jsonplaceholder.typicode.com/', diff --git a/examples/proxy-hot-reload/webpack.config.js b/examples/proxy-hot-reload/webpack.config.js index a2312e61d3..d35b92322e 100644 --- a/examples/proxy-hot-reload/webpack.config.js +++ b/examples/proxy-hot-reload/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + /* eslint global-require: off */ const fs = require('fs'); diff --git a/examples/proxy-simple/app.js b/examples/proxy-simple/app.js index 82ac1968f5..7b9ea7ebaa 100644 --- a/examples/proxy-simple/app.js +++ b/examples/proxy-simple/app.js @@ -1 +1,3 @@ +'use strict'; + document.write("It's working."); diff --git a/examples/proxy-simple/webpack.config.js b/examples/proxy-simple/webpack.config.js index b1882b65f9..08e51cb80c 100644 --- a/examples/proxy-simple/webpack.config.js +++ b/examples/proxy-simple/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/watch-content-base/app.js b/examples/watch-content-base/app.js index f38bd110e4..3ac3dcda45 100644 --- a/examples/watch-content-base/app.js +++ b/examples/watch-content-base/app.js @@ -1,2 +1,4 @@ +'use strict'; + const myText = document.getElementById('mytext'); myText.textContent = 'Does it work? yes'; diff --git a/examples/watch-content-base/webpack.config.js b/examples/watch-content-base/webpack.config.js index e6366a2065..82e7265169 100644 --- a/examples/watch-content-base/webpack.config.js +++ b/examples/watch-content-base/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './app.js', diff --git a/examples/webpack-config-array/app.js b/examples/webpack-config-array/app.js index e262ee52e9..1f541b00d1 100644 --- a/examples/webpack-config-array/app.js +++ b/examples/webpack-config-array/app.js @@ -1,3 +1,5 @@ +'use strict'; + require('./style.less'); document.write("It's working."); diff --git a/examples/webpack-config-array/webpack.config.js b/examples/webpack-config-array/webpack.config.js index d0f12b7253..54a68018e0 100644 --- a/examples/webpack-config-array/webpack.config.js +++ b/examples/webpack-config-array/webpack.config.js @@ -1,4 +1,4 @@ - +'use strict'; const webpack = require('webpack'); diff --git a/examples/webworker/web.js b/examples/webworker/web.js index 8b365d3ed9..bc2a2d3a68 100644 --- a/examples/webworker/web.js +++ b/examples/webworker/web.js @@ -1,5 +1,6 @@ -/* eslint-env browser */ +'use strict'; +/* eslint-env browser */ const worker = new Worker('worker.bundle.js'); worker.onmessage = function onMessage(e) { diff --git a/examples/webworker/webpack.config.js b/examples/webworker/webpack.config.js index a382ee9014..4b9f8d4ee8 100644 --- a/examples/webworker/webpack.config.js +++ b/examples/webworker/webpack.config.js @@ -1,4 +1,4 @@ - +'use strict'; module.exports = [ { diff --git a/examples/webworker/worker.js b/examples/webworker/worker.js index 24ceef1b78..23a0791b1d 100644 --- a/examples/webworker/worker.js +++ b/examples/webworker/worker.js @@ -1,5 +1,6 @@ -/* eslint-env worker */ +'use strict'; +/* eslint-env worker */ self.onmessage = function onMessage(e) { console.log('[WORKER]', e); diff --git a/lib/OptionsValidationError.js b/lib/OptionsValidationError.js index c52ecbf918..f23dbf1363 100644 --- a/lib/OptionsValidationError.js +++ b/lib/OptionsValidationError.js @@ -1,3 +1,5 @@ +'use strict'; + /* eslint no-param-reassign: 'off' */ const optionsSchema = require('./optionsSchema.json'); diff --git a/lib/Server.js b/lib/Server.js index 478190b125..d0ea042d50 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1,3 +1,5 @@ +'use strict'; + /* eslint no-console: off, func-names: off */ const fs = require('fs'); @@ -20,6 +22,8 @@ const webpackDevMiddleware = require('webpack-dev-middleware'); const OptionsValidationError = require('./OptionsValidationError'); const optionsSchema = require('./optionsSchema.json'); +require('./polyfills'); + const clientStats = { errorDetails: false }; function Server(compiler, options) { @@ -436,7 +440,7 @@ Server.prototype.checkHost = function (headers) { if (!hostHeader) return false; // use the node url-parser to retrieve the hostname from the host-header. - const { hostname } = url.parse(`//${hostHeader}`, false, true); + const hostname = url.parse(`//${hostHeader}`, false, true).hostname; // always allow requests with explicit IPv4 or IPv6-address. // A note on IPv6 addresses: hostHeader will always contain the brackets denoting diff --git a/lib/polyfills.js b/lib/polyfills.js new file mode 100644 index 0000000000..887c5b3f3f --- /dev/null +++ b/lib/polyfills.js @@ -0,0 +1,9 @@ +'use strict'; + +/* polyfills for Node 4.8.x users */ +/* eslint no-extend-native: off, global-require: off */ + +// internal-ip@2.x uses [].includes +if (!Array.prototype.includes) { + Array.prototype.includes = require('array-includes'); +} diff --git a/lib/util/addDevServerEntrypoints.js b/lib/util/addDevServerEntrypoints.js index 015181a353..f68b6d0bb5 100644 --- a/lib/util/addDevServerEntrypoints.js +++ b/lib/util/addDevServerEntrypoints.js @@ -1,3 +1,5 @@ +'use strict'; + /* eslint no-param-reassign: 'off' */ const createDomain = require('./createDomain'); diff --git a/lib/util/createDomain.js b/lib/util/createDomain.js index 30c591baa3..54fa36ccc9 100644 --- a/lib/util/createDomain.js +++ b/lib/util/createDomain.js @@ -1,4 +1,4 @@ - +'use strict'; const url = require('url'); const internalIp = require('internal-ip'); diff --git a/package.json b/package.json index 14cbc33e58..180faf8cc6 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ }, "dependencies": { "ansi-html": "0.0.7", + "array-includes": "^3.0.3", "bonjour": "^3.5.0", "chokidar": "^1.6.0", "compression": "^1.5.2", diff --git a/test/Compress.test.js b/test/Compress.test.js index 26cf17d4b7..3b6d4ad7a0 100644 --- a/test/Compress.test.js +++ b/test/Compress.test.js @@ -1,4 +1,4 @@ - +'use strict'; const request = require('supertest'); const helper = require('./helper'); diff --git a/test/ContentBase.test.js b/test/ContentBase.test.js index d69610d66e..c2d105f50e 100644 --- a/test/ContentBase.test.js +++ b/test/ContentBase.test.js @@ -1,3 +1,4 @@ +'use strict'; const path = require('path'); const request = require('supertest'); diff --git a/test/HistoryApiFallback.test.js b/test/HistoryApiFallback.test.js index 5c94a831d5..c034131125 100644 --- a/test/HistoryApiFallback.test.js +++ b/test/HistoryApiFallback.test.js @@ -1,3 +1,4 @@ +'use strict'; const assert = require('assert'); const path = require('path'); diff --git a/test/Lazy.test.js b/test/Lazy.test.js index a62d1b9f24..afc54e5716 100644 --- a/test/Lazy.test.js +++ b/test/Lazy.test.js @@ -1,3 +1,4 @@ +'use strict'; const should = require('should'); const helper = require('./helper'); diff --git a/test/Proxy.test.js b/test/Proxy.test.js index 9262f5fcdf..49c40f9e9a 100644 --- a/test/Proxy.test.js +++ b/test/Proxy.test.js @@ -1,3 +1,4 @@ +'use strict'; const path = require('path'); const request = require('supertest'); diff --git a/test/Routes.test.js b/test/Routes.test.js index 8733a2f790..c226415624 100644 --- a/test/Routes.test.js +++ b/test/Routes.test.js @@ -1,3 +1,4 @@ +'use strict'; const fs = require('fs'); const path = require('path'); diff --git a/test/Validation.test.js b/test/Validation.test.js index 8d8e75f6e9..cfe7f368fd 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -1,3 +1,4 @@ +'use strict'; const webpack = require('webpack'); const OptionsValidationError = require('../lib/OptionsValidationError'); diff --git a/test/fixtures/contentbase-config/foo.js b/test/fixtures/contentbase-config/foo.js index c45a498241..d1168ef6e3 100644 --- a/test/fixtures/contentbase-config/foo.js +++ b/test/fixtures/contentbase-config/foo.js @@ -1,3 +1,5 @@ +'use strict'; + require('./index.html'); // eslint-disable-line console.log('Hey.'); diff --git a/test/fixtures/contentbase-config/webpack.config.js b/test/fixtures/contentbase-config/webpack.config.js index 49df998a77..ac0c9e881f 100644 --- a/test/fixtures/contentbase-config/webpack.config.js +++ b/test/fixtures/contentbase-config/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './foo.js', diff --git a/test/fixtures/historyapifallback-2-config/foo.js b/test/fixtures/historyapifallback-2-config/foo.js index fd3d63ff92..5048f70fc8 100644 --- a/test/fixtures/historyapifallback-2-config/foo.js +++ b/test/fixtures/historyapifallback-2-config/foo.js @@ -1 +1,3 @@ +'use strict'; + console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-2-config/webpack.config.js b/test/fixtures/historyapifallback-2-config/webpack.config.js index c18f7e157d..8adf2fae5f 100644 --- a/test/fixtures/historyapifallback-2-config/webpack.config.js +++ b/test/fixtures/historyapifallback-2-config/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './foo.js', diff --git a/test/fixtures/historyapifallback-3-config/foo.js b/test/fixtures/historyapifallback-3-config/foo.js index 6236950572..de1b13b15b 100644 --- a/test/fixtures/historyapifallback-3-config/foo.js +++ b/test/fixtures/historyapifallback-3-config/foo.js @@ -1,3 +1,5 @@ +'use strict'; + require('./bar.html'); console.log("Hey."); // eslint-disable-line diff --git a/test/fixtures/historyapifallback-3-config/webpack.config.js b/test/fixtures/historyapifallback-3-config/webpack.config.js index 5592f88b58..97e9e0efc4 100644 --- a/test/fixtures/historyapifallback-3-config/webpack.config.js +++ b/test/fixtures/historyapifallback-3-config/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './foo.js', diff --git a/test/fixtures/historyapifallback-config/foo.js b/test/fixtures/historyapifallback-config/foo.js index b8cb52c592..0da543f0a3 100644 --- a/test/fixtures/historyapifallback-config/foo.js +++ b/test/fixtures/historyapifallback-config/foo.js @@ -1,3 +1,5 @@ +'use strict'; + require('./index.html'); require('./bar.html'); diff --git a/test/fixtures/historyapifallback-config/webpack.config.js b/test/fixtures/historyapifallback-config/webpack.config.js index fd3d45a45a..6c8b350f36 100644 --- a/test/fixtures/historyapifallback-config/webpack.config.js +++ b/test/fixtures/historyapifallback-config/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './foo.js', diff --git a/test/fixtures/proxy-config/foo.js b/test/fixtures/proxy-config/foo.js index cd23a458ba..eab26534f3 100644 --- a/test/fixtures/proxy-config/foo.js +++ b/test/fixtures/proxy-config/foo.js @@ -1 +1,3 @@ +'use strict'; + console.log('Hey.'); diff --git a/test/fixtures/proxy-config/webpack.config.js b/test/fixtures/proxy-config/webpack.config.js index c18f7e157d..8adf2fae5f 100644 --- a/test/fixtures/proxy-config/webpack.config.js +++ b/test/fixtures/proxy-config/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './foo.js', diff --git a/test/fixtures/simple-config/foo.js b/test/fixtures/simple-config/foo.js index cd23a458ba..eab26534f3 100644 --- a/test/fixtures/simple-config/foo.js +++ b/test/fixtures/simple-config/foo.js @@ -1 +1,3 @@ +'use strict'; + console.log('Hey.'); diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index c18f7e157d..8adf2fae5f 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: './foo.js', diff --git a/test/helper.js b/test/helper.js index 499fe1ea1b..4a4dda7c7d 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,3 +1,4 @@ +'use strict'; const webpack = require('webpack'); const Server = require('../lib/Server');