@rsbuild/core 1.1.0 → 1.1.2

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 (54) hide show
  1. package/compiled/chokidar/index.d.ts +318 -189
  2. package/compiled/chokidar/index.js +1069 -4439
  3. package/compiled/chokidar/license +1 -1
  4. package/compiled/chokidar/package.json +1 -1
  5. package/compiled/css-loader/index.js +46 -46
  6. package/compiled/html-rspack-plugin/index.js +14 -14
  7. package/compiled/http-proxy-middleware/index.d.ts +4 -3
  8. package/compiled/postcss/index.js +120 -114
  9. package/compiled/postcss/package.json +1 -1
  10. package/compiled/postcss-load-config/index.js +10 -10
  11. package/compiled/postcss-loader/index.js +11 -11
  12. package/compiled/rsbuild-dev-middleware/index.js +64 -101
  13. package/compiled/rsbuild-dev-middleware/package.json +1 -1
  14. package/compiled/rspack-manifest-plugin/index.js +4 -4
  15. package/compiled/tinyglobby/index.d.ts +25 -0
  16. package/compiled/tinyglobby/index.js +2749 -0
  17. package/compiled/tinyglobby/index1.js +17 -0
  18. package/compiled/tinyglobby/license +21 -0
  19. package/compiled/tinyglobby/package.json +1 -0
  20. package/dist/client/hmr.js +195 -213
  21. package/dist/client/overlay.js +88 -90
  22. package/dist/ignoreCssLoader.cjs +43 -29
  23. package/dist/index.cjs +6931 -13749
  24. package/dist/index.cjs.LICENSE.txt +13 -0
  25. package/dist/index.js +6754 -13826
  26. package/dist/index.js.LICENSE.txt +13 -0
  27. package/dist/transformLoader.cjs +59 -51
  28. package/dist/transformRawLoader.cjs +78 -60
  29. package/dist-types/cli/init.d.ts +2 -1
  30. package/dist-types/config.d.ts +2 -2
  31. package/dist-types/configChain.d.ts +1 -1
  32. package/dist-types/helpers/index.d.ts +3 -1
  33. package/dist-types/index.d.ts +1 -1
  34. package/dist-types/internal.d.ts +1 -13
  35. package/dist-types/logger.d.ts +1 -1
  36. package/dist-types/plugins/css.d.ts +1 -2
  37. package/dist-types/plugins/lazyCompilation.d.ts +1 -1
  38. package/dist-types/provider/createCompiler.d.ts +1 -1
  39. package/dist-types/provider/helpers.d.ts +12 -0
  40. package/dist-types/server/compilerDevMiddleware.d.ts +4 -3
  41. package/dist-types/server/devServer.d.ts +1 -1
  42. package/dist-types/server/helper.d.ts +1 -0
  43. package/dist-types/server/httpServer.d.ts +1 -1
  44. package/dist-types/server/middlewares.d.ts +2 -2
  45. package/dist-types/server/prodServer.d.ts +1 -1
  46. package/dist-types/server/restart.d.ts +4 -0
  47. package/dist-types/server/watchFiles.d.ts +4 -1
  48. package/dist-types/types/config.d.ts +20 -12
  49. package/dist-types/types/hooks.d.ts +1 -1
  50. package/dist-types/types/plugin.d.ts +2 -2
  51. package/dist-types/types/rsbuild.d.ts +3 -1
  52. package/dist-types/types/rspack.d.ts +1 -1
  53. package/dist-types/types/thirdParty.d.ts +1 -1
  54. package/package.json +15 -14
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const pico = require('./lib/picomatch');
4
+ const utils = require('./lib/utils');
5
+
6
+ function picomatch(glob, options, returnState = false) {
7
+ // default to os.platform()
8
+ if (options && (options.windows === null || options.windows === undefined)) {
9
+ // don't mutate the original options object
10
+ options = { ...options, windows: utils.isWindows() };
11
+ }
12
+
13
+ return pico(glob, options, returnState);
14
+ }
15
+
16
+ Object.assign(picomatch, pico);
17
+ module.exports = picomatch;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Madeline Gurriarán
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 @@
1
+ {"name":"tinyglobby","author":"Superchupu","version":"0.2.10","license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -1,245 +1,227 @@
1
- // src/client/format.ts
2
1
  function resolveFileName(stats) {
3
- if (stats.moduleIdentifier) {
4
- const regex = /(?:\!|^)([^!]+)$/;
5
- const matched = stats.moduleIdentifier.match(regex);
6
- if (matched) {
7
- const fileName = matched.pop();
8
- if (fileName) {
9
- return `File: ${fileName}:1:1
10
- `;
11
- }
2
+ // Get the real source file path with stats.moduleIdentifier.
3
+ // e.g. moduleIdentifier is "builtin:react-refresh-loader!/Users/x/src/App.jsx"
4
+ if (stats.moduleIdentifier) {
5
+ const regex = /(?:\!|^)([^!]+)$/;
6
+ const matched = stats.moduleIdentifier.match(regex);
7
+ if (matched) {
8
+ const fileName = matched.pop();
9
+ if (fileName) // add default column add lines for linking
10
+ return `File: ${fileName}:1:1\n`;
11
+ }
12
12
  }
13
- }
14
- const file = stats.file || stats.moduleName;
15
- return file ? `File: ${file}
16
- ` : "";
13
+ // fallback to file or moduleName if moduleIdentifier parse failed
14
+ const file = stats.file || stats.moduleName;
15
+ return file ? `File: ${file}\n` : '';
17
16
  }
18
17
  function hintUnknownFiles(message) {
19
- const hint = "You may need an appropriate loader to handle this file type.";
20
- if (message.indexOf(hint) === -1) {
18
+ const hint = 'You may need an appropriate loader to handle this file type.';
19
+ if (-1 === message.indexOf(hint)) return message;
20
+ if (/File: .+\.s(c|a)ss/.test(message)) return message.replace(hint, 'To enable support for Sass, use "@rsbuild/plugin-sass".');
21
+ if (/File: .+\.less/.test(message)) return message.replace(hint, 'To enable support for Less, use "@rsbuild/plugin-less".');
22
+ if (/File: .+\.styl(us)?/.test(message)) return message.replace(hint, 'To enable support for Stylus, use "@rsbuild/plugin-stylus".');
21
23
  return message;
22
- }
23
- if (/File: .+\.s(c|a)ss/.test(message)) {
24
- return message.replace(hint, `To enable support for Sass, use "@rsbuild/plugin-sass".`);
25
- }
26
- if (/File: .+\.less/.test(message)) {
27
- return message.replace(hint, `To enable support for Less, use "@rsbuild/plugin-less".`);
28
- }
29
- if (/File: .+\.styl(us)?/.test(message)) {
30
- return message.replace(hint, `To enable support for Stylus, use "@rsbuild/plugin-stylus".`);
31
- }
32
- return message;
33
24
  }
25
+ // Cleans up Rspack error messages.
34
26
  function formatMessage(stats, verbose) {
35
- let lines = [];
36
- let message;
37
- if (typeof stats === "object") {
38
- const fileName = resolveFileName(stats);
39
- const mainMessage = stats.message;
40
- const details = verbose && stats.details ? `
41
- Details: ${stats.details}
42
- ` : "";
43
- const stack = verbose && stats.stack ? `
44
- ${stats.stack}` : "";
45
- message = `${fileName}${mainMessage}${details}${stack}`;
46
- } else {
47
- message = stats;
48
- }
49
- message = hintUnknownFiles(message);
50
- lines = message.split("\n");
51
- lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
52
- message = lines.join("\n");
53
- const innerError = "-- inner error --";
54
- if (!verbose && message.includes(innerError)) {
55
- message = message.split(innerError)[0];
56
- }
57
- return message.trim();
27
+ let lines = [];
28
+ let message;
29
+ // Stats error object
30
+ if ('object' == typeof stats) {
31
+ const fileName = resolveFileName(stats);
32
+ const mainMessage = stats.message;
33
+ const details = verbose && stats.details ? `\nDetails: ${stats.details}\n` : '';
34
+ const stack = verbose && stats.stack ? `\n${stats.stack}` : '';
35
+ message = `${fileName}${mainMessage}${details}${stack}`;
36
+ } else message = stats;
37
+ message = hintUnknownFiles(message);
38
+ lines = message.split('\n');
39
+ // Remove duplicated newlines
40
+ lines = lines.filter((line, index, arr)=>0 === index || '' !== line.trim() || line.trim() !== arr[index - 1].trim());
41
+ // Reassemble the message
42
+ message = lines.join('\n');
43
+ const innerError = '-- inner error --';
44
+ if (!verbose && message.includes(innerError)) message = message.split(innerError)[0];
45
+ return message.trim();
58
46
  }
59
47
  function formatStatsMessages(stats, verbose) {
60
- var _stats_errors, _stats_warnings;
61
- const formattedErrors = ((_stats_errors = stats.errors) === null || _stats_errors === void 0 ? void 0 : _stats_errors.map((error) => formatMessage(error, verbose))) || [];
62
- const formattedWarnings = ((_stats_warnings = stats.warnings) === null || _stats_warnings === void 0 ? void 0 : _stats_warnings.map((warning) => formatMessage(warning, verbose))) || [];
63
- return {
64
- errors: formattedErrors,
65
- warnings: formattedWarnings
66
- };
67
- }
68
-
69
- // src/client/hmr.ts
70
- var compilationId = RSBUILD_COMPILATION_NAME;
71
- var config = RSBUILD_CLIENT_CONFIG;
72
- function formatURL({ port, protocol, hostname, pathname }) {
73
- if (typeof URL !== "undefined") {
74
- const url = new URL("http://localhost");
75
- url.port = String(port);
76
- url.hostname = hostname;
77
- url.protocol = protocol;
78
- url.pathname = pathname;
79
- url.searchParams.append("compilationId", compilationId);
80
- return url.toString();
81
- }
82
- const colon = protocol.indexOf(":") === -1 ? ":" : "";
83
- return `${protocol}${colon}//${hostname}:${port}${pathname}`;
84
- }
85
- var isFirstCompilation = true;
86
- var lastCompilationHash = null;
87
- var hasCompileErrors = false;
48
+ var _stats_errors, _stats_warnings;
49
+ const formattedErrors = (null === (_stats_errors = stats.errors) || void 0 === _stats_errors ? void 0 : _stats_errors.map((error)=>formatMessage(error, verbose))) || [];
50
+ const formattedWarnings = (null === (_stats_warnings = stats.warnings) || void 0 === _stats_warnings ? void 0 : _stats_warnings.map((warning)=>formatMessage(warning, verbose))) || [];
51
+ return {
52
+ errors: formattedErrors,
53
+ warnings: formattedWarnings
54
+ };
55
+ }
56
+ const compilationId = RSBUILD_COMPILATION_NAME;
57
+ const config = RSBUILD_CLIENT_CONFIG;
58
+ function formatURL(param) {
59
+ let { port, protocol, hostname, pathname } = param;
60
+ if ('undefined' != typeof URL) {
61
+ const url = new URL('http://localhost');
62
+ url.port = String(port);
63
+ url.hostname = hostname;
64
+ url.protocol = protocol;
65
+ url.pathname = pathname;
66
+ url.searchParams.append('compilationId', compilationId);
67
+ return url.toString();
68
+ }
69
+ // compatible with IE11
70
+ const colon = -1 === protocol.indexOf(':') ? ':' : '';
71
+ return `${protocol}${colon}//${hostname}:${port}${pathname}`;
72
+ }
73
+ // Remember some state related to hot module replacement.
74
+ let isFirstCompilation = true;
75
+ let lastCompilationHash = null;
76
+ let hasCompileErrors = false;
88
77
  function clearOutdatedErrors() {
89
- if (console.clear && hasCompileErrors) {
90
- console.clear();
91
- }
92
- }
93
- var createOverlay;
94
- var clearOverlay;
95
- var registerOverlay = (createFn, clearFn) => {
96
- createOverlay = createFn;
97
- clearOverlay = clearFn;
78
+ // Clean up outdated compile errors, if any.
79
+ if (console.clear && hasCompileErrors) console.clear();
80
+ }
81
+ let createOverlay;
82
+ let clearOverlay;
83
+ const registerOverlay = (createFn, clearFn)=>{
84
+ createOverlay = createFn;
85
+ clearOverlay = clearFn;
98
86
  };
87
+ // Successful compilation.
99
88
  function handleSuccess() {
100
- clearOutdatedErrors();
101
- const isHotUpdate = !isFirstCompilation;
102
- isFirstCompilation = false;
103
- hasCompileErrors = false;
104
- if (isHotUpdate) {
105
- tryApplyUpdates();
106
- }
107
- }
89
+ clearOutdatedErrors();
90
+ const isHotUpdate = !isFirstCompilation;
91
+ isFirstCompilation = false;
92
+ hasCompileErrors = false;
93
+ // Attempt to apply hot updates or reload.
94
+ if (isHotUpdate) tryApplyUpdates();
95
+ }
96
+ // Compilation with warnings (e.g. ESLint).
108
97
  function handleWarnings(warnings) {
109
- clearOutdatedErrors();
110
- const isHotUpdate = !isFirstCompilation;
111
- isFirstCompilation = false;
112
- hasCompileErrors = false;
113
- const formatted = formatStatsMessages({
114
- warnings,
115
- errors: []
116
- });
117
- for (let i = 0; i < formatted.warnings.length; i++) {
118
- if (i === 5) {
119
- console.warn("There were more warnings in other files, you can find a complete log in the terminal.");
120
- break;
98
+ clearOutdatedErrors();
99
+ const isHotUpdate = !isFirstCompilation;
100
+ isFirstCompilation = false;
101
+ hasCompileErrors = false;
102
+ const formatted = formatStatsMessages({
103
+ warnings,
104
+ errors: []
105
+ });
106
+ for(let i = 0; i < formatted.warnings.length; i++){
107
+ if (5 === i) {
108
+ console.warn('There were more warnings in other files, you can find a complete log in the terminal.');
109
+ break;
110
+ }
111
+ console.warn(formatted.warnings[i]);
121
112
  }
122
- console.warn(formatted.warnings[i]);
123
- }
124
- if (isHotUpdate) {
125
- tryApplyUpdates();
126
- }
113
+ // Attempt to apply hot updates or reload.
114
+ if (isHotUpdate) tryApplyUpdates();
127
115
  }
116
+ // Compilation with errors (e.g. syntax error or missing modules).
128
117
  function handleErrors(errors) {
129
- clearOutdatedErrors();
130
- isFirstCompilation = false;
131
- hasCompileErrors = true;
132
- const formatted = formatStatsMessages({
133
- errors,
134
- warnings: []
135
- });
136
- for (const error of formatted.errors) {
137
- console.error(error);
138
- }
139
- if (createOverlay) {
140
- createOverlay(formatted.errors);
141
- }
142
- }
143
- var isUpdateAvailable = () => lastCompilationHash !== __webpack_hash__;
118
+ clearOutdatedErrors();
119
+ isFirstCompilation = false;
120
+ hasCompileErrors = true;
121
+ const formatted = formatStatsMessages({
122
+ errors,
123
+ warnings: []
124
+ });
125
+ // Also log them to the console.
126
+ for (const error of formatted.errors)console.error(error);
127
+ if (createOverlay) createOverlay(formatted.errors);
128
+ }
129
+ // __webpack_hash__ is the hash of the current compilation.
130
+ // It's a global variable injected by Rspack.
131
+ const isUpdateAvailable = ()=>lastCompilationHash !== __webpack_hash__;
132
+ // Attempt to update code on the fly, fall back to a hard reload.
144
133
  function tryApplyUpdates() {
145
- if (!isUpdateAvailable()) {
146
- return;
147
- }
148
- if (!import.meta.webpackHot) {
149
- reloadPage();
150
- return;
151
- }
152
- if (import.meta.webpackHot.status() !== "idle") {
153
- return;
154
- }
155
- const handleApplyUpdates = (err, updatedModules) => {
156
- const forcedReload = err || !updatedModules;
157
- if (forcedReload) {
158
- if (err) {
159
- console.error("[HMR] Forced reload caused by: ", err);
160
- }
161
- reloadPage();
162
- return;
134
+ // detect is there a newer version of this code available
135
+ if (!isUpdateAvailable()) return;
136
+ if (!import.meta.webpackHot) {
137
+ // HotModuleReplacementPlugin is not in Rspack configuration.
138
+ reloadPage();
139
+ return;
163
140
  }
164
- if (isUpdateAvailable()) {
165
- tryApplyUpdates();
166
- }
167
- };
168
- import.meta.webpackHot.check(true).then((updatedModules) => handleApplyUpdates(null, updatedModules), (err) => handleApplyUpdates(err, null));
169
- }
170
- var connection = null;
171
- var reconnectCount = 0;
141
+ // Rspack disallows updates in other states.
142
+ if ('idle' !== import.meta.webpackHot.status()) return;
143
+ const handleApplyUpdates = (err, updatedModules)=>{
144
+ const forcedReload = err || !updatedModules;
145
+ if (forcedReload) {
146
+ if (err) console.error('[HMR] Forced reload caused by: ', err);
147
+ reloadPage();
148
+ return;
149
+ }
150
+ if (isUpdateAvailable()) // While we were updating, there was a new update! Do it again.
151
+ tryApplyUpdates();
152
+ };
153
+ // https://rspack.dev/api/runtime-api/module-variables#importmetawebpackhot
154
+ import.meta.webpackHot.check(true).then((updatedModules)=>handleApplyUpdates(null, updatedModules), (err)=>handleApplyUpdates(err, null));
155
+ }
156
+ let connection = null;
157
+ let reconnectCount = 0;
172
158
  function onOpen() {
173
- console.info("[HMR] connected.");
159
+ // Notify users that the HMR has successfully connected.
160
+ console.info('[HMR] connected.');
174
161
  }
175
162
  function onMessage(e) {
176
- const message = JSON.parse(e.data);
177
- if (message.compilationId && message.compilationId !== compilationId) {
178
- return;
179
- }
180
- switch (message.type) {
181
- case "hash":
182
- lastCompilationHash = message.data;
183
- if (clearOverlay && isUpdateAvailable()) {
184
- clearOverlay();
185
- }
186
- break;
187
- case "still-ok":
188
- case "ok":
189
- handleSuccess();
190
- break;
191
- case "static-changed":
192
- case "content-changed":
193
- reloadPage();
194
- break;
195
- case "warnings":
196
- handleWarnings(message.data);
197
- break;
198
- case "errors":
199
- handleErrors(message.data);
200
- break;
201
- }
163
+ const message = JSON.parse(e.data);
164
+ if (message.compilationId && message.compilationId !== compilationId) return;
165
+ switch(message.type){
166
+ case 'hash':
167
+ // Update the last compilation hash
168
+ lastCompilationHash = message.data;
169
+ if (clearOverlay && isUpdateAvailable()) clearOverlay();
170
+ break;
171
+ case 'still-ok':
172
+ case 'ok':
173
+ handleSuccess();
174
+ break;
175
+ // Triggered when static files changed
176
+ case 'static-changed':
177
+ case 'content-changed':
178
+ reloadPage();
179
+ break;
180
+ case 'warnings':
181
+ handleWarnings(message.data);
182
+ break;
183
+ case 'errors':
184
+ handleErrors(message.data);
185
+ break;
186
+ }
202
187
  }
203
188
  function onClose() {
204
- if (reconnectCount >= config.reconnect) {
205
- if (config.reconnect > 0) {
206
- console.info("[HMR] Connection failure after maximum reconnect limit exceeded.");
189
+ if (reconnectCount >= config.reconnect) {
190
+ if (config.reconnect > 0) console.info('[HMR] Connection failure after maximum reconnect limit exceeded.');
191
+ return;
207
192
  }
208
- return;
209
- }
210
- console.info("[HMR] disconnected. Attempting to reconnect.");
211
- removeListeners();
212
- connection = null;
213
- reconnectCount++;
214
- setTimeout(connect, 1e3 * 1.5 ** reconnectCount);
193
+ console.info('[HMR] disconnected. Attempting to reconnect.');
194
+ removeListeners();
195
+ connection = null;
196
+ reconnectCount++;
197
+ setTimeout(connect, 1000 * 1.5 ** reconnectCount);
215
198
  }
199
+ // Establishing a WebSocket connection with the server.
216
200
  function connect() {
217
- const { location } = self;
218
- const { host, port, path, protocol } = config;
219
- const socketUrl = formatURL({
220
- protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
221
- hostname: host || location.hostname,
222
- port: port || location.port,
223
- pathname: path || "/rsbuild-hmr"
224
- });
225
- connection = new WebSocket(socketUrl);
226
- connection.addEventListener("open", onOpen);
227
- connection.addEventListener("close", onClose);
228
- connection.addEventListener("message", onMessage);
201
+ const { location } = self;
202
+ const { host, port, path, protocol } = config;
203
+ const socketUrl = formatURL({
204
+ protocol: protocol || ('https:' === location.protocol ? 'wss' : 'ws'),
205
+ hostname: host || location.hostname,
206
+ port: port || location.port,
207
+ pathname: path || '/rsbuild-hmr'
208
+ });
209
+ connection = new WebSocket(socketUrl);
210
+ connection.addEventListener('open', onOpen);
211
+ // Attempt to reconnect after disconnection
212
+ connection.addEventListener('close', onClose);
213
+ // Handle messages from the server.
214
+ connection.addEventListener('message', onMessage);
229
215
  }
230
216
  function removeListeners() {
231
- if (connection) {
232
- connection.removeEventListener("open", onOpen);
233
- connection.removeEventListener("close", onClose);
234
- connection.removeEventListener("message", onMessage);
235
- }
217
+ if (connection) {
218
+ connection.removeEventListener('open', onOpen);
219
+ connection.removeEventListener('close', onClose);
220
+ connection.removeEventListener('message', onMessage);
221
+ }
236
222
  }
237
223
  function reloadPage() {
238
- if (RSBUILD_DEV_LIVE_RELOAD) {
239
- window.location.reload();
240
- }
224
+ if (RSBUILD_DEV_LIVE_RELOAD) window.location.reload();
241
225
  }
242
226
  connect();
243
- export {
244
- registerOverlay
245
- };
227
+ export { registerOverlay };