webpack-dev-server 3.7.1 → 3.8.2

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.
@@ -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
- return 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;
@@ -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.1",
3
+ "version": "3.8.2",
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,9 +17,10 @@
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",
@@ -31,81 +32,86 @@
31
32
  "build:client:live": "webpack ./client-src/live/index.js -o client/live.bundle.js --color --config client-src/live/webpack.config.js",
32
33
  "build:client:sockjs": "webpack ./client-src/sockjs/index.js -o client/sockjs.bundle.js --color --config client-src/sockjs/webpack.config.js",
33
34
  "build:client": "rimraf ./client/* && npm-run-all -s -l -p \"build:client:**\"",
34
- "webpack-dev-server": "cd $INIT_CWD && node ../../../bin/webpack-dev-server.js",
35
+ "webpack-dev-server": "node examples/run-example.js",
35
36
  "release": "standard-version"
36
37
  },
37
38
  "dependencies": {
38
39
  "ansi-html": "0.0.7",
39
40
  "bonjour": "^3.5.0",
40
- "chokidar": "^2.1.6",
41
+ "chokidar": "^2.1.8",
41
42
  "compression": "^1.7.4",
42
43
  "connect-history-api-fallback": "^1.6.0",
43
44
  "debug": "^4.1.1",
44
45
  "del": "^4.1.1",
45
46
  "express": "^4.17.1",
46
47
  "html-entities": "^1.2.1",
47
- "http-proxy-middleware": "^0.19.1",
48
+ "http-proxy-middleware": "0.19.1",
48
49
  "import-local": "^2.0.0",
49
50
  "internal-ip": "^4.3.0",
50
51
  "ip": "^1.1.5",
52
+ "is-absolute-url": "^3.0.3",
51
53
  "killable": "^1.0.1",
52
- "loglevel": "^1.6.2",
54
+ "loglevel": "^1.6.4",
53
55
  "opn": "^5.5.0",
54
56
  "p-retry": "^3.0.1",
55
- "portfinder": "^1.0.20",
57
+ "portfinder": "^1.0.24",
56
58
  "schema-utils": "^1.0.0",
57
- "selfsigned": "^1.10.4",
58
- "semver": "^6.1.1",
59
+ "selfsigned": "^1.10.7",
60
+ "semver": "^6.3.0",
59
61
  "serve-index": "^1.9.1",
60
62
  "sockjs": "0.3.19",
61
- "sockjs-client": "1.3.0",
62
- "spdy": "^4.0.0",
63
+ "sockjs-client": "1.4.0",
64
+ "spdy": "^4.0.1",
63
65
  "strip-ansi": "^3.0.1",
64
66
  "supports-color": "^6.1.0",
65
67
  "url": "^0.11.0",
66
- "webpack-dev-middleware": "^3.7.0",
68
+ "webpack-dev-middleware": "^3.7.2",
67
69
  "webpack-log": "^2.0.0",
70
+ "ws": "^6.2.1",
68
71
  "yargs": "12.0.5"
69
72
  },
70
73
  "devDependencies": {
71
- "@babel/cli": "^7.4.4",
72
- "@babel/core": "^7.4.5",
73
- "@babel/preset-env": "^7.4.5",
74
- "@commitlint/cli": "^7.6.1",
75
- "@commitlint/config-conventional": "^7.6.0",
74
+ "@babel/cli": "^7.6.2",
75
+ "@babel/core": "^7.6.2",
76
+ "@babel/plugin-transform-runtime": "^7.6.2",
77
+ "@babel/preset-env": "^7.6.2",
78
+ "@babel/runtime": "^7.6.2",
79
+ "@commitlint/cli": "^8.1.0",
80
+ "@commitlint/config-conventional": "^8.1.0",
76
81
  "babel-loader": "^8.0.6",
77
82
  "body-parser": "^1.19.0",
78
83
  "commitlint-azure-pipelines-cli": "^1.0.2",
79
- "copy-webpack-plugin": "^5.0.3",
84
+ "copy-webpack-plugin": "^5.0.4",
80
85
  "css-loader": "^2.1.1",
81
- "eslint": "^5.16.0",
82
- "eslint-config-prettier": "^4.3.0",
86
+ "eslint": "^6.4.0",
87
+ "eslint-config-prettier": "^6.3.0",
83
88
  "eslint-config-webpack": "^1.2.5",
84
- "eslint-plugin-import": "^2.17.3",
89
+ "eslint-plugin-import": "^2.18.2",
85
90
  "execa": "^1.0.0",
86
91
  "file-loader": "^3.0.1",
87
92
  "html-loader": "^0.5.5",
88
93
  "html-webpack-plugin": "^3.2.0",
89
- "husky": "^2.4.0",
90
- "jest": "^24.8.0",
91
- "jest-junit": "^6.4.0",
94
+ "husky": "^3.0.8",
95
+ "jest": "^24.9.0",
96
+ "jest-junit": "^8.0.0",
92
97
  "jquery": "^3.4.1",
93
- "less": "^3.9.0",
98
+ "less": "^3.10.3",
94
99
  "less-loader": "^5.0.0",
95
- "lint-staged": "^8.2.0",
96
- "marked": "^0.6.2",
97
- "memfs": "^2.15.4",
100
+ "lint-staged": "^9.2.5",
101
+ "marked": "^0.7.0",
102
+ "memfs": "^2.15.5",
98
103
  "npm-run-all": "^4.1.5",
99
- "prettier": "^1.18.0",
100
- "puppeteer": "^1.17.0",
101
- "rimraf": "^2.6.3",
102
- "standard-version": "^6.0.1",
103
- "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",
104
109
  "supertest": "^4.0.2",
110
+ "tcp-port-used": "^1.0.1",
111
+ "typescript": "^3.6.3",
105
112
  "url-loader": "^1.1.2",
106
- "webpack": "^4.33.0",
107
- "webpack-cli": "^3.3.3",
108
- "ws": "^6.2.1"
113
+ "webpack": "^4.40.2",
114
+ "webpack-cli": "^3.3.9"
109
115
  },
110
116
  "peerDependencies": {
111
117
  "webpack": "^4.0.0"