@rspack/dev-server 0.0.0-0074001a71-20230224065505

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +234 -0
  2. package/LICENSE +22 -0
  3. package/README.md +16 -0
  4. package/dist/config.d.ts +25 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/config.js +3 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +6 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/reload.d.ts +9 -0
  13. package/dist/reload.d.ts.map +1 -0
  14. package/dist/reload.js +23 -0
  15. package/dist/reload.js.map +1 -0
  16. package/dist/server.d.ts +28 -0
  17. package/dist/server.d.ts.map +1 -0
  18. package/dist/server.js +401 -0
  19. package/dist/server.js.map +1 -0
  20. package/jest.config.js +10 -0
  21. package/package.json +40 -0
  22. package/src/config.ts +27 -0
  23. package/src/index.ts +1 -0
  24. package/src/reload.ts +31 -0
  25. package/src/server.ts +474 -0
  26. package/tests/__snapshots__/normalizeOptions.test.ts.snap +232 -0
  27. package/tests/e2e/hot-reaload.test.ts +115 -0
  28. package/tests/e2e-fixtures/react/app.jsx +14 -0
  29. package/tests/e2e-fixtures/react/index.css +3 -0
  30. package/tests/e2e-fixtures/react/index.html +12 -0
  31. package/tests/e2e-fixtures/react/index.jsx +6 -0
  32. package/tests/e2e-fixtures/react/node_modules/react/LICENSE +21 -0
  33. package/tests/e2e-fixtures/react/node_modules/react/README.md +37 -0
  34. package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-dev-runtime.development.js +1296 -0
  35. package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-dev-runtime.production.min.js +10 -0
  36. package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-dev-runtime.profiling.min.js +10 -0
  37. package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-runtime.development.js +1314 -0
  38. package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-runtime.production.min.js +11 -0
  39. package/tests/e2e-fixtures/react/node_modules/react/cjs/react-jsx-runtime.profiling.min.js +11 -0
  40. package/tests/e2e-fixtures/react/node_modules/react/cjs/react.development.js +2739 -0
  41. package/tests/e2e-fixtures/react/node_modules/react/cjs/react.production.min.js +26 -0
  42. package/tests/e2e-fixtures/react/node_modules/react/cjs/react.shared-subset.development.js +20 -0
  43. package/tests/e2e-fixtures/react/node_modules/react/cjs/react.shared-subset.production.min.js +10 -0
  44. package/tests/e2e-fixtures/react/node_modules/react/index.js +7 -0
  45. package/tests/e2e-fixtures/react/node_modules/react/jsx-dev-runtime.js +7 -0
  46. package/tests/e2e-fixtures/react/node_modules/react/jsx-runtime.js +7 -0
  47. package/tests/e2e-fixtures/react/node_modules/react/package.json +47 -0
  48. package/tests/e2e-fixtures/react/node_modules/react/react.shared-subset.js +7 -0
  49. package/tests/e2e-fixtures/react/node_modules/react/umd/react.development.js +3342 -0
  50. package/tests/e2e-fixtures/react/node_modules/react/umd/react.production.min.js +31 -0
  51. package/tests/e2e-fixtures/react/node_modules/react/umd/react.profiling.min.js +31 -0
  52. package/tests/e2e-fixtures/react/node_modules/react-dom/LICENSE +21 -0
  53. package/tests/e2e-fixtures/react/node_modules/react-dom/README.md +60 -0
  54. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.browser.development.js +7018 -0
  55. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +93 -0
  56. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js +7078 -0
  57. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server-legacy.node.production.min.js +101 -0
  58. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.browser.development.js +7003 -0
  59. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js +96 -0
  60. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.node.development.js +7059 -0
  61. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-server.node.production.min.js +102 -0
  62. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-test-utils.development.js +1741 -0
  63. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom-test-utils.production.min.js +40 -0
  64. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom.development.js +29868 -0
  65. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom.production.min.js +323 -0
  66. package/tests/e2e-fixtures/react/node_modules/react-dom/cjs/react-dom.profiling.min.js +367 -0
  67. package/tests/e2e-fixtures/react/node_modules/react-dom/client.js +25 -0
  68. package/tests/e2e-fixtures/react/node_modules/react-dom/index.js +38 -0
  69. package/tests/e2e-fixtures/react/node_modules/react-dom/package.json +62 -0
  70. package/tests/e2e-fixtures/react/node_modules/react-dom/profiling.js +38 -0
  71. package/tests/e2e-fixtures/react/node_modules/react-dom/server.browser.js +17 -0
  72. package/tests/e2e-fixtures/react/node_modules/react-dom/server.js +3 -0
  73. package/tests/e2e-fixtures/react/node_modules/react-dom/server.node.js +17 -0
  74. package/tests/e2e-fixtures/react/node_modules/react-dom/test-utils.js +7 -0
  75. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server-legacy.browser.development.js +7015 -0
  76. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server-legacy.browser.production.min.js +75 -0
  77. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server.browser.development.js +7000 -0
  78. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-server.browser.production.min.js +76 -0
  79. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-test-utils.development.js +1737 -0
  80. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom-test-utils.production.min.js +33 -0
  81. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom.development.js +29869 -0
  82. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom.production.min.js +267 -0
  83. package/tests/e2e-fixtures/react/node_modules/react-dom/umd/react-dom.profiling.min.js +285 -0
  84. package/tests/e2e-fixtures/react/node_modules/scheduler/LICENSE +21 -0
  85. package/tests/e2e-fixtures/react/node_modules/scheduler/README.md +9 -0
  86. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +700 -0
  87. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_mock.production.min.js +20 -0
  88. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_post_task.development.js +207 -0
  89. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_post_task.production.min.js +14 -0
  90. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler.development.js +634 -0
  91. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler.production.min.js +19 -0
  92. package/tests/e2e-fixtures/react/node_modules/scheduler/index.js +7 -0
  93. package/tests/e2e-fixtures/react/node_modules/scheduler/package.json +36 -0
  94. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler-unstable_mock.development.js +699 -0
  95. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js +19 -0
  96. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.development.js +152 -0
  97. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.production.min.js +146 -0
  98. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.profiling.min.js +146 -0
  99. package/tests/e2e-fixtures/react/node_modules/scheduler/unstable_mock.js +7 -0
  100. package/tests/e2e-fixtures/react/node_modules/scheduler/unstable_post_task.js +7 -0
  101. package/tests/e2e-fixtures/react/package.json +8 -0
  102. package/tests/e2e-fixtures/react/webpack.config.js +26 -0
  103. package/tests/helpers/emitFile.ts +69 -0
  104. package/tests/helpers/runBrowser.ts +85 -0
  105. package/tests/helpers/tempDir.ts +58 -0
  106. package/tests/normalizeOptions.test.ts +107 -0
  107. package/tsconfig.json +15 -0
  108. package/tsconfig.tsbuildinfo +1 -0
package/dist/server.js ADDED
@@ -0,0 +1,401 @@
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
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.RspackDevServer = void 0;
30
+ const core_1 = require("@rspack/core");
31
+ const dev_middleware_1 = __importStar(require("@rspack/dev-middleware"));
32
+ const fs_1 = __importDefault(require("fs"));
33
+ const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
34
+ class RspackDevServer extends webpack_dev_server_1.default {
35
+ constructor(options, compiler) {
36
+ // @ts-expect-error
37
+ super(options, compiler);
38
+ }
39
+ addAdditionEntires(compiler) {
40
+ var _a;
41
+ const additionalEntries = [];
42
+ const isWebTarget = isWebTarget2(compiler);
43
+ if (this.options.client && isWebTarget) {
44
+ let webSocketURLStr = "";
45
+ if (this.options.webSocketServer) {
46
+ const webSocketURL = this.options.client
47
+ .webSocketURL;
48
+ const webSocketServer = this.options.webSocketServer;
49
+ const searchParams = new URLSearchParams();
50
+ let protocol;
51
+ // We are proxying dev server and need to specify custom `hostname`
52
+ if (typeof webSocketURL.protocol !== "undefined") {
53
+ protocol = webSocketURL.protocol;
54
+ }
55
+ else {
56
+ protocol = this.options.server.type === "http" ? "ws:" : "wss:";
57
+ }
58
+ searchParams.set("protocol", protocol);
59
+ if (typeof webSocketURL.username !== "undefined") {
60
+ searchParams.set("username", webSocketURL.username);
61
+ }
62
+ if (typeof webSocketURL.password !== "undefined") {
63
+ searchParams.set("password", webSocketURL.password);
64
+ }
65
+ let hostname;
66
+ // SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
67
+ // TODO show warning about this
68
+ const isSockJSType = webSocketServer.type === "sockjs";
69
+ // We are proxying dev server and need to specify custom `hostname`
70
+ if (typeof webSocketURL.hostname !== "undefined") {
71
+ hostname = webSocketURL.hostname;
72
+ }
73
+ // Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
74
+ else if (typeof webSocketServer.options.host !== "undefined" &&
75
+ !isSockJSType) {
76
+ hostname = webSocketServer.options.host;
77
+ }
78
+ // The `host` option is specified
79
+ else if (typeof this.options.host !== "undefined") {
80
+ hostname = this.options.host;
81
+ }
82
+ // The `port` option is not specified
83
+ else {
84
+ hostname = "0.0.0.0";
85
+ }
86
+ searchParams.set("hostname", hostname);
87
+ let port;
88
+ // We are proxying dev server and need to specify custom `port`
89
+ if (typeof webSocketURL.port !== "undefined") {
90
+ port = webSocketURL.port;
91
+ }
92
+ // Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
93
+ else if (typeof webSocketServer.options.port !== "undefined" &&
94
+ !isSockJSType) {
95
+ port = webSocketServer.options.port;
96
+ }
97
+ // The `port` option is specified
98
+ else if (typeof this.options.port === "number") {
99
+ port = this.options.port;
100
+ }
101
+ // The `port` option is specified using `string`
102
+ else if (typeof this.options.port === "string" &&
103
+ this.options.port !== "auto") {
104
+ port = Number(this.options.port);
105
+ }
106
+ // The `port` option is not specified or set to `auto`
107
+ else {
108
+ port = "0";
109
+ }
110
+ searchParams.set("port", String(port));
111
+ let pathname = "";
112
+ // We are proxying dev server and need to specify custom `pathname`
113
+ if (typeof webSocketURL.pathname !== "undefined") {
114
+ pathname = webSocketURL.pathname;
115
+ }
116
+ // Web socket server works on custom `path`
117
+ else if (typeof webSocketServer.options.prefix !== "undefined" ||
118
+ typeof webSocketServer.options.path !== "undefined") {
119
+ pathname =
120
+ webSocketServer.options.prefix || webSocketServer.options.path;
121
+ }
122
+ searchParams.set("pathname", pathname);
123
+ const client = /** @type {ClientConfiguration} */ this.options.client;
124
+ if (typeof client.logging !== "undefined") {
125
+ searchParams.set("logging", client.logging);
126
+ }
127
+ if (typeof client.progress !== "undefined") {
128
+ searchParams.set("progress", String(client.progress));
129
+ }
130
+ if (typeof client.overlay !== "undefined") {
131
+ searchParams.set("overlay", typeof client.overlay === "boolean"
132
+ ? String(client.overlay)
133
+ : JSON.stringify(client.overlay));
134
+ }
135
+ if (typeof client.reconnect !== "undefined") {
136
+ searchParams.set("reconnect", typeof client.reconnect === "number"
137
+ ? String(client.reconnect)
138
+ : "10");
139
+ }
140
+ if (typeof this.options.hot !== "undefined") {
141
+ searchParams.set("hot", String(this.options.hot));
142
+ }
143
+ if (typeof this.options.liveReload !== "undefined") {
144
+ searchParams.set("live-reload", String(this.options.liveReload));
145
+ }
146
+ webSocketURLStr = searchParams.toString();
147
+ }
148
+ // TODO: should use providerPlugin
149
+ additionalEntries.push(this.getClientTransport());
150
+ additionalEntries.push(`${require.resolve("@rspack/dev-client")}?${webSocketURLStr}`);
151
+ }
152
+ if (this.options.hot) {
153
+ const hotUpdateEntryPath = require.resolve("@rspack/dev-client/devServer");
154
+ additionalEntries.push(hotUpdateEntryPath);
155
+ if ((_a = compiler.options.builtins.react) === null || _a === void 0 ? void 0 : _a.refresh) {
156
+ const reactRefreshEntryPath = require.resolve("@rspack/dev-client/react-refresh");
157
+ additionalEntries.push(reactRefreshEntryPath);
158
+ }
159
+ }
160
+ for (const key in compiler.options.entry) {
161
+ compiler.options.entry[key].import.unshift(...additionalEntries);
162
+ }
163
+ }
164
+ watchFiles(watchPath, watchOptions) {
165
+ const chokidar = require("chokidar");
166
+ const watcher = chokidar.watch(watchPath, watchOptions);
167
+ // disabling refreshing on changing the content
168
+ if (this.options.liveReload) {
169
+ // TODO: remove this after we had memory filesystem
170
+ if (this.options.hot) {
171
+ return;
172
+ }
173
+ watcher.on("change", item => {
174
+ if (this.webSocketServer) {
175
+ this.sendMessage(this.webSocketServer.clients, "static-changed", item);
176
+ }
177
+ });
178
+ }
179
+ this.staticWatchers.push(watcher);
180
+ }
181
+ getClientTransport() {
182
+ // WARNING: we can't use `super.getClientTransport`,
183
+ // because we doesn't had same directory structure.
184
+ // and TODO: we need impelement `webpack.providerPlugin`
185
+ let clientImplementation;
186
+ let clientImplementationFound = true;
187
+ const isKnownWebSocketServerImplementation = this.options.webSocketServer &&
188
+ typeof this.options.webSocketServer.type === "string" &&
189
+ (this.options.webSocketServer.type === "ws" ||
190
+ this.options.webSocketServer.type === "sockjs");
191
+ let clientTransport;
192
+ if (this.options.client) {
193
+ if (
194
+ // @ts-ignore
195
+ typeof this.options.client.webSocketTransport !== "undefined") {
196
+ // @ts-ignore
197
+ clientTransport = this.options.client.webSocketTransport;
198
+ }
199
+ else if (isKnownWebSocketServerImplementation) {
200
+ // @ts-ignore
201
+ clientTransport = this.options.webSocketServer.type;
202
+ }
203
+ else {
204
+ clientTransport = "ws";
205
+ }
206
+ }
207
+ else {
208
+ clientTransport = "ws";
209
+ }
210
+ switch (typeof clientTransport) {
211
+ case "string":
212
+ // could be 'sockjs', 'ws', or a path that should be required
213
+ if (clientTransport === "sockjs") {
214
+ clientImplementation = require.resolve("@rspack/dev-client/clients/SockJSClient");
215
+ }
216
+ else if (clientTransport === "ws") {
217
+ clientImplementation = require.resolve("@rspack/dev-client/clients/WebSocketClient");
218
+ }
219
+ else {
220
+ try {
221
+ clientImplementation = require.resolve(clientTransport);
222
+ throw Error("Do not support custom ws client now");
223
+ }
224
+ catch (e) {
225
+ clientImplementationFound = false;
226
+ }
227
+ }
228
+ break;
229
+ default:
230
+ clientImplementationFound = false;
231
+ }
232
+ if (!clientImplementationFound) {
233
+ throw new Error(`${!isKnownWebSocketServerImplementation
234
+ ? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
235
+ : ""}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 `);
236
+ }
237
+ return clientImplementation;
238
+ }
239
+ async initialize() {
240
+ const compilers = this.compiler instanceof core_1.MultiCompiler
241
+ ? this.compiler.compilers
242
+ : [this.compiler];
243
+ compilers.forEach(compiler => {
244
+ var _a, _b, _c;
245
+ var _d, _e, _f;
246
+ (_a = (_d = compiler.options.builtins).react) !== null && _a !== void 0 ? _a : (_d.react = {});
247
+ if (this.options.hot) {
248
+ (_b = (_e = compiler.options.builtins.react).refresh) !== null && _b !== void 0 ? _b : (_e.refresh = true);
249
+ (_c = (_f = compiler.options.builtins.react).development) !== null && _c !== void 0 ? _c : (_f.development = true);
250
+ }
251
+ else if (compiler.options.builtins.react.refresh) {
252
+ this.logger.warn("builtins.react.refresh needs builtins.react.development and devServer.hot enabled");
253
+ }
254
+ });
255
+ if (this.options.webSocketServer) {
256
+ compilers.forEach(compiler => {
257
+ this.addAdditionEntires(compiler);
258
+ });
259
+ }
260
+ this.setupHooks();
261
+ // @ts-expect-error: `setupApp` is private function in base class.
262
+ this.setupApp();
263
+ // @ts-expect-error: `setupHostHeaderCheck` is private function in base class.
264
+ this.setupHostHeaderCheck();
265
+ this.setupDevMiddleware();
266
+ // @ts-expect-error: `setupBuiltInRoutes` is private function in base class.
267
+ this.setupBuiltInRoutes();
268
+ // @ts-expect-error: `setupWatchFiles` is private function in base class.
269
+ this.setupWatchFiles();
270
+ // @ts-expect-error: `setupWatchStaticFiles` is private function in base class.
271
+ this.setupWatchStaticFiles();
272
+ this.setupMiddlewares();
273
+ // @ts-expect-error: `createServer` is private function in base class.
274
+ this.createServer();
275
+ if (this.options.setupExitSignals) {
276
+ const signals = ["SIGINT", "SIGTERM"];
277
+ let needForceShutdown = false;
278
+ signals.forEach(signal => {
279
+ const listener = () => {
280
+ if (needForceShutdown) {
281
+ process.exit();
282
+ }
283
+ this.logger.info("Gracefully shutting down. To force exit, press ^C again. Please wait...");
284
+ needForceShutdown = true;
285
+ this.stopCallback(() => {
286
+ if (typeof this.compiler.close === "function") {
287
+ this.compiler.close(() => {
288
+ process.exit();
289
+ });
290
+ }
291
+ else {
292
+ process.exit();
293
+ }
294
+ });
295
+ };
296
+ // @ts-expect-error: `listeners` is private function in base class.
297
+ this.listeners.push({ name: signal, listener });
298
+ process.on(signal, listener);
299
+ });
300
+ }
301
+ // Proxy WebSocket without the initial http request
302
+ // https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
303
+ // @ts-expect-error: `webSocketProxies` is private function in base class.
304
+ this.webSocketProxies.forEach(webSocketProxy => {
305
+ this.server.on("upgrade", webSocketProxy.upgrade);
306
+ }, this);
307
+ }
308
+ setupDevMiddleware() {
309
+ // @ts-ignored
310
+ this.middleware = (0, dev_middleware_1.default)(this.compiler, this.options.devMiddleware);
311
+ }
312
+ setupMiddlewares() {
313
+ const middlewares = [];
314
+ const compilers = this.compiler instanceof core_1.MultiCompiler
315
+ ? this.compiler.compilers
316
+ : [this.compiler];
317
+ if (Array.isArray(this.options.static)) {
318
+ this.options.static.forEach(staticOptions => {
319
+ staticOptions.publicPath.forEach(publicPath => {
320
+ compilers.forEach(compiler => {
321
+ if (compiler.options.builtins.noEmitAssets) {
322
+ middlewares.push({
323
+ name: "rspack-memory-assets",
324
+ path: publicPath,
325
+ middleware: (0, dev_middleware_1.getRspackMemoryAssets)(compiler, this.middleware)
326
+ });
327
+ }
328
+ });
329
+ });
330
+ });
331
+ }
332
+ compilers.forEach(compiler => {
333
+ if (compiler.options.experiments.lazyCompilation) {
334
+ middlewares.push({
335
+ middleware: (req, res, next) => {
336
+ if (req.url.indexOf("/lazy-compilation-web/") > -1) {
337
+ const path = req.url.replace("/lazy-compilation-web/", "");
338
+ if (fs_1.default.existsSync(path)) {
339
+ compiler.rebuild(new Set([path]), new Set(), error => {
340
+ if (error) {
341
+ throw error;
342
+ }
343
+ res.write("");
344
+ res.end();
345
+ console.log("lazy compiler success");
346
+ });
347
+ }
348
+ }
349
+ }
350
+ });
351
+ }
352
+ });
353
+ middlewares.forEach(middleware => {
354
+ if (typeof middleware === "function") {
355
+ this.app.use(middleware);
356
+ }
357
+ else if (typeof middleware.path !== "undefined") {
358
+ this.app.use(middleware.path, middleware.middleware);
359
+ }
360
+ else {
361
+ this.app.use(middleware.middleware);
362
+ }
363
+ });
364
+ // @ts-expect-error
365
+ super.setupMiddlewares();
366
+ }
367
+ setupHooks() {
368
+ this.compiler.hooks.done.tap("dev-server", stats => {
369
+ // send Message
370
+ if (this.webSocketServer) {
371
+ this.sendMessage(this.webSocketServer.clients, "ok"); // TODO: send hash
372
+ }
373
+ });
374
+ }
375
+ }
376
+ exports.RspackDevServer = RspackDevServer;
377
+ // TODO: use WebpackDevServer.isWebTarget instead of this once we have a new webpack-dev-server version
378
+ function isWebTarget2(compiler) {
379
+ if (compiler.options.resolve.conditionNames &&
380
+ compiler.options.resolve.conditionNames.includes("browser")) {
381
+ return true;
382
+ }
383
+ const target = compiler.options.target;
384
+ const webTargets = [
385
+ "web",
386
+ "webworker",
387
+ "electron-preload",
388
+ "electron-renderer",
389
+ "node-webkit",
390
+ undefined,
391
+ null
392
+ ];
393
+ if (Array.isArray(target)) {
394
+ return target.some(r => webTargets.includes(r));
395
+ }
396
+ if (typeof target === "string") {
397
+ return webTargets.includes(target);
398
+ }
399
+ return false;
400
+ }
401
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuD;AAGvD,yEAAoE;AAEpE,4CAAoB;AACpB,4EAAkD;AAGlD,MAAa,eAAgB,SAAQ,4BAAgB;IAYpD,YAAY,OAAkB,EAAE,QAAkC;QACjE,mBAAmB;QACnB,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAED,kBAAkB,CAAC,QAAkB;;QACpC,MAAM,iBAAiB,GAAa,EAAE,CAAC;QACvC,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,WAAW,EAAE;YACvC,IAAI,eAAe,GAAG,EAAE,CAAC;YAEzB,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE;gBACjC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;qBACtC,YAA6C,CAAC;gBAChD,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;gBACrD,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;gBAE3C,IAAI,QAAgB,CAAC;gBAErB,mEAAmE;gBACnE,IAAI,OAAO,YAAY,CAAC,QAAQ,KAAK,WAAW,EAAE;oBACjD,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;iBACjC;qBAAM;oBACN,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;iBAChE;gBAED,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBAEvC,IAAI,OAAO,YAAY,C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,CAAC,CAAC;KACnC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
package/jest.config.js ADDED
@@ -0,0 +1,10 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: "ts-jest",
4
+ testEnvironmentOptions: {
5
+ url: "http://localhost/"
6
+ },
7
+ testMatch: ["<rootDir>/tests/*.test.ts", "<rootDir>/tests/e2e/*.test.ts"],
8
+ cache: false,
9
+ testTimeout: process.env.CI ? 60000 : 30000
10
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@rspack/dev-server",
3
+ "version": "0.0.0-0074001a71-20230224065505",
4
+ "license": "MIT",
5
+ "description": "Development server for rspack",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "homepage": "https://rspack.org",
9
+ "bugs": "https://github.com/modern-js-dev/rspack/issues",
10
+ "repository": "modern-js-dev/rspack",
11
+ "devDependencies": {
12
+ "typescript": "^4.7.4",
13
+ "@types/ws": "8.5.3",
14
+ "@types/node": "16.11.7",
15
+ "@types/express": "4.17.14",
16
+ "@types/connect-history-api-fallback": "1.3.5",
17
+ "fs-extra": "11.1.0",
18
+ "puppeteer": "19.4.0",
19
+ "@rspack/core": "0.0.0-0074001a71-20230224065505"
20
+ },
21
+ "dependencies": {
22
+ "express": "4.18.1",
23
+ "chokidar": "3.5.3",
24
+ "ws": "8.8.1",
25
+ "webpack-dev-server": "4.11.1",
26
+ "connect-history-api-fallback": "2.0.0",
27
+ "http-proxy-middleware": "2.0.6",
28
+ "@rspack/dev-client": "0.0.0-0074001a71-20230224065505",
29
+ "@rspack/dev-server": "0.0.0-0074001a71-20230224065505",
30
+ "@rspack/dev-middleware": "0.0.0-0074001a71-20230224065505"
31
+ },
32
+ "peerDependencies": {
33
+ "@rspack/core": "0.0.0-0074001a71-20230224065505"
34
+ },
35
+ "scripts": {
36
+ "build": "rm -rf dist/ && tsc",
37
+ "dev": "tsc -w",
38
+ "test": "rm -rf .test-temp && jest --verbose"
39
+ }
40
+ }
package/src/config.ts ADDED
@@ -0,0 +1,27 @@
1
+ import WebpackDevServer from "webpack-dev-server";
2
+ import type { DevServer } from "@rspack/core";
3
+
4
+ export type { DevServer };
5
+
6
+ export interface ResolvedDevServer extends DevServer {
7
+ port: number | string;
8
+ static: false | Array<WebpackDevServer.NormalizedStatic>;
9
+ devMiddleware: DevServer["devMiddleware"];
10
+ // FIXME: hot should be `boolean | 'only'`
11
+ hot: boolean;
12
+ host?: string;
13
+ open: WebpackDevServer.Open[];
14
+ magicHtml: boolean;
15
+ liveReload: boolean;
16
+ webSocketServer: false | WebpackDevServer.WebSocketServerConfiguration;
17
+ proxy: WebpackDevServer.ProxyConfigArray;
18
+ client: WebpackDevServer.ClientConfiguration;
19
+ allowedHosts: "auto" | string[] | "all";
20
+ bonjour: false | Record<string, never> | WebpackDevServer.BonjourOptions;
21
+ compress: boolean;
22
+ historyApiFallback: false | WebpackDevServer.ConnectHistoryApiFallbackOptions;
23
+ server: WebpackDevServer.ServerConfiguration;
24
+ ipc: string | undefined;
25
+ setupExitSignals: boolean;
26
+ watchFiles: WebpackDevServer.WatchFiles[];
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { RspackDevServer } from "./server";
package/src/reload.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { RspackOptionsNormalized } from "@rspack/core";
2
+
3
+ interface Status {
4
+ isUnloading: boolean;
5
+ currentHash: string;
6
+ previousHash: string[];
7
+ }
8
+
9
+ export function reloadApp(
10
+ { liveReload, hot }: RspackOptionsNormalized["devServer"],
11
+ status: Status
12
+ ) {
13
+ if (status.isUnloading) {
14
+ return;
15
+ }
16
+
17
+ function applyReload(rootWindow: Window, intervalId: number) {
18
+ clearInterval(intervalId);
19
+ console.log("App update, Reloading...");
20
+ rootWindow.location.reload();
21
+ }
22
+
23
+ if (liveReload) {
24
+ let rootWindow = self;
25
+ const intervalId = self.setInterval(() => {
26
+ if (rootWindow.location.protocol !== "about:") {
27
+ applyReload(rootWindow, intervalId);
28
+ }
29
+ });
30
+ }
31
+ }