@rspack/dev-server 0.0.20 → 0.0.22
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/CHANGELOG.md +30 -0
- package/LICENSE +1 -1
- package/dist/config.d.ts +20 -15
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -52
- package/dist/config.js.map +1 -1
- package/dist/server.d.ts +14 -41
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +308 -255
- package/dist/server.js.map +1 -1
- package/jest.config.js +6 -3
- package/package.json +13 -10
- package/src/config.ts +22 -68
- package/src/server.ts +350 -309
- package/tests/__snapshots__/normalizeOptions.test.ts.snap +226 -16
- package/tests/e2e/hot-reaload.test.ts +115 -0
- package/tests/e2e-fixtures/react/app.jsx +14 -0
- package/tests/e2e-fixtures/react/index.css +3 -0
- package/tests/e2e-fixtures/react/index.html +12 -0
- package/tests/e2e-fixtures/react/index.jsx +6 -0
- package/tests/e2e-fixtures/react/node_modules/react/LICENSE +21 -0
- package/tests/e2e-fixtures/react/node_modules/react/README.md +37 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-dev-runtime.development.js +1296 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-dev-runtime.production.min.js +10 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-dev-runtime.profiling.min.js +10 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-runtime.development.js +1314 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-runtime.production.min.js +11 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-runtime.profiling.min.js +11 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react.development.js +2739 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react.production.min.js +26 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react.shared-subset.development.js +20 -0
- package/tests/e2e-fixtures/react/node_modules/react/cjs/react.shared-subset.production.min.js +10 -0
- package/tests/e2e-fixtures/react/node_modules/react/index.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/react/jsx-dev-runtime.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/react/jsx-runtime.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/react/package.json +47 -0
- package/tests/e2e-fixtures/react/node_modules/react/react.shared-subset.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/react/umd/react.development.js +3342 -0
- package/tests/e2e-fixtures/react/node_modules/react/umd/react.production.min.js +31 -0
- package/tests/e2e-fixtures/react/node_modules/react/umd/react.profiling.min.js +31 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/LICENSE +21 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/README.md +60 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.browser.development.js +7018 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +93 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js +7078 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.node.production.min.js +101 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.browser.development.js +7003 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js +96 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.node.development.js +7059 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.node.production.min.js +102 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-test-utils.development.js +1741 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-test-utils.production.min.js +40 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom.development.js +29868 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom.production.min.js +323 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom.profiling.min.js +367 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/client.js +25 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/index.js +38 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/package.json +62 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/profiling.js +38 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/server.browser.js +17 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/server.js +3 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/server.node.js +17 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/test-utils.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server-legacy.browser.development.js +7015 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server-legacy.browser.production.min.js +75 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server.browser.development.js +7000 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server.browser.production.min.js +76 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-test-utils.development.js +1737 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-test-utils.production.min.js +33 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom.development.js +29869 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom.production.min.js +267 -0
- package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom.profiling.min.js +285 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/LICENSE +21 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/README.md +9 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +700 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_mock.production.min.js +20 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_post_task.development.js +207 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_post_task.production.min.js +14 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler.development.js +634 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler.production.min.js +19 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/index.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/package.json +36 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler-unstable_mock.development.js +699 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js +19 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.development.js +152 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.production.min.js +146 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.profiling.min.js +146 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/unstable_mock.js +7 -0
- package/tests/e2e-fixtures/react/node_modules/scheduler/unstable_post_task.js +7 -0
- package/tests/e2e-fixtures/react/package.json +8 -0
- package/tests/e2e-fixtures/react/webpack.config.js +26 -0
- package/tests/helpers/emitFile.ts +69 -0
- package/tests/helpers/runBrowser.ts +85 -0
- package/tests/helpers/tempDir.ts +58 -0
- package/tests/normalizeOptions.test.ts +59 -17
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/logger.d.ts +0 -7
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -28
- package/dist/logger.js.map +0 -1
- package/dist/ws.d.ts +0 -13
- package/dist/ws.d.ts.map +0 -1
- package/dist/ws.js +0 -12
- package/dist/ws.js.map +0 -1
- package/src/logger.ts +0 -30
- package/src/ws.ts +0 -18
package/dist/server.js
CHANGED
|
@@ -1,97 +1,171 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
exports.RspackDevServer = void 0;
|
|
30
|
+
const core_1 = require("@rspack/core");
|
|
31
|
+
const dev_middleware_1 = __importStar(require("@rspack/dev-middleware"));
|
|
7
32
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const chokidar_1 = __importDefault(require("chokidar"));
|
|
9
|
-
const http_1 = __importDefault(require("http"));
|
|
10
|
-
const logger_1 = require("./logger");
|
|
11
33
|
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// copy from webpack-dev-server
|
|
17
|
-
class RspackDevServer {
|
|
18
|
-
constructor(compiler) {
|
|
19
|
-
this.compiler = compiler;
|
|
20
|
-
this.logger = (0, logger_1.createLogger)("rspack-dev-server");
|
|
21
|
-
this.staticWatchers = [];
|
|
22
|
-
this.listeners = [];
|
|
23
|
-
this.sockets = [];
|
|
24
|
-
this.currentHash = "";
|
|
25
|
-
this.options = this.normalizeOptions(compiler.options.devServer);
|
|
26
|
-
this.rewriteCompilerOptions();
|
|
27
|
-
this.addAdditionEntires();
|
|
28
|
-
}
|
|
29
|
-
normalizeOptions(dev = {}) {
|
|
30
|
-
return (0, config_1.resolveDevOptions)(dev, this.compiler.options);
|
|
31
|
-
}
|
|
32
|
-
rewriteCompilerOptions() {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
if (!this.compiler.options.builtins.react) {
|
|
35
|
-
this.compiler.options.builtins.react = {};
|
|
36
|
-
}
|
|
37
|
-
this.compiler.options.builtins.react.development =
|
|
38
|
-
(_a = this.compiler.options.builtins.react.development) !== null && _a !== void 0 ? _a : true;
|
|
39
|
-
if (this.options.hot) {
|
|
40
|
-
this.compiler.options.builtins.react.refresh =
|
|
41
|
-
(_b = this.compiler.options.builtins.react.refresh) !== null && _b !== void 0 ? _b : true;
|
|
42
|
-
}
|
|
34
|
+
class RspackDevServer extends webpack_dev_server_1.default {
|
|
35
|
+
constructor(options, compiler) {
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
super(options, compiler);
|
|
43
38
|
}
|
|
44
|
-
addAdditionEntires() {
|
|
39
|
+
addAdditionEntires(compiler) {
|
|
45
40
|
var _a;
|
|
46
|
-
const
|
|
41
|
+
const additionalEntries = [];
|
|
42
|
+
// TODO: align with webpack-dev-server after options.target is aligned
|
|
43
|
+
const isWebTarget = compiler.options.target.includes("web") ||
|
|
44
|
+
compiler.options.target.includes("webworker");
|
|
45
|
+
if (this.options.client && isWebTarget) {
|
|
46
|
+
let webSocketURLStr = "";
|
|
47
|
+
if (this.options.webSocketServer) {
|
|
48
|
+
const webSocketURL = this.options.client
|
|
49
|
+
.webSocketURL;
|
|
50
|
+
const webSocketServer = this.options.webSocketServer;
|
|
51
|
+
const searchParams = new URLSearchParams();
|
|
52
|
+
let protocol;
|
|
53
|
+
// We are proxying dev server and need to specify custom `hostname`
|
|
54
|
+
if (typeof webSocketURL.protocol !== "undefined") {
|
|
55
|
+
protocol = webSocketURL.protocol;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
protocol = this.options.server.type === "http" ? "ws:" : "wss:";
|
|
59
|
+
}
|
|
60
|
+
searchParams.set("protocol", protocol);
|
|
61
|
+
if (typeof webSocketURL.username !== "undefined") {
|
|
62
|
+
searchParams.set("username", webSocketURL.username);
|
|
63
|
+
}
|
|
64
|
+
if (typeof webSocketURL.password !== "undefined") {
|
|
65
|
+
searchParams.set("password", webSocketURL.password);
|
|
66
|
+
}
|
|
67
|
+
let hostname;
|
|
68
|
+
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
|
|
69
|
+
// TODO show warning about this
|
|
70
|
+
const isSockJSType = webSocketServer.type === "sockjs";
|
|
71
|
+
// We are proxying dev server and need to specify custom `hostname`
|
|
72
|
+
if (typeof webSocketURL.hostname !== "undefined") {
|
|
73
|
+
hostname = webSocketURL.hostname;
|
|
74
|
+
}
|
|
75
|
+
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
|
|
76
|
+
else if (typeof webSocketServer.options.host !== "undefined" &&
|
|
77
|
+
!isSockJSType) {
|
|
78
|
+
hostname = webSocketServer.options.host;
|
|
79
|
+
}
|
|
80
|
+
// The `host` option is specified
|
|
81
|
+
else if (typeof this.options.host !== "undefined") {
|
|
82
|
+
hostname = this.options.host;
|
|
83
|
+
}
|
|
84
|
+
// The `port` option is not specified
|
|
85
|
+
else {
|
|
86
|
+
hostname = "0.0.0.0";
|
|
87
|
+
}
|
|
88
|
+
searchParams.set("hostname", hostname);
|
|
89
|
+
let port;
|
|
90
|
+
// We are proxying dev server and need to specify custom `port`
|
|
91
|
+
if (typeof webSocketURL.port !== "undefined") {
|
|
92
|
+
port = webSocketURL.port;
|
|
93
|
+
}
|
|
94
|
+
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
|
|
95
|
+
else if (typeof webSocketServer.options.port !== "undefined" &&
|
|
96
|
+
!isSockJSType) {
|
|
97
|
+
port = webSocketServer.options.port;
|
|
98
|
+
}
|
|
99
|
+
// The `port` option is specified
|
|
100
|
+
else if (typeof this.options.port === "number") {
|
|
101
|
+
port = this.options.port;
|
|
102
|
+
}
|
|
103
|
+
// The `port` option is specified using `string`
|
|
104
|
+
else if (typeof this.options.port === "string" &&
|
|
105
|
+
this.options.port !== "auto") {
|
|
106
|
+
port = Number(this.options.port);
|
|
107
|
+
}
|
|
108
|
+
// The `port` option is not specified or set to `auto`
|
|
109
|
+
else {
|
|
110
|
+
port = "0";
|
|
111
|
+
}
|
|
112
|
+
searchParams.set("port", String(port));
|
|
113
|
+
let pathname = "";
|
|
114
|
+
// We are proxying dev server and need to specify custom `pathname`
|
|
115
|
+
if (typeof webSocketURL.pathname !== "undefined") {
|
|
116
|
+
pathname = webSocketURL.pathname;
|
|
117
|
+
}
|
|
118
|
+
// Web socket server works on custom `path`
|
|
119
|
+
else if (typeof webSocketServer.options.prefix !== "undefined" ||
|
|
120
|
+
typeof webSocketServer.options.path !== "undefined") {
|
|
121
|
+
pathname =
|
|
122
|
+
webSocketServer.options.prefix || webSocketServer.options.path;
|
|
123
|
+
}
|
|
124
|
+
searchParams.set("pathname", pathname);
|
|
125
|
+
const client = /** @type {ClientConfiguration} */ this.options.client;
|
|
126
|
+
if (typeof client.logging !== "undefined") {
|
|
127
|
+
searchParams.set("logging", client.logging);
|
|
128
|
+
}
|
|
129
|
+
if (typeof client.progress !== "undefined") {
|
|
130
|
+
searchParams.set("progress", String(client.progress));
|
|
131
|
+
}
|
|
132
|
+
if (typeof client.overlay !== "undefined") {
|
|
133
|
+
searchParams.set("overlay", typeof client.overlay === "boolean"
|
|
134
|
+
? String(client.overlay)
|
|
135
|
+
: JSON.stringify(client.overlay));
|
|
136
|
+
}
|
|
137
|
+
if (typeof client.reconnect !== "undefined") {
|
|
138
|
+
searchParams.set("reconnect", typeof client.reconnect === "number"
|
|
139
|
+
? String(client.reconnect)
|
|
140
|
+
: "10");
|
|
141
|
+
}
|
|
142
|
+
if (typeof this.options.hot !== "undefined") {
|
|
143
|
+
searchParams.set("hot", String(this.options.hot));
|
|
144
|
+
}
|
|
145
|
+
if (typeof this.options.liveReload !== "undefined") {
|
|
146
|
+
searchParams.set("live-reload", String(this.options.liveReload));
|
|
147
|
+
}
|
|
148
|
+
webSocketURLStr = searchParams.toString();
|
|
149
|
+
}
|
|
150
|
+
// TODO: should use providerPlugin
|
|
151
|
+
additionalEntries.push(this.getClientTransport());
|
|
152
|
+
additionalEntries.push(`${require.resolve("@rspack/dev-client")}?${webSocketURLStr}`);
|
|
153
|
+
}
|
|
47
154
|
if (this.options.hot) {
|
|
48
155
|
const hotUpdateEntryPath = require.resolve("@rspack/dev-client/devServer");
|
|
49
|
-
|
|
50
|
-
if ((_a =
|
|
156
|
+
additionalEntries.push(hotUpdateEntryPath);
|
|
157
|
+
if ((_a = compiler.options.builtins.react) === null || _a === void 0 ? void 0 : _a.refresh) {
|
|
51
158
|
const reactRefreshEntryPath = require.resolve("@rspack/dev-client/react-refresh");
|
|
52
|
-
|
|
159
|
+
additionalEntries.push(reactRefreshEntryPath);
|
|
53
160
|
}
|
|
54
161
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
for (const key in this.compiler.options.entry) {
|
|
58
|
-
this.compiler.options.entry[key].import.unshift(...entries);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
static isAbsoluteURL(URL) {
|
|
62
|
-
return webpack_dev_server_1.default.isAbsoluteURL(URL);
|
|
63
|
-
}
|
|
64
|
-
static findIp(gateway) {
|
|
65
|
-
return webpack_dev_server_1.default.findIp(gateway);
|
|
66
|
-
}
|
|
67
|
-
static async internalIP(family) {
|
|
68
|
-
return webpack_dev_server_1.default.internalIP(family);
|
|
69
|
-
}
|
|
70
|
-
static async internalIPSync(family) {
|
|
71
|
-
return webpack_dev_server_1.default.internalIPSync(family);
|
|
72
|
-
}
|
|
73
|
-
static async getHostname(hostname) {
|
|
74
|
-
return webpack_dev_server_1.default.getHostname(hostname);
|
|
75
|
-
}
|
|
76
|
-
static async getFreePort(port, host) {
|
|
77
|
-
return webpack_dev_server_1.default.getFreePort(port, host);
|
|
78
|
-
}
|
|
79
|
-
static findCacheDir() {
|
|
80
|
-
// TODO: we need remove the `webpack-dev-server` tag in WebpackDevServer;
|
|
81
|
-
return "";
|
|
82
|
-
}
|
|
83
|
-
getCompilerOptions() {
|
|
84
|
-
return this.compiler.options;
|
|
85
|
-
}
|
|
86
|
-
sendMessage(clients, type, data, params) {
|
|
87
|
-
for (const client of clients) {
|
|
88
|
-
if (client.readyState === 1) {
|
|
89
|
-
client.send(JSON.stringify({ type, data, params }));
|
|
90
|
-
}
|
|
162
|
+
for (const key in compiler.options.entry) {
|
|
163
|
+
compiler.options.entry[key].import.unshift(...additionalEntries);
|
|
91
164
|
}
|
|
92
165
|
}
|
|
93
166
|
watchFiles(watchPath, watchOptions) {
|
|
94
|
-
const
|
|
167
|
+
const chokidar = require("chokidar");
|
|
168
|
+
const watcher = chokidar.watch(watchPath, watchOptions);
|
|
95
169
|
// disabling refreshing on changing the content
|
|
96
170
|
if (this.options.liveReload) {
|
|
97
171
|
// TODO: remove this after we had memory filesystem
|
|
@@ -106,212 +180,191 @@ class RspackDevServer {
|
|
|
106
180
|
}
|
|
107
181
|
this.staticWatchers.push(watcher);
|
|
108
182
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
183
|
+
getClientTransport() {
|
|
184
|
+
// WARNING: we can't use `super.getClientTransport`,
|
|
185
|
+
// because we doesn't had same directory structure.
|
|
186
|
+
// and TODO: we need impelement `webpack.providerPlugin`
|
|
187
|
+
let clientImplementation;
|
|
188
|
+
let clientImplementationFound = true;
|
|
189
|
+
const isKnownWebSocketServerImplementation = this.options.webSocketServer &&
|
|
190
|
+
typeof this.options.webSocketServer.type === "string" &&
|
|
191
|
+
(this.options.webSocketServer.type === "ws" ||
|
|
192
|
+
this.options.webSocketServer.type === "sockjs");
|
|
193
|
+
let clientTransport;
|
|
194
|
+
if (this.options.client) {
|
|
195
|
+
if (
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
typeof this.options.client.webSocketTransport !== "undefined") {
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
clientTransport = this.options.client.webSocketTransport;
|
|
200
|
+
}
|
|
201
|
+
else if (isKnownWebSocketServerImplementation) {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
clientTransport = this.options.webSocketServer.type;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
clientTransport = "ws";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
clientTransport = "ws";
|
|
211
|
+
}
|
|
212
|
+
switch (typeof clientTransport) {
|
|
213
|
+
case "string":
|
|
214
|
+
// could be 'sockjs', 'ws', or a path that should be required
|
|
215
|
+
if (clientTransport === "sockjs") {
|
|
216
|
+
clientImplementation = require.resolve("@rspack/dev-client/clients/SockJSClient");
|
|
217
|
+
}
|
|
218
|
+
else if (clientTransport === "ws") {
|
|
219
|
+
clientImplementation = require.resolve("@rspack/dev-client/clients/WebSocketClient");
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
try {
|
|
223
|
+
clientImplementation = require.resolve(clientTransport);
|
|
224
|
+
throw Error("Do not support custom ws client now");
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
clientImplementationFound = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
default:
|
|
232
|
+
clientImplementationFound = false;
|
|
233
|
+
}
|
|
234
|
+
if (!clientImplementationFound) {
|
|
235
|
+
throw new Error(`${!isKnownWebSocketServerImplementation
|
|
236
|
+
? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
|
|
237
|
+
: ""}client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class `);
|
|
112
238
|
}
|
|
239
|
+
return clientImplementation;
|
|
113
240
|
}
|
|
114
|
-
async
|
|
241
|
+
async initialize() {
|
|
242
|
+
const compilers = this.compiler instanceof core_1.MultiCompiler
|
|
243
|
+
? this.compiler.compilers
|
|
244
|
+
: [this.compiler];
|
|
245
|
+
compilers.forEach(compiler => {
|
|
246
|
+
var _a, _b, _c;
|
|
247
|
+
var _d, _e, _f;
|
|
248
|
+
(_a = (_d = compiler.options.builtins).react) !== null && _a !== void 0 ? _a : (_d.react = {});
|
|
249
|
+
if (this.options.hot) {
|
|
250
|
+
(_b = (_e = compiler.options.builtins.react).refresh) !== null && _b !== void 0 ? _b : (_e.refresh = true);
|
|
251
|
+
(_c = (_f = compiler.options.builtins.react).development) !== null && _c !== void 0 ? _c : (_f.development = true);
|
|
252
|
+
}
|
|
253
|
+
else if (compiler.options.builtins.react.refresh) {
|
|
254
|
+
this.logger.warn("builtins.react.refresh needs builtins.react.development and devServer.hot enabled");
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
if (this.options.webSocketServer) {
|
|
258
|
+
compilers.forEach(compiler => {
|
|
259
|
+
this.addAdditionEntires(compiler);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
115
262
|
this.setupHooks();
|
|
263
|
+
// @ts-expect-error: `setupApp` is private function in base class.
|
|
116
264
|
this.setupApp();
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
this.createWebsocketServer();
|
|
265
|
+
// @ts-expect-error: `setupHostHeaderCheck` is private function in base class.
|
|
266
|
+
this.setupHostHeaderCheck();
|
|
120
267
|
this.setupDevMiddleware();
|
|
268
|
+
// @ts-expect-error: `setupBuiltInRoutes` is private function in base class.
|
|
269
|
+
this.setupBuiltInRoutes();
|
|
270
|
+
// @ts-expect-error: `setupWatchFiles` is private function in base class.
|
|
271
|
+
this.setupWatchFiles();
|
|
272
|
+
// @ts-expect-error: `setupWatchStaticFiles` is private function in base class.
|
|
273
|
+
this.setupWatchStaticFiles();
|
|
121
274
|
this.setupMiddlewares();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.middleware = null;
|
|
149
|
-
this.staticWatchers = [];
|
|
150
|
-
if (this.server) {
|
|
151
|
-
this.server.close();
|
|
152
|
-
}
|
|
153
|
-
if (this.webSocketServer) {
|
|
154
|
-
await new Promise(resolve => {
|
|
155
|
-
this.webSocketServer.implementation.close(() => {
|
|
156
|
-
resolve(void 0);
|
|
157
|
-
});
|
|
158
|
-
for (const client of this.webSocketServer.clients)
|
|
159
|
-
client.terminate();
|
|
275
|
+
// @ts-expect-error: `createServer` is private function in base class.
|
|
276
|
+
this.createServer();
|
|
277
|
+
if (this.options.setupExitSignals) {
|
|
278
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
279
|
+
let needForceShutdown = false;
|
|
280
|
+
signals.forEach(signal => {
|
|
281
|
+
const listener = () => {
|
|
282
|
+
if (needForceShutdown) {
|
|
283
|
+
process.exit();
|
|
284
|
+
}
|
|
285
|
+
this.logger.info("Gracefully shutting down. To force exit, press ^C again. Please wait...");
|
|
286
|
+
needForceShutdown = true;
|
|
287
|
+
this.stopCallback(() => {
|
|
288
|
+
if (typeof this.compiler.close === "function") {
|
|
289
|
+
this.compiler.close(() => {
|
|
290
|
+
process.exit();
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
process.exit();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
// @ts-expect-error: `listeners` is private function in base class.
|
|
299
|
+
this.listeners.push({ name: signal, listener });
|
|
300
|
+
process.on(signal, listener);
|
|
160
301
|
});
|
|
161
302
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
this.watchFiles(this.options.static.directory, this.options.static.watch);
|
|
303
|
+
// Proxy WebSocket without the initial http request
|
|
304
|
+
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
|
|
305
|
+
// @ts-expect-error: `webSocketProxies` is private function in base class.
|
|
306
|
+
this.webSocketProxies.forEach(webSocketProxy => {
|
|
307
|
+
this.server.on("upgrade", webSocketProxy.upgrade);
|
|
308
|
+
}, this);
|
|
171
309
|
}
|
|
172
310
|
setupDevMiddleware() {
|
|
173
311
|
// @ts-ignored
|
|
174
312
|
this.middleware = (0, dev_middleware_1.default)(this.compiler, this.options.devMiddleware);
|
|
175
313
|
}
|
|
176
|
-
createWebsocketServer() {
|
|
177
|
-
if (this.options.webSocketServer !== false) {
|
|
178
|
-
this.webSocketServer = (0, ws_1.createWebsocketServer)(this);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
314
|
setupMiddlewares() {
|
|
182
|
-
const options = this.options;
|
|
183
315
|
const middlewares = [];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
res.write("");
|
|
199
|
-
res.end();
|
|
200
|
-
console.log("lazy compiler success");
|
|
316
|
+
const compilers = this.compiler instanceof core_1.MultiCompiler
|
|
317
|
+
? this.compiler.compilers
|
|
318
|
+
: [this.compiler];
|
|
319
|
+
if (Array.isArray(this.options.static)) {
|
|
320
|
+
this.options.static.forEach(staticOptions => {
|
|
321
|
+
staticOptions.publicPath.forEach(publicPath => {
|
|
322
|
+
compilers.forEach(compiler => {
|
|
323
|
+
if (compiler.options.builtins.noEmitAssets) {
|
|
324
|
+
middlewares.push({
|
|
325
|
+
name: "rspack-memory-assets",
|
|
326
|
+
path: publicPath,
|
|
327
|
+
middleware: (0, dev_middleware_1.getRspackMemoryAssets)(compiler, this.middleware)
|
|
201
328
|
});
|
|
202
329
|
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
205
332
|
});
|
|
206
333
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
224
|
-
function getProxyMiddleware(proxyConfig) {
|
|
225
|
-
if (proxyConfig.target) {
|
|
226
|
-
const context = proxyConfig.context || proxyConfig.path;
|
|
227
|
-
return createProxyMiddleware(context, proxyConfig);
|
|
228
|
-
}
|
|
229
|
-
if (proxyConfig.router) {
|
|
230
|
-
return createProxyMiddleware(proxyConfig);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (!Array.isArray(options.proxy)) {
|
|
234
|
-
if (Object.prototype.hasOwnProperty.call(options.proxy, "target") ||
|
|
235
|
-
Object.prototype.hasOwnProperty.call(options.proxy, "router")) {
|
|
236
|
-
options.proxy = [options.proxy];
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
options.proxy = Object.keys(options.proxy).map(context => {
|
|
240
|
-
let proxyOptions;
|
|
241
|
-
// For backwards compatibility reasons.
|
|
242
|
-
const correctedContext = context
|
|
243
|
-
.replace(/^\*$/, "**")
|
|
244
|
-
.replace(/\/\*$/, "");
|
|
245
|
-
if (typeof ( /** @type {ProxyConfigMap} */options.proxy[context]) ===
|
|
246
|
-
"string") {
|
|
247
|
-
proxyOptions = {
|
|
248
|
-
context: correctedContext,
|
|
249
|
-
target:
|
|
250
|
-
/** @type {ProxyConfigMap} */
|
|
251
|
-
options.proxy[context]
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
proxyOptions = {
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
... /** @type {ProxyConfigMap} */options.proxy[context]
|
|
258
|
-
};
|
|
259
|
-
proxyOptions.context = correctedContext;
|
|
334
|
+
compilers.forEach(compiler => {
|
|
335
|
+
if (compiler.options.experiments.lazyCompilation) {
|
|
336
|
+
middlewares.push({
|
|
337
|
+
middleware: (req, res, next) => {
|
|
338
|
+
if (req.url.indexOf("/lazy-compilation-web/") > -1) {
|
|
339
|
+
const path = req.url.replace("/lazy-compilation-web/", "");
|
|
340
|
+
if (fs_1.default.existsSync(path)) {
|
|
341
|
+
compiler.rebuild(new Set([path]), new Set(), error => {
|
|
342
|
+
if (error) {
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
res.write("");
|
|
346
|
+
res.end();
|
|
347
|
+
console.log("lazy compiler success");
|
|
348
|
+
});
|
|
349
|
+
}
|
|
260
350
|
}
|
|
261
|
-
return proxyOptions;
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
options.proxy.forEach(proxyConfig => {
|
|
266
|
-
const handler = async (req, res, next) => {
|
|
267
|
-
let proxyMiddleware = getProxyMiddleware(proxyConfig);
|
|
268
|
-
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
|
|
269
|
-
const bypassUrl = isByPassFuncDefined
|
|
270
|
-
? await proxyConfig.bypass(req, res, proxyConfig)
|
|
271
|
-
: null;
|
|
272
|
-
if (typeof bypassUrl === "boolean") {
|
|
273
|
-
req.url = null;
|
|
274
|
-
next();
|
|
275
|
-
}
|
|
276
|
-
else if (typeof bypassUrl === "string") {
|
|
277
|
-
req.url = bypassUrl;
|
|
278
|
-
}
|
|
279
|
-
else if (proxyMiddleware) {
|
|
280
|
-
return proxyMiddleware(req, res, next);
|
|
281
351
|
}
|
|
282
|
-
else {
|
|
283
|
-
next();
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
middlewares.push({
|
|
287
|
-
name: "http-proxy-middleware",
|
|
288
|
-
middleware: handler
|
|
289
352
|
});
|
|
290
|
-
|
|
291
|
-
name: "http-proxy-middleware-error-handler",
|
|
292
|
-
middleware: (error, req, res, next) => handler(req, res, next)
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
const publicPath = this.compiler.options.output.publicPath === "auto"
|
|
297
|
-
? ""
|
|
298
|
-
: this.compiler.options.output.publicPath;
|
|
299
|
-
middlewares.push({
|
|
300
|
-
name: "express-static",
|
|
301
|
-
path: publicPath,
|
|
302
|
-
middleware: express_1.default.static(this.options.static.directory)
|
|
353
|
+
}
|
|
303
354
|
});
|
|
304
|
-
middlewares.forEach(
|
|
305
|
-
if (
|
|
306
|
-
this.app.use(
|
|
355
|
+
middlewares.forEach(middleware => {
|
|
356
|
+
if (typeof middleware === "function") {
|
|
357
|
+
this.app.use(middleware);
|
|
358
|
+
}
|
|
359
|
+
else if (typeof middleware.path !== "undefined") {
|
|
360
|
+
this.app.use(middleware.path, middleware.middleware);
|
|
307
361
|
}
|
|
308
362
|
else {
|
|
309
|
-
this.app.use(
|
|
363
|
+
this.app.use(middleware.middleware);
|
|
310
364
|
}
|
|
311
365
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
this.server = http_1.default.createServer(this.app);
|
|
366
|
+
// @ts-expect-error
|
|
367
|
+
super.setupMiddlewares();
|
|
315
368
|
}
|
|
316
369
|
setupHooks() {
|
|
317
370
|
this.compiler.hooks.done.tap("dev-server", stats => {
|