webpack-dev-server 4.8.1 → 4.9.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.
- package/README.md +120 -130
- package/bin/cli-flags.js +15 -0
- package/client/index.js +5 -3
- package/client/modules/logger/index.js +1 -2
- package/client/modules/sockjs-client/index.js +1 -1
- package/client/overlay.js +23 -6
- package/client/utils/createSocketURL.js +1 -1
- package/lib/Server.js +7 -6
- package/lib/getPort.js +133 -0
- package/lib/options.json +4 -0
- package/package.json +6 -5
- package/types/bin/cli-flags.d.ts +11 -0
- package/types/lib/Server.d.ts +231 -115
- package/types/lib/getPort.d.ts +10 -0
package/lib/getPort.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Based on the packages get-port https://www.npmjs.com/package/get-port
|
|
5
|
+
* and portfinder https://www.npmjs.com/package/portfinder
|
|
6
|
+
* The code structure is similar to get-port, but it searches
|
|
7
|
+
* ports deterministically like portfinder
|
|
8
|
+
*/
|
|
9
|
+
const net = require("net");
|
|
10
|
+
const os = require("os");
|
|
11
|
+
|
|
12
|
+
const minPort = 1024;
|
|
13
|
+
const maxPort = 65_535;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @return {Set<string|undefined>}
|
|
17
|
+
*/
|
|
18
|
+
const getLocalHosts = () => {
|
|
19
|
+
const interfaces = os.networkInterfaces();
|
|
20
|
+
|
|
21
|
+
// Add undefined value for createServer function to use default host,
|
|
22
|
+
// and default IPv4 host in case createServer defaults to IPv6.
|
|
23
|
+
// eslint-disable-next-line no-undefined
|
|
24
|
+
const results = new Set([undefined, "0.0.0.0"]);
|
|
25
|
+
|
|
26
|
+
for (const _interface of Object.values(interfaces)) {
|
|
27
|
+
if (_interface) {
|
|
28
|
+
for (const config of _interface) {
|
|
29
|
+
results.add(config.address);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return results;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {number} basePort
|
|
39
|
+
* @param {string | undefined} host
|
|
40
|
+
* @return {Promise<number>}
|
|
41
|
+
*/
|
|
42
|
+
const checkAvailablePort = (basePort, host) =>
|
|
43
|
+
new Promise((resolve, reject) => {
|
|
44
|
+
const server = net.createServer();
|
|
45
|
+
server.unref();
|
|
46
|
+
server.on("error", reject);
|
|
47
|
+
|
|
48
|
+
server.listen(basePort, host, () => {
|
|
49
|
+
// Next line should return AdressInfo because we're calling it after listen() and before close()
|
|
50
|
+
const { port } = /** @type {import("net").AddressInfo} */ (
|
|
51
|
+
server.address()
|
|
52
|
+
);
|
|
53
|
+
server.close(() => {
|
|
54
|
+
resolve(port);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {number} port
|
|
61
|
+
* @param {Set<string|undefined>} hosts
|
|
62
|
+
* @return {Promise<number>}
|
|
63
|
+
*/
|
|
64
|
+
const getAvailablePort = async (port, hosts) => {
|
|
65
|
+
/**
|
|
66
|
+
* Errors that mean that host is not available.
|
|
67
|
+
* @type {Set<string | undefined>}
|
|
68
|
+
*/
|
|
69
|
+
const nonExistentInterfaceErrors = new Set(["EADDRNOTAVAIL", "EINVAL"]);
|
|
70
|
+
/* Check if the post is available on every local host name */
|
|
71
|
+
for (const host of hosts) {
|
|
72
|
+
try {
|
|
73
|
+
await checkAvailablePort(port, host); // eslint-disable-line no-await-in-loop
|
|
74
|
+
} catch (error) {
|
|
75
|
+
/* We throw an error only if the interface exists */
|
|
76
|
+
if (
|
|
77
|
+
!nonExistentInterfaceErrors.has(
|
|
78
|
+
/** @type {NodeJS.ErrnoException} */ (error).code
|
|
79
|
+
)
|
|
80
|
+
) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return port;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {number} basePort
|
|
91
|
+
* @param {string=} host
|
|
92
|
+
* @return {Promise<number>}
|
|
93
|
+
*/
|
|
94
|
+
async function getPorts(basePort, host) {
|
|
95
|
+
if (basePort < minPort || basePort > maxPort) {
|
|
96
|
+
throw new Error(`Port number must lie between ${minPort} and ${maxPort}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let port = basePort;
|
|
100
|
+
const localhosts = getLocalHosts();
|
|
101
|
+
let hosts;
|
|
102
|
+
if (host && !localhosts.has(host)) {
|
|
103
|
+
hosts = new Set([host]);
|
|
104
|
+
} else {
|
|
105
|
+
/* If the host is equivalent to localhost
|
|
106
|
+
we need to check every equivalent host
|
|
107
|
+
else the port might falsely appear as available
|
|
108
|
+
on some operating systems */
|
|
109
|
+
hosts = localhosts;
|
|
110
|
+
}
|
|
111
|
+
/** @type {Set<string | undefined>} */
|
|
112
|
+
const portUnavailableErrors = new Set(["EADDRINUSE", "EACCES"]);
|
|
113
|
+
while (port <= maxPort) {
|
|
114
|
+
try {
|
|
115
|
+
const availablePort = await getAvailablePort(port, hosts); // eslint-disable-line no-await-in-loop
|
|
116
|
+
return availablePort;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
/* Try next port if port is busy; throw for any other error */
|
|
119
|
+
if (
|
|
120
|
+
!portUnavailableErrors.has(
|
|
121
|
+
/** @type {NodeJS.ErrnoException} */ (error).code
|
|
122
|
+
)
|
|
123
|
+
) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
port += 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
throw new Error("No available ports found");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = getPorts;
|
package/lib/options.json
CHANGED
|
@@ -110,6 +110,10 @@
|
|
|
110
110
|
"cli": {
|
|
111
111
|
"negatedDescription": "Disables the full-screen overlay in the browser when there are compiler warnings."
|
|
112
112
|
}
|
|
113
|
+
},
|
|
114
|
+
"trustedTypesPolicyName": {
|
|
115
|
+
"description": "The name of a Trusted Types policy for the overlay. Defaults to 'webpack-dev-server#overlay'.",
|
|
116
|
+
"type": "string"
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-dev-server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.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",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@types/connect-history-api-fallback": "^1.3.5",
|
|
40
40
|
"@types/express": "^4.17.13",
|
|
41
41
|
"@types/serve-index": "^1.9.1",
|
|
42
|
+
"@types/serve-static": "^1.13.10",
|
|
42
43
|
"@types/sockjs": "^0.3.33",
|
|
43
44
|
"@types/ws": "^8.5.1",
|
|
44
45
|
"ansi-html-community": "^0.0.8",
|
|
@@ -55,12 +56,11 @@
|
|
|
55
56
|
"ipaddr.js": "^2.0.1",
|
|
56
57
|
"open": "^8.0.9",
|
|
57
58
|
"p-retry": "^4.5.0",
|
|
58
|
-
"portfinder": "^1.0.28",
|
|
59
59
|
"rimraf": "^3.0.2",
|
|
60
60
|
"schema-utils": "^4.0.0",
|
|
61
61
|
"selfsigned": "^2.0.1",
|
|
62
62
|
"serve-index": "^1.9.1",
|
|
63
|
-
"sockjs": "^0.3.
|
|
63
|
+
"sockjs": "^0.3.24",
|
|
64
64
|
"spdy": "^4.0.2",
|
|
65
65
|
"webpack-dev-middleware": "^5.3.1",
|
|
66
66
|
"ws": "^8.4.2"
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"@types/default-gateway": "^3.0.1",
|
|
80
80
|
"@types/rimraf": "^3.0.2",
|
|
81
81
|
"@types/sockjs-client": "^1.5.1",
|
|
82
|
+
"@types/trusted-types": "^2.0.2",
|
|
82
83
|
"acorn": "^8.2.4",
|
|
83
84
|
"babel-jest": "^27.5.1",
|
|
84
85
|
"babel-loader": "^8.2.4",
|
|
@@ -106,13 +107,13 @@
|
|
|
106
107
|
"puppeteer": "^13.4.1",
|
|
107
108
|
"require-from-string": "^2.0.2",
|
|
108
109
|
"rimraf": "^3.0.2",
|
|
109
|
-
"sockjs-client": "^1.6.
|
|
110
|
+
"sockjs-client": "^1.6.1",
|
|
110
111
|
"standard-version": "^9.3.0",
|
|
111
112
|
"strip-ansi-v6": "npm:strip-ansi@^6.0.0",
|
|
112
113
|
"style-loader": "^2.0.0",
|
|
113
114
|
"supertest": "^6.1.3",
|
|
114
115
|
"tcp-port-used": "^1.0.2",
|
|
115
|
-
"typescript": "^4.
|
|
116
|
+
"typescript": "^4.7.2",
|
|
116
117
|
"url-loader": "^4.1.1",
|
|
117
118
|
"webpack": "^5.71.0",
|
|
118
119
|
"webpack-cli": "^4.7.2",
|
package/types/bin/cli-flags.d.ts
CHANGED
|
@@ -91,6 +91,17 @@ declare const _exports: {
|
|
|
91
91
|
simpleType: string;
|
|
92
92
|
multiple: boolean;
|
|
93
93
|
};
|
|
94
|
+
"client-overlay-trusted-types-policy-name": {
|
|
95
|
+
configs: {
|
|
96
|
+
description: string;
|
|
97
|
+
multiple: boolean;
|
|
98
|
+
path: string;
|
|
99
|
+
type: string;
|
|
100
|
+
}[];
|
|
101
|
+
description: string;
|
|
102
|
+
multiple: boolean;
|
|
103
|
+
simpleType: string;
|
|
104
|
+
};
|
|
94
105
|
"client-overlay-warnings": {
|
|
95
106
|
configs: {
|
|
96
107
|
type: string;
|