webpack-dev-server 3.7.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,26 @@
1
1
  'use strict';
2
2
 
3
- const { getPortPromise } = require('portfinder');
3
+ const pRetry = require('p-retry');
4
+ const portfinder = require('portfinder');
4
5
  const defaultPort = require('./defaultPort');
5
6
  const defaultTo = require('./defaultTo');
6
7
  const tryParseInt = require('./tryParseInt');
7
8
 
9
+ function runPortFinder() {
10
+ return new Promise((resolve, reject) => {
11
+ portfinder.basePort = defaultPort;
12
+ portfinder.getPort((error, port) => {
13
+ if (error) {
14
+ return reject(error);
15
+ }
16
+
17
+ return resolve(port);
18
+ });
19
+ });
20
+ }
21
+
8
22
  function findPort(port) {
9
- if (typeof port !== 'undefined') {
23
+ if (port) {
10
24
  return Promise.resolve(port);
11
25
  }
12
26
 
@@ -19,10 +33,7 @@ function findPort(port) {
19
33
  3
20
34
  );
21
35
 
22
- return getPortPromise({
23
- port: defaultPort,
24
- stopPort: defaultPort + defaultPortRetry,
25
- });
36
+ return pRetry(runPortFinder, { retries: defaultPortRetry });
26
37
  }
27
38
 
28
39
  module.exports = findPort;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ function getSocketClientPath(options) {
4
+ let ClientImplementation;
5
+ let clientImplFound = true;
6
+ switch (typeof options.transportMode.client) {
7
+ case 'string':
8
+ // could be 'sockjs', 'ws', or a path that should be required
9
+ if (options.transportMode.client === 'sockjs') {
10
+ ClientImplementation = require('../../client/clients/SockJSClient');
11
+ } else if (options.transportMode.client === 'ws') {
12
+ ClientImplementation = require('../../client/clients/WebsocketClient');
13
+ } else {
14
+ try {
15
+ // eslint-disable-next-line import/no-dynamic-require
16
+ ClientImplementation = require(options.transportMode.client);
17
+ } catch (e) {
18
+ clientImplFound = false;
19
+ }
20
+ }
21
+ break;
22
+ default:
23
+ clientImplFound = false;
24
+ }
25
+
26
+ if (!clientImplFound) {
27
+ throw new Error(
28
+ "transportMode.client must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to " +
29
+ 'a JS file which exports a class extending BaseClient (webpack-dev-server/client-src/clients/BaseClient) ' +
30
+ 'via require.resolve(...)'
31
+ );
32
+ }
33
+
34
+ return ClientImplementation.getClientPath(options);
35
+ }
36
+
37
+ module.exports = getSocketClientPath;
@@ -3,16 +3,17 @@
3
3
  function getSocketServerImplementation(options) {
4
4
  let ServerImplementation;
5
5
  let serverImplFound = true;
6
- switch (typeof options.serverMode) {
6
+ switch (typeof options.transportMode.server) {
7
7
  case 'string':
8
8
  // could be 'sockjs', in the future 'ws', or a path that should be required
9
- if (options.serverMode === 'sockjs') {
10
- // eslint-disable-next-line global-require
9
+ if (options.transportMode.server === 'sockjs') {
11
10
  ServerImplementation = require('../servers/SockJSServer');
11
+ } else if (options.transportMode.server === 'ws') {
12
+ ServerImplementation = require('../servers/WebsocketServer');
12
13
  } else {
13
14
  try {
14
- // eslint-disable-next-line global-require, import/no-dynamic-require
15
- ServerImplementation = require(options.serverMode);
15
+ // eslint-disable-next-line import/no-dynamic-require
16
+ ServerImplementation = require(options.transportMode.server);
16
17
  } catch (e) {
17
18
  serverImplFound = false;
18
19
  }
@@ -21,7 +22,7 @@ function getSocketServerImplementation(options) {
21
22
  case 'function':
22
23
  // potentially do more checks here to confirm that the user implemented this properlly
23
24
  // since errors could be difficult to understand
24
- ServerImplementation = options.serverMode;
25
+ ServerImplementation = options.transportMode.server;
25
26
  break;
26
27
  default:
27
28
  serverImplFound = false;
@@ -29,7 +30,7 @@ function getSocketServerImplementation(options) {
29
30
 
30
31
  if (!serverImplFound) {
31
32
  throw new Error(
32
- "serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to " +
33
+ "transportMode.server must be a string denoting a default implementation (e.g. 'sockjs', 'ws'), a full path to " +
33
34
  'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
34
35
  'via require.resolve(...), or the class itself which extends BaseServer'
35
36
  );
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable global-require */
4
-
5
3
  function getVersions() {
6
4
  return (
7
5
  `webpack-dev-server ${require('../../package.json').version}\n` +
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable
4
+ no-undefined
5
+ */
6
+
7
+ function normalizeOptions(compiler, options) {
8
+ // Setup default value
9
+ options.contentBase =
10
+ options.contentBase !== undefined ? options.contentBase : process.cwd();
11
+
12
+ // normalize transportMode option
13
+ if (options.transportMode === undefined) {
14
+ options.transportMode = {
15
+ server: 'sockjs',
16
+ client: 'sockjs',
17
+ };
18
+ } else {
19
+ switch (typeof options.transportMode) {
20
+ case 'string':
21
+ options.transportMode = {
22
+ server: options.transportMode,
23
+ client: options.transportMode,
24
+ };
25
+ break;
26
+ // if not a string, it is an object
27
+ default:
28
+ options.transportMode.server = options.transportMode.server || 'sockjs';
29
+ options.transportMode.client = options.transportMode.client || 'sockjs';
30
+ }
31
+ }
32
+
33
+ if (!options.watchOptions) {
34
+ options.watchOptions = {};
35
+ }
36
+ }
37
+
38
+ module.exports = normalizeOptions;
@@ -2,6 +2,7 @@
2
2
 
3
3
  const createConfig = require('./createConfig');
4
4
  const defaultPort = require('./defaultPort');
5
+ const findPort = require('./findPort');
5
6
 
6
7
  function processOptions(config, argv, callback) {
7
8
  // processOptions {Promise}
@@ -23,7 +24,21 @@ function processOptions(config, argv, callback) {
23
24
  // we should use portfinder.
24
25
  const options = createConfig(config, argv, { port: defaultPort });
25
26
 
26
- callback(config, options);
27
+ if (options.socket) {
28
+ callback(config, options);
29
+ } else {
30
+ findPort(options.port)
31
+ .then((port) => {
32
+ options.port = port;
33
+ callback(config, options);
34
+ })
35
+ .catch((err) => {
36
+ // eslint-disable-next-line no-console
37
+ console.error(err.stack || err);
38
+ // eslint-disable-next-line no-process-exit
39
+ process.exit(1);
40
+ });
41
+ }
27
42
  }
28
43
 
29
44
  module.exports = processOptions;
@@ -3,37 +3,31 @@
3
3
  const { createReadStream } = require('fs');
4
4
  const { join } = require('path');
5
5
 
6
+ const clientBasePath = join(__dirname, '..', '..', 'client');
7
+
6
8
  function routes(app, middleware, options) {
7
9
  app.get('/__webpack_dev_server__/live.bundle.js', (req, res) => {
8
10
  res.setHeader('Content-Type', 'application/javascript');
9
11
 
10
- createReadStream(
11
- join(__dirname, '..', '..', 'client', 'live.bundle.js')
12
- ).pipe(res);
12
+ createReadStream(join(clientBasePath, 'live.bundle.js')).pipe(res);
13
13
  });
14
14
 
15
15
  app.get('/__webpack_dev_server__/sockjs.bundle.js', (req, res) => {
16
16
  res.setHeader('Content-Type', 'application/javascript');
17
17
 
18
- createReadStream(
19
- join(__dirname, '..', '..', 'client', 'sockjs.bundle.js')
20
- ).pipe(res);
18
+ createReadStream(join(clientBasePath, 'sockjs.bundle.js')).pipe(res);
21
19
  });
22
20
 
23
21
  app.get('/webpack-dev-server.js', (req, res) => {
24
22
  res.setHeader('Content-Type', 'application/javascript');
25
23
 
26
- createReadStream(
27
- join(__dirname, '..', '..', 'client', 'index.bundle.js')
28
- ).pipe(res);
24
+ createReadStream(join(clientBasePath, 'index.bundle.js')).pipe(res);
29
25
  });
30
26
 
31
27
  app.get('/webpack-dev-server/*', (req, res) => {
32
28
  res.setHeader('Content-Type', 'text/html');
33
29
 
34
- createReadStream(join(__dirname, '..', '..', 'client', 'live.html')).pipe(
35
- res
36
- );
30
+ createReadStream(join(clientBasePath, 'live.html')).pipe(res);
37
31
  });
38
32
 
39
33
  app.get('/webpack-dev-server', (req, res) => {
@@ -59,35 +53,27 @@ function routes(app, middleware, options) {
59
53
  const p = `${basePath}/${item}`;
60
54
 
61
55
  if (filesystem.statSync(p).isFile()) {
62
- res.write('<li><a href="');
63
- res.write(baseUrl + item);
64
- res.write('">');
65
- res.write(item);
66
- res.write('</a></li>');
56
+ res.write(`<li><a href="${baseUrl + item}">${item}</a></li>`);
67
57
 
68
58
  if (/\.js$/.test(item)) {
69
59
  const html = item.substr(0, item.length - 3);
60
+ const containerHref = baseUrl + html;
70
61
 
71
- res.write('<li><a href="');
72
- res.write(baseUrl + html);
73
- res.write('">');
74
- res.write(html);
75
- res.write('</a> (magic html for ');
76
- res.write(item);
77
- res.write(') (<a href="');
78
- res.write(
62
+ const magicHtmlHref =
79
63
  baseUrl.replace(
80
64
  // eslint-disable-next-line
81
65
  /(^(https?:\/\/[^\/]+)?\/)/,
82
66
  '$1webpack-dev-server/'
83
- ) + html
67
+ ) + html;
68
+
69
+ res.write(
70
+ `<li><a href="${containerHref}">${html}</a>` +
71
+ ` (magic html for ${item}) (<a href="${magicHtmlHref}">webpack-dev-server</a>)` +
72
+ `</li>`
84
73
  );
85
- res.write('">webpack-dev-server</a>)</li>');
86
74
  }
87
75
  } else {
88
- res.write('<li>');
89
- res.write(item);
90
- res.write('<br>');
76
+ res.write(`<li>${item}<br>`);
91
77
 
92
78
  writeDirectory(`${baseUrl + item}/`, p);
93
79
 
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
- function runBonjour(options) {
4
- // eslint-disable-next-line global-require
3
+ function runBonjour({ port }) {
5
4
  const bonjour = require('bonjour')();
6
5
 
7
6
  bonjour.publish({
8
7
  name: 'Webpack Dev Server',
9
- port: options.port,
8
+ port,
10
9
  type: 'http',
11
10
  subtypes: ['webpack'],
12
11
  });
@@ -1,17 +1,24 @@
1
1
  'use strict';
2
2
 
3
3
  const open = require('opn');
4
+ const isAbsoluteUrl = require('is-absolute-url');
4
5
 
5
6
  function runOpen(uri, options, log) {
6
- let openOptions = {};
7
+ // https://github.com/webpack/webpack-dev-server/issues/1990
8
+ let openOptions = { wait: false };
7
9
  let openMessage = 'Unable to open browser';
8
10
 
9
11
  if (typeof options.open === 'string') {
10
- openOptions = { app: options.open };
12
+ openOptions = Object.assign({}, openOptions, { app: options.open });
11
13
  openMessage += `: ${options.open}`;
12
14
  }
13
15
 
14
- open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
16
+ const pageUrl =
17
+ options.openPage && isAbsoluteUrl(options.openPage)
18
+ ? options.openPage
19
+ : `${uri}${options.openPage || ''}`;
20
+
21
+ return open(pageUrl, openOptions).catch(() => {
15
22
  log.warn(
16
23
  `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
17
24
  );
@@ -2,11 +2,11 @@
2
2
 
3
3
  const signals = ['SIGINT', 'SIGTERM'];
4
4
 
5
- function setupExitSignals(server) {
5
+ function setupExitSignals(serverData) {
6
6
  signals.forEach((signal) => {
7
7
  process.on(signal, () => {
8
- if (server) {
9
- server.close(() => {
8
+ if (serverData.server) {
9
+ serverData.server.close(() => {
10
10
  // eslint-disable-next-line no-process-exit
11
11
  process.exit();
12
12
  });
@@ -1,10 +1,20 @@
1
1
  'use strict';
2
2
 
3
+ const logger = require('webpack-log');
3
4
  const colors = require('./colors');
4
5
  const runOpen = require('./runOpen');
5
6
 
6
7
  // TODO: don't emit logs when webpack-dev-server is used via Node.js API
7
8
  function status(uri, options, log, useColor) {
9
+ if (options.quiet === true) {
10
+ // Add temporary logger to output just the status of the dev server
11
+ log = logger({
12
+ name: 'wds',
13
+ level: 'info',
14
+ timestamp: options.logTime,
15
+ });
16
+ }
17
+
8
18
  const contentBase = Array.isArray(options.contentBase)
9
19
  ? options.contentBase.join(', ')
10
20
  : options.contentBase;
@@ -2,9 +2,11 @@
2
2
 
3
3
  function tryParseInt(input) {
4
4
  const output = parseInt(input, 10);
5
+
5
6
  if (Number.isNaN(output)) {
6
7
  return null;
7
8
  }
9
+
8
10
  return output;
9
11
  }
10
12
 
@@ -6,6 +6,7 @@
6
6
  */
7
7
  const webpack = require('webpack');
8
8
  const addEntries = require('./addEntries');
9
+ const getSocketClientPath = require('./getSocketClientPath');
9
10
 
10
11
  function updateCompiler(compiler, options) {
11
12
  if (options.inline !== false) {
@@ -50,10 +51,7 @@ function updateCompiler(compiler, options) {
50
51
  compiler.hooks.entryOption.call(config.context, config.entry);
51
52
 
52
53
  const providePlugin = new webpack.ProvidePlugin({
53
- // SockJSClient.getClientPath(options)
54
- __webpack_dev_server_client__: require.resolve(
55
- '../../client/clients/SockJSClient.js'
56
- ),
54
+ __webpack_dev_server_client__: getSocketClientPath(options),
57
55
  });
58
56
  providePlugin.apply(compiler);
59
57
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-server",
3
- "version": "3.7.0",
3
+ "version": "3.8.1",
4
4
  "description": "Serves a webpack app. Updates the browser on changes.",
5
5
  "bin": "bin/webpack-dev-server.js",
6
6
  "main": "lib/Server.js",
@@ -17,26 +17,28 @@
17
17
  "lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
18
18
  "lint:js": "eslint . --cache",
19
19
  "lint": "npm-run-all -l -p \"lint:**\"",
20
+ "lint:type": "tsc --noEmit",
20
21
  "commitlint": "commitlint --from=master",
21
22
  "security": "npm audit",
22
- "test:only": "jest --runInBand",
23
+ "test:only": "jest --forceExit",
23
24
  "test:coverage": "npm run test:only -- --coverage",
24
25
  "test:watch": "npm run test:coverage --watch",
25
26
  "test": "npm run test:coverage",
26
27
  "pretest": "npm run lint",
27
- "prepare": "rimraf ./ssl/*.pem && npm run -s transpile:index && npm run transpile:clients && npm run -s build:live && npm run -s build:index && npm run -s build:sockjs",
28
- "transpile:index": "babel client-src/default --out-dir client --ignore \"./client-src/default/*.config.js\"",
29
- "transpile:clients": "babel client-src/clients --out-dir client/clients",
30
- "build:index": "webpack ./client-src/default/index.js -o client/index.bundle.js --color --config client-src/default/webpack.config.js",
31
- "build:live": "webpack ./client-src/live/index.js -o client/live.bundle.js --color --config client-src/live/webpack.config.js",
32
- "build:sockjs": "webpack ./client-src/sockjs/index.js -o client/sockjs.bundle.js --color --config client-src/sockjs/webpack.config.js",
33
- "webpack-dev-server": "cd $INIT_CWD && node ../../../bin/webpack-dev-server.js",
28
+ "prepare": "rimraf ./ssl/*.pem && npm run build:client",
29
+ "build:client:default": "babel client-src/default --out-dir client --ignore \"./client-src/default/*.config.js\"",
30
+ "build:client:clients": "babel client-src/clients --out-dir client/clients",
31
+ "build:client:index": "webpack ./client-src/default/index.js -o client/index.bundle.js --color --config client-src/default/webpack.config.js",
32
+ "build:client:live": "webpack ./client-src/live/index.js -o client/live.bundle.js --color --config client-src/live/webpack.config.js",
33
+ "build:client:sockjs": "webpack ./client-src/sockjs/index.js -o client/sockjs.bundle.js --color --config client-src/sockjs/webpack.config.js",
34
+ "build:client": "rimraf ./client/* && npm-run-all -s -l -p \"build:client:**\"",
35
+ "webpack-dev-server": "node examples/run-example.js",
34
36
  "release": "standard-version"
35
37
  },
36
38
  "dependencies": {
37
39
  "ansi-html": "0.0.7",
38
40
  "bonjour": "^3.5.0",
39
- "chokidar": "^2.1.6",
41
+ "chokidar": "^2.1.8",
40
42
  "compression": "^1.7.4",
41
43
  "connect-history-api-fallback": "^1.6.0",
42
44
  "debug": "^4.1.1",
@@ -47,63 +49,69 @@
47
49
  "import-local": "^2.0.0",
48
50
  "internal-ip": "^4.3.0",
49
51
  "ip": "^1.1.5",
52
+ "is-absolute-url": "^3.0.2",
50
53
  "killable": "^1.0.1",
51
- "loglevel": "^1.6.2",
54
+ "loglevel": "^1.6.4",
52
55
  "opn": "^5.5.0",
53
- "portfinder": "^1.0.20",
56
+ "p-retry": "^3.0.1",
57
+ "portfinder": "^1.0.24",
54
58
  "schema-utils": "^1.0.0",
55
- "selfsigned": "^1.10.4",
56
- "semver": "^6.1.1",
59
+ "selfsigned": "^1.10.6",
60
+ "semver": "^6.3.0",
57
61
  "serve-index": "^1.9.1",
58
62
  "sockjs": "0.3.19",
59
- "sockjs-client": "1.3.0",
60
- "spdy": "^4.0.0",
63
+ "sockjs-client": "1.4.0",
64
+ "spdy": "^4.0.1",
61
65
  "strip-ansi": "^3.0.1",
62
66
  "supports-color": "^6.1.0",
63
67
  "url": "^0.11.0",
64
- "webpack-dev-middleware": "^3.7.0",
68
+ "webpack-dev-middleware": "^3.7.1",
65
69
  "webpack-log": "^2.0.0",
70
+ "ws": "^6.2.1",
66
71
  "yargs": "12.0.5"
67
72
  },
68
73
  "devDependencies": {
69
- "@babel/cli": "^7.4.4",
70
- "@babel/core": "^7.4.5",
71
- "@babel/preset-env": "^7.4.5",
72
- "@commitlint/cli": "^7.6.1",
73
- "@commitlint/config-conventional": "^7.6.0",
74
+ "@babel/cli": "^7.6.0",
75
+ "@babel/core": "^7.6.0",
76
+ "@babel/plugin-transform-runtime": "^7.6.0",
77
+ "@babel/preset-env": "^7.6.0",
78
+ "@babel/runtime": "^7.6.0",
79
+ "@commitlint/cli": "^8.1.0",
80
+ "@commitlint/config-conventional": "^8.1.0",
74
81
  "babel-loader": "^8.0.6",
75
82
  "body-parser": "^1.19.0",
76
83
  "commitlint-azure-pipelines-cli": "^1.0.2",
77
- "copy-webpack-plugin": "^5.0.3",
84
+ "copy-webpack-plugin": "^5.0.4",
78
85
  "css-loader": "^2.1.1",
79
- "eslint": "^5.16.0",
80
- "eslint-config-prettier": "^4.3.0",
86
+ "eslint": "^6.4.0",
87
+ "eslint-config-prettier": "^6.3.0",
81
88
  "eslint-config-webpack": "^1.2.5",
82
- "eslint-plugin-import": "^2.17.3",
89
+ "eslint-plugin-import": "^2.18.2",
83
90
  "execa": "^1.0.0",
84
91
  "file-loader": "^3.0.1",
85
92
  "html-loader": "^0.5.5",
86
93
  "html-webpack-plugin": "^3.2.0",
87
- "husky": "^2.4.0",
88
- "jest": "^24.8.0",
89
- "jest-junit": "^6.4.0",
94
+ "husky": "^3.0.5",
95
+ "jest": "^24.9.0",
96
+ "jest-junit": "^8.0.0",
90
97
  "jquery": "^3.4.1",
91
- "less": "^3.9.0",
98
+ "less": "^3.10.3",
92
99
  "less-loader": "^5.0.0",
93
- "lint-staged": "^8.2.0",
94
- "marked": "^0.6.2",
95
- "memfs": "^2.15.4",
100
+ "lint-staged": "^9.2.5",
101
+ "marked": "^0.7.0",
102
+ "memfs": "^2.15.5",
96
103
  "npm-run-all": "^4.1.5",
97
- "prettier": "^1.17.1",
98
- "puppeteer": "^1.17.0",
99
- "rimraf": "^2.6.3",
100
- "standard-version": "^6.0.1",
101
- "style-loader": "^0.23.1",
104
+ "prettier": "^1.18.2",
105
+ "puppeteer": "^1.20.0",
106
+ "rimraf": "^3.0.0",
107
+ "standard-version": "^7.0.0",
108
+ "style-loader": "^1.0.0",
102
109
  "supertest": "^4.0.2",
110
+ "tcp-port-used": "^1.0.1",
111
+ "typescript": "^3.6.3",
103
112
  "url-loader": "^1.1.2",
104
- "webpack": "^4.33.0",
105
- "webpack-cli": "^3.3.2",
106
- "ws": "^6.2.1"
113
+ "webpack": "^4.40.2",
114
+ "webpack-cli": "^3.3.8"
107
115
  },
108
116
  "peerDependencies": {
109
117
  "webpack": "^4.0.0"