@rspack/dev-server 1.1.5 → 1.2.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.
- package/README.md +3 -1
- package/client/clients/SockJSClient.js +34 -0
- package/client/clients/WebSocketClient.js +32 -0
- package/client/index.js +22 -105
- package/client/modules/logger/index.js +725 -0
- package/client/modules/sockjs-client/index.js +4506 -0
- package/client/overlay.js +503 -0
- package/client/progress.js +130 -0
- package/client/socket.js +60 -0
- package/client/utils/ansiHTML.js +2 -3
- package/client/utils/log.js +21 -0
- package/client/utils/sendMessage.js +17 -0
- package/dist/config.d.ts +10 -11
- package/dist/getPort.d.ts +10 -0
- package/dist/getPort.js +131 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -1
- package/dist/options.json +1034 -0
- package/dist/server.d.ts +106 -23
- package/dist/server.js +2187 -40
- package/dist/servers/BaseServer.d.ts +17 -0
- package/dist/servers/BaseServer.js +20 -0
- package/dist/servers/SockJSServer.d.ts +10 -0
- package/dist/servers/SockJSServer.js +110 -0
- package/dist/servers/WebsocketServer.d.ts +10 -0
- package/dist/servers/WebsocketServer.js +72 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.js +5 -0
- package/package.json +39 -5
- package/dist/patch.d.ts +0 -3
- package/dist/patch.js +0 -32
package/client/socket.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
import WebSocketClient from './clients/WebSocketClient.js';
|
|
11
|
+
import { log } from './utils/log.js';
|
|
12
|
+
// this WebsocketClient is here as a default fallback, in case the client is not injected
|
|
13
|
+
var Client = typeof __webpack_dev_server_client__ !== 'undefined'
|
|
14
|
+
? typeof __webpack_dev_server_client__.default !== 'undefined'
|
|
15
|
+
? __webpack_dev_server_client__.default
|
|
16
|
+
: __webpack_dev_server_client__
|
|
17
|
+
: WebSocketClient;
|
|
18
|
+
var retries = 0;
|
|
19
|
+
var maxRetries = 10;
|
|
20
|
+
// Initialized client is exported so external consumers can utilize the same instance
|
|
21
|
+
// It is mutable to enforce singleton
|
|
22
|
+
export var client = null;
|
|
23
|
+
var timeout;
|
|
24
|
+
function socket(url, handlers, reconnect) {
|
|
25
|
+
client = new Client(url);
|
|
26
|
+
client.onOpen(function () {
|
|
27
|
+
retries = 0;
|
|
28
|
+
if (timeout) {
|
|
29
|
+
clearTimeout(timeout);
|
|
30
|
+
}
|
|
31
|
+
if (typeof reconnect !== 'undefined') {
|
|
32
|
+
maxRetries = reconnect;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
client.onClose(function () {
|
|
36
|
+
if (retries === 0) {
|
|
37
|
+
handlers.close();
|
|
38
|
+
}
|
|
39
|
+
// Try to reconnect.
|
|
40
|
+
client = null;
|
|
41
|
+
// After 10 retries stop trying, to prevent logspam.
|
|
42
|
+
if (retries < maxRetries) {
|
|
43
|
+
// Exponentially increase timeout to reconnect.
|
|
44
|
+
// Respectfully copied from the package `got`.
|
|
45
|
+
var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
|
|
46
|
+
retries += 1;
|
|
47
|
+
log.info('Trying to reconnect...');
|
|
48
|
+
timeout = setTimeout(function () {
|
|
49
|
+
socket(url, handlers, reconnect);
|
|
50
|
+
}, retryInMs);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
client.onMessage(function (data) {
|
|
54
|
+
var message = JSON.parse(data);
|
|
55
|
+
if (handlers[message.type]) {
|
|
56
|
+
handlers[message.type](message.data, message.params);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export default socket;
|
package/client/utils/ansiHTML.js
CHANGED
|
@@ -108,8 +108,9 @@ export default function ansiHTML(text) {
|
|
|
108
108
|
// Cache opened sequence.
|
|
109
109
|
var ansiCodes = [];
|
|
110
110
|
// Replace with markup.
|
|
111
|
+
var ret = text.replace(
|
|
111
112
|
//@ts-ignore TS1487 error
|
|
112
|
-
|
|
113
|
+
/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, function (m) {
|
|
113
114
|
var _a;
|
|
114
115
|
var match = (_a = m.match(/(;?\d+)/g)) === null || _a === void 0 ? void 0 : _a.map(normalizeSeq);
|
|
115
116
|
Object.defineProperty(match, 'advance', {
|
|
@@ -162,7 +163,6 @@ export default function ansiHTML(text) {
|
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Customize colors.
|
|
165
|
-
* @param {Object} colors reference to _defColors
|
|
166
166
|
*/
|
|
167
167
|
ansiHTML.setColors = function (colors) {
|
|
168
168
|
if (typeof colors !== 'object') {
|
|
@@ -209,7 +209,6 @@ ansiHTML.reset = function () {
|
|
|
209
209
|
};
|
|
210
210
|
/**
|
|
211
211
|
* Expose tags, including open and close.
|
|
212
|
-
* @type {Object}
|
|
213
212
|
*/
|
|
214
213
|
ansiHTML.tags = {};
|
|
215
214
|
if (Object.defineProperty) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
import logger from '../modules/logger/index';
|
|
11
|
+
var name = 'webpack-dev-server';
|
|
12
|
+
// default level is set on the client side, so it does not need
|
|
13
|
+
// to be set by the CLI or API
|
|
14
|
+
var defaultLevel = 'info';
|
|
15
|
+
// options new options, merge with old options
|
|
16
|
+
function setLogLevel(level) {
|
|
17
|
+
logger.configureDefaultLogger({ level: level });
|
|
18
|
+
}
|
|
19
|
+
setLogLevel(defaultLevel);
|
|
20
|
+
var log = logger.getLogger(name);
|
|
21
|
+
export { log, setLogLevel };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
function sendMsg(type, data) {
|
|
11
|
+
if (typeof self !== 'undefined' &&
|
|
12
|
+
(typeof WorkerGlobalScope === 'undefined' ||
|
|
13
|
+
!(self instanceof WorkerGlobalScope))) {
|
|
14
|
+
self.postMessage({ type: "webpack".concat(type), data: data }, '*');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default sendMsg;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import type
|
|
3
|
-
export type { DevServer };
|
|
1
|
+
/// <reference types="connect-history-api-fallback" />
|
|
2
|
+
import type { BonjourOptions, ClientConfiguration, ConnectHistoryApiFallbackOptions, DevServer, NormalizedStatic, Open, ServerConfiguration, WatchFiles, WebSocketServerConfiguration } from './types';
|
|
4
3
|
export interface ResolvedDevServer extends DevServer {
|
|
5
4
|
port: number | string;
|
|
6
|
-
static: false | Array<
|
|
5
|
+
static: false | Array<NormalizedStatic>;
|
|
7
6
|
devMiddleware: DevServer['devMiddleware'];
|
|
8
7
|
hot: boolean | 'only';
|
|
9
8
|
host?: string;
|
|
10
|
-
open:
|
|
9
|
+
open: Open[];
|
|
11
10
|
magicHtml: boolean;
|
|
12
11
|
liveReload: boolean;
|
|
13
|
-
webSocketServer: false |
|
|
12
|
+
webSocketServer: false | WebSocketServerConfiguration;
|
|
14
13
|
proxy: Required<DevServer['proxy']>;
|
|
15
|
-
client:
|
|
14
|
+
client: ClientConfiguration;
|
|
16
15
|
allowedHosts: 'auto' | string[] | 'all';
|
|
17
|
-
bonjour: false | Record<string, never> |
|
|
16
|
+
bonjour: false | Record<string, never> | BonjourOptions;
|
|
18
17
|
compress: boolean;
|
|
19
|
-
historyApiFallback: false |
|
|
20
|
-
server:
|
|
18
|
+
historyApiFallback: false | ConnectHistoryApiFallbackOptions;
|
|
19
|
+
server: ServerConfiguration;
|
|
21
20
|
ipc: string | undefined;
|
|
22
21
|
setupExitSignals: boolean;
|
|
23
|
-
watchFiles:
|
|
22
|
+
watchFiles: WatchFiles[];
|
|
24
23
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack-dev-server
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Tobias Koppers @sokra
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
package/dist/getPort.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The following code is modified based on
|
|
4
|
+
* https://github.com/webpack/webpack-dev-server
|
|
5
|
+
*
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
* Author Tobias Koppers @sokra
|
|
8
|
+
* Copyright (c) JS Foundation and other contributors
|
|
9
|
+
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
/*
|
|
36
|
+
* Based on the packages get-port https://www.npmjs.com/package/get-port
|
|
37
|
+
* and portfinder https://www.npmjs.com/package/portfinder
|
|
38
|
+
* The code structure is similar to get-port, but it searches
|
|
39
|
+
* ports deterministically like portfinder
|
|
40
|
+
*/
|
|
41
|
+
const net = __importStar(require("node:net"));
|
|
42
|
+
const os = __importStar(require("node:os"));
|
|
43
|
+
const minPort = 1024;
|
|
44
|
+
const maxPort = 65535;
|
|
45
|
+
/**
|
|
46
|
+
* Get all local hosts
|
|
47
|
+
*/
|
|
48
|
+
const getLocalHosts = () => {
|
|
49
|
+
const interfaces = os.networkInterfaces();
|
|
50
|
+
// Add undefined value for createServer function to use default host,
|
|
51
|
+
// and default IPv4 host in case createServer defaults to IPv6.
|
|
52
|
+
const results = new Set([undefined, '0.0.0.0']);
|
|
53
|
+
for (const _interface of Object.values(interfaces)) {
|
|
54
|
+
if (_interface) {
|
|
55
|
+
for (const config of _interface) {
|
|
56
|
+
results.add(config.address);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Check if a port is available on a given host
|
|
64
|
+
*/
|
|
65
|
+
const checkAvailablePort = (basePort, host) => new Promise((resolve, reject) => {
|
|
66
|
+
const server = net.createServer();
|
|
67
|
+
server.unref();
|
|
68
|
+
server.on('error', reject);
|
|
69
|
+
server.listen(basePort, host, () => {
|
|
70
|
+
// Next line should return AddressInfo because we're calling it after listen() and before close()
|
|
71
|
+
const { port } = server.address();
|
|
72
|
+
server.close(() => {
|
|
73
|
+
resolve(port);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Get available port from hosts
|
|
79
|
+
*/
|
|
80
|
+
const getAvailablePort = async (port, hosts) => {
|
|
81
|
+
/**
|
|
82
|
+
* Errors that mean that host is not available.
|
|
83
|
+
*/
|
|
84
|
+
const nonExistentInterfaceErrors = new Set(['EADDRNOTAVAIL', 'EINVAL']);
|
|
85
|
+
/* Check if the post is available on every local host name */
|
|
86
|
+
for (const host of hosts) {
|
|
87
|
+
try {
|
|
88
|
+
await checkAvailablePort(port, host);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
/* We throw an error only if the interface exists */
|
|
92
|
+
if (!nonExistentInterfaceErrors.has(error.code || '')) {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return port;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Get available ports
|
|
101
|
+
*/
|
|
102
|
+
async function getPorts(basePort, host) {
|
|
103
|
+
if (basePort < minPort || basePort > maxPort) {
|
|
104
|
+
throw new Error(`Port number must lie between ${minPort} and ${maxPort}`);
|
|
105
|
+
}
|
|
106
|
+
let port = basePort;
|
|
107
|
+
const localhosts = getLocalHosts();
|
|
108
|
+
const hosts = host && !localhosts.has(host)
|
|
109
|
+
? new Set([host])
|
|
110
|
+
: /* If the host is equivalent to localhost
|
|
111
|
+
we need to check every equivalent host
|
|
112
|
+
else the port might falsely appear as available
|
|
113
|
+
on some operating systems */
|
|
114
|
+
localhosts;
|
|
115
|
+
const portUnavailableErrors = new Set(['EADDRINUSE', 'EACCES']);
|
|
116
|
+
while (port <= maxPort) {
|
|
117
|
+
try {
|
|
118
|
+
const availablePort = await getAvailablePort(port, hosts);
|
|
119
|
+
return availablePort;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
/* Try next port if port is busy; throw for any other error */
|
|
123
|
+
if (!portUnavailableErrors.has(error.code || '')) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
port += 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
throw new Error('No available ports found');
|
|
130
|
+
}
|
|
131
|
+
module.exports = getPorts;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { RspackDevServer } from './server';
|
|
1
|
+
export { default as RspackDevServer } from './server';
|
|
2
2
|
export type { DevServer as Configuration } from '@rspack/core';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.RspackDevServer = void 0;
|
|
4
7
|
var server_1 = require("./server");
|
|
5
|
-
Object.defineProperty(exports, "RspackDevServer", { enumerable: true, get: function () { return server_1.
|
|
8
|
+
Object.defineProperty(exports, "RspackDevServer", { enumerable: true, get: function () { return __importDefault(server_1).default; } });
|