@rspack/core 1.0.0-beta.1 → 1.0.0-beta.3

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 (121) hide show
  1. package/dist/ChunkGroup.d.ts +1 -0
  2. package/dist/ChunkGroup.js +3 -0
  3. package/dist/Compilation.d.ts +38 -1
  4. package/dist/Compilation.js +109 -44
  5. package/dist/Compiler.d.ts +1 -0
  6. package/dist/Compiler.js +31 -26
  7. package/dist/ExecuteModulePlugin.d.ts +0 -1
  8. package/dist/ExecuteModulePlugin.js +0 -1
  9. package/dist/Module.d.ts +1 -2
  10. package/dist/Module.js +0 -1
  11. package/dist/MultiCompiler.js +11 -7
  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/Resolver.d.ts +1 -2
  16. package/dist/RspackError.js +1 -1
  17. package/dist/Stats.d.ts +1 -1
  18. package/dist/Stats.js +22 -2
  19. package/dist/Template.d.ts +4 -4
  20. package/dist/Template.js +8 -6
  21. package/dist/Watching.js +3 -5
  22. package/dist/builtin-loader/lightningcss/index.js +1 -1
  23. package/dist/builtin-plugin/DefinePlugin.js +1 -1
  24. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +11 -10
  25. package/dist/builtin-plugin/DynamicEntryPlugin.js +26 -15
  26. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
  27. package/dist/builtin-plugin/EnableChunkLoadingPlugin.js +1 -1
  28. package/dist/builtin-plugin/EnableLibraryPlugin.js +1 -6
  29. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +2 -2
  30. package/dist/builtin-plugin/EnableWasmLoadingPlugin.js +1 -1
  31. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  32. package/dist/builtin-plugin/ExternalsPlugin.js +1 -1
  33. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +0 -1
  34. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -1
  35. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +21 -4
  36. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +29 -5
  37. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +4 -6
  38. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +17 -12
  39. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +11 -9
  40. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +13 -11
  41. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +1 -1
  42. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +9 -7
  43. package/dist/builtin-plugin/css-extract/loader.js +5 -12
  44. package/dist/builtin-plugin/lazy-compilation/backend.js +4 -4
  45. package/dist/config/adapter.d.ts +2 -2
  46. package/dist/config/adapter.js +1 -0
  47. package/dist/config/adapterRuleUse.d.ts +2 -6
  48. package/dist/config/adapterRuleUse.js +7 -6
  49. package/dist/config/defaults.js +21 -32
  50. package/dist/config/normalization.d.ts +1 -0
  51. package/dist/config/normalization.js +5 -2
  52. package/dist/config/zod.d.ts +762 -114
  53. package/dist/config/zod.js +29 -6
  54. package/dist/container/default.runtime.js +1 -1
  55. package/dist/exports.d.ts +4 -3
  56. package/dist/exports.js +5 -2
  57. package/dist/lib/AbstractMethodError.js +2 -3
  58. package/dist/lib/Cache.d.ts +1 -1
  59. package/dist/lib/Cache.js +6 -4
  60. package/dist/lib/CacheFacade.js +8 -9
  61. package/dist/lib/Dependency.d.ts +23 -0
  62. package/dist/lib/Dependency.js +11 -0
  63. package/dist/lib/EnvironmentPlugin.js +1 -3
  64. package/dist/lib/LoaderOptionsPlugin.d.ts +4 -2
  65. package/dist/lib/LoaderOptionsPlugin.js +0 -2
  66. package/dist/lib/ModuleFilenameHelpers.js +1 -1
  67. package/dist/lib/WebpackError.d.ts +0 -6
  68. package/dist/lib/WebpackError.js +0 -8
  69. package/dist/lib/cache/MemoryCachePlugin.d.ts +5 -0
  70. package/dist/lib/cache/MemoryCachePlugin.js +40 -0
  71. package/dist/lib/cache/mergeEtags.d.ts +3 -3
  72. package/dist/lib/cache/mergeEtags.js +5 -3
  73. package/dist/lib/formatLocation.d.ts +1 -1
  74. package/dist/loader-runner/index.js +10 -9
  75. package/dist/loader-runner/loadLoader.js +8 -11
  76. package/dist/logging/Logger.js +3 -3
  77. package/dist/logging/createConsoleLogger.d.ts +26 -6
  78. package/dist/logging/createConsoleLogger.js +21 -58
  79. package/dist/logging/runtime.d.ts +4 -10
  80. package/dist/logging/runtime.js +8 -23
  81. package/dist/logging/truncateArgs.d.ts +4 -4
  82. package/dist/logging/truncateArgs.js +5 -10
  83. package/dist/node/NodeEnvironmentPlugin.js +2 -2
  84. package/dist/node/NodeWatchFileSystem.js +6 -6
  85. package/dist/node/nodeConsole.d.ts +7 -21
  86. package/dist/node/nodeConsole.js +31 -38
  87. package/dist/rspackOptionsApply.d.ts +0 -1
  88. package/dist/rspackOptionsApply.js +8 -7
  89. package/dist/sharing/ProvideSharedPlugin.d.ts +20 -19
  90. package/dist/sharing/ProvideSharedPlugin.js +26 -17
  91. package/dist/sharing/SharePlugin.d.ts +3 -0
  92. package/dist/sharing/SharePlugin.js +4 -1
  93. package/dist/stats/DefaultStatsFactoryPlugin.js +187 -96
  94. package/dist/stats/DefaultStatsPresetPlugin.js +2 -5
  95. package/dist/stats/DefaultStatsPrinterPlugin.js +18 -19
  96. package/dist/stats/StatsFactory.d.ts +2 -1
  97. package/dist/stats/StatsFactory.js +5 -10
  98. package/dist/stats/StatsPrinter.js +3 -4
  99. package/dist/stats/statsFactoryUtils.d.ts +155 -28
  100. package/dist/util/SizeFormatHelpers.js +1 -1
  101. package/dist/util/assertNotNil.d.ts +1 -1
  102. package/dist/util/assetCondition.d.ts +2 -0
  103. package/dist/util/assetCondition.js +2 -0
  104. package/dist/util/bindingVersionCheck.js +3 -3
  105. package/dist/util/cleverMerge.js +8 -6
  106. package/dist/util/comparators.d.ts +1 -1
  107. package/dist/util/comparators.js +5 -4
  108. package/dist/util/createHash.js +11 -6
  109. package/dist/util/fs.js +2 -2
  110. package/dist/util/hash/wasm-hash.js +5 -4
  111. package/dist/util/identifier.d.ts +4 -4
  112. package/dist/util/identifier.js +10 -10
  113. package/dist/util/index.js +1 -1
  114. package/dist/util/memoize.js +4 -6
  115. package/dist/util/smartGrouping.js +4 -6
  116. package/dist/util/webpack.d.ts +1 -1
  117. package/dist/util/webpack.js +2 -1
  118. package/module.d.ts +1 -1
  119. package/package.json +3 -3
  120. package/dist/builtin-plugin/css-extract/loader-options.json +0 -37
  121. package/dist/builtin-plugin/css-extract/plugin-options.json +0 -79
@@ -206,7 +206,7 @@ const SIMPLE_PRINTERS = {
206
206
  "module.codeGenerated": (codeGenerated, { formatFlag, yellow }) => codeGenerated ? yellow(formatFlag("code generated")) : undefined,
207
207
  "module.buildTimeExecuted": (buildTimeExecuted, { formatFlag, green }) => buildTimeExecuted ? green(formatFlag("build time executed")) : undefined,
208
208
  "module.cached": (cached, { formatFlag, green }) => cached ? green(formatFlag("cached")) : undefined,
209
- "module.assets": (assets, { formatFlag, magenta }) => assets && assets.length
209
+ "module.assets": (assets, { formatFlag, magenta }) => assets?.length
210
210
  ? magenta(formatFlag(`${assets.length} ${plural(assets.length, "asset", "assets")}`))
211
211
  : undefined,
212
212
  "module.warnings": (warnings, { formatFlag, yellow }) => warnings === true
@@ -700,7 +700,7 @@ const joinInBrackets = (items) => {
700
700
  return res.join("");
701
701
  };
702
702
  const indent = (str, prefix, noPrefixInFirstLine) => {
703
- const rem = str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
703
+ const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
704
704
  if (noPrefixInFirstLine)
705
705
  return rem;
706
706
  const ind = str[0] === "\n" ? "" : prefix;
@@ -722,7 +722,7 @@ const joinExplicitNewLine = (items, indenter) => {
722
722
  first = false;
723
723
  const noJoiner = firstInLine || content.startsWith("\n");
724
724
  firstInLine = content.endsWith("\n");
725
- return noJoiner ? content : " " + content;
725
+ return noJoiner ? content : ` ${content}`;
726
726
  })
727
727
  .filter(Boolean)
728
728
  .join("")
@@ -803,20 +803,19 @@ const SIMPLE_ELEMENT_JOINERS = {
803
803
  },
804
804
  chunk: items => {
805
805
  let hasEntry = false;
806
- return ("chunk " +
807
- joinExplicitNewLine(items.filter(item => {
808
- switch (item.element) {
809
- case "entry":
810
- if (item.content)
811
- hasEntry = true;
812
- break;
813
- case "initial":
814
- if (hasEntry)
815
- return false;
816
- break;
817
- }
818
- return true;
819
- }), " "));
806
+ return `chunk ${joinExplicitNewLine(items.filter(item => {
807
+ switch (item.element) {
808
+ case "entry":
809
+ if (item.content)
810
+ hasEntry = true;
811
+ break;
812
+ case "initial":
813
+ if (hasEntry)
814
+ return false;
815
+ break;
816
+ }
817
+ return true;
818
+ }), " ")}`;
820
819
  },
821
820
  "chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
822
821
  chunkGroup: items => joinExplicitNewLine(items, " "),
@@ -856,11 +855,11 @@ const SIMPLE_ELEMENT_JOINERS = {
856
855
  },
857
856
  "module.profile": joinInBrackets,
858
857
  moduleIssuer: joinOneLine,
859
- chunkOrigin: items => "> " + joinOneLine(items),
858
+ chunkOrigin: items => `> ${joinOneLine(items)}`,
860
859
  "errors[].error": joinError(true),
861
860
  "warnings[].error": joinError(false),
862
861
  loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
863
- moduleTraceItem: items => " @ " + joinOneLine(items),
862
+ moduleTraceItem: items => ` @ ${joinOneLine(items)}`,
864
863
  moduleTraceDependency: joinOneLine
865
864
  };
866
865
  const AVAILABLE_COLORS = {
@@ -7,7 +7,7 @@
7
7
  * Copyright (c) JS Foundation and other contributors
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
- import type { JsStats, JsStatsError, JsStatsWarning } from "@rspack/binding";
10
+ import type { JsStats, JsStatsCompilation, JsStatsError, JsStatsWarning } from "@rspack/binding";
11
11
  import { HookMap, SyncBailHook, SyncWaterfallHook } from "@rspack/lite-tapable";
12
12
  import type { Compilation } from "../Compilation";
13
13
  import { type GroupConfig } from "../util/smartGrouping";
@@ -17,6 +17,7 @@ export type KnownStatsFactoryContext = {
17
17
  compilation?: Compilation | undefined;
18
18
  cachedGetErrors?: ((arg0: Compilation) => JsStatsError[]) | undefined;
19
19
  cachedGetWarnings?: ((arg0: Compilation) => JsStatsWarning[]) | undefined;
20
+ getStatsCompilation: (compilation: Compilation) => JsStatsCompilation;
20
21
  getInner: (compilation: Compilation) => JsStats;
21
22
  };
22
23
  export type StatsFactoryContext = KnownStatsFactoryContext & Record<string, any>;
@@ -71,10 +71,9 @@ class StatsFactory {
71
71
  }
72
72
  }
73
73
  _forEachLevelWaterfall(hookMap, cache, type, data, fn) {
74
- for (const hook of this._getAllLevelHooks(hookMap, cache, type)) {
75
- data = fn(hook, data);
76
- }
77
- return data;
74
+ return this._getAllLevelHooks(hookMap, cache, type).reduce((data, hook) => {
75
+ return fn(hook, data);
76
+ }, data);
78
77
  }
79
78
  _forEachLevelFilter(hookMap, cache, type, items, fn, forceClone) {
80
79
  const hooks = this._getAllLevelHooks(hookMap, cache, type);
@@ -121,9 +120,7 @@ class StatsFactory {
121
120
  const comparators = [];
122
121
  this._forEachLevel(this.hooks.sort, this._caches.sort, type, h => h.call(comparators, context));
123
122
  if (comparators.length > 0) {
124
- items.sort(
125
- // @ts-expect-error number of arguments is correct
126
- (0, comparators_1.concatComparators)(...comparators));
123
+ items.sort((0, comparators_1.concatComparators)(...comparators));
127
124
  }
128
125
  // run filter on sorted items
129
126
  const items2 = this._forEachLevelFilter(this.hooks.filterSorted, this._caches.filterSorted, type, items, (h, r, idx, i) => h.call(r, context, idx, i), false);
@@ -147,9 +144,7 @@ class StatsFactory {
147
144
  const comparators2 = [];
148
145
  this._forEachLevel(this.hooks.sortResults, this._caches.sortResults, type, h => h.call(comparators2, context));
149
146
  if (comparators2.length > 0) {
150
- resultItems.sort(
151
- // @ts-expect-error number of arguments is correct
152
- (0, comparators_1.concatComparators)(...comparators2));
147
+ resultItems.sort((0, comparators_1.concatComparators)(...comparators2));
153
148
  }
154
149
  // group result items
155
150
  const groupConfigs = [];
@@ -71,10 +71,9 @@ class StatsPrinter {
71
71
  }
72
72
  }
73
73
  _forEachLevelWaterfall(hookMap, type, data, fn) {
74
- for (const hook of this._getAllLevelHooks(hookMap, type)) {
75
- data = fn(hook, data);
76
- }
77
- return data;
74
+ return this._getAllLevelHooks(hookMap, type).reduce((data, hook) => {
75
+ return fn(hook, data);
76
+ }, data);
78
77
  }
79
78
  print(type, object, baseContext) {
80
79
  if (this._inPrint) {
@@ -1,27 +1,126 @@
1
+ /// <reference types="node" />
1
2
  import type * as binding from "@rspack/binding";
2
3
  import type { Compilation, NormalizedStatsOptions } from "../Compilation";
3
4
  import { type Comparator } from "../util/comparators";
4
5
  import type { StatsFactory, StatsFactoryContext } from "./StatsFactory";
5
- type Writable<T> = {
6
- -readonly [K in keyof T]: T[K];
6
+ export type KnownStatsChunkGroup = {
7
+ name?: string;
8
+ chunks?: (string | number)[];
9
+ assets?: {
10
+ name: string;
11
+ size?: number;
12
+ }[];
13
+ filteredAssets?: number;
14
+ assetsSize?: number;
15
+ auxiliaryAssets?: {
16
+ name: string;
17
+ size?: number;
18
+ }[];
19
+ filteredAuxiliaryAssets?: number;
20
+ auxiliaryAssetsSize?: number;
21
+ children?: {
22
+ preload?: StatsChunkGroup[];
23
+ prefetch?: StatsChunkGroup[];
24
+ };
25
+ childAssets?: {
26
+ [index: string]: string[];
27
+ };
7
28
  };
8
- export type KnownStatsChunkGroup = binding.JsStatsChunkGroup;
9
- export type KnownStatsChunk = Omit<Writable<binding.JsStatsChunk>, "sizes"> & {
10
- sizes: Record<string, number>;
29
+ export type KnownStatsChunk = {
30
+ type: string;
31
+ rendered: boolean;
32
+ initial: boolean;
33
+ entry: boolean;
34
+ reason?: string;
35
+ size: number;
36
+ sizes?: Record<string, number>;
37
+ names?: string[];
38
+ idHints?: string[];
39
+ runtime?: string[];
40
+ files?: string[];
41
+ auxiliaryFiles?: string[];
42
+ hash?: string;
43
+ childrenByOrder?: Record<string, (string | number)[]>;
44
+ id?: string | number;
45
+ siblings?: (string | number)[];
46
+ parents?: (string | number)[];
47
+ children?: (string | number)[];
48
+ modules?: StatsModule[];
49
+ filteredModules?: number;
50
+ origins?: StatsChunkOrigin[];
51
+ };
52
+ export type KnownAssetInfo = {
53
+ immutable?: boolean;
54
+ minimized?: boolean;
55
+ fullhash?: string | string[];
56
+ chunkhash?: string | string[];
57
+ contenthash?: string | string[];
58
+ sourceFilename?: string;
59
+ size?: number;
60
+ development?: boolean;
61
+ hotModuleReplacement?: boolean;
62
+ javascriptModule?: boolean;
63
+ related?: Record<string, string | string[]>;
64
+ };
65
+ export type AssetInfo = KnownAssetInfo & Record<string, any>;
66
+ export type StatsChunkGroup = KnownStatsChunkGroup & Record<string, any>;
67
+ export type KnownStatsAsset = {
68
+ type: string;
69
+ name: string;
70
+ info: AssetInfo;
71
+ size: number;
72
+ emitted: boolean;
73
+ chunkNames?: (string | number)[];
74
+ chunkIdHints?: (string | number)[];
75
+ chunks?: (string | null | undefined)[];
76
+ auxiliaryChunkNames?: (string | number)[];
77
+ auxiliaryChunks?: (string | null | undefined)[];
78
+ auxiliaryChunkIdHints?: (string | number)[];
79
+ filteredRelated?: number;
80
+ isOverSizeLimit?: boolean;
11
81
  };
12
- export type KnownStatsAssetInfo = Omit<binding.JsStatsAssetInfo, "related">;
13
- export type StatsChunkGroup = binding.JsStatsChunkGroup & Record<string, any>;
14
- export type KnownStatsAsset = Omit<binding.JsStatsAsset, "info">;
15
82
  export type StatsAsset = KnownStatsAsset & Record<string, any>;
16
83
  export type StatsChunk = KnownStatsChunk & Record<string, any>;
17
- export type KnownStatsModule = Omit<Writable<binding.JsStatsModule>, "usedExports" | "providedExports" | "optimizationBailout" | "sizes"> & {
18
- profile?: StatsProfile;
19
- usedExports?: null | string[] | boolean;
20
- providedExports?: null | string[];
21
- optimizationBailout?: null | string[];
22
- sizes: Record<string, number>;
84
+ export type KnownStatsModule = {
85
+ type: string;
86
+ moduleType: string;
87
+ layer?: string;
88
+ identifier?: string;
89
+ name?: string;
90
+ nameForCondition?: string;
23
91
  index?: number;
24
92
  index2?: number;
93
+ preOrderIndex?: number;
94
+ postOrderIndex?: number;
95
+ size: number;
96
+ sizes: Record<string, number>;
97
+ cacheable?: boolean;
98
+ built: boolean;
99
+ codeGenerated: boolean;
100
+ buildTimeExecuted: boolean;
101
+ cached: boolean;
102
+ optional?: boolean;
103
+ orphan?: boolean;
104
+ id?: string;
105
+ issuerId?: string;
106
+ chunks?: string[];
107
+ assets?: string[];
108
+ dependent?: boolean;
109
+ issuer?: string;
110
+ issuerName?: string;
111
+ issuerPath?: StatsModuleIssuer[];
112
+ failed?: boolean;
113
+ errors?: number;
114
+ warnings?: number;
115
+ profile?: StatsProfile;
116
+ reasons?: StatsModuleReason[];
117
+ usedExports?: boolean | string[] | null;
118
+ providedExports?: string[] | null;
119
+ optimizationBailout?: string[] | null;
120
+ depth?: number;
121
+ modules?: StatsModule[];
122
+ filteredModules?: number;
123
+ source?: string | Buffer;
25
124
  };
26
125
  export type StatsProfile = KnownStatsProfile & Record<string, any>;
27
126
  export type KnownStatsProfile = {
@@ -30,9 +129,28 @@ export type KnownStatsProfile = {
30
129
  building: number;
31
130
  };
32
131
  export type StatsModule = KnownStatsModule & Record<string, any>;
33
- export type StatsModuleIssuer = binding.JsStatsModuleIssuer & Record<string, any>;
34
- export type StatsError = binding.JsStatsError & Record<string, any>;
35
- export type StatsWarnings = binding.JsStatsWarning & Record<string, any>;
132
+ export type KnownStatsModuleIssuer = {
133
+ identifier?: string;
134
+ name?: string;
135
+ id?: string | number;
136
+ };
137
+ export type StatsModuleIssuer = KnownStatsModuleIssuer & Record<string, any>;
138
+ export type KnownStatsError = {
139
+ message: string;
140
+ chunkName?: string;
141
+ chunkEntry?: boolean;
142
+ chunkInitial?: boolean;
143
+ file?: string;
144
+ moduleIdentifier?: string;
145
+ moduleName?: string;
146
+ loc?: string;
147
+ chunkId?: string | number;
148
+ moduleId?: string | number;
149
+ moduleTrace?: StatsModuleTraceItem[];
150
+ details?: any;
151
+ stack?: string;
152
+ };
153
+ export type StatsError = KnownStatsError & Record<string, any>;
36
154
  export type StatsModuleTraceItem = {
37
155
  originIdentifier?: string;
38
156
  originName?: string;
@@ -41,7 +159,24 @@ export type StatsModuleTraceItem = {
41
159
  originId?: string;
42
160
  moduleId?: string;
43
161
  };
44
- export type StatsModuleReason = Writable<binding.JsStatsModuleReason> & Record<string, any>;
162
+ export type KnownStatsModuleReason = {
163
+ moduleIdentifier?: string;
164
+ module?: string;
165
+ moduleName?: string;
166
+ type?: string;
167
+ userRequest?: string;
168
+ moduleId?: string | null;
169
+ };
170
+ export type StatsModuleReason = KnownStatsModuleReason & Record<string, any>;
171
+ export type KnownStatsChunkOrigin = {
172
+ module: string;
173
+ moduleIdentifier: string;
174
+ moduleName: string;
175
+ loc: string;
176
+ request: string;
177
+ moduleId?: string;
178
+ };
179
+ export type StatsChunkOrigin = KnownStatsChunkOrigin & Record<string, any>;
45
180
  export type KnownStatsCompilation = {
46
181
  /**
47
182
  * webpack version.
@@ -64,7 +199,7 @@ export type KnownStatsCompilation = {
64
199
  namedChunkGroups?: Record<string, StatsChunkGroup>;
65
200
  errors?: StatsError[];
66
201
  errorsCount?: number;
67
- warnings?: StatsWarnings[];
202
+ warnings?: StatsError[];
68
203
  warningsCount?: number;
69
204
  filteredModules?: number;
70
205
  children?: StatsCompilation[];
@@ -86,18 +221,10 @@ export type KnownStatsLoggingEntry = {
86
221
  args?: any[] | undefined;
87
222
  time?: number | undefined;
88
223
  };
89
- export type KnownStatsChunkOrigin = {
90
- module?: string | undefined;
91
- moduleIdentifier?: string | undefined;
92
- moduleName?: string | undefined;
93
- loc?: string | undefined;
94
- request?: string | undefined;
95
- moduleId?: (string | number) | undefined;
96
- };
97
224
  type ExtractorsByOption<T, O> = {
98
225
  [x: string]: (object: O, data: T, context: StatsFactoryContext, options: any, factory: StatsFactory) => void;
99
226
  };
100
- export type PreprocessedAsset = StatsAsset & {
227
+ export type PreprocessedAsset = binding.JsStatsAsset & {
101
228
  type: string;
102
229
  related: PreprocessedAsset[];
103
230
  info: binding.JsStatsAssetInfo;
@@ -19,6 +19,6 @@ const formatSize = (size) => {
19
19
  }
20
20
  const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
21
21
  const index = Math.floor(Math.log(size) / Math.log(1024));
22
- return `${+(size / Math.pow(1024, index)).toPrecision(3)} ${abbreviations[index]}`;
22
+ return `${+(size / 1024 ** index).toPrecision(3)} ${abbreviations[index]}`;
23
23
  };
24
24
  exports.formatSize = formatSize;
@@ -1 +1 @@
1
- export declare function assertNotNill(value: any): asserts value;
1
+ export declare function assertNotNill(value: unknown): asserts value;
@@ -0,0 +1,2 @@
1
+ export type AssetCondition = string | RegExp;
2
+ export type AssetConditions = AssetCondition | AssetCondition[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -64,12 +64,12 @@ const getAddonPlatformArchAbi = () => {
64
64
  const abi = NodePlatformArchToAbi[platform][arch];
65
65
  if (abi === undefined)
66
66
  return new Error(`unsupported cpu arch: ${arch}`);
67
- binding += "-" + arch;
67
+ binding += `-${arch}`;
68
68
  if (typeof abi === "string") {
69
- binding += abi.length ? "-" + abi : "";
69
+ binding += abi.length ? `-${abi}` : "";
70
70
  }
71
71
  else if (typeof abi === "object") {
72
- binding += "-" + abi[isMusl() ? "musl" : "gnu"];
72
+ binding += `-${abi[isMusl() ? "musl" : "gnu"]}`;
73
73
  }
74
74
  else {
75
75
  return new Error(`unsupported abi: ${abi}`);
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveByProperty = exports.removeOperations = exports.cleverMerge = exports.cachedSetProperty = exports.cachedCleverMerge = exports.DELETE = void 0;
4
+ const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
4
5
  const mergeCache = new WeakMap();
5
6
  const setPropertyCache = new WeakMap();
6
7
  exports.DELETE = Symbol("DELETE");
7
- const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
8
8
  /**
9
9
  * Merges two given objects and caches the result to avoid computation if same objects passed as arguments again.
10
10
  * @example
@@ -247,11 +247,12 @@ const _cleverMerge = (first, second, internalCaching = false) => {
247
247
  : parseObject(first);
248
248
  const { static: firstInfo, dynamic: firstDynamicInfo } = firstObject;
249
249
  // If the first argument has a dynamic part we modify the dynamic part to merge the second argument
250
+ let secondObj = second;
250
251
  if (firstDynamicInfo !== undefined) {
251
252
  let { byProperty, fn } = firstDynamicInfo;
252
253
  const fnInfo = fn[DYNAMIC_INFO];
253
254
  if (fnInfo) {
254
- second = internalCaching
255
+ secondObj = internalCaching
255
256
  ? (0, exports.cachedCleverMerge)(fnInfo[1], second)
256
257
  : (0, exports.cleverMerge)(fnInfo[1], second);
257
258
  fn = fnInfo[0];
@@ -259,10 +260,10 @@ const _cleverMerge = (first, second, internalCaching = false) => {
259
260
  const newFn = (...args) => {
260
261
  const fnResult = fn(...args);
261
262
  return internalCaching
262
- ? (0, exports.cachedCleverMerge)(fnResult, second)
263
- : (0, exports.cleverMerge)(fnResult, second);
263
+ ? (0, exports.cachedCleverMerge)(fnResult, secondObj)
264
+ : (0, exports.cleverMerge)(fnResult, secondObj);
264
265
  };
265
- newFn[DYNAMIC_INFO] = [fn, second];
266
+ newFn[DYNAMIC_INFO] = [fn, secondObj];
266
267
  return serializeObject(firstObject.static, { byProperty, fn: newFn });
267
268
  }
268
269
  // If the first part is static only, we merge the static parts and keep the dynamic part of the second argument
@@ -299,7 +300,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
299
300
  // second value override everything
300
301
  // = second.base + second.byProperty
301
302
  return secondEntry;
302
- case VALUE_TYPE_UNDEFINED:
303
+ case VALUE_TYPE_UNDEFINED: {
303
304
  if (!firstEntry.byProperty) {
304
305
  // = first.base + second.byProperty
305
306
  return {
@@ -323,6 +324,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
323
324
  byProperty: firstEntry.byProperty,
324
325
  byValues: newByValues
325
326
  };
327
+ }
326
328
  default: {
327
329
  if (!firstEntry.byProperty) {
328
330
  // The simple case
@@ -11,7 +11,7 @@ import type { JsStatsChunk as Chunk } from "@rspack/binding";
11
11
  import type { ChunkGroup } from "../ChunkGroup";
12
12
  export type Comparator = <T>(arg0: T, arg1: T) => -1 | 0 | 1;
13
13
  type Selector<A, B> = (input: A) => B;
14
- export declare const concatComparators: (c1: Comparator, c2: Comparator, ...cRest: Comparator[]) => Comparator;
14
+ export declare const concatComparators: (...comps: Array<Comparator>) => Comparator;
15
15
  export declare const compareIds: (a: string | number, b: string | number) => -1 | 0 | 1;
16
16
  export declare const compareChunksById: (a: Chunk, b: Chunk) => -1 | 0 | 1;
17
17
  export declare const compareChunkGroupsByIndex: (a: ChunkGroup, b: ChunkGroup) => -1 | 0 | 1;
@@ -31,14 +31,15 @@ class TwoKeyWeakMap {
31
31
  }
32
32
  }
33
33
  const concatComparatorsCache = new TwoKeyWeakMap();
34
- const concatComparators = (c1, c2, ...cRest) => {
34
+ const concatComparators = (...comps) => {
35
+ const [c1, c2, ...cRest] = comps;
36
+ if (c2 === undefined) {
37
+ return c1;
38
+ }
35
39
  if (cRest.length > 0) {
36
40
  const [c3, ...cRest2] = cRest;
37
41
  return (0, exports.concatComparators)(c1, (0, exports.concatComparators)(c2, c3, ...cRest2));
38
42
  }
39
- if (c2 === undefined) {
40
- return c1;
41
- }
42
43
  const cacheEntry = concatComparatorsCache.get(c1, c2);
43
44
  if (cacheEntry !== undefined)
44
45
  return cacheEntry;
@@ -113,12 +113,17 @@ class DebugHash extends hash_1.default {
113
113
  * @returns updated hash
114
114
  */
115
115
  update(data, _inputEncoding) {
116
- if (typeof data !== "string")
117
- data = data.toString("utf-8");
118
- if (data.startsWith("debug-digest-")) {
119
- data = Buffer.from(data.slice("debug-digest-".length), "hex").toString();
116
+ let normalizedData;
117
+ if (typeof data !== "string") {
118
+ normalizedData = data.toString("utf-8");
120
119
  }
121
- this.string += `[${data}](${new Error().stack?.split("\n", 3)[2]})\n`;
120
+ else {
121
+ normalizedData = data;
122
+ }
123
+ if (normalizedData.startsWith("debug-digest-")) {
124
+ normalizedData = Buffer.from(normalizedData.slice("debug-digest-".length), "hex").toString();
125
+ }
126
+ this.string += `[${normalizedData}](${new Error().stack?.split("\n", 3)[2]})\n`;
122
127
  return this;
123
128
  }
124
129
  /**
@@ -127,7 +132,7 @@ class DebugHash extends hash_1.default {
127
132
  * @returns digest
128
133
  */
129
134
  digest(encoding) {
130
- return ("debug-digest-" + Buffer.from(this.string).toString(encoding || "hex"));
135
+ return `debug-digest-${Buffer.from(this.string).toString(encoding || "hex")}`;
131
136
  }
132
137
  }
133
138
  /**
package/dist/util/fs.js CHANGED
@@ -56,7 +56,7 @@ function rmrf(fs, p, callback) {
56
56
  }
57
57
  exports.rmrf = rmrf;
58
58
  const join = (fs, rootPath, filename) => {
59
- if (fs && fs.join) {
59
+ if (fs?.join) {
60
60
  return fs.join(rootPath, filename);
61
61
  }
62
62
  if (node_path_1.default.posix.isAbsolute(rootPath)) {
@@ -68,7 +68,7 @@ const join = (fs, rootPath, filename) => {
68
68
  throw new Error(`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`);
69
69
  };
70
70
  const dirname = (fs, absPath) => {
71
- if (fs && fs.dirname) {
71
+ if (fs?.dirname) {
72
72
  return fs.dirname(absPath);
73
73
  }
74
74
  if (node_path_1.default.posix.isAbsolute(absPath)) {
@@ -43,11 +43,12 @@ class WasmHash {
43
43
  */
44
44
  update(data, encoding) {
45
45
  if (typeof data === "string") {
46
- while (data.length > exports.MAX_SHORT_STRING) {
47
- this._updateWithShortString(data.slice(0, exports.MAX_SHORT_STRING), encoding);
48
- data = data.slice(exports.MAX_SHORT_STRING);
46
+ let normalizedData = data;
47
+ while (normalizedData.length > exports.MAX_SHORT_STRING) {
48
+ this._updateWithShortString(normalizedData.slice(0, exports.MAX_SHORT_STRING), encoding);
49
+ normalizedData = normalizedData.slice(exports.MAX_SHORT_STRING);
49
50
  }
50
- this._updateWithShortString(data, encoding);
51
+ this._updateWithShortString(normalizedData, encoding);
51
52
  return this;
52
53
  }
53
54
  this._updateWithBuffer(data);
@@ -70,10 +70,10 @@ export declare const parseResourceWithoutFragment: {
70
70
  bindCache(associatedObjectForCache: object): (str: string) => ParsedResourceWithoutFragment;
71
71
  };
72
72
  /**
73
- * @param {string} filename the filename which should be undone
74
- * @param {string} outputPath the output path that is restored (only relevant when filename contains "..")
75
- * @param {boolean} enforceRelative true returns ./ for empty paths
76
- * @returns {string} repeated ../ to leave the directory of the provided filename to be back on output dir
73
+ * @param filename the filename which should be undone
74
+ * @param outputPath the output path that is restored (only relevant when filename contains "..")
75
+ * @param enforceRelative true returns ./ for empty paths
76
+ * @returns repeated ../ to leave the directory of the provided filename to be back on output dir
77
77
  */
78
78
  export declare const getUndoPath: (filename: string, outputPath: string, enforceRelative: boolean) => string;
79
79
  export {};
@@ -293,28 +293,28 @@ const _parseResourceWithoutFragment = (str) => {
293
293
  };
294
294
  exports.parseResourceWithoutFragment = makeCacheable(_parseResourceWithoutFragment);
295
295
  /**
296
- * @param {string} filename the filename which should be undone
297
- * @param {string} outputPath the output path that is restored (only relevant when filename contains "..")
298
- * @param {boolean} enforceRelative true returns ./ for empty paths
299
- * @returns {string} repeated ../ to leave the directory of the provided filename to be back on output dir
296
+ * @param filename the filename which should be undone
297
+ * @param outputPath the output path that is restored (only relevant when filename contains "..")
298
+ * @param enforceRelative true returns ./ for empty paths
299
+ * @returns repeated ../ to leave the directory of the provided filename to be back on output dir
300
300
  */
301
301
  const getUndoPath = (filename, outputPath, enforceRelative) => {
302
302
  let depth = -1;
303
303
  let append = "";
304
- outputPath = outputPath.replace(/[\\/]$/, "");
304
+ let path = outputPath.replace(/[\\/]$/, "");
305
305
  for (const part of filename.split(/[/\\]+/)) {
306
306
  if (part === "..") {
307
307
  if (depth > -1) {
308
308
  depth--;
309
309
  }
310
310
  else {
311
- const i = outputPath.lastIndexOf("/");
312
- const j = outputPath.lastIndexOf("\\");
311
+ const i = path.lastIndexOf("/");
312
+ const j = path.lastIndexOf("\\");
313
313
  const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
314
314
  if (pos < 0)
315
- return outputPath + "/";
316
- append = outputPath.slice(pos + 1) + "/" + append;
317
- outputPath = outputPath.slice(0, pos);
315
+ return `${path}/`;
316
+ append = `${path.slice(pos + 1)}/${append}`;
317
+ path = path.slice(0, pos);
318
318
  }
319
319
  }
320
320
  else if (part !== ".") {
@@ -73,7 +73,7 @@ function concatErrorMsgAndStack(err) {
73
73
  }
74
74
  exports.concatErrorMsgAndStack = concatErrorMsgAndStack;
75
75
  function indent(str, prefix) {
76
- const rem = str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
76
+ const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
77
77
  return prefix + rem;
78
78
  }
79
79
  exports.indent = indent;
@@ -3,19 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.memoizeValue = exports.memoizeFn = exports.memoize = void 0;
4
4
  const memoize = (fn) => {
5
5
  let cache = false;
6
- // @ts-expect-error
7
- let result = undefined;
6
+ let result;
7
+ let callback = fn;
8
8
  return () => {
9
9
  if (cache) {
10
- // @ts-expect-error
11
10
  return result;
12
11
  }
13
- result = fn();
12
+ result = callback();
14
13
  cache = true;
15
14
  // Allow to clean up memory for fn
16
15
  // and all dependent resources
17
- // @ts-expect-error
18
- fn = undefined;
16
+ callback = undefined;
19
17
  return result;
20
18
  };
21
19
  };