@rspack/dev-server 0.0.21 → 0.0.23

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 (48) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/LICENSE +2 -1
  3. package/dist/config.d.ts +20 -14
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +0 -52
  6. package/dist/config.js.map +1 -1
  7. package/dist/server.d.ts +14 -41
  8. package/dist/server.d.ts.map +1 -1
  9. package/dist/server.js +330 -257
  10. package/dist/server.js.map +1 -1
  11. package/jest.config.js +3 -1
  12. package/package.json +14 -12
  13. package/src/config.ts +22 -67
  14. package/src/server.ts +374 -311
  15. package/tests/__snapshots__/normalizeOptions.test.ts.snap +164 -26
  16. package/tests/e2e/hot-reaload.test.ts +35 -39
  17. package/tests/e2e-fixtures/react/node_modules/scheduler/LICENSE +21 -0
  18. package/tests/e2e-fixtures/react/node_modules/scheduler/README.md +9 -0
  19. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_mock.development.js +700 -0
  20. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_mock.production.min.js +20 -0
  21. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_post_task.development.js +207 -0
  22. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler-unstable_post_task.production.min.js +14 -0
  23. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler.development.js +634 -0
  24. package/tests/e2e-fixtures/react/node_modules/scheduler/cjs/scheduler.production.min.js +19 -0
  25. package/tests/e2e-fixtures/react/node_modules/scheduler/index.js +7 -0
  26. package/tests/e2e-fixtures/react/node_modules/scheduler/package.json +36 -0
  27. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler-unstable_mock.development.js +699 -0
  28. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js +19 -0
  29. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.development.js +152 -0
  30. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.production.min.js +146 -0
  31. package/tests/e2e-fixtures/react/node_modules/scheduler/umd/scheduler.profiling.min.js +146 -0
  32. package/tests/e2e-fixtures/react/node_modules/scheduler/unstable_mock.js +7 -0
  33. package/tests/e2e-fixtures/react/node_modules/scheduler/unstable_post_task.js +7 -0
  34. package/tests/e2e-fixtures/react/package.json +2 -0
  35. package/tests/e2e-fixtures/react/webpack.config.js +6 -2
  36. package/tests/helpers/emitFile.ts +58 -4
  37. package/tests/normalizeOptions.test.ts +50 -16
  38. package/tsconfig.tsbuildinfo +1 -1
  39. package/dist/logger.d.ts +0 -7
  40. package/dist/logger.d.ts.map +0 -1
  41. package/dist/logger.js +0 -28
  42. package/dist/logger.js.map +0 -1
  43. package/dist/ws.d.ts +0 -13
  44. package/dist/ws.d.ts.map +0 -1
  45. package/dist/ws.js +0 -12
  46. package/dist/ws.js.map +0 -1
  47. package/src/logger.ts +0 -30
  48. package/src/ws.ts +0 -18
@@ -3,9 +3,10 @@
3
3
  exports[`normalize options snapshot additional entires should added 1`] = `
4
4
  {
5
5
  "main": [
6
+ "<prefix>/dist/clients/WebSocketClient.js",
7
+ "<prefix>/rspack-dev-client/dist/index.js?protocol=ws%3A&hostname=0.0.0.0&port=8080&pathname=%2Fws&logging=info&overlay=true&reconnect=10&hot=true&live-reload=true",
6
8
  "<prefix>/rspack-dev-client/dist/devServer.js",
7
9
  "<prefix>/rspack-dev-client/dist/reactRefresh.js",
8
- "<prefix>/rspack-dev-client/dist/index.js",
9
10
  "<prefix>/something",
10
11
  ],
11
12
  }
@@ -13,71 +14,207 @@ exports[`normalize options snapshot additional entires should added 1`] = `
13
14
 
14
15
  exports[`normalize options snapshot no options 1`] = `
15
16
  {
17
+ "allowedHosts": "auto",
18
+ "bonjour": false,
19
+ "client": {
20
+ "logging": "info",
21
+ "overlay": true,
22
+ "reconnect": 10,
23
+ "webSocketURL": {},
24
+ },
25
+ "compress": true,
16
26
  "devMiddleware": {},
27
+ "historyApiFallback": false,
17
28
  "host": undefined,
18
29
  "hot": true,
19
30
  "liveReload": true,
20
- "open": true,
21
- "port": undefined,
22
- "proxy": undefined,
23
- "static": {
24
- "directory": "<PROJECT_ROOT>/dist",
25
- "watch": {},
31
+ "magicHtml": true,
32
+ "open": [],
33
+ "port": 8080,
34
+ "server": {
35
+ "options": {},
36
+ "type": "http",
37
+ },
38
+ "setupExitSignals": true,
39
+ "static": [
40
+ {
41
+ "directory": "<PROJECT_ROOT>/public",
42
+ "publicPath": [
43
+ "/",
44
+ ],
45
+ "serveIndex": {
46
+ "icons": true,
47
+ },
48
+ "staticOptions": {},
49
+ "watch": {
50
+ "alwaysStat": true,
51
+ "atomic": false,
52
+ "followSymlinks": false,
53
+ "ignoreInitial": true,
54
+ "ignorePermissionErrors": true,
55
+ "ignored": undefined,
56
+ "interval": undefined,
57
+ "persistent": true,
58
+ "usePolling": false,
59
+ },
60
+ },
61
+ ],
62
+ "watchFiles": [],
63
+ "webSocketServer": {
64
+ "options": {
65
+ "path": "/ws",
66
+ },
67
+ "type": "ws",
26
68
  },
27
- "webSocketServer": {},
28
69
  }
29
70
  `;
30
71
 
31
72
  exports[`normalize options snapshot port string 1`] = `
32
73
  {
74
+ "allowedHosts": "auto",
75
+ "bonjour": false,
76
+ "client": {
77
+ "logging": "info",
78
+ "overlay": true,
79
+ "reconnect": 10,
80
+ "webSocketURL": {},
81
+ },
82
+ "compress": true,
33
83
  "devMiddleware": {},
84
+ "historyApiFallback": false,
34
85
  "host": undefined,
35
86
  "hot": true,
36
87
  "liveReload": true,
37
- "open": true,
88
+ "magicHtml": true,
89
+ "open": [],
38
90
  "port": 9000,
39
- "proxy": undefined,
40
- "static": {
41
- "directory": "<PROJECT_ROOT>/dist",
42
- "watch": {},
91
+ "server": {
92
+ "options": {},
93
+ "type": "http",
94
+ },
95
+ "setupExitSignals": true,
96
+ "static": [
97
+ {
98
+ "directory": "<PROJECT_ROOT>/public",
99
+ "publicPath": [
100
+ "/",
101
+ ],
102
+ "serveIndex": {
103
+ "icons": true,
104
+ },
105
+ "staticOptions": {},
106
+ "watch": {
107
+ "alwaysStat": true,
108
+ "atomic": false,
109
+ "followSymlinks": false,
110
+ "ignoreInitial": true,
111
+ "ignorePermissionErrors": true,
112
+ "ignored": undefined,
113
+ "interval": undefined,
114
+ "persistent": true,
115
+ "usePolling": false,
116
+ },
117
+ },
118
+ ],
119
+ "watchFiles": [],
120
+ "webSocketServer": {
121
+ "options": {
122
+ "path": "/ws",
123
+ },
124
+ "type": "ws",
43
125
  },
44
- "webSocketServer": {},
45
126
  }
46
127
  `;
47
128
 
48
129
  exports[`normalize options snapshot react.development and react.refresh should be true in default when hot enabled 1`] = `
49
130
  {
50
131
  "builtins": {
51
- "browserslist": [],
132
+ "copy": undefined,
133
+ "css": {
134
+ "modules": {
135
+ "exportsOnly": false,
136
+ "localIdentName": "[hash]",
137
+ "localsConvention": "asIs",
138
+ },
139
+ },
52
140
  "decorator": {
53
141
  "emitMetadata": true,
54
142
  "legacy": true,
55
- "useDefineForClassFields": true,
56
143
  },
57
144
  "define": {},
145
+ "devFriendlySplitChunks": false,
146
+ "emotion": undefined,
58
147
  "html": [],
59
- "minify": {
60
- "enable": true,
148
+ "minifyOptions": {
149
+ "dropConsole": false,
61
150
  "passes": 1,
151
+ "pureFuncs": [],
62
152
  },
153
+ "noEmitAssets": false,
154
+ "postcss": {
155
+ "pxtorem": undefined,
156
+ },
157
+ "presetEnv": undefined,
158
+ "progress": undefined,
63
159
  "react": {
64
160
  "development": true,
65
161
  "refresh": true,
66
162
  },
163
+ "treeShaking": true,
67
164
  },
68
165
  "devServer": {
166
+ "allowedHosts": "auto",
167
+ "bonjour": false,
168
+ "client": {
169
+ "logging": "info",
170
+ "overlay": true,
171
+ "reconnect": 10,
172
+ "webSocketURL": {},
173
+ },
174
+ "compress": true,
69
175
  "devMiddleware": {},
176
+ "historyApiFallback": false,
70
177
  "host": undefined,
71
178
  "hot": true,
72
179
  "liveReload": true,
73
- "open": true,
74
- "port": undefined,
75
- "proxy": undefined,
76
- "static": {
77
- "directory": "<PROJECT_ROOT>/dist",
78
- "watch": {},
180
+ "magicHtml": true,
181
+ "open": [],
182
+ "port": 8080,
183
+ "server": {
184
+ "options": {},
185
+ "type": "http",
186
+ },
187
+ "setupExitSignals": true,
188
+ "static": [
189
+ {
190
+ "directory": "<PROJECT_ROOT>/public",
191
+ "publicPath": [
192
+ "/",
193
+ ],
194
+ "serveIndex": {
195
+ "icons": true,
196
+ },
197
+ "staticOptions": {},
198
+ "watch": {
199
+ "alwaysStat": true,
200
+ "atomic": false,
201
+ "followSymlinks": false,
202
+ "ignoreInitial": true,
203
+ "ignorePermissionErrors": true,
204
+ "ignored": undefined,
205
+ "interval": undefined,
206
+ "persistent": true,
207
+ "usePolling": false,
208
+ },
209
+ },
210
+ ],
211
+ "watchFiles": [],
212
+ "webSocketServer": {
213
+ "options": {
214
+ "path": "/ws",
215
+ },
216
+ "type": "ws",
79
217
  },
80
- "webSocketServer": {},
81
218
  },
82
219
  }
83
220
  `;
@@ -85,9 +222,10 @@ exports[`normalize options snapshot react.development and react.refresh should b
85
222
  exports[`normalize options snapshot react-refresh client added when react/refresh enabled 1`] = `
86
223
  {
87
224
  "main": [
225
+ "<prefix>/dist/clients/WebSocketClient.js",
226
+ "<prefix>/rspack-dev-client/dist/index.js?protocol=ws%3A&hostname=0.0.0.0&port=8080&pathname=%2Fws&logging=info&overlay=true&reconnect=10&hot=true&live-reload=true",
88
227
  "<prefix>/rspack-dev-client/dist/devServer.js",
89
228
  "<prefix>/rspack-dev-client/dist/reactRefresh.js",
90
- "<prefix>/rspack-dev-client/dist/index.js",
91
229
  "<prefix>/something",
92
230
  ],
93
231
  }
@@ -1,29 +1,26 @@
1
1
  import { RspackDevServer } from "@rspack/dev-server";
2
2
  import { createCompiler } from "@rspack/core";
3
3
  import { initFixture, installDeps } from "../helpers/tempDir";
4
- import { editFile } from "../helpers/emitFile";
4
+ import { editFile, waitingForBuild } from "../helpers/emitFile";
5
5
  import path from "path";
6
6
  import runBrowser from "../helpers/runBrowser";
7
7
  import type { Browser, Page } from "puppeteer";
8
8
 
9
- describe("reload and hot should works", () => {
10
- let browser: Browser;
11
- let server: RspackDevServer;
12
-
13
- afterEach(async () => {
14
- if (browser) {
15
- await browser.close();
16
- }
17
- if (server) {
18
- await server.stop();
19
- }
9
+ async function wait(time) {
10
+ return new Promise(resolve => {
11
+ setTimeout(() => {
12
+ resolve(undefined);
13
+ }, time);
20
14
  });
15
+ }
21
16
 
22
- it("reload should works", async () => {
23
- const tempDir = await initFixture("react");
17
+ describe("reload and hot should works", () => {
18
+ it.skip("reload and hot should works", async () => {
19
+ // reload should works
20
+ let tempDir = await initFixture("react");
24
21
  await installDeps(tempDir);
25
- const config = require(path.resolve(tempDir, "./webpack.config.js"));
26
- const compiler = createCompiler({
22
+ let config = require(path.resolve(tempDir, "./webpack.config.js"));
23
+ let compiler = createCompiler({
27
24
  ...config,
28
25
  context: tempDir,
29
26
  devServer: {
@@ -31,23 +28,19 @@ describe("reload and hot should works", () => {
31
28
  liveReload: true
32
29
  }
33
30
  });
34
- server = new RspackDevServer(compiler);
31
+ let server = new RspackDevServer(compiler.options.devServer, compiler);
35
32
  await server.start();
36
- const launched = await runBrowser();
37
- ({ browser } = launched);
38
- const { page } = launched;
39
-
40
- const consoleMessages: string[] = [];
41
- page.on("console", message => {
42
- const text = message.text();
43
- consoleMessages.push(text);
44
- });
33
+ await waitingForBuild(server.options.port);
34
+ console.log("=== before goto page ===");
35
+ let { browser, page } = await runBrowser();
45
36
 
46
37
  await page.goto(`http://localhost:${server.options.port}`);
47
38
  await page.click(".test-button");
48
39
  expect(await getText(page, ".test-button-content")).toBe("1");
49
40
  expect(await getText(page, ".placeholder")).toBe("__PLACE_HOLDER__");
50
- await editFile(path.resolve(tempDir, "./app.jsx"), code =>
41
+
42
+ const appFilePath = path.resolve(tempDir, "./app.jsx");
43
+ await editFile(appFilePath, code =>
51
44
  code.replace("__PLACE_HOLDER__", "update")
52
45
  );
53
46
  expect(await getText(page, ".test-button-content")).toBe("0");
@@ -60,31 +53,31 @@ describe("reload and hot should works", () => {
60
53
  expect((await getComputedStyle(page, "body")).backgroundColor).toBe(
61
54
  "rgba(255, 0, 0, 0)"
62
55
  );
63
- });
56
+ await server.stop();
57
+ await browser.close();
58
+ console.log("=== first end ===");
64
59
 
65
- it("hot should works", async () => {
66
- const tempDir = await initFixture("react");
60
+ // hot should works;
61
+ console.log("=== second start ===");
62
+ tempDir = await initFixture("react");
67
63
  await installDeps(tempDir);
68
- const config = require(path.resolve(tempDir, "./webpack.config.js"));
69
- const compiler = createCompiler({
64
+ config = require(path.resolve(tempDir, "./webpack.config.js"));
65
+ compiler = createCompiler({
70
66
  ...config,
71
67
  context: tempDir
72
68
  });
73
- server = new RspackDevServer(compiler);
69
+ server = new RspackDevServer(compiler.options.devServer, compiler);
74
70
  await server.start();
71
+ await waitingForBuild(server.options.port);
72
+ console.log("=== before goto page ===");
75
73
 
76
- const launched = await runBrowser();
77
- ({ browser } = launched);
78
- const { page } = launched;
79
-
74
+ ({ browser, page } = await runBrowser());
80
75
  const consoleMessages: string[] = [];
81
76
  page.on("console", message => {
82
77
  const text = message.text();
83
78
  consoleMessages.push(text);
84
79
  });
85
-
86
80
  await page.goto(`http://localhost:${server.options.port}`);
87
-
88
81
  await page.click(".test-button");
89
82
  expect(await getText(page, ".test-button-content")).toBe("1");
90
83
  expect(await getText(page, ".placeholder")).toBe("__PLACE_HOLDER__");
@@ -100,6 +93,9 @@ describe("reload and hot should works", () => {
100
93
  );
101
94
  expect(await getText(page, ".test-button-content")).toBe("1");
102
95
  expect(consoleMessages).toContain("App hot update...");
96
+ await server.stop();
97
+ await browser.close();
98
+ console.log("=== second end ===");
103
99
  });
104
100
  });
105
101
 
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Facebook, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ # `scheduler`
2
+
3
+ This is a package for cooperative scheduling in a browser environment. It is currently used internally by React, but we plan to make it more generic.
4
+
5
+ The public API for this package is not yet finalized.
6
+
7
+ ### Thanks
8
+
9
+ The React team thanks [Anton Podviaznikov](https://podviaznikov.com/) for donating the `scheduler` package name.