@rspack/core 0.6.5-canary-5042eed-20240515115707 → 0.6.5-canary-b7b5c75-20240821125908

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 (149) hide show
  1. package/dist/Chunk.d.ts +1 -1
  2. package/dist/Chunk.js +1 -1
  3. package/dist/ChunkGroup.d.ts +1 -1
  4. package/dist/ChunkGroup.js +3 -3
  5. package/dist/Compilation.d.ts +65 -46
  6. package/dist/Compilation.js +222 -128
  7. package/dist/Compiler.d.ts +44 -75
  8. package/dist/Compiler.js +260 -301
  9. package/dist/Entrypoint.d.ts +1 -1
  10. package/dist/Entrypoint.js +1 -1
  11. package/dist/ExecuteModulePlugin.js +1 -1
  12. package/dist/Module.js +2 -2
  13. package/dist/MultiCompiler.d.ts +25 -10
  14. package/dist/MultiCompiler.js +3 -3
  15. package/dist/MultiStats.d.ts +1 -1
  16. package/dist/NormalModuleFactory.d.ts +1 -1
  17. package/dist/Stats.d.ts +2 -2
  18. package/dist/Watching.d.ts +9 -1
  19. package/dist/Watching.js +2 -15
  20. package/dist/builtin-loader/swc/index.d.ts +6 -6
  21. package/dist/builtin-loader/swc/index.js +3 -3
  22. package/dist/builtin-loader/swc/types.d.ts +2 -2
  23. package/dist/builtin-plugin/APIPlugin.d.ts +1 -1
  24. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +1 -1
  25. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +1 -1
  26. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +1 -1
  27. package/dist/builtin-plugin/BannerPlugin.d.ts +2 -2
  28. package/dist/builtin-plugin/BannerPlugin.js +1 -1
  29. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -1
  30. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +1 -1
  31. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +1 -1
  32. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +1 -1
  33. package/dist/builtin-plugin/CssModulesPlugin.d.ts +1 -1
  34. package/dist/builtin-plugin/DataUriPlugin.d.ts +1 -1
  35. package/dist/builtin-plugin/DefinePlugin.d.ts +1 -1
  36. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
  37. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
  38. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +1 -1
  39. package/dist/builtin-plugin/DynamicEntryPlugin.js +1 -1
  40. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +1 -1
  41. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +1 -1
  42. package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +1 -1
  43. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +1 -1
  44. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +1 -1
  45. package/dist/builtin-plugin/EntryPlugin.d.ts +1 -1
  46. package/dist/builtin-plugin/EntryPlugin.js +1 -1
  47. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +1 -1
  48. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +1 -1
  49. package/dist/builtin-plugin/ExternalsPlugin.d.ts +3 -3
  50. package/dist/builtin-plugin/FileUriPlugin.d.ts +1 -1
  51. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +1 -1
  52. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
  53. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +2 -2
  54. package/dist/builtin-plugin/HtmlRspackPlugin.js +2 -2
  55. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +1 -1
  56. package/dist/builtin-plugin/IgnorePlugin.d.ts +1 -1
  57. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +1 -1
  58. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +1 -1
  59. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +1 -1
  60. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +1 -1
  61. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +1 -1
  62. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +1 -1
  63. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
  64. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +1 -1
  65. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +1 -1
  66. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
  67. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +1 -1
  68. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +1 -1
  69. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +1 -1
  70. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  71. package/dist/builtin-plugin/ProvidePlugin.d.ts +1 -1
  72. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +1 -1
  73. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +1 -1
  74. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +1 -1
  75. package/dist/builtin-plugin/RuntimePlugin.d.ts +1 -1
  76. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +1 -1
  77. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +1 -1
  78. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +1 -1
  79. package/dist/builtin-plugin/SplitChunksPlugin.d.ts +2 -2
  80. package/dist/builtin-plugin/SplitChunksPlugin.js +4 -4
  81. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +1 -1
  82. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -1
  83. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.d.ts +1 -1
  84. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +1 -1
  85. package/dist/builtin-plugin/WorkerPlugin.d.ts +2 -2
  86. package/dist/builtin-plugin/base.d.ts +1 -1
  87. package/dist/builtin-plugin/base.js +1 -1
  88. package/dist/builtin-plugin/css-extract/index.d.ts +4 -5
  89. package/dist/builtin-plugin/css-extract/loader.d.ts +1 -1
  90. package/dist/builtin-plugin/css-extract/loader.js +2 -2
  91. package/dist/builtin-plugin/index.d.ts +43 -44
  92. package/dist/builtin-plugin/index.js +43 -44
  93. package/dist/config/adapter.d.ts +2 -2
  94. package/dist/config/adapter.js +5 -6
  95. package/dist/config/adapterRuleUse.d.ts +1 -2
  96. package/dist/config/adapterRuleUse.js +2 -2
  97. package/dist/config/defaults.js +4 -6
  98. package/dist/config/index.d.ts +2 -2
  99. package/dist/config/index.js +2 -2
  100. package/dist/config/normalization.d.ts +3 -2
  101. package/dist/config/normalization.js +1 -2
  102. package/dist/config/zod.d.ts +192 -328
  103. package/dist/config/zod.js +29 -17
  104. package/dist/container/ContainerPlugin.d.ts +1 -1
  105. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  106. package/dist/container/ContainerReferencePlugin.js +1 -1
  107. package/dist/container/ModuleFederationPlugin.js +1 -1
  108. package/dist/container/ModuleFederationPluginV1.d.ts +1 -1
  109. package/dist/container/ModuleFederationPluginV1.js +1 -1
  110. package/dist/container/ModuleFederationRuntimePlugin.d.ts +1 -1
  111. package/dist/exports.d.ts +30 -32
  112. package/dist/exports.js +17 -15
  113. package/dist/fileSystem.d.ts +8 -12
  114. package/dist/fileSystem.js +48 -25
  115. package/dist/index.d.ts +1 -1
  116. package/dist/index.js +1 -1
  117. package/dist/loader-runner/index.js +13 -13
  118. package/dist/logging/Logger.d.ts +1 -1
  119. package/dist/logging/createConsoleLogger.js +14 -0
  120. package/dist/node/NodeEnvironmentPlugin.d.ts +1 -1
  121. package/dist/node/NodeEnvironmentPlugin.js +1 -1
  122. package/dist/node/nodeConsole.js +4 -0
  123. package/dist/rspack.d.ts +13 -4
  124. package/dist/rspack.js +8 -8
  125. package/dist/rspackOptionsApply.d.ts +10 -1
  126. package/dist/rspackOptionsApply.js +6 -34
  127. package/dist/sharing/ConsumeSharedPlugin.d.ts +1 -1
  128. package/dist/sharing/ConsumeSharedPlugin.js +1 -1
  129. package/dist/stats/DefaultStatsFactoryPlugin.js +2 -2
  130. package/dist/stats/StatsFactory.d.ts +2 -2
  131. package/dist/stats/StatsFactory.js +9 -0
  132. package/dist/stats/StatsPrinter.d.ts +1 -1
  133. package/dist/stats/statsFactoryUtils.d.ts +1 -1
  134. package/dist/util/comparators.d.ts +1 -1
  135. package/dist/util/createSource.d.ts +5 -0
  136. package/dist/util/createSource.js +65 -0
  137. package/dist/util/fs.d.ts +0 -64
  138. package/dist/util/fs.js +0 -122
  139. package/dist/util/index.d.ts +1 -2
  140. package/dist/util/index.js +11 -16
  141. package/package.json +4 -4
  142. package/dist/builtin-plugin/lazy-compilation/backend.d.ts +0 -50
  143. package/dist/builtin-plugin/lazy-compilation/backend.js +0 -139
  144. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +0 -30
  145. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.js +0 -6
  146. package/dist/builtin-plugin/lazy-compilation/plugin.d.ts +0 -13
  147. package/dist/builtin-plugin/lazy-compilation/plugin.js +0 -60
  148. package/dist/util/source.d.ts +0 -18
  149. package/dist/util/source.js +0 -66
@@ -36,31 +36,40 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _Compilation_instances, _Compilation_inner, _Compilation_cachedAssets, _Compilation_createCachedAssets;
39
+ var _Compilation_inner;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Compilation = void 0;
42
+ /**
43
+ * The following code is modified based on
44
+ * https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/Compilation.js
45
+ *
46
+ * MIT Licensed
47
+ * Author Tobias Koppers @sokra
48
+ * Copyright (c) JS Foundation and other contributors
49
+ * https://github.com/webpack/webpack/blob/main/LICENSE
50
+ */
42
51
  const tapable = __importStar(require("tapable"));
43
52
  const liteTapable = __importStar(require("./lite-tapable"));
44
- const Chunk_1 = require("./Chunk");
45
- const ChunkGraph_1 = require("./ChunkGraph");
46
- const Entrypoint_1 = require("./Entrypoint");
47
53
  const ErrorHelpers_1 = __importDefault(require("./ErrorHelpers"));
48
54
  const Logger_1 = require("./logging/Logger");
49
- const Module_1 = require("./Module");
50
55
  const NormalModule_1 = require("./NormalModule");
51
56
  const Stats_1 = require("./Stats");
52
57
  const StatsFactory_1 = require("./stats/StatsFactory");
53
58
  const StatsPrinter_1 = require("./stats/StatsPrinter");
54
59
  const util_1 = require("./util");
60
+ const createSource_1 = require("./util/createSource");
55
61
  const fake_1 = require("./util/fake");
56
- const memoize_1 = require("./util/memoize");
57
62
  const MergeCaller_1 = __importDefault(require("./util/MergeCaller"));
58
- const source_1 = require("./util/source");
63
+ const memoize_1 = require("./util/memoize");
64
+ const Chunk_1 = require("./Chunk");
65
+ const Module_1 = require("./Module");
66
+ const ChunkGraph_1 = require("./ChunkGraph");
67
+ const Entrypoint_1 = require("./Entrypoint");
59
68
  class Compilation {
60
69
  constructor(compiler, inner) {
61
- _Compilation_instances.add(this);
62
70
  _Compilation_inner.set(this, void 0);
63
- _Compilation_cachedAssets.set(this, void 0);
71
+ this.childrenCounters = {};
72
+ this.children = [];
64
73
  this.fileSystemInfo = {
65
74
  createSnapshot() {
66
75
  // fake implement to support html-webpack-plugin
@@ -84,8 +93,9 @@ class Compilation {
84
93
  }
85
94
  });
86
95
  }, 10);
87
- __classPrivateFieldSet(this, _Compilation_inner, inner, "f");
88
- __classPrivateFieldSet(this, _Compilation_cachedAssets, __classPrivateFieldGet(this, _Compilation_instances, "m", _Compilation_createCachedAssets).call(this), "f");
96
+ this.name = undefined;
97
+ this.startTime = undefined;
98
+ this.endTime = undefined;
89
99
  const processAssetsHook = new liteTapable.AsyncSeriesHook([
90
100
  "assets"
91
101
  ]);
@@ -153,9 +163,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
153
163
  this.options = compiler.options;
154
164
  this.outputOptions = compiler.options.output;
155
165
  this.logging = new Map();
156
- this.childrenCounters = {};
157
- this.children = [];
158
166
  this.chunkGraph = new ChunkGraph_1.ChunkGraph(this);
167
+ __classPrivateFieldSet(this, _Compilation_inner, inner, "f");
168
+ // Cache the current NormalModuleHooks
159
169
  }
160
170
  get currentNormalModuleHooks() {
161
171
  return NormalModule_1.NormalModule.getCompilationHooks(this);
@@ -168,9 +178,48 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
168
178
  }
169
179
  /**
170
180
  * Get a map of all assets.
181
+ *
182
+ * Source: [assets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L1008-L1009)
171
183
  */
172
184
  get assets() {
173
- return __classPrivateFieldGet(this, _Compilation_cachedAssets, "f");
185
+ return new Proxy({}, {
186
+ get: (_, property) => {
187
+ if (typeof property === "string") {
188
+ return this.__internal__getAssetSource(property);
189
+ }
190
+ },
191
+ set: (target, p, newValue, receiver) => {
192
+ if (typeof p === "string") {
193
+ this.__internal__setAssetSource(p, newValue);
194
+ return true;
195
+ }
196
+ return false;
197
+ },
198
+ deleteProperty: (target, p) => {
199
+ if (typeof p === "string") {
200
+ this.__internal__deleteAssetSource(p);
201
+ return true;
202
+ }
203
+ return false;
204
+ },
205
+ has: (_, property) => {
206
+ if (typeof property === "string") {
207
+ return this.__internal__hasAsset(property);
208
+ }
209
+ return false;
210
+ },
211
+ ownKeys: _ => {
212
+ return this.__internal__getAssetFilenames();
213
+ },
214
+ getOwnPropertyDescriptor() {
215
+ // To work with `Object.keys`, you should mark the property as enumerable.
216
+ // See: https://262.ecma-international.org/7.0/#sec-enumerableownnames
217
+ return {
218
+ enumerable: true,
219
+ configurable: true
220
+ };
221
+ }
222
+ });
174
223
  }
175
224
  /**
176
225
  * Get a map of all entrypoints.
@@ -181,32 +230,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
181
230
  Entrypoint_1.Entrypoint.__from_binding(e, __classPrivateFieldGet(this, _Compilation_inner, "f"))
182
231
  ]));
183
232
  }
184
- get modules() {
185
- return (0, memoize_1.memoizeValue)(() => {
186
- return this.__internal__getModules().map(item => Module_1.Module.__from_binding(item));
187
- });
188
- }
189
- // FIXME: Webpack returns a `Set`
190
- get chunks() {
191
- return (0, memoize_1.memoizeValue)(() => {
192
- return this.__internal__getChunks();
193
- });
194
- }
195
- /**
196
- * Get the named chunks.
197
- *
198
- * Note: This is a proxy for webpack internal API, only method `get` is supported now.
199
- */
200
- get namedChunks() {
201
- return {
202
- get: (property) => {
203
- if (typeof property === "string") {
204
- const chunk = __classPrivateFieldGet(this, _Compilation_inner, "f").getNamedChunk(property) || undefined;
205
- return chunk && Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compilation_inner, "f"));
206
- }
207
- }
208
- };
209
- }
210
233
  getCache(name) {
211
234
  return this.compiler.getCache(name);
212
235
  }
@@ -268,17 +291,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
268
291
  /**
269
292
  * Update an existing asset. Trying to update an asset that doesn't exist will throw an error.
270
293
  *
294
+ * See: [Compilation.updateAsset](https://webpack.js.org/api/compilation-object/#updateasset)
295
+ * Source: [updateAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4320)
296
+ *
271
297
  * FIXME: *AssetInfo* may be undefined in update fn for webpack impl, but still not implemented in rspack
272
298
  */
273
299
  updateAsset(filename, newSourceOrFunction, assetInfoUpdateOrFunction) {
274
300
  let compatNewSourceOrFunction;
275
301
  if (typeof newSourceOrFunction === "function") {
276
302
  compatNewSourceOrFunction = function newSourceFunction(source) {
277
- return source_1.JsSource.__to_binding(newSourceOrFunction(source_1.JsSource.__from_binding(source)));
303
+ return (0, createSource_1.createRawFromSource)(newSourceOrFunction((0, createSource_1.createSourceFromRaw)(source)));
278
304
  };
279
305
  }
280
306
  else {
281
- compatNewSourceOrFunction = source_1.JsSource.__to_binding(newSourceOrFunction);
307
+ compatNewSourceOrFunction = (0, createSource_1.createRawFromSource)(newSourceOrFunction);
282
308
  }
283
309
  __classPrivateFieldGet(this, _Compilation_inner, "f").updateAsset(filename, compatNewSourceOrFunction, assetInfoUpdateOrFunction === undefined
284
310
  ? assetInfoUpdateOrFunction
@@ -289,12 +315,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
289
315
  /**
290
316
  * Emit an not existing asset. Trying to emit an asset that already exists will throw an error.
291
317
  *
318
+ * See: [Compilation.emitAsset](https://webpack.js.org/api/compilation-object/#emitasset)
319
+ * Source: [emitAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4239)
320
+ *
292
321
  * @param file - file name
293
322
  * @param source - asset source
294
323
  * @param assetInfo - extra asset information
295
324
  */
296
325
  emitAsset(filename, source, assetInfo) {
297
- __classPrivateFieldGet(this, _Compilation_inner, "f").emitAsset(filename, source_1.JsSource.__to_binding(source), (0, util_1.toJsAssetInfo)(assetInfo));
326
+ __classPrivateFieldGet(this, _Compilation_inner, "f").emitAsset(filename, (0, createSource_1.createRawFromSource)(source), (0, util_1.toJsAssetInfo)(assetInfo));
298
327
  }
299
328
  deleteAsset(filename) {
300
329
  __classPrivateFieldGet(this, _Compilation_inner, "f").deleteAsset(filename);
@@ -304,6 +333,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
304
333
  }
305
334
  /**
306
335
  * Get an array of Asset
336
+ *
337
+ * See: [Compilation.getAssets](https://webpack.js.org/api/compilation-object/#getassets)
338
+ * Source: [getAssets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4448)
307
339
  */
308
340
  getAssets() {
309
341
  const assets = __classPrivateFieldGet(this, _Compilation_inner, "f").getAssets();
@@ -322,19 +354,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
322
354
  get: () => this.__internal__getAssetSource(asset.name)
323
355
  });
324
356
  }
325
- /**
326
- * Note: This is not a webpack public API, maybe removed in future.
327
- *
328
- * @internal
329
- */
330
- __internal__pushDiagnostic(severity, title, message) {
357
+ pushDiagnostic(severity, title, message) {
331
358
  __classPrivateFieldGet(this, _Compilation_inner, "f").pushDiagnostic(severity, title, message);
332
359
  }
333
- /**
334
- * Note: This is not a webpack public API, maybe removed in future.
335
- *
336
- * @internal
337
- */
338
360
  __internal__pushNativeDiagnostics(diagnostics) {
339
361
  __classPrivateFieldGet(this, _Compilation_inner, "f").pushNativeDiagnostics(diagnostics);
340
362
  }
@@ -347,7 +369,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
347
369
  handler(target, thisArg, errs) {
348
370
  for (let i = 0; i < errs.length; i++) {
349
371
  const error = errs[i];
350
- inner.pushDiagnostic("error", error instanceof Error ? error.name : "Error", (0, util_1.concatErrorMsgAndStack)(error));
372
+ if ((0, util_1.isJsStatsError)(error)) {
373
+ inner.pushDiagnostic("error", "Error", (0, util_1.concatErrorMsgAndStack)(error));
374
+ }
375
+ else if (typeof error === "string") {
376
+ inner.pushDiagnostic("error", "Error", error);
377
+ }
378
+ else {
379
+ inner.pushDiagnostic("error", error.name, (0, util_1.concatErrorMsgAndStack)(error));
380
+ }
351
381
  }
352
382
  return Reflect.apply(target, thisArg, errs);
353
383
  }
@@ -370,11 +400,27 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
370
400
  method: "unshift",
371
401
  handler(target, thisArg, errs) {
372
402
  const errList = errs.map(error => {
373
- return {
374
- severity: "error",
375
- title: error instanceof Error ? error.name : "Error",
376
- message: (0, util_1.concatErrorMsgAndStack)(error)
377
- };
403
+ if ((0, util_1.isJsStatsError)(error)) {
404
+ return {
405
+ severity: "error",
406
+ title: "Error",
407
+ message: (0, util_1.concatErrorMsgAndStack)(error)
408
+ };
409
+ }
410
+ else if (typeof error === "string") {
411
+ return {
412
+ severity: "error",
413
+ title: "Error",
414
+ message: error
415
+ };
416
+ }
417
+ else {
418
+ return {
419
+ severity: "error",
420
+ title: error.name,
421
+ message: (0, util_1.concatErrorMsgAndStack)(error)
422
+ };
423
+ }
378
424
  });
379
425
  inner.spliceDiagnostic(0, 0, errList);
380
426
  return Reflect.apply(target, thisArg, errs);
@@ -384,11 +430,27 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
384
430
  method: "splice",
385
431
  handler(target, thisArg, [startIdx, delCount, ...errors]) {
386
432
  const errList = errors.map(error => {
387
- return {
388
- severity: "error",
389
- title: error instanceof Error ? error.name : "Error",
390
- message: (0, util_1.concatErrorMsgAndStack)(error)
391
- };
433
+ if ((0, util_1.isJsStatsError)(error)) {
434
+ return {
435
+ severity: "error",
436
+ title: "Error",
437
+ message: (0, util_1.concatErrorMsgAndStack)(error)
438
+ };
439
+ }
440
+ else if (typeof error === "string") {
441
+ return {
442
+ severity: "error",
443
+ title: "Error",
444
+ message: error
445
+ };
446
+ }
447
+ else {
448
+ return {
449
+ severity: "error",
450
+ title: error.name,
451
+ message: (0, util_1.concatErrorMsgAndStack)(error)
452
+ };
453
+ }
392
454
  });
393
455
  inner.spliceDiagnostic(startIdx, startIdx + delCount, errList);
394
456
  return Reflect.apply(target, thisArg, [
@@ -418,7 +480,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
418
480
  warns = processWarningsHook.call(warns);
419
481
  for (let i = 0; i < warns.length; i++) {
420
482
  const warn = warns[i];
421
- inner.pushDiagnostic("warning", warn instanceof Error ? warn.name : "Warning", (0, util_1.concatErrorMsgAndStack)(warn));
483
+ inner.pushDiagnostic("warning", (0, util_1.isJsStatsError)(warn) ? "Warning" : warn.name, (0, util_1.concatErrorMsgAndStack)(warn));
422
484
  }
423
485
  return Reflect.apply(target, thisArg, warns);
424
486
  }
@@ -444,7 +506,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
444
506
  const warnList = warns.map(warn => {
445
507
  return {
446
508
  severity: "warning",
447
- title: warn instanceof Error ? warn.name : "Warning",
509
+ title: (0, util_1.isJsStatsError)(warn) ? "Warning" : warn.name,
448
510
  message: (0, util_1.concatErrorMsgAndStack)(warn)
449
511
  };
450
512
  });
@@ -459,7 +521,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
459
521
  const warnList = warns.map(warn => {
460
522
  return {
461
523
  severity: "warning",
462
- title: warn instanceof Error ? warn.name : "Warning",
524
+ title: (0, util_1.isJsStatsError)(warn) ? "Warning" : warn.name,
463
525
  message: (0, util_1.concatErrorMsgAndStack)(warn)
464
526
  };
465
527
  });
@@ -517,6 +579,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
517
579
  const logEntry = {
518
580
  time: Date.now(),
519
581
  type,
582
+ // @ts-expect-error
520
583
  args,
521
584
  // @ts-expect-error
522
585
  trace
@@ -590,6 +653,94 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
590
653
  }
591
654
  });
592
655
  }
656
+ get modules() {
657
+ return (0, memoize_1.memoizeValue)(() => {
658
+ return this.__internal__getModules().map(item => Module_1.Module.__from_binding(item));
659
+ });
660
+ }
661
+ // FIXME: This is not aligned with Webpack.
662
+ get chunks() {
663
+ return (0, memoize_1.memoizeValue)(() => {
664
+ return this.__internal__getChunks();
665
+ });
666
+ }
667
+ /**
668
+ * Get the named chunks.
669
+ *
670
+ * Note: This is a proxy for webpack internal API, only method `get` is supported now.
671
+ */
672
+ get namedChunks() {
673
+ return {
674
+ get: (property) => {
675
+ if (typeof property === "string") {
676
+ const chunk = __classPrivateFieldGet(this, _Compilation_inner, "f").getNamedChunk(property);
677
+ return chunk && Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compilation_inner, "f"));
678
+ }
679
+ }
680
+ };
681
+ }
682
+ /**
683
+ * Get the associated `modules` of an given chunk.
684
+ *
685
+ * Note: This is not a webpack public API, maybe removed in future.
686
+ *
687
+ * @internal
688
+ */
689
+ __internal__getAssociatedModules(chunk) {
690
+ var _a;
691
+ const modules = this.__internal__getModules();
692
+ const moduleMap = new Map();
693
+ for (const module of modules) {
694
+ moduleMap.set(module.moduleIdentifier, module);
695
+ }
696
+ return (_a = chunk.modules) === null || _a === void 0 ? void 0 : _a.flatMap(chunkModule => {
697
+ var _a;
698
+ const jsModule = this.__internal__findJsModule((_a = chunkModule.issuer) !== null && _a !== void 0 ? _a : chunkModule.identifier, moduleMap);
699
+ return {
700
+ ...jsModule
701
+ // dependencies: chunkModule.reasons?.flatMap(jsReason => {
702
+ // let jsOriginModule = this.__internal__findJsModule(
703
+ // jsReason.moduleIdentifier ?? "",
704
+ // moduleMap
705
+ // );
706
+ // return {
707
+ // ...jsReason,
708
+ // originModule: jsOriginModule
709
+ // };
710
+ // })
711
+ };
712
+ });
713
+ }
714
+ /**
715
+ * Find a modules in an array.
716
+ *
717
+ * Note: This is not a webpack public API, maybe removed in future.
718
+ *
719
+ * @internal
720
+ */
721
+ __internal__findJsModule(identifier, modules) {
722
+ return modules.get(identifier);
723
+ }
724
+ /**
725
+ *
726
+ * Note: This is not a webpack public API, maybe removed in future.
727
+ *
728
+ * @internal
729
+ */
730
+ __internal__getModules() {
731
+ return __classPrivateFieldGet(this, _Compilation_inner, "f").getModules();
732
+ }
733
+ /**
734
+ *
735
+ * Note: This is not a webpack public API, maybe removed in future.
736
+ *
737
+ * @internal
738
+ */
739
+ __internal__getChunks() {
740
+ return __classPrivateFieldGet(this, _Compilation_inner, "f")
741
+ .getChunks()
742
+ .map(c => Chunk_1.Chunk.__from_binding(c, __classPrivateFieldGet(this, _Compilation_inner, "f")));
743
+ }
593
744
  getStats() {
594
745
  return new Stats_1.Stats(this);
595
746
  }
@@ -613,7 +764,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
613
764
  if (!rawSource) {
614
765
  return;
615
766
  }
616
- return source_1.JsSource.__from_binding(rawSource);
767
+ return (0, createSource_1.createSourceFromRaw)(rawSource);
617
768
  }
618
769
  /**
619
770
  * Set the `Source` of an given asset filename.
@@ -623,7 +774,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
623
774
  * @internal
624
775
  */
625
776
  __internal__setAssetSource(filename, source) {
626
- __classPrivateFieldGet(this, _Compilation_inner, "f").setAssetSource(filename, source_1.JsSource.__to_binding(source));
777
+ __classPrivateFieldGet(this, _Compilation_inner, "f").setAssetSource(filename, (0, createSource_1.createRawFromSource)(source));
627
778
  }
628
779
  /**
629
780
  * Delete the `Source` of an given asset filename.
@@ -655,70 +806,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
655
806
  __internal__hasAsset(name) {
656
807
  return __classPrivateFieldGet(this, _Compilation_inner, "f").hasAsset(name);
657
808
  }
658
- /**
659
- * Note: This is not a webpack public API, maybe removed in future.
660
- *
661
- * @internal
662
- */
663
- __internal__getModules() {
664
- return __classPrivateFieldGet(this, _Compilation_inner, "f").getModules();
665
- }
666
- /**
667
- * Note: This is not a webpack public API, maybe removed in future.
668
- *
669
- * @internal
670
- */
671
- __internal__getChunks() {
672
- return __classPrivateFieldGet(this, _Compilation_inner, "f")
673
- .getChunks()
674
- .map(c => Chunk_1.Chunk.__from_binding(c, __classPrivateFieldGet(this, _Compilation_inner, "f")));
675
- }
676
809
  __internal_getInner() {
677
810
  return __classPrivateFieldGet(this, _Compilation_inner, "f");
678
811
  }
679
812
  seal() { }
680
813
  unseal() { }
681
814
  }
682
- _Compilation_inner = new WeakMap(), _Compilation_cachedAssets = new WeakMap(), _Compilation_instances = new WeakSet(), _Compilation_createCachedAssets = function _Compilation_createCachedAssets() {
683
- return new Proxy({}, {
684
- get: (_, property) => {
685
- if (typeof property === "string") {
686
- return this.__internal__getAssetSource(property);
687
- }
688
- },
689
- set: (_, p, newValue) => {
690
- if (typeof p === "string") {
691
- this.__internal__setAssetSource(p, newValue);
692
- return true;
693
- }
694
- return false;
695
- },
696
- deleteProperty: (_, p) => {
697
- if (typeof p === "string") {
698
- this.__internal__deleteAssetSource(p);
699
- return true;
700
- }
701
- return false;
702
- },
703
- has: (_, property) => {
704
- if (typeof property === "string") {
705
- return this.__internal__hasAsset(property);
706
- }
707
- return false;
708
- },
709
- ownKeys: _ => {
710
- return this.__internal__getAssetFilenames();
711
- },
712
- getOwnPropertyDescriptor() {
713
- // To work with `Object.keys`, you should mark the property as enumerable.
714
- // See: https://262.ecma-international.org/7.0/#sec-enumerableownnames
715
- return {
716
- enumerable: true,
717
- configurable: true
718
- };
719
- }
720
- });
721
- };
815
+ _Compilation_inner = new WeakMap();
722
816
  Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL = -2000;
723
817
  Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS = -1000;
724
818
  Compilation.PROCESS_ASSETS_STAGE_DERIVED = -200;