webpack-dev-server 3.4.1 → 3.7.0

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,35 +1,28 @@
1
1
  'use strict';
2
2
 
3
- const portfinder = require('portfinder');
4
-
5
- function runPortFinder(defaultPort, cb) {
6
- portfinder.basePort = defaultPort;
7
- portfinder.getPort((err, port) => {
8
- cb(err, port);
9
- });
10
- }
11
-
12
- function findPort(server, defaultPort, defaultPortRetry, fn) {
13
- let tryCount = 0;
14
- const portFinderRunCb = (err, port) => {
15
- tryCount += 1;
16
- fn(err, port);
17
- };
18
-
19
- server.listeningApp.on('error', (err) => {
20
- if (err && err.code !== 'EADDRINUSE') {
21
- throw err;
22
- }
23
-
24
- if (tryCount >= defaultPortRetry) {
25
- fn(err);
26
- return;
27
- }
28
-
29
- runPortFinder(defaultPort, portFinderRunCb);
3
+ const { getPortPromise } = require('portfinder');
4
+ const defaultPort = require('./defaultPort');
5
+ const defaultTo = require('./defaultTo');
6
+ const tryParseInt = require('./tryParseInt');
7
+
8
+ function findPort(port) {
9
+ if (typeof port !== 'undefined') {
10
+ return Promise.resolve(port);
11
+ }
12
+
13
+ // Try to find unused port and listen on it for 3 times,
14
+ // if port is not specified in options.
15
+ // Because NaN == null is false, defaultTo fails if parseInt returns NaN
16
+ // so the tryParseInt function is introduced to handle NaN
17
+ const defaultPortRetry = defaultTo(
18
+ tryParseInt(process.env.DEFAULT_PORT_RETRY),
19
+ 3
20
+ );
21
+
22
+ return getPortPromise({
23
+ port: defaultPort,
24
+ stopPort: defaultPort + defaultPortRetry,
30
25
  });
31
-
32
- runPortFinder(defaultPort, portFinderRunCb);
33
26
  }
34
27
 
35
28
  module.exports = findPort;
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ function getSocketServerImplementation(options) {
4
+ let ServerImplementation;
5
+ let serverImplFound = true;
6
+ switch (typeof options.serverMode) {
7
+ case 'string':
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
11
+ ServerImplementation = require('../servers/SockJSServer');
12
+ } else {
13
+ try {
14
+ // eslint-disable-next-line global-require, import/no-dynamic-require
15
+ ServerImplementation = require(options.serverMode);
16
+ } catch (e) {
17
+ serverImplFound = false;
18
+ }
19
+ }
20
+ break;
21
+ case 'function':
22
+ // potentially do more checks here to confirm that the user implemented this properlly
23
+ // since errors could be difficult to understand
24
+ ServerImplementation = options.serverMode;
25
+ break;
26
+ default:
27
+ serverImplFound = false;
28
+ }
29
+
30
+ if (!serverImplFound) {
31
+ throw new Error(
32
+ "serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to " +
33
+ 'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
34
+ 'via require.resolve(...), or the class itself which extends BaseServer'
35
+ );
36
+ }
37
+
38
+ return ServerImplementation;
39
+ }
40
+
41
+ module.exports = getSocketServerImplementation;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const createConfig = require('./createConfig');
4
+ const defaultPort = require('./defaultPort');
5
+
6
+ function processOptions(config, argv, callback) {
7
+ // processOptions {Promise}
8
+ if (typeof config.then === 'function') {
9
+ config
10
+ .then((conf) => processOptions(conf, argv, callback))
11
+ .catch((err) => {
12
+ // eslint-disable-next-line no-console
13
+ console.error(err.stack || err);
14
+ // eslint-disable-next-line no-process-exit
15
+ process.exit(1);
16
+ });
17
+
18
+ return;
19
+ }
20
+
21
+ // Taken out of yargs because we must know if
22
+ // it wasn't given by the user, in which case
23
+ // we should use portfinder.
24
+ const options = createConfig(config, argv, { port: defaultPort });
25
+
26
+ callback(config, options);
27
+ }
28
+
29
+ module.exports = processOptions;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const open = require('opn');
4
+
5
+ function runOpen(uri, options, log) {
6
+ let openOptions = {};
7
+ let openMessage = 'Unable to open browser';
8
+
9
+ if (typeof options.open === 'string') {
10
+ openOptions = { app: options.open };
11
+ openMessage += `: ${options.open}`;
12
+ }
13
+
14
+ open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
15
+ log.warn(
16
+ `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
17
+ );
18
+ });
19
+ }
20
+
21
+ module.exports = runOpen;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const signals = ['SIGINT', 'SIGTERM'];
4
+
5
+ function setupExitSignals(server) {
6
+ signals.forEach((signal) => {
7
+ process.on(signal, () => {
8
+ if (server) {
9
+ server.close(() => {
10
+ // eslint-disable-next-line no-process-exit
11
+ process.exit();
12
+ });
13
+ } else {
14
+ // eslint-disable-next-line no-process-exit
15
+ process.exit();
16
+ }
17
+ });
18
+ });
19
+ }
20
+
21
+ module.exports = setupExitSignals;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const open = require('opn');
4
3
  const colors = require('./colors');
4
+ const runOpen = require('./runOpen');
5
5
 
6
6
  // TODO: don't emit logs when webpack-dev-server is used via Node.js API
7
7
  function status(uri, options, log, useColor) {
@@ -44,19 +44,7 @@ function status(uri, options, log, useColor) {
44
44
  }
45
45
 
46
46
  if (options.open) {
47
- let openOptions = {};
48
- let openMessage = 'Unable to open browser';
49
-
50
- if (typeof options.open === 'string') {
51
- openOptions = { app: options.open };
52
- openMessage += `: ${options.open}`;
53
- }
54
-
55
- open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
56
- log.warn(
57
- `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
58
- );
59
- });
47
+ runOpen(uri, options, log);
60
48
  }
61
49
  }
62
50
 
@@ -48,6 +48,14 @@ function updateCompiler(compiler, options) {
48
48
  compilers.forEach((compiler) => {
49
49
  const config = compiler.options;
50
50
  compiler.hooks.entryOption.call(config.context, config.entry);
51
+
52
+ const providePlugin = new webpack.ProvidePlugin({
53
+ // SockJSClient.getClientPath(options)
54
+ __webpack_dev_server_client__: require.resolve(
55
+ '../../client/clients/SockJSClient.js'
56
+ ),
57
+ });
58
+ providePlugin.apply(compiler);
51
59
  });
52
60
 
53
61
  // do not apply the plugin unless it didn't exist before.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-server",
3
- "version": "3.4.1",
3
+ "version": "3.7.0",
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",
@@ -14,9 +14,9 @@
14
14
  "node": ">= 6.11.5"
15
15
  },
16
16
  "scripts": {
17
- "lint:prettier": "prettier '{**/*,*}.{js,json,md,yml,css}' --list-different",
17
+ "lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
18
18
  "lint:js": "eslint . --cache",
19
- "lint": "npm-run-all -l -p 'lint:**'",
19
+ "lint": "npm-run-all -l -p \"lint:**\"",
20
20
  "commitlint": "commitlint --from=master",
21
21
  "security": "npm audit",
22
22
  "test:only": "jest --runInBand",
@@ -24,8 +24,9 @@
24
24
  "test:watch": "npm run test:coverage --watch",
25
25
  "test": "npm run test:coverage",
26
26
  "pretest": "npm run lint",
27
- "prepare": "rimraf ./ssl/*.pem && npm run -s transpile:index && 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'",
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",
29
30
  "build:index": "webpack ./client-src/default/index.js -o client/index.bundle.js --color --config client-src/default/webpack.config.js",
30
31
  "build:live": "webpack ./client-src/live/index.js -o client/live.bundle.js --color --config client-src/live/webpack.config.js",
31
32
  "build:sockjs": "webpack ./client-src/sockjs/index.js -o client/sockjs.bundle.js --color --config client-src/sockjs/webpack.config.js",
@@ -40,19 +41,19 @@
40
41
  "connect-history-api-fallback": "^1.6.0",
41
42
  "debug": "^4.1.1",
42
43
  "del": "^4.1.1",
43
- "express": "^4.17.0",
44
+ "express": "^4.17.1",
44
45
  "html-entities": "^1.2.1",
45
46
  "http-proxy-middleware": "^0.19.1",
46
47
  "import-local": "^2.0.0",
47
48
  "internal-ip": "^4.3.0",
48
49
  "ip": "^1.1.5",
49
50
  "killable": "^1.0.1",
50
- "loglevel": "^1.6.1",
51
+ "loglevel": "^1.6.2",
51
52
  "opn": "^5.5.0",
52
53
  "portfinder": "^1.0.20",
53
54
  "schema-utils": "^1.0.0",
54
55
  "selfsigned": "^1.10.4",
55
- "semver": "^6.0.0",
56
+ "semver": "^6.1.1",
56
57
  "serve-index": "^1.9.1",
57
58
  "sockjs": "0.3.19",
58
59
  "sockjs-client": "1.3.0",
@@ -66,41 +67,41 @@
66
67
  },
67
68
  "devDependencies": {
68
69
  "@babel/cli": "^7.4.4",
69
- "@babel/core": "^7.4.4",
70
- "@babel/preset-env": "^7.4.4",
70
+ "@babel/core": "^7.4.5",
71
+ "@babel/preset-env": "^7.4.5",
71
72
  "@commitlint/cli": "^7.6.1",
72
73
  "@commitlint/config-conventional": "^7.6.0",
73
74
  "babel-loader": "^8.0.6",
74
- "commitlint-azure-pipelines-cli": "^1.0.1",
75
+ "body-parser": "^1.19.0",
76
+ "commitlint-azure-pipelines-cli": "^1.0.2",
75
77
  "copy-webpack-plugin": "^5.0.3",
76
78
  "css-loader": "^2.1.1",
77
79
  "eslint": "^5.16.0",
78
80
  "eslint-config-prettier": "^4.3.0",
79
81
  "eslint-config-webpack": "^1.2.5",
80
- "eslint-plugin-import": "^2.17.2",
82
+ "eslint-plugin-import": "^2.17.3",
81
83
  "execa": "^1.0.0",
82
84
  "file-loader": "^3.0.1",
83
85
  "html-loader": "^0.5.5",
84
86
  "html-webpack-plugin": "^3.2.0",
85
- "husky": "^2.3.0",
87
+ "husky": "^2.4.0",
86
88
  "jest": "^24.8.0",
87
89
  "jest-junit": "^6.4.0",
88
90
  "jquery": "^3.4.1",
89
91
  "less": "^3.9.0",
90
92
  "less-loader": "^5.0.0",
91
- "lint-staged": "^8.1.7",
93
+ "lint-staged": "^8.2.0",
92
94
  "marked": "^0.6.2",
93
- "memfs": "^2.15.2",
95
+ "memfs": "^2.15.4",
94
96
  "npm-run-all": "^4.1.5",
95
- "nyc": "^14.1.1",
96
97
  "prettier": "^1.17.1",
97
- "puppeteer": "^1.16.0",
98
+ "puppeteer": "^1.17.0",
98
99
  "rimraf": "^2.6.3",
99
100
  "standard-version": "^6.0.1",
100
101
  "style-loader": "^0.23.1",
101
102
  "supertest": "^4.0.2",
102
103
  "url-loader": "^1.1.2",
103
- "webpack": "^4.31.0",
104
+ "webpack": "^4.33.0",
104
105
  "webpack-cli": "^3.3.2",
105
106
  "ws": "^6.2.1"
106
107
  },