@rspack/core 1.0.0-beta.2 → 1.0.0-beta.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.
Files changed (65) hide show
  1. package/dist/Compilation.d.ts +21 -8
  2. package/dist/Compilation.js +114 -57
  3. package/dist/Compiler.d.ts +1 -0
  4. package/dist/Compiler.js +29 -24
  5. package/dist/DependenciesBlock.d.ts +8 -0
  6. package/dist/DependenciesBlock.js +30 -0
  7. package/dist/Dependency.d.ts +8 -0
  8. package/dist/Dependency.js +32 -0
  9. package/dist/Module.d.ts +6 -3
  10. package/dist/Module.js +13 -0
  11. package/dist/MultiCompiler.js +10 -6
  12. package/dist/MultiStats.d.ts +1 -1
  13. package/dist/MultiStats.js +19 -16
  14. package/dist/NormalModule.js +3 -4
  15. package/dist/Stats.d.ts +1 -1
  16. package/dist/Template.d.ts +4 -4
  17. package/dist/Template.js +6 -4
  18. package/dist/Watching.js +3 -5
  19. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +11 -10
  20. package/dist/builtin-plugin/DynamicEntryPlugin.js +26 -15
  21. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  22. package/dist/builtin-plugin/ExternalsPlugin.d.ts +4 -4
  23. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +21 -4
  24. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +29 -5
  25. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +4 -6
  26. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +16 -10
  27. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +11 -9
  28. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +28 -17
  29. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +1 -1
  30. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +2 -2
  31. package/dist/builtin-plugin/css-extract/loader.js +1 -2
  32. package/dist/config/adapter.d.ts +2 -2
  33. package/dist/config/defaults.js +9 -6
  34. package/dist/config/zod.d.ts +537 -141
  35. package/dist/config/zod.js +18 -10
  36. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  37. package/dist/exports.d.ts +4 -3
  38. package/dist/exports.js +5 -2
  39. package/dist/lib/Cache.js +6 -4
  40. package/dist/lib/CacheFacade.js +8 -9
  41. package/dist/lib/LoaderOptionsPlugin.d.ts +4 -2
  42. package/dist/lib/LoaderOptionsPlugin.js +0 -2
  43. package/dist/lib/cache/mergeEtags.d.ts +3 -3
  44. package/dist/lib/cache/mergeEtags.js +5 -3
  45. package/dist/loader-runner/index.js +4 -2
  46. package/dist/node/nodeConsole.js +5 -5
  47. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +0 -10
  48. package/dist/stats/DefaultStatsFactoryPlugin.js +130 -90
  49. package/dist/stats/DefaultStatsPresetPlugin.js +17 -18
  50. package/dist/stats/StatsFactory.js +8 -10
  51. package/dist/stats/StatsPrinter.js +3 -4
  52. package/dist/stats/statsFactoryUtils.d.ts +119 -19
  53. package/dist/stats/statsFactoryUtils.js +62 -1
  54. package/dist/util/assertNotNil.d.ts +1 -1
  55. package/dist/util/assetCondition.d.ts +2 -0
  56. package/dist/util/assetCondition.js +2 -0
  57. package/dist/util/cleverMerge.js +5 -4
  58. package/dist/util/createHash.js +10 -5
  59. package/dist/util/hash/wasm-hash.js +5 -4
  60. package/dist/util/identifier.d.ts +4 -4
  61. package/dist/util/identifier.js +10 -10
  62. package/dist/util/memoize.js +3 -2
  63. package/package.json +3 -3
  64. package/dist/builtin-plugin/css-extract/loader-options.json +0 -37
  65. package/dist/builtin-plugin/css-extract/plugin-options.json +0 -79
@@ -8,7 +8,7 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type * as binding from "@rspack/binding";
11
- import { type ExternalObject, type JsCompilation, type JsModule, type JsPathData, type JsRuntimeModule } from "@rspack/binding";
11
+ import { type ExternalObject, type JsCompilation, type JsPathData, type JsRuntimeModule } from "@rspack/binding";
12
12
  import * as liteTapable from "@rspack/lite-tapable";
13
13
  import type { Source } from "../compiled/webpack-sources";
14
14
  import { Chunk } from "./Chunk";
@@ -167,6 +167,7 @@ export declare class Compilation {
167
167
  Set<string>
168
168
  ], void>;
169
169
  runtimeModule: RuntimeModule;
170
+ seal: liteTapable.SyncHook<[], void>;
170
171
  afterSeal: liteTapable.AsyncSeriesHook<[], void>;
171
172
  }>;
172
173
  name?: string;
@@ -210,6 +211,7 @@ export declare class Compilation {
210
211
  * Note: This is a proxy for webpack internal API, only method `get` and `keys` is supported now.
211
212
  */
212
213
  get namedChunks(): ReadonlyMap<string, Readonly<Chunk>>;
214
+ get entries(): Map<string, EntryData>;
213
215
  /**
214
216
  * Note: This is not a webpack public API, maybe removed in future.
215
217
  *
@@ -220,7 +222,7 @@ export declare class Compilation {
220
222
  buildMeta: Record<string, unknown>;
221
223
  };
222
224
  getCache(name: string): import("./lib/CacheFacade").CacheFacade;
223
- createStatsOptions(optionsOrPreset: StatsValue | undefined, context?: CreateStatsOptionsContext): NormalizedStatsOptions;
225
+ createStatsOptions(statsValue: StatsValue | undefined, context?: CreateStatsOptionsContext): NormalizedStatsOptions;
224
226
  createStatsFactory(options: StatsOptions): StatsFactory;
225
227
  createStatsPrinter(options: StatsOptions): StatsPrinter;
226
228
  /**
@@ -336,12 +338,6 @@ export declare class Compilation {
336
338
  * @internal
337
339
  */
338
340
  __internal__hasAsset(name: string): boolean;
339
- /**
340
- * Note: This is not a webpack public API, maybe removed in future.
341
- *
342
- * @internal
343
- */
344
- __internal__getModules(): JsModule[];
345
341
  /**
346
342
  * Note: This is not a webpack public API, maybe removed in future.
347
343
  *
@@ -373,3 +369,20 @@ export declare class Compilation {
373
369
  static PROCESS_ASSETS_STAGE_ANALYSE: number;
374
370
  static PROCESS_ASSETS_STAGE_REPORT: number;
375
371
  }
372
+ export type EntryData = binding.JsEntryData;
373
+ export declare class Entries implements Map<string, EntryData> {
374
+ #private;
375
+ constructor(data: binding.JsEntries);
376
+ clear(): void;
377
+ forEach(callback: (value: binding.JsEntryData, key: string, map: Map<string, binding.JsEntryData>) => void, thisArg?: any): void;
378
+ get size(): number;
379
+ entries(): IterableIterator<[string, binding.JsEntryData]>;
380
+ values(): IterableIterator<binding.JsEntryData>;
381
+ [Symbol.iterator](): IterableIterator<[string, binding.JsEntryData]>;
382
+ get [Symbol.toStringTag](): string;
383
+ has(key: string): boolean;
384
+ set(key: string, value: EntryData): this;
385
+ delete(key: string): boolean;
386
+ get(key: string): EntryData | undefined;
387
+ keys(): IterableIterator<string>;
388
+ }
@@ -36,9 +36,9 @@ 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_customModules, _Compilation_createCachedAssets, _Compilation_rebuildModuleCaller;
39
+ var _Compilation_instances, _Compilation_inner, _Compilation_customModules, _Compilation_createCachedAssets, _Compilation_rebuildModuleCaller, _Entries_data;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.Compilation = void 0;
41
+ exports.Entries = exports.Compilation = void 0;
42
42
  const binding_1 = require("@rspack/binding");
43
43
  const liteTapable = __importStar(require("@rspack/lite-tapable"));
44
44
  const Chunk_1 = require("./Chunk");
@@ -72,10 +72,10 @@ class Compilation {
72
72
  * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
73
73
  */
74
74
  _Compilation_customModules.set(this, void 0);
75
- this.fileDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getFileDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addFileDependencies(d));
76
- this.contextDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getContextDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addContextDependencies(d));
77
- this.missingDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getMissingDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addMissingDependencies(d));
78
- this.buildDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getBuildDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addBuildDependencies(d));
75
+ this.fileDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().fileDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addFileDependencies(d));
76
+ this.contextDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().contextDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addContextDependencies(d));
77
+ this.missingDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().missingDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addMissingDependencies(d));
78
+ this.buildDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").dependencies().buildDependencies, d => __classPrivateFieldGet(this, _Compilation_inner, "f").addBuildDependencies(d));
79
79
  _Compilation_rebuildModuleCaller.set(this, ((compilation) => new MergeCaller_1.default((args) => {
80
80
  __classPrivateFieldGet(compilation, _Compilation_inner, "f").rebuildModule(args.map(item => item[0]), (err, modules) => {
81
81
  for (const [id, callback] of args) {
@@ -98,12 +98,14 @@ class Compilation {
98
98
  const errorMessage = (reason) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
99
99
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
100
100
  const getOptions = (options) => {
101
- if (typeof options === "string")
102
- options = { name: options };
103
- if (options.stage) {
101
+ const isString = typeof options === "string";
102
+ if (!isString && options.stage) {
104
103
  throw new Error(errorMessage("it's using the 'stage' option"));
105
104
  }
106
- return { ...options, stage: stage };
105
+ return {
106
+ ...(isString ? { name: options } : options),
107
+ stage: stage
108
+ };
107
109
  };
108
110
  return Object.freeze({
109
111
  name,
@@ -157,6 +159,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
157
159
  "runtimeRequirements"
158
160
  ]),
159
161
  runtimeModule: new liteTapable.SyncHook(["module", "chunk"]),
162
+ seal: new liteTapable.SyncHook([]),
160
163
  afterSeal: new liteTapable.AsyncSeriesHook([])
161
164
  };
162
165
  this.compiler = compiler;
@@ -213,7 +216,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
213
216
  };
214
217
  }
215
218
  get modules() {
216
- return (0, memoize_1.memoizeValue)(() => new Set(this.__internal__getModules().map(item => Module_1.Module.__from_binding(item, this))));
219
+ return new Set(__classPrivateFieldGet(this, _Compilation_inner, "f").modules.map(module => Module_1.Module.__from_binding(module, this)));
217
220
  }
218
221
  get chunks() {
219
222
  return (0, memoize_1.memoizeValue)(() => new Set(this.__internal__getChunks()));
@@ -237,6 +240,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
237
240
  }
238
241
  };
239
242
  }
243
+ get entries() {
244
+ return new Entries(__classPrivateFieldGet(this, _Compilation_inner, "f").entries);
245
+ }
240
246
  /**
241
247
  * Note: This is not a webpack public API, maybe removed in future.
242
248
  *
@@ -255,7 +261,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
255
261
  getCache(name) {
256
262
  return this.compiler.getCache(name);
257
263
  }
258
- createStatsOptions(optionsOrPreset, context = {}) {
264
+ createStatsOptions(statsValue, context = {}) {
265
+ let optionsOrPreset = statsValue;
259
266
  if (typeof optionsOrPreset === "boolean" ||
260
267
  typeof optionsOrPreset === "string") {
261
268
  optionsOrPreset = { preset: optionsOrPreset };
@@ -448,12 +455,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
448
455
  {
449
456
  method: "push",
450
457
  handler(target, thisArg, warns) {
451
- warns = processWarningsHook.call(warns);
452
- for (let i = 0; i < warns.length; i++) {
453
- const warn = warns[i];
458
+ return Reflect.apply(target, thisArg, processWarningsHook.call(warns).map(warn => {
454
459
  inner.pushDiagnostic(RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn));
455
- }
456
- return Reflect.apply(target, thisArg, warns);
460
+ return warn;
461
+ }));
457
462
  }
458
463
  },
459
464
  {
@@ -473,12 +478,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
473
478
  {
474
479
  method: "unshift",
475
480
  handler(target, thisArg, warns) {
476
- warns = processWarningsHook.call(warns);
477
- const warnList = warns.map(warn => {
481
+ const warnings = processWarningsHook.call(warns);
482
+ inner.spliceDiagnostic(0, 0, warnings.map(warn => {
478
483
  return RspackError_1.JsDiagnostic.__to_binding(warn, binding_1.JsRspackSeverity.Warn);
479
- });
480
- inner.spliceDiagnostic(0, 0, warnList);
481
- return Reflect.apply(target, thisArg, warns);
484
+ }));
485
+ return Reflect.apply(target, thisArg, warnings);
482
486
  }
483
487
  },
484
488
  {
@@ -521,11 +525,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
521
525
  if (!name) {
522
526
  throw new TypeError("Compilation.getLogger(name) called without a name");
523
527
  }
528
+ let logName = name;
524
529
  let logEntries;
525
530
  return new Logger_1.Logger((type, args) => {
526
- if (typeof name === "function") {
527
- name = name();
528
- if (!name) {
531
+ if (typeof logName === "function") {
532
+ logName = logName();
533
+ if (!logName) {
529
534
  throw new TypeError("Compilation.getLogger(name) called with a function not returning a name");
530
535
  }
531
536
  }
@@ -545,67 +550,68 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
545
550
  args,
546
551
  trace
547
552
  };
548
- if (this.hooks.log.call(name, logEntry) === undefined) {
553
+ if (this.hooks.log.call(logName, logEntry) === undefined) {
549
554
  if (logEntry.type === Logger_1.LogType.profileEnd) {
550
555
  if (typeof console.profileEnd === "function") {
551
- console.profileEnd(`[${name}] ${logEntry.args[0]}`);
556
+ console.profileEnd(`[${logName}] ${logEntry.args[0]}`);
552
557
  }
553
558
  }
554
559
  if (logEntries === undefined) {
555
- logEntries = this.logging.get(name);
560
+ logEntries = this.logging.get(logName);
556
561
  if (logEntries === undefined) {
557
562
  logEntries = [];
558
- this.logging.set(name, logEntries);
563
+ this.logging.set(logName, logEntries);
559
564
  }
560
565
  }
561
566
  logEntries.push(logEntry);
562
567
  if (logEntry.type === Logger_1.LogType.profile) {
563
568
  if (typeof console.profile === "function") {
564
- console.profile(`[${name}] ${logEntry.args[0]}`);
569
+ console.profile(`[${logName}] ${logEntry.args[0]}`);
565
570
  }
566
571
  }
567
572
  }
568
573
  }, (childName) => {
569
- if (typeof name === "function") {
570
- if (typeof childName === "function") {
574
+ let normalizedChildName = childName;
575
+ if (typeof logName === "function") {
576
+ if (typeof normalizedChildName === "function") {
571
577
  return this.getLogger(() => {
572
- if (typeof name === "function") {
573
- name = name();
574
- if (!name) {
578
+ if (typeof logName === "function") {
579
+ logName = logName();
580
+ if (!logName) {
575
581
  throw new TypeError("Compilation.getLogger(name) called with a function not returning a name");
576
582
  }
577
583
  }
578
- if (typeof childName === "function") {
579
- childName = childName();
580
- if (!childName) {
584
+ if (typeof normalizedChildName === "function") {
585
+ normalizedChildName = normalizedChildName();
586
+ if (!normalizedChildName) {
581
587
  throw new TypeError("Logger.getChildLogger(name) called with a function not returning a name");
582
588
  }
583
589
  }
584
- return `${name}/${childName}`;
590
+ return `${logName}/${normalizedChildName}`;
585
591
  });
586
592
  }
587
593
  return this.getLogger(() => {
588
- if (typeof name === "function") {
589
- name = name();
590
- if (!name) {
594
+ if (typeof logName === "function") {
595
+ logName = logName();
596
+ if (!logName) {
591
597
  throw new TypeError("Compilation.getLogger(name) called with a function not returning a name");
592
598
  }
593
599
  }
594
- return `${name}/${childName}`;
600
+ return `${logName}/${normalizedChildName}`;
595
601
  });
596
602
  }
597
- if (typeof childName === "function") {
603
+ if (typeof normalizedChildName === "function") {
598
604
  return this.getLogger(() => {
599
- if (typeof childName === "function") {
600
- childName = childName();
601
- if (!childName) {
605
+ if (typeof normalizedChildName === "function") {
606
+ normalizedChildName = normalizedChildName();
607
+ if (!normalizedChildName) {
602
608
  throw new TypeError("Logger.getChildLogger(name) called with a function not returning a name");
603
609
  }
604
610
  }
605
- return `${name}/${childName}`;
611
+ return `${logName}/${normalizedChildName}`;
606
612
  });
607
613
  }
608
- return this.getLogger(`${name}/${childName}`);
614
+ return this.getLogger(`${logName}/${normalizedChildName}`);
609
615
  });
610
616
  }
611
617
  getStats() {
@@ -673,14 +679,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
673
679
  __internal__hasAsset(name) {
674
680
  return __classPrivateFieldGet(this, _Compilation_inner, "f").hasAsset(name);
675
681
  }
676
- /**
677
- * Note: This is not a webpack public API, maybe removed in future.
678
- *
679
- * @internal
680
- */
681
- __internal__getModules() {
682
- return __classPrivateFieldGet(this, _Compilation_inner, "f").getModules();
683
- }
684
682
  /**
685
683
  * Note: This is not a webpack public API, maybe removed in future.
686
684
  *
@@ -759,3 +757,62 @@ Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER = 3000;
759
757
  Compilation.PROCESS_ASSETS_STAGE_ANALYSE = 4000;
760
758
  Compilation.PROCESS_ASSETS_STAGE_REPORT = 5000;
761
759
  exports.Compilation = Compilation;
760
+ class Entries {
761
+ constructor(data) {
762
+ _Entries_data.set(this, void 0);
763
+ __classPrivateFieldSet(this, _Entries_data, data, "f");
764
+ }
765
+ clear() {
766
+ __classPrivateFieldGet(this, _Entries_data, "f").clear();
767
+ }
768
+ forEach(callback, thisArg) {
769
+ for (const [key, value] of this) {
770
+ callback.call(thisArg, value, key, this);
771
+ }
772
+ }
773
+ get size() {
774
+ return __classPrivateFieldGet(this, _Entries_data, "f").size;
775
+ }
776
+ entries() {
777
+ const self = this;
778
+ const keys = this.keys();
779
+ return {
780
+ [Symbol.iterator]() {
781
+ return this;
782
+ },
783
+ next() {
784
+ const { done, value } = keys.next();
785
+ return {
786
+ done,
787
+ value: done ? undefined : [value, self.get(value)]
788
+ };
789
+ }
790
+ };
791
+ }
792
+ values() {
793
+ return __classPrivateFieldGet(this, _Entries_data, "f").values()[Symbol.iterator]();
794
+ }
795
+ [(_Entries_data = new WeakMap(), Symbol.iterator)]() {
796
+ return this.entries();
797
+ }
798
+ get [Symbol.toStringTag]() {
799
+ return "Map";
800
+ }
801
+ has(key) {
802
+ return __classPrivateFieldGet(this, _Entries_data, "f").has(key);
803
+ }
804
+ set(key, value) {
805
+ __classPrivateFieldGet(this, _Entries_data, "f").set(key, value);
806
+ return this;
807
+ }
808
+ delete(key) {
809
+ return __classPrivateFieldGet(this, _Entries_data, "f").delete(key);
810
+ }
811
+ get(key) {
812
+ return __classPrivateFieldGet(this, _Entries_data, "f").get(key);
813
+ }
814
+ keys() {
815
+ return __classPrivateFieldGet(this, _Entries_data, "f").keys()[Symbol.iterator]();
816
+ }
817
+ }
818
+ exports.Entries = Entries;
@@ -69,6 +69,7 @@ declare class Compiler {
69
69
  entryOption: liteTapable.SyncBailHook<[string, EntryNormalized], any>;
70
70
  };
71
71
  webpack: typeof rspack;
72
+ rspack: typeof rspack;
72
73
  name?: string;
73
74
  parentCompilation?: Compilation;
74
75
  root: Compiler;
package/dist/Compiler.js CHANGED
@@ -137,6 +137,7 @@ class Compiler {
137
137
  entryOption: new liteTapable.SyncBailHook(["context", "entry"])
138
138
  };
139
139
  this.webpack = index_1.rspack;
140
+ this.rspack = index_1.rspack;
140
141
  this.root = this;
141
142
  this.outputPath = "";
142
143
  this.inputFileSystem = null;
@@ -199,62 +200,65 @@ class Compiler {
199
200
  if (!name) {
200
201
  throw new TypeError("Compiler.getInfrastructureLogger(name) called without a name");
201
202
  }
203
+ let normalizedName = name;
202
204
  return new Logger_1.Logger((type, args) => {
203
- if (typeof name === "function") {
204
- name = name();
205
- if (!name) {
205
+ if (typeof normalizedName === "function") {
206
+ normalizedName = normalizedName();
207
+ if (!normalizedName) {
206
208
  throw new TypeError("Compiler.getInfrastructureLogger(name) called with a function not returning a name");
207
209
  }
208
210
  }
209
211
  else {
210
- if (this.hooks.infrastructureLog.call(name, type, args) === undefined) {
212
+ if (this.hooks.infrastructureLog.call(normalizedName, type, args) ===
213
+ undefined) {
211
214
  if (this.infrastructureLogger !== undefined) {
212
- this.infrastructureLogger(name, type, args);
215
+ this.infrastructureLogger(normalizedName, type, args);
213
216
  }
214
217
  }
215
218
  }
216
219
  }, (childName) => {
217
- if (typeof name === "function") {
218
- if (typeof childName === "function") {
220
+ let normalizedChildName = childName;
221
+ if (typeof normalizedName === "function") {
222
+ if (typeof normalizedChildName === "function") {
219
223
  // @ts-expect-error
220
224
  return this.getInfrastructureLogger(_ => {
221
- if (typeof name === "function") {
222
- name = name();
223
- if (!name) {
225
+ if (typeof normalizedName === "function") {
226
+ normalizedName = normalizedName();
227
+ if (!normalizedName) {
224
228
  throw new TypeError("Compiler.getInfrastructureLogger(name) called with a function not returning a name");
225
229
  }
226
230
  }
227
- if (typeof childName === "function") {
228
- childName = childName();
229
- if (!childName) {
231
+ if (typeof normalizedChildName === "function") {
232
+ normalizedChildName = normalizedChildName();
233
+ if (!normalizedChildName) {
230
234
  throw new TypeError("Logger.getChildLogger(name) called with a function not returning a name");
231
235
  }
232
236
  }
233
- return `${name}/${childName}`;
237
+ return `${normalizedName}/${normalizedChildName}`;
234
238
  });
235
239
  }
236
240
  return this.getInfrastructureLogger(() => {
237
- if (typeof name === "function") {
238
- name = name();
239
- if (!name) {
241
+ if (typeof normalizedName === "function") {
242
+ normalizedName = normalizedName();
243
+ if (!normalizedName) {
240
244
  throw new TypeError("Compiler.getInfrastructureLogger(name) called with a function not returning a name");
241
245
  }
242
246
  }
243
- return `${name}/${childName}`;
247
+ return `${normalizedName}/${normalizedChildName}`;
244
248
  });
245
249
  }
246
- if (typeof childName === "function") {
250
+ if (typeof normalizedChildName === "function") {
247
251
  return this.getInfrastructureLogger(() => {
248
- if (typeof childName === "function") {
249
- childName = childName();
250
- if (!childName) {
252
+ if (typeof normalizedChildName === "function") {
253
+ normalizedChildName = normalizedChildName();
254
+ if (!normalizedChildName) {
251
255
  throw new TypeError("Logger.getChildLogger(name) called with a function not returning a name");
252
256
  }
253
257
  }
254
- return `${name}/${childName}`;
258
+ return `${normalizedName}/${normalizedChildName}`;
255
259
  });
256
260
  }
257
- return this.getInfrastructureLogger(`${name}/${childName}`);
261
+ return this.getInfrastructureLogger(`${normalizedName}/${normalizedChildName}`);
258
262
  });
259
263
  }
260
264
  /**
@@ -665,6 +669,7 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
665
669
  registerCompilationChunkAssetTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationChunkAsset, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.chunkAsset, queried => ({ chunk, filename }) => queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), filename)),
666
670
  registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationProcessAssets, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.processAssets, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").assets)),
667
671
  registerCompilationAfterProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterProcessAssets, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterProcessAssets, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").assets)),
672
+ registerCompilationSealTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationSeal, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.seal, queried => () => queried.call()),
668
673
  registerCompilationAfterSealTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterSeal, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterSeal, queried => async () => await queried.promise()),
669
674
  registerNormalModuleFactoryBeforeResolveTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.NormalModuleFactoryBeforeResolve, () => __classPrivateFieldGet(this, _Compiler_compilationParams, "f").normalModuleFactory.hooks.beforeResolve, queried => async (resolveData) => {
670
675
  const normalizedResolveData = {
@@ -0,0 +1,8 @@
1
+ import type { DependenciesBlockDTO } from "@rspack/binding";
2
+ import { Dependency } from "./Dependency";
3
+ export declare class DependenciesBlock {
4
+ #private;
5
+ constructor(binding: DependenciesBlockDTO);
6
+ get dependencies(): Dependency[];
7
+ get blocks(): DependenciesBlock[];
8
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _DependenciesBlock_binding;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DependenciesBlock = void 0;
16
+ const Dependency_1 = require("./Dependency");
17
+ class DependenciesBlock {
18
+ constructor(binding) {
19
+ _DependenciesBlock_binding.set(this, void 0);
20
+ __classPrivateFieldSet(this, _DependenciesBlock_binding, binding, "f");
21
+ }
22
+ get dependencies() {
23
+ return __classPrivateFieldGet(this, _DependenciesBlock_binding, "f").dependencies.map(d => new Dependency_1.Dependency(d));
24
+ }
25
+ get blocks() {
26
+ return __classPrivateFieldGet(this, _DependenciesBlock_binding, "f").blocks.map(b => new DependenciesBlock(b));
27
+ }
28
+ }
29
+ exports.DependenciesBlock = DependenciesBlock;
30
+ _DependenciesBlock_binding = new WeakMap();
@@ -0,0 +1,8 @@
1
+ import type { DependencyDTO } from "@rspack/binding";
2
+ export declare class Dependency {
3
+ #private;
4
+ constructor(binding: DependencyDTO);
5
+ get type(): string;
6
+ get category(): string;
7
+ get request(): string | undefined;
8
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Dependency_binding;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Dependency = void 0;
16
+ class Dependency {
17
+ constructor(binding) {
18
+ _Dependency_binding.set(this, void 0);
19
+ __classPrivateFieldSet(this, _Dependency_binding, binding, "f");
20
+ }
21
+ get type() {
22
+ return __classPrivateFieldGet(this, _Dependency_binding, "f").type;
23
+ }
24
+ get category() {
25
+ return __classPrivateFieldGet(this, _Dependency_binding, "f").category;
26
+ }
27
+ get request() {
28
+ return __classPrivateFieldGet(this, _Dependency_binding, "f").request;
29
+ }
30
+ }
31
+ exports.Dependency = Dependency;
32
+ _Dependency_binding = new WeakMap();
package/dist/Module.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { JsCodegenerationResult, JsCreateData, JsFactoryMeta, JsModule } from "@rspack/binding";
1
+ import type { JsCodegenerationResult, JsCreateData, JsFactoryMeta, JsModule, ModuleDTO } from "@rspack/binding";
2
2
  import type { Source } from "../compiled/webpack-sources";
3
3
  import type { Compilation } from "./Compilation";
4
+ import { DependenciesBlock } from "./DependenciesBlock";
4
5
  export type ResourceData = {
5
6
  resource: string;
6
7
  path: string;
@@ -56,11 +57,13 @@ export declare class Module {
56
57
  * @see {@link Compilation#customModules}
57
58
  */
58
59
  buildMeta: Record<string, any>;
59
- static __from_binding(module: JsModule, compilation?: Compilation): Module;
60
- constructor(module: JsModule, compilation?: Compilation);
60
+ static __from_binding(module: JsModule | ModuleDTO, compilation?: Compilation): Module;
61
+ constructor(module: JsModule | ModuleDTO, compilation?: Compilation);
61
62
  originalSource(): Source | null;
62
63
  identifier(): string;
63
64
  nameForCondition(): string | null;
65
+ get blocks(): DependenciesBlock[];
66
+ size(type?: string): number;
64
67
  }
65
68
  export declare class CodeGenerationResult {
66
69
  #private;
package/dist/Module.js CHANGED
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _Module_inner, _Module_originalSource, _CodeGenerationResult_inner;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CodeGenerationResults = exports.CodeGenerationResult = exports.Module = void 0;
16
+ const DependenciesBlock_1 = require("./DependenciesBlock");
16
17
  const source_1 = require("./util/source");
17
18
  class Module {
18
19
  static __from_binding(module, compilation) {
@@ -52,6 +53,18 @@ class Module {
52
53
  }
53
54
  return null;
54
55
  }
56
+ get blocks() {
57
+ if ("blocks" in __classPrivateFieldGet(this, _Module_inner, "f")) {
58
+ return __classPrivateFieldGet(this, _Module_inner, "f").blocks.map(b => new DependenciesBlock_1.DependenciesBlock(b));
59
+ }
60
+ return [];
61
+ }
62
+ size(type) {
63
+ if ("size" in __classPrivateFieldGet(this, _Module_inner, "f")) {
64
+ return __classPrivateFieldGet(this, _Module_inner, "f").size(type);
65
+ }
66
+ return 0;
67
+ }
55
68
  }
56
69
  exports.Module = Module;
57
70
  _Module_inner = new WeakMap(), _Module_originalSource = new WeakMap();