@rsbuild/core 2.3.2 → 2.3.4

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.
@@ -1,19 +1,106 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 720: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- module.exports = __nccwpck_require__(286)["default"];
4
+ 58: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ module.exports = __nccwpck_require__(984)["default"];
6
6
  },
7
- 286: (__unused_webpack_module, exports, __nccwpck_require__) => {
7
+ 388: (__unused_webpack_module, exports) => {
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createCompilationCache = createCompilationCache;
10
+ exports.getCompilation = getCompilation;
11
+ const VALUE = Symbol("value");
12
+ function isObjectKey(key) {
13
+ return (
14
+ (typeof key === "object" && key !== null) || typeof key === "function"
15
+ );
16
+ }
17
+ function getChild(node, key, create) {
18
+ const store = isObjectKey(key) ? "weak" : "strong";
19
+ if (!node[store]) {
20
+ if (!create) {
21
+ return undefined;
22
+ }
23
+ node[store] = store === "weak" ? new WeakMap() : new Map();
24
+ }
25
+ let child = node[store].get(key);
26
+ if (!child && create) {
27
+ child = {};
28
+ node[store].set(key, child);
29
+ }
30
+ return child;
31
+ }
32
+ function getCompilation(loaderContext) {
33
+ return (loaderContext && loaderContext._compilation) || undefined;
34
+ }
35
+ function createCompilationCache() {
36
+ const compilations = new WeakMap();
37
+ function find(compilation, keys, create) {
38
+ let node = compilations.get(compilation);
39
+ if (!node) {
40
+ if (!create) {
41
+ return undefined;
42
+ }
43
+ node = {};
44
+ compilations.set(compilation, node);
45
+ }
46
+ for (const key of keys) {
47
+ node = getChild(node, key, create);
48
+ if (!node) {
49
+ return undefined;
50
+ }
51
+ }
52
+ return node;
53
+ }
54
+ return {
55
+ get(loaderContext, keys, factory) {
56
+ const compilation = getCompilation(loaderContext);
57
+ if (!compilation) {
58
+ return factory();
59
+ }
60
+ const node = find(compilation, keys, true);
61
+ if (VALUE in node) {
62
+ return node[VALUE];
63
+ }
64
+ const value = factory();
65
+ node[VALUE] = value;
66
+ if (value && typeof value.then === "function") {
67
+ value.then(undefined, () => {
68
+ if (node[VALUE] === value) {
69
+ delete node[VALUE];
70
+ }
71
+ });
72
+ }
73
+ return value;
74
+ },
75
+ has(loaderContext, keys) {
76
+ const compilation = getCompilation(loaderContext);
77
+ const node = compilation && find(compilation, keys, false);
78
+ return Boolean(node) && VALUE in node;
79
+ },
80
+ delete(loaderContext, keys) {
81
+ const compilation = getCompilation(loaderContext);
82
+ const node = compilation && find(compilation, keys, false);
83
+ if (!node || !(VALUE in node)) {
84
+ return false;
85
+ }
86
+ delete node[VALUE];
87
+ return true;
88
+ },
89
+ };
90
+ }
91
+ },
92
+ 984: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
93
  var __webpack_unused_export__;
9
94
  __webpack_unused_export__ = { value: true };
10
95
  exports["default"] = loader;
11
96
  var _nodePath = _interopRequireDefault(__nccwpck_require__(760));
12
- var _utils = __nccwpck_require__(567);
97
+ var _compilationCache = __nccwpck_require__(388);
98
+ var _utils = __nccwpck_require__(97);
13
99
  function _interopRequireDefault(e) {
14
100
  return e && e.__esModule ? e : { default: e };
15
101
  }
16
102
  let hasExplicitDependencyOnPostCSS = false;
103
+ const processorCache = (0, _compilationCache.createCompilationCache)();
17
104
  async function loader(content, sourceMap, meta) {
18
105
  const options = this.getOptions();
19
106
  const callback = this.async();
@@ -70,10 +157,10 @@
70
157
  };
71
158
  }
72
159
  if (sourceMap && processOptions.map) {
73
- processOptions.map.prev = (0, _utils.normalizeSourceMap)(
74
- sourceMap,
75
- this.context,
76
- );
160
+ processOptions.map = {
161
+ ...processOptions.map,
162
+ prev: (0, _utils.normalizeSourceMap)(sourceMap, this.context),
163
+ };
77
164
  }
78
165
  let root;
79
166
  if (meta && meta.ast && meta.ast.type === "postcss") {
@@ -85,7 +172,9 @@
85
172
  let result;
86
173
  let processor;
87
174
  try {
88
- processor = implementation(plugins);
175
+ processor = processorCache.get(this, [implementation, plugins], () =>
176
+ implementation(plugins),
177
+ );
89
178
  result = await processor.process(root || content, processOptions);
90
179
  } catch (error) {
91
180
  if (
@@ -179,7 +268,7 @@
179
268
  callback(null, result.css, map, { ast });
180
269
  }
181
270
  },
182
- 567: (module, exports, __nccwpck_require__) => {
271
+ 97: (module, exports, __nccwpck_require__) => {
183
272
  module = __nccwpck_require__.nmd(module);
184
273
  Object.defineProperty(exports, "__esModule", { value: true });
185
274
  exports.exec = exec;
@@ -195,6 +284,7 @@
195
284
  var _nodePath = _interopRequireDefault(__nccwpck_require__(760));
196
285
  var _nodeUrl = _interopRequireDefault(__nccwpck_require__(136));
197
286
  var _cosmiconfig = {};
287
+ var _compilationCache = __nccwpck_require__(388);
198
288
  function _interopRequireDefault(e) {
199
289
  return e && e.__esModule ? e : { default: e };
200
290
  }
@@ -217,18 +307,9 @@
217
307
  return module.exports;
218
308
  }
219
309
  let tsLoader;
220
- async function loadConfig(loaderContext, config, postcssOptions) {
221
- const searchPath =
222
- typeof config === "string"
223
- ? _nodePath.default.resolve(config)
224
- : _nodePath.default.dirname(loaderContext.resourcePath);
225
- let stats;
226
- try {
227
- stats = await stat(loaderContext.fs, searchPath);
228
- } catch {
229
- throw new Error(`No PostCSS config found in: ${searchPath}`);
230
- }
231
- const moduleName = "postcss";
310
+ const MODULE_NAME = "postcss";
311
+ function createExplorer() {
312
+ const moduleName = MODULE_NAME;
232
313
  const searchPlaces = [
233
314
  "package.json",
234
315
  `${moduleName}.config.js`,
@@ -316,11 +397,29 @@
316
397
  loaders[".cts"] = tsLoader;
317
398
  loaders[".mts"] = tsLoader;
318
399
  loaders[".ts"] = tsLoader;
319
- const explorer = (0, _cosmiconfig.cosmiconfig)(moduleName, {
400
+ return (0, _cosmiconfig.cosmiconfig)(moduleName, {
320
401
  searchStrategy: "global",
321
402
  searchPlaces,
322
403
  loaders,
323
404
  });
405
+ }
406
+ const explorerCache = (0, _compilationCache.createCompilationCache)();
407
+ async function loadConfig(loaderContext, config, postcssOptions) {
408
+ const searchPath =
409
+ typeof config === "string"
410
+ ? _nodePath.default.resolve(config)
411
+ : _nodePath.default.dirname(loaderContext.resourcePath);
412
+ let stats;
413
+ try {
414
+ stats = await stat(loaderContext.fs, searchPath);
415
+ } catch {
416
+ throw new Error(`No PostCSS config found in: ${searchPath}`);
417
+ }
418
+ const explorer = explorerCache.get(
419
+ loaderContext,
420
+ [MODULE_NAME],
421
+ createExplorer,
422
+ );
324
423
  const result = await (stats.isFile()
325
424
  ? explorer.load(searchPath)
326
425
  : explorer.search(searchPath));
@@ -340,7 +439,15 @@
340
439
  env: loaderContext.mode,
341
440
  options: postcssOptions || {},
342
441
  };
343
- return { ...result, config: result.config(api) };
442
+ const config = result.config(api);
443
+ return {
444
+ ...result,
445
+ config:
446
+ config && typeof config === "object" && !Array.isArray(config)
447
+ ? { ...config }
448
+ : config,
449
+ isFunction: true,
450
+ };
344
451
  }
345
452
  return result;
346
453
  }
@@ -424,30 +531,45 @@
424
531
  throw err;
425
532
  }
426
533
  }
534
+ function resolvePlugins(config, postcssOptions, file) {
535
+ const factory = pluginFactory();
536
+ if (config && config.plugins) {
537
+ factory(config.plugins);
538
+ }
539
+ factory(postcssOptions.plugins);
540
+ return [...factory()].map((item) => {
541
+ const [plugin, options] = item;
542
+ if (typeof plugin === "string") {
543
+ return loadPlugin(plugin, options, file);
544
+ }
545
+ return plugin;
546
+ });
547
+ }
548
+ const NO_CONFIG = {};
549
+ const NO_OPTIONS = {};
550
+ const pluginsCache = (0, _compilationCache.createCompilationCache)();
427
551
  async function getPostcssOptions(
428
552
  loaderContext,
429
553
  loadedConfig = {},
430
- postcssOptions = {},
554
+ postcssOptions = NO_OPTIONS,
431
555
  ) {
432
556
  const file = loaderContext.resourcePath;
433
557
  let normalizedPostcssOptions = postcssOptions;
434
558
  if (typeof normalizedPostcssOptions === "function") {
435
559
  normalizedPostcssOptions = normalizedPostcssOptions(loaderContext);
436
560
  }
561
+ const createPlugins = () =>
562
+ resolvePlugins(loadedConfig.config, normalizedPostcssOptions, file);
437
563
  let plugins = [];
438
564
  try {
439
- const factory = pluginFactory();
440
- if (loadedConfig.config && loadedConfig.config.plugins) {
441
- factory(loadedConfig.config.plugins);
442
- }
443
- factory(normalizedPostcssOptions.plugins);
444
- plugins = [...factory()].map((item) => {
445
- const [plugin, options] = item;
446
- if (typeof plugin === "string") {
447
- return loadPlugin(plugin, options, file);
448
- }
449
- return plugin;
450
- });
565
+ plugins =
566
+ loadedConfig.isFunction || typeof postcssOptions === "function"
567
+ ? createPlugins()
568
+ : pluginsCache.get(
569
+ loaderContext,
570
+ [loadedConfig.config || NO_CONFIG, normalizedPostcssOptions],
571
+ createPlugins,
572
+ );
451
573
  } catch (error) {
452
574
  loaderContext.emitError(error);
453
575
  }
@@ -716,6 +838,6 @@
716
838
  })();
717
839
  if (typeof __nccwpck_require__ !== "undefined")
718
840
  __nccwpck_require__.ab = __dirname + "/";
719
- var __webpack_exports__ = __nccwpck_require__(720);
841
+ var __webpack_exports__ = __nccwpck_require__(58);
720
842
  module.exports = __webpack_exports__;
721
843
  })();
@@ -1 +1 @@
1
- {"name":"postcss-loader","author":"Andrey Sitnik <andrey@sitnik.ru>","version":"8.2.1","funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"postcss-loader","author":"Andrey Sitnik <andrey@sitnik.ru>","version":"8.2.2","funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -1 +1 @@
1
- {"name":"rspack-chain","version":"2.3.2","license":"MIT","types":"types/index.d.ts","type":"module"}
1
+ {"name":"rspack-chain","version":"2.3.3","license":"MIT","types":"types/index.d.ts","type":"module"}
@@ -42,6 +42,7 @@ declare namespace __Config {
42
42
  set<T extends keyof OptionsType>(key: T, value: OptionsType[T]): this;
43
43
  merge(obj: Partial<OptionsType>): this;
44
44
  entries(): OptionsType;
45
+ order(): { entries: OptionsType; order: string[] };
45
46
  values<T extends keyof OptionsType>(): OptionsType[T][];
46
47
  when(
47
48
  condition: boolean,
package/dist/1.js CHANGED
@@ -62,6 +62,7 @@ function relativeWithin(parent, target) {
62
62
  if (!('..' === relativePath || relativePath.startsWith(`..${sep}`) || isAbsolute(relativePath))) return relativePath;
63
63
  }
64
64
  function getCommonParentPath(paths) {
65
+ if (1 === paths.length) return paths[0];
65
66
  let uniquePaths = [
66
67
  ...new Set(paths)
67
68
  ];
@@ -15,8 +15,9 @@ const formatErrorLikeMessage = (error)=>{
15
15
  const name = getErrorField(error, 'name');
16
16
  return name ? `${name}: ${message}` : message;
17
17
  };
18
- function setupCustomHMRListeners(customListenersMap) {
18
+ function setupCustomHMR(customListenersMap, send) {
19
19
  __webpack_require__.i.push(({ module })=>{
20
+ module.hot.send = send;
20
21
  const newListeners = new Map();
21
22
  const addToMap = (map, event, cb)=>{
22
23
  const existing = map.get(event) || [];
@@ -142,16 +143,21 @@ function hmr_init(token, config, serverHost, serverPort, serverBase, liveReload,
142
143
  let reconnectCount = 0;
143
144
  let pingIntervalId;
144
145
  const isSocketReady = ()=>socket && socket.readyState === socket.OPEN;
145
- const socketSend = (data)=>{
146
- if (isSocketReady()) socket.send(JSON.stringify(data));
146
+ const socketSend = (message)=>{
147
+ if (isSocketReady()) socket.send(message);
148
+ };
149
+ const sendOrQueue = (data)=>{
150
+ const message = JSON.stringify(data);
151
+ if (isSocketReady()) socketSend(message);
152
+ else queuedMessages.push(message);
147
153
  };
148
154
  function onOpen() {
149
155
  logger.info('[rsbuild] WebSocket connected.');
150
156
  reconnectCount = 0;
151
157
  pingIntervalId = setInterval(()=>{
152
- socketSend({
158
+ socketSend(JSON.stringify({
153
159
  type: 'ping'
154
- });
160
+ }));
155
161
  }, 30000);
156
162
  if (queuedMessages.length) {
157
163
  queuedMessages.forEach(socketSend);
@@ -233,8 +239,7 @@ function hmr_init(token, config, serverHost, serverPort, serverBase, liveReload,
233
239
  clientErrors.push({
234
240
  id
235
241
  });
236
- if (isSocketReady()) socketSend(messageInfo);
237
- else queuedMessages.push(messageInfo);
242
+ sendOrQueue(messageInfo);
238
243
  }
239
244
  function onUnhandledRejection({ reason }) {
240
245
  let message;
@@ -284,7 +289,13 @@ function hmr_init(token, config, serverHost, serverPort, serverBase, liveReload,
284
289
  });
285
290
  window.addEventListener('unhandledrejection', onUnhandledRejection);
286
291
  }
287
- if (import.meta.webpackHot) setupCustomHMRListeners(customListenersMap);
292
+ if (import.meta.webpackHot) setupCustomHMR(customListenersMap, (event, data)=>{
293
+ sendOrQueue({
294
+ type: 'custom',
295
+ event,
296
+ data
297
+ });
298
+ });
288
299
  connect();
289
300
  }
290
301
  export { hmr_init as init, registerOverlay };