@rspack/dev-server 0.3.2 → 0.3.3-canary-0f5a67f-20230913040612

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.
@@ -0,0 +1,3 @@
1
+ declare function restoreDevServerPatch(): void;
2
+ declare function applyDevServerPatch(): typeof restoreDevServerPatch;
3
+ export { applyDevServerPatch };
package/dist/patch.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.applyDevServerPatch = void 0;
7
+ const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
8
+ let old;
9
+ function restoreDevServerPatch() {
10
+ // @ts-expect-error private API
11
+ webpack_dev_server_1.default.prototype.sendStats = old;
12
+ }
13
+ // Patch webpack-dev-server to prevent it from failing to send stats.
14
+ // See https://github.com/web-infra-dev/rspack/pull/4028 for details.
15
+ function applyDevServerPatch() {
16
+ if (old)
17
+ return restoreDevServerPatch;
18
+ // @ts-expect-error private API
19
+ old = webpack_dev_server_1.default.prototype.sendStats;
20
+ // @ts-expect-error private API
21
+ webpack_dev_server_1.default.prototype.sendStats = function sendStats__rspack_patched(...args) {
22
+ let stats = args[1];
23
+ if (!stats) {
24
+ return;
25
+ }
26
+ return old.apply(this, args);
27
+ };
28
+ return restoreDevServerPatch;
29
+ }
30
+ exports.applyDevServerPatch = applyDevServerPatch;
package/dist/server.d.ts CHANGED
@@ -26,7 +26,6 @@ export declare class RspackDevServer extends WebpackDevServer {
26
26
  compiler: Compiler | MultiCompiler;
27
27
  webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;
28
28
  constructor(options: DevServer, compiler: Compiler | MultiCompiler);
29
- addAdditionalEntries(compiler: Compiler): void;
30
29
  getClientTransport(): string;
31
30
  initialize(): Promise<void>;
32
31
  private setupDevMiddleware;
package/dist/server.js CHANGED
@@ -16,10 +16,11 @@ exports.RspackDevServer = void 0;
16
16
  const core_1 = require("@rspack/core");
17
17
  const webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
18
18
  const fs_1 = __importDefault(require("fs"));
19
+ const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-refresh"));
19
20
  const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
20
21
  const middleware_1 = require("./middleware");
21
- // @ts-expect-error
22
- const runtime_paths_1 = require("@rspack/dev-client/runtime-paths");
22
+ const patch_1 = require("./patch");
23
+ (0, patch_1.applyDevServerPatch)();
23
24
  class RspackDevServer extends webpack_dev_server_1.default {
24
25
  constructor(options, compiler) {
25
26
  super({
@@ -49,137 +50,6 @@ class RspackDevServer extends webpack_dev_server_1.default {
49
50
  }
50
51
  }, compiler);
51
52
  }
52
- addAdditionalEntries(compiler) {
53
- var _a;
54
- const additionalEntries = [];
55
- // @ts-expect-error
56
- const isWebTarget = webpack_dev_server_1.default.isWebTarget(compiler);
57
- // inject runtime first, avoid other additional entry after transfrom depend on it
58
- const clientPath = require.resolve("webpack-dev-server/client/index.js");
59
- if (this.options.hot) {
60
- if ((_a = compiler.options.builtins.react) === null || _a === void 0 ? void 0 : _a.refresh) {
61
- const reactRefreshEntryPath = require.resolve("@rspack/dev-client/react-refresh-entry");
62
- additionalEntries.push(reactRefreshEntryPath);
63
- }
64
- // #3356 make sure resolve webpack/hot/dev-server from webpack-dev-server
65
- const hotUpdateEntryPath = require.resolve("webpack/hot/dev-server", {
66
- paths: [clientPath]
67
- });
68
- additionalEntries.push(hotUpdateEntryPath);
69
- }
70
- if (this.options.client && isWebTarget) {
71
- let webSocketURLStr = "";
72
- if (this.options.webSocketServer) {
73
- const webSocketURL = this.options.client
74
- .webSocketURL;
75
- const webSocketServer = this.options.webSocketServer;
76
- const searchParams = new URLSearchParams();
77
- let protocol;
78
- // We are proxying dev server and need to specify custom `hostname`
79
- if (typeof webSocketURL.protocol !== "undefined") {
80
- protocol = webSocketURL.protocol;
81
- }
82
- else {
83
- protocol = this.options.server.type === "http" ? "ws:" : "wss:";
84
- }
85
- searchParams.set("protocol", protocol);
86
- if (typeof webSocketURL.username !== "undefined") {
87
- searchParams.set("username", webSocketURL.username);
88
- }
89
- if (typeof webSocketURL.password !== "undefined") {
90
- searchParams.set("password", webSocketURL.password);
91
- }
92
- let hostname;
93
- // SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
94
- // TODO show warning about this
95
- const isSockJSType = webSocketServer.type === "sockjs";
96
- // We are proxying dev server and need to specify custom `hostname`
97
- if (typeof webSocketURL.hostname !== "undefined") {
98
- hostname = webSocketURL.hostname;
99
- }
100
- // Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
101
- else if (typeof webSocketServer.options.host !== "undefined" &&
102
- !isSockJSType) {
103
- hostname = webSocketServer.options.host;
104
- }
105
- // The `host` option is specified
106
- else if (typeof this.options.host !== "undefined") {
107
- hostname = this.options.host;
108
- }
109
- // The `port` option is not specified
110
- else {
111
- hostname = "0.0.0.0";
112
- }
113
- searchParams.set("hostname", hostname);
114
- let port;
115
- // We are proxying dev server and need to specify custom `port`
116
- if (typeof webSocketURL.port !== "undefined") {
117
- port = webSocketURL.port;
118
- }
119
- // Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
120
- else if (typeof webSocketServer.options.port !== "undefined" &&
121
- !isSockJSType) {
122
- port = webSocketServer.options.port;
123
- }
124
- // The `port` option is specified
125
- else if (typeof this.options.port === "number") {
126
- port = this.options.port;
127
- }
128
- // The `port` option is specified using `string`
129
- else if (typeof this.options.port === "string" &&
130
- this.options.port !== "auto") {
131
- port = Number(this.options.port);
132
- }
133
- // The `port` option is not specified or set to `auto`
134
- else {
135
- port = "0";
136
- }
137
- searchParams.set("port", String(port));
138
- let pathname = "";
139
- // We are proxying dev server and need to specify custom `pathname`
140
- if (typeof webSocketURL.pathname !== "undefined") {
141
- pathname = webSocketURL.pathname;
142
- }
143
- // Web socket server works on custom `path`
144
- else if (typeof webSocketServer.options.prefix !== "undefined" ||
145
- typeof webSocketServer.options.path !== "undefined") {
146
- pathname =
147
- webSocketServer.options.prefix || webSocketServer.options.path;
148
- }
149
- searchParams.set("pathname", pathname);
150
- const client = /** @type {ClientConfiguration} */ this.options.client;
151
- if (typeof client.logging !== "undefined") {
152
- searchParams.set("logging", client.logging);
153
- }
154
- if (typeof client.progress !== "undefined") {
155
- searchParams.set("progress", String(client.progress));
156
- }
157
- if (typeof client.overlay !== "undefined") {
158
- searchParams.set("overlay", typeof client.overlay === "boolean"
159
- ? String(client.overlay)
160
- : JSON.stringify(client.overlay));
161
- }
162
- if (typeof client.reconnect !== "undefined") {
163
- searchParams.set("reconnect", typeof client.reconnect === "number"
164
- ? String(client.reconnect)
165
- : "10");
166
- }
167
- if (typeof this.options.hot !== "undefined") {
168
- searchParams.set("hot", String(this.options.hot));
169
- }
170
- if (typeof this.options.liveReload !== "undefined") {
171
- searchParams.set("live-reload", String(this.options.liveReload));
172
- }
173
- webSocketURLStr = searchParams.toString();
174
- }
175
- additionalEntries.push(`${clientPath}?${webSocketURLStr}`);
176
- }
177
- for (const additionalEntry of additionalEntries) {
178
- new compiler.webpack.EntryPlugin(compiler.context, additionalEntry, {
179
- name: undefined
180
- }).apply(compiler);
181
- }
182
- }
183
53
  getClientTransport() {
184
54
  // WARNING: we can't use `super.getClientTransport`,
185
55
  // because we doesn't had same directory structure.
@@ -239,23 +109,20 @@ class RspackDevServer extends webpack_dev_server_1.default {
239
109
  ? this.compiler.compilers
240
110
  : [this.compiler];
241
111
  compilers.forEach(compiler => {
242
- var _a, _b, _c, _d, _e, _f;
243
- var _g, _h, _j, _k, _l, _m;
112
+ var _a, _b, _c, _d;
113
+ var _e, _f, _g, _h;
244
114
  const mode = compiler.options.mode || process.env.NODE_ENV;
245
115
  if (this.options.hot) {
246
116
  if (mode === "production") {
247
117
  this.logger.warn("Hot Module Replacement (HMR) is enabled for the production build. \n" +
248
118
  "Make sure to disable HMR for production by setting `devServer.hot` to `false` in the configuration.");
249
119
  }
250
- (_a = (_g = compiler.options).devServer) !== null && _a !== void 0 ? _a : (_g.devServer = {});
120
+ (_a = (_e = compiler.options).devServer) !== null && _a !== void 0 ? _a : (_e.devServer = {});
251
121
  compiler.options.devServer.hot = true;
252
- (_b = (_h = compiler.options.builtins).react) !== null && _b !== void 0 ? _b : (_h.react = {});
253
- (_c = (_j = compiler.options.builtins.react).refresh) !== null && _c !== void 0 ? _c : (_j.refresh = true);
254
- (_d = (_k = compiler.options.builtins.react).development) !== null && _d !== void 0 ? _d : (_k.development = true);
255
- (_e = (_l = compiler.options.builtins).provide) !== null && _e !== void 0 ? _e : (_l.provide = {});
256
- (_f = (_m = compiler.options.builtins.provide).$ReactRefreshRuntime$) !== null && _f !== void 0 ? _f : (_m.$ReactRefreshRuntime$ = [
257
- require.resolve("@rspack/dev-client/react-refresh")
258
- ]);
122
+ (_b = (_f = compiler.options.builtins).react) !== null && _b !== void 0 ? _b : (_f.react = {});
123
+ (_c = (_g = compiler.options.builtins.react).refresh) !== null && _c !== void 0 ? _c : (_g.refresh = true);
124
+ (_d = (_h = compiler.options.builtins.react).development) !== null && _d !== void 0 ? _d : (_h.development = true);
125
+ new plugin_react_refresh_1.default().apply(compiler);
259
126
  }
260
127
  else if (compiler.options.builtins.react.refresh) {
261
128
  if (mode === "production") {
@@ -269,18 +136,11 @@ class RspackDevServer extends webpack_dev_server_1.default {
269
136
  });
270
137
  if (this.options.webSocketServer) {
271
138
  compilers.forEach(compiler => {
139
+ // @ts-expect-error: `addAdditionalEntries` is private function in base class.
272
140
  this.addAdditionalEntries(compiler);
273
- if (this.options.hot) {
274
- console.log(runtime_paths_1.runtimePaths);
275
- compiler.options.module.rules.push({
276
- include: runtime_paths_1.runtimePaths,
277
- type: "js"
278
- });
279
- }
280
- compiler.options.builtins.provide = {
281
- ...compiler.options.builtins.provide,
282
- __webpack_dev_server_client__: [this.getClientTransport()]
283
- };
141
+ new compiler.webpack.ProvidePlugin({
142
+ __webpack_dev_server_client__: this.getClientTransport()
143
+ }).apply(compiler);
284
144
  });
285
145
  }
286
146
  // @ts-expect-error: `setupHooks` is private function in base class.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/dev-server",
3
- "version": "0.3.2",
3
+ "version": "0.3.3-canary-0f5a67f-20230913040612",
4
4
  "license": "MIT",
5
5
  "description": "Development server for rspack",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "@types/ws": "8.5.3",
29
29
  "fs-extra": "11.1.0",
30
30
  "puppeteer": "19.4.0",
31
- "@rspack/core": "0.3.2"
31
+ "@rspack/core": "0.3.3-canary-0f5a67f-20230913040612"
32
32
  },
33
33
  "dependencies": {
34
34
  "chokidar": "3.5.3",
@@ -40,8 +40,8 @@
40
40
  "webpack-dev-middleware": "6.0.2",
41
41
  "webpack-dev-server": "4.13.1",
42
42
  "ws": "8.8.1",
43
- "@rspack/dev-client": "0.3.2",
44
- "@rspack/dev-server": "0.3.2"
43
+ "@rspack/dev-server": "0.3.3-canary-0f5a67f-20230913040612",
44
+ "@rspack/plugin-react-refresh": "0.3.3-canary-0f5a67f-20230913040612"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@rspack/core": "*"