@rsbuild/core 2.2.7 → 2.2.9

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 (43) hide show
  1. package/compiled/css-loader/index.js +2 -2
  2. package/compiled/html-rspack-plugin/htmlLoader.js +8 -17
  3. package/compiled/html-rspack-plugin/index.d.ts +8 -4
  4. package/compiled/html-rspack-plugin/index.js +61 -69
  5. package/compiled/html-rspack-plugin/package.json +1 -1
  6. package/compiled/postcss-loader/index.js +6 -6
  7. package/compiled/ws/index.d.ts +445 -0
  8. package/compiled/ws/license +21 -0
  9. package/compiled/ws/package.json +1 -0
  10. package/dist/chokidar.js +1 -1
  11. package/dist/client/hmr.js +1 -1
  12. package/dist/client/overlay.js +1 -1
  13. package/dist/cssUrlLoader.mjs +1 -1
  14. package/dist/helpers/cachedImport.d.ts +2 -0
  15. package/dist/http-proxy-middleware.js +4 -4
  16. package/dist/ignoreCssLoader.mjs +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/launch-editor-middleware.js +1 -1
  20. package/dist/{626.js → m.js} +121 -160
  21. package/dist/manifest-plugin.js +1 -1
  22. package/dist/memfs.js +1 -1
  23. package/dist/open.js +2 -2
  24. package/dist/r.js +7 -0
  25. package/dist/remapping.js +8 -3
  26. package/dist/rslib-runtime.js +1 -1
  27. package/dist/server/assets-middleware/memoryFileSystem.d.ts +2 -0
  28. package/dist/server/buildManager.d.ts +3 -2
  29. package/dist/server/devServer.d.ts +5 -0
  30. package/dist/server/runner/asModule.d.ts +1 -1
  31. package/dist/server/runner/basic.d.ts +5 -4
  32. package/dist/server/runner/type.d.ts +1 -1
  33. package/dist/server/socketServer.d.ts +7 -4
  34. package/dist/sirv.js +1 -1
  35. package/dist/tinyglobby.js +1 -1
  36. package/dist/trace-mapping.js +220 -8
  37. package/dist/transformLoader.mjs +3 -2
  38. package/dist/types/config.d.ts +6 -2
  39. package/dist/ws.js +2 -2
  40. package/package.json +7 -6
  41. /package/dist/{252.js → c.js} +0 -0
  42. /package/dist/client/{307~0.js → f~0.js} +0 -0
  43. /package/dist/{626.js.LICENSE.txt → m.js.LICENSE.txt} +0 -0
@@ -33,7 +33,7 @@ const stringEscapes = {
33
33
  const WITH_PLACEHOLDER = 'function __with_placeholder__';
34
34
  const escapeStringChar = (chr) => '\\' + stringEscapes[chr];
35
35
 
36
- function template(string) {
36
+ function template(string, interpolate = reInterpolate) {
37
37
  let isEscaping;
38
38
  let isEvaluating;
39
39
  let index = 0;
@@ -41,24 +41,13 @@ function template(string) {
41
41
 
42
42
  // Compile the regexp to match each delimiter.
43
43
  const reDelimiters = RegExp(
44
- reEscape.source +
45
- '|' +
46
- reInterpolate.source +
47
- '|' +
48
- reEvaluate.source +
49
- '|$',
44
+ reEscape.source + '|' + interpolate.source + '|' + reEvaluate.source + '|$',
50
45
  'g',
51
46
  );
52
47
 
53
48
  string.replace(
54
49
  reDelimiters,
55
- function (
56
- match,
57
- escapeValue,
58
- interpolateValue,
59
- evaluateValue,
60
- offset,
61
- ) {
50
+ function (match, escapeValue, interpolateValue, evaluateValue, offset) {
62
51
  // Escape characters that can't be included in string literals.
63
52
  source += string
64
53
  .slice(index, offset)
@@ -110,12 +99,14 @@ function template(string) {
110
99
  }
111
100
 
112
101
  module.exports = function (source) {
102
+ const options = this.getOptions();
103
+ const force = options.force || false;
113
104
  const allLoadersButThisOne = this.loaders.filter(
114
105
  (loader) => loader.normal !== module.exports,
115
106
  );
116
107
 
117
108
  // This loader shouldn't kick in if there is any other loader
118
- if (allLoadersButThisOne.length > 0) {
109
+ if (allLoadersButThisOne.length > 0 && !force) {
119
110
  return source;
120
111
  }
121
112
 
@@ -129,7 +120,7 @@ module.exports = function (source) {
129
120
  return source;
130
121
  }
131
122
 
132
- if (/\.(c|m)?js$/.test(this.resourcePath)) {
123
+ if (/\.(c|m)?js$/.test(this.resourcePath) && !force) {
133
124
  return source;
134
125
  }
135
126
 
@@ -156,7 +147,7 @@ function lodashEscape(input) {
156
147
  // The following part renders the template with lodash as a minimalistic loader
157
148
  // The WITH_PLACEHOLDER will be replaced with `with` in the next step
158
149
  // to make the code compatible with SWC strict mode
159
- const { compiled, isEscaping } = template(source);
150
+ const { compiled, isEscaping } = template(source, options.interpolate);
160
151
  return `
161
152
  module.exports = function (templateParams) { ${WITH_PLACEHOLDER}(templateParams) {
162
153
  ${isEscaping ? escapeCode : ''}
@@ -20,15 +20,16 @@ type AsArray<T> = T extends any[] ? T : [T];
20
20
  type Fn<T, R> = (...args: AsArray<T>) => R;
21
21
  type FnAsync<T, R> = (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void;
22
22
  type FnPromise<T, R> = (...args: AsArray<T>) => Promise<R>;
23
+ type TapFunction = (...args: any[]) => any;
23
24
  type UnsetAdditionalOptions = {
24
25
  _UnsetAdditionalOptions: true;
25
26
  };
26
- type IfSet<X> = X extends UnsetAdditionalOptions ? {} : X;
27
+ type IfSet<X> = X extends UnsetAdditionalOptions ? unknown : X;
27
28
  type Callback<E, T> = (error: E | null, result?: T) => void;
28
29
  type InnerCallback<E, T> = (error?: E | null | false, result?: T) => void;
29
30
  type FullTap = Tap & {
30
31
  type: 'sync' | 'async' | 'promise';
31
- fn: Function;
32
+ fn: TapFunction;
32
33
  };
33
34
  type Tap = TapOptions & {
34
35
  name: string;
@@ -82,7 +83,7 @@ declare class HookBase<T, R, AdditionalOptions = UnsetAdditionalOptions> impleme
82
83
  tap(options: Options<AdditionalOptions>, fn: Fn<T, R>): void;
83
84
  tapAsync(options: Options<AdditionalOptions>, fn: FnAsync<T, R>): void;
84
85
  tapPromise(options: Options<AdditionalOptions>, fn: FnPromise<T, R>): void;
85
- _tap(type: 'sync' | 'async' | 'promise', options: Options<AdditionalOptions>, fn: Function): void;
86
+ _tap(type: 'sync' | 'async' | 'promise', options: Options<AdditionalOptions>, fn: TapFunction): void;
86
87
  _insert(item: FullTap & IfSet<AdditionalOptions>): void;
87
88
  _prepareArgs(args: AsArray<T>): (T | undefined)[];
88
89
  }
@@ -270,7 +271,10 @@ declare namespace HtmlRspackPlugin {
270
271
  /**
271
272
  * The plugin options after adding default values
272
273
  */
273
- interface ProcessedOptions extends Required<Options> {}
274
+ type ProcessedOptions = {
275
+ // Preserve named properties alongside the index signature in Options.
276
+ [K in keyof Options as Exclude<K, 'minify'>]-?: Options[K];
277
+ } & Pick<Options, 'minify'>;
274
278
 
275
279
  /**
276
280
  * The values which are available during template execution
@@ -1,8 +1,8 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 25: (module, __unused_webpack_exports, __nccwpck_require__) => {
3
+ 535: (module, __unused_webpack_exports, __nccwpck_require__) => {
4
4
  "use strict";
5
- const { HtmlWebpackChildCompiler } = __nccwpck_require__(634);
5
+ const { HtmlWebpackChildCompiler } = __nccwpck_require__(284);
6
6
  const compilerMap = new WeakMap();
7
7
  class CachedChildCompilation {
8
8
  constructor(compiler) {
@@ -65,7 +65,7 @@
65
65
  } else {
66
66
  timestamps[file] = null;
67
67
  }
68
- resolve();
68
+ resolve(undefined);
69
69
  });
70
70
  }),
71
71
  ),
@@ -125,7 +125,6 @@
125
125
  });
126
126
  let mainCompilationHashOfLastChildRecompile = "";
127
127
  let previousFileSystemSnapshot;
128
- let compilationStartTime = Date.now();
129
128
  compiler.hooks.make.tapAsync(
130
129
  "PersistentChildCompilerSingletonPlugin",
131
130
  (mainCompilation, callback) => {
@@ -137,7 +136,6 @@
137
136
  new Error("Child compilation has already started"),
138
137
  );
139
138
  }
140
- compilationStartTime = Date.now();
141
139
  this.compilationState = {
142
140
  isCompiling: false,
143
141
  isVerifyingCache: true,
@@ -172,24 +170,6 @@
172
170
  return compiledEntriesPromise;
173
171
  },
174
172
  );
175
- mainCompilation.hooks.optimizeTree.tapAsync(
176
- "PersistentChildCompilerSingletonPlugin",
177
- (chunks, modules, callback) => {
178
- const handleCompilationDonePromise =
179
- childCompilationResultPromise.then(
180
- (childCompilationResult) => {
181
- this.watchFiles(
182
- mainCompilation,
183
- childCompilationResult.dependencies,
184
- );
185
- },
186
- );
187
- handleCompilationDonePromise.then(
188
- () => callback(null, chunks, modules),
189
- callback,
190
- );
191
- },
192
- );
193
173
  mainCompilation.hooks.additionalAssets.tapAsync(
194
174
  "PersistentChildCompilerSingletonPlugin",
195
175
  (callback) => {
@@ -227,6 +207,22 @@
227
207
  callback(null);
228
208
  },
229
209
  );
210
+ compiler.hooks.finishMake.tapAsync(
211
+ "PersistentChildCompilerSingletonPlugin",
212
+ (mainCompilation, callback) => {
213
+ if (mainCompilation.compiler !== compiler) {
214
+ return callback(null);
215
+ }
216
+ const handleCompilationDonePromise =
217
+ childCompilationResultPromise.then((childCompilationResult) => {
218
+ this.watchFiles(
219
+ mainCompilation,
220
+ childCompilationResult.dependencies,
221
+ );
222
+ });
223
+ handleCompilationDonePromise.then(() => callback(null), callback);
224
+ },
225
+ );
230
226
  }
231
227
  addEntry(entry) {
232
228
  if (
@@ -311,12 +307,12 @@
311
307
  }
312
308
  module.exports = { CachedChildCompilation };
313
309
  },
314
- 634: (module) => {
310
+ 284: (module) => {
315
311
  "use strict";
316
312
  class HtmlWebpackChildCompiler {
313
+ compilationPromise;
317
314
  constructor(templates) {
318
315
  this.templates = templates;
319
- this.compilationPromise;
320
316
  this.compilationStartedTimestamp;
321
317
  this.compilationEndedTimestamp;
322
318
  this.fileDependencies = {
@@ -480,26 +476,23 @@
480
476
  }
481
477
  module.exports = { HtmlWebpackChildCompiler };
482
478
  },
483
- 914: (module) => {
479
+ 876: (module) => {
484
480
  "use strict";
485
- module.exports = {};
486
- module.exports.none = (chunks) => chunks;
487
- module.exports.manual = (
488
- entryPointNames,
489
- compilation,
490
- htmlWebpackPluginOptions,
491
- ) => {
492
- const chunks = htmlWebpackPluginOptions.chunks;
481
+ function none(chunks) {
482
+ return chunks;
483
+ }
484
+ function manual(entryPointNames, compilation, htmlRspackPluginOptions) {
485
+ const chunks = htmlRspackPluginOptions.chunks;
493
486
  if (!Array.isArray(chunks)) {
494
487
  return entryPointNames;
495
488
  }
496
489
  return chunks.filter((entryPointName) =>
497
490
  compilation.entrypoints.has(entryPointName),
498
491
  );
499
- };
500
- module.exports.auto = module.exports.none;
492
+ }
493
+ module.exports = { auto: none, manual, none };
501
494
  },
502
- 253: (module) => {
495
+ 123: (module) => {
503
496
  "use strict";
504
497
  module.exports = function (err) {
505
498
  return {
@@ -523,9 +516,9 @@
523
516
  };
524
517
  };
525
518
  },
526
- 604: (module, __unused_webpack_exports, __nccwpck_require__) => {
519
+ 90: (module, __unused_webpack_exports, __nccwpck_require__) => {
527
520
  "use strict";
528
- const { AsyncSeriesWaterfallHook } = __nccwpck_require__(84);
521
+ const { AsyncSeriesWaterfallHook } = __nccwpck_require__(176);
529
522
  const htmlWebpackPluginHooksMap = new WeakMap();
530
523
  function getHtmlRspackPluginHooks(compilation) {
531
524
  let hooks = htmlWebpackPluginHooksMap.get(compilation);
@@ -549,7 +542,7 @@
549
542
  }
550
543
  module.exports = { getHtmlRspackPluginHooks };
551
544
  },
552
- 1: (module) => {
545
+ 527: (module) => {
553
546
  const voidTags = [
554
547
  "area",
555
548
  "base",
@@ -617,19 +610,19 @@
617
610
  htmlTagObjectToString,
618
611
  };
619
612
  },
620
- 28: (module, __unused_webpack_exports, __nccwpck_require__) => {
613
+ 718: (module, __unused_webpack_exports, __nccwpck_require__) => {
621
614
  "use strict";
622
615
  const promisify = __nccwpck_require__(23).promisify;
623
616
  const vm = __nccwpck_require__(154);
624
617
  const fs = __nccwpck_require__(896);
625
618
  const path = __nccwpck_require__(928);
626
- const { CachedChildCompilation } = __nccwpck_require__(25);
619
+ const { CachedChildCompilation } = __nccwpck_require__(535);
627
620
  const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } =
628
- __nccwpck_require__(1);
629
- const prettyError = __nccwpck_require__(253);
630
- const chunkSorter = __nccwpck_require__(914);
621
+ __nccwpck_require__(527);
622
+ const prettyError = __nccwpck_require__(123);
623
+ const chunkSorter = __nccwpck_require__(876);
631
624
  const getHtmlRspackPluginHooks =
632
- __nccwpck_require__(604).getHtmlRspackPluginHooks;
625
+ __nccwpck_require__(90).getHtmlRspackPluginHooks;
633
626
  const WITH_PLACEHOLDER = "function __with_placeholder__";
634
627
  class HtmlRspackPlugin {
635
628
  constructor(userOptions = {}) {
@@ -818,6 +811,7 @@
818
811
  { hash: compilation.hash },
819
812
  );
820
813
  const isPublicPathDefined = webpackPublicPath !== "auto";
814
+ const outputPath = compilation.options.output.path;
821
815
  let publicPath =
822
816
  customPublicPath !== "auto"
823
817
  ? customPublicPath
@@ -825,11 +819,8 @@
825
819
  ? webpackPublicPath
826
820
  : path
827
821
  .relative(
828
- path.resolve(
829
- compilation.options.output.path,
830
- path.dirname(filename),
831
- ),
832
- compilation.options.output.path,
822
+ path.resolve(outputPath, path.dirname(filename)),
823
+ outputPath,
833
824
  )
834
825
  .split(path.sep)
835
826
  .join("/");
@@ -1097,12 +1088,13 @@
1097
1088
  }
1098
1089
  const isProductionLikeMode =
1099
1090
  compiler.options.mode === "production" || !compiler.options.mode;
1091
+ const minify = this.options.minify;
1100
1092
  const needMinify =
1101
- typeof this.options.minify === "function" && isProductionLikeMode;
1093
+ typeof minify === "function" && isProductionLikeMode;
1102
1094
  if (!needMinify) {
1103
1095
  return Promise.resolve(html);
1104
1096
  }
1105
- return Promise.resolve(this.options.minify(html));
1097
+ return Promise.resolve(minify(html));
1106
1098
  }
1107
1099
  getAssetFiles(assets) {
1108
1100
  const uniq = (arr) => Array.from(new Set(arr));
@@ -1130,7 +1122,8 @@
1130
1122
  return Promise.resolve(undefined);
1131
1123
  }
1132
1124
  const filename = path.resolve(compilation.compiler.context, favicon);
1133
- return promisify(compilation.inputFileSystem.readFile)(filename)
1125
+ const inputFileSystem = compilation.inputFileSystem;
1126
+ return promisify(inputFileSystem.readFile)(filename)
1134
1127
  .then((buf) => {
1135
1128
  const source = new compiler.webpack.sources.RawSource(buf, false);
1136
1129
  const name = path.basename(filename);
@@ -1198,17 +1191,12 @@
1198
1191
  : metaTagContent;
1199
1192
  })
1200
1193
  .filter((attribute) => attribute !== false);
1201
- return metaTagAttributeObjects.map((metaTagAttributes) => {
1202
- if (metaTagAttributes === false) {
1203
- throw new Error("Invalid meta tag");
1204
- }
1205
- return {
1206
- tagName: "meta",
1207
- voidTag: true,
1208
- meta: { plugin: "html-webpack-plugin" },
1209
- attributes: metaTagAttributes,
1210
- };
1211
- });
1194
+ return metaTagAttributeObjects.map((metaTagAttributes) => ({
1195
+ tagName: "meta",
1196
+ voidTag: true,
1197
+ meta: { plugin: "html-webpack-plugin" },
1198
+ attributes: metaTagAttributes,
1199
+ }));
1212
1200
  }
1213
1201
  generateFaviconTag(favicon) {
1214
1202
  return [
@@ -1248,9 +1236,13 @@
1248
1236
  const hash = compiler.webpack.util.createHash(
1249
1237
  compilation.outputOptions.hashFunction,
1250
1238
  );
1251
- hash.update(fileContent);
1239
+ if (typeof fileContent === "string") {
1240
+ hash.update(fileContent, "utf8");
1241
+ } else {
1242
+ hash.update(fileContent);
1243
+ }
1252
1244
  if (compilation.outputOptions.hashSalt) {
1253
- hash.update(compilation.outputOptions.hashSalt);
1245
+ hash.update(compilation.outputOptions.hashSalt, "utf8");
1254
1246
  }
1255
1247
  const contentHash = hash
1256
1248
  .digest(compilation.outputOptions.hashDigest)
@@ -1528,7 +1520,7 @@
1528
1520
  "use strict";
1529
1521
  module.exports = require("vm");
1530
1522
  },
1531
- 84: (__unused_webpack_module, exports) => {
1523
+ 176: (__unused_webpack_module, exports) => {
1532
1524
  "use strict";
1533
1525
  var __nested_webpack_require_18__ = {};
1534
1526
  (() => {
@@ -2403,6 +2395,6 @@
2403
2395
  }
2404
2396
  if (typeof __nccwpck_require__ !== "undefined")
2405
2397
  __nccwpck_require__.ab = __dirname + "/";
2406
- var __webpack_exports__ = __nccwpck_require__(28);
2398
+ var __webpack_exports__ = __nccwpck_require__(718);
2407
2399
  module.exports = __webpack_exports__;
2408
2400
  })();
@@ -1 +1 @@
1
- {"name":"html-rspack-plugin","author":"Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)","version":"6.1.9","funding":{"type":"opencollective","url":"https://opencollective.com/html-webpack-plugin"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"html-rspack-plugin","author":"Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)","version":"6.1.11","funding":{"type":"opencollective","url":"https://opencollective.com/html-webpack-plugin"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -1,15 +1,15 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 54: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- module.exports = __nccwpck_require__(388)["default"];
4
+ 841: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ module.exports = __nccwpck_require__(147)["default"];
6
6
  },
7
- 388: (__unused_webpack_module, exports, __nccwpck_require__) => {
7
+ 147: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
8
  var __webpack_unused_export__;
9
9
  __webpack_unused_export__ = { value: true };
10
10
  exports["default"] = loader;
11
11
  var _nodePath = _interopRequireDefault(__nccwpck_require__(760));
12
- var _utils = __nccwpck_require__(637);
12
+ var _utils = __nccwpck_require__(870);
13
13
  function _interopRequireDefault(e) {
14
14
  return e && e.__esModule ? e : { default: e };
15
15
  }
@@ -179,7 +179,7 @@
179
179
  callback(null, result.css, map, { ast });
180
180
  }
181
181
  },
182
- 637: (module, exports, __nccwpck_require__) => {
182
+ 870: (module, exports, __nccwpck_require__) => {
183
183
  module = __nccwpck_require__.nmd(module);
184
184
  Object.defineProperty(exports, "__esModule", { value: true });
185
185
  exports.exec = exec;
@@ -716,6 +716,6 @@
716
716
  })();
717
717
  if (typeof __nccwpck_require__ !== "undefined")
718
718
  __nccwpck_require__.ab = __dirname + "/";
719
- var __webpack_exports__ = __nccwpck_require__(54);
719
+ var __webpack_exports__ = __nccwpck_require__(841);
720
720
  module.exports = __webpack_exports__;
721
721
  })();