@rspack/core 1.0.9 → 1.0.11

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 (219) hide show
  1. package/dist/Dependency.d.ts +7 -6
  2. package/dist/Module.d.ts +19 -17
  3. package/dist/builtin-plugin/css-extract/utils.d.ts +1 -0
  4. package/dist/config/types.d.ts +545 -0
  5. package/dist/config/zod.d.ts +202 -1347
  6. package/dist/cssExtractHmr.js +224 -0
  7. package/dist/cssExtractLoader.js +277 -0
  8. package/dist/index.js +23347 -31
  9. package/dist/{builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts → runtime/cssExtractHmr.d.ts} +1 -0
  10. package/dist/runtime/moduleFederationDefaultRuntime.d.ts +2 -0
  11. package/dist/stats/statsFactoryUtils.d.ts +1 -0
  12. package/package.json +8 -5
  13. package/compiled/json-parse-even-better-errors/index.d.ts +0 -1
  14. package/compiled/json-parse-even-better-errors/index.js +0 -193
  15. package/compiled/json-parse-even-better-errors/package.json +0 -1
  16. package/compiled/neo-async/index.d.ts +0 -685
  17. package/compiled/neo-async/index.js +0 -9207
  18. package/compiled/neo-async/license +0 -22
  19. package/compiled/neo-async/package.json +0 -1
  20. package/compiled/zod-validation-error/index.d.ts +0 -41
  21. package/compiled/zod-validation-error/index.js +0 -335
  22. package/compiled/zod-validation-error/license +0 -9
  23. package/compiled/zod-validation-error/package.json +0 -1
  24. package/dist/Chunk.js +0 -118
  25. package/dist/ChunkGraph.js +0 -27
  26. package/dist/ChunkGroup.js +0 -76
  27. package/dist/Compilation.js +0 -854
  28. package/dist/Compiler.js +0 -920
  29. package/dist/ContextModuleFactory.js +0 -36
  30. package/dist/DependenciesBlock.js +0 -30
  31. package/dist/Dependency.js +0 -32
  32. package/dist/Entrypoint.js +0 -21
  33. package/dist/ErrorHelpers.js +0 -62
  34. package/dist/ExecuteModulePlugin.js +0 -46
  35. package/dist/FileSystem.js +0 -34
  36. package/dist/FileSystemInfo.js +0 -2
  37. package/dist/Module.js +0 -143
  38. package/dist/ModuleTypeConstants.js +0 -92
  39. package/dist/MultiCompiler.js +0 -440
  40. package/dist/MultiStats.js +0 -161
  41. package/dist/MultiWatching.js +0 -62
  42. package/dist/NormalModule.js +0 -97
  43. package/dist/NormalModuleFactory.js +0 -43
  44. package/dist/Resolver.js +0 -39
  45. package/dist/ResolverFactory.js +0 -61
  46. package/dist/RspackError.js +0 -21
  47. package/dist/RuleSetCompiler.js +0 -10
  48. package/dist/RuntimeGlobals.js +0 -357
  49. package/dist/RuntimeModule.js +0 -58
  50. package/dist/Stats.js +0 -161
  51. package/dist/Template.js +0 -206
  52. package/dist/Watching.js +0 -290
  53. package/dist/builtin-loader/index.js +0 -17
  54. package/dist/builtin-loader/lightningcss/index.js +0 -175
  55. package/dist/builtin-loader/swc/index.js +0 -5
  56. package/dist/builtin-loader/swc/pluginImport.js +0 -35
  57. package/dist/builtin-loader/swc/react.js +0 -7
  58. package/dist/builtin-loader/swc/types.js +0 -2
  59. package/dist/builtin-plugin/APIPlugin.js +0 -6
  60. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.js +0 -6
  61. package/dist/builtin-plugin/AssetModulesPlugin.js +0 -6
  62. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.js +0 -6
  63. package/dist/builtin-plugin/BannerPlugin.js +0 -22
  64. package/dist/builtin-plugin/BundlerInfoRspackPlugin.js +0 -12
  65. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.js +0 -6
  66. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.js +0 -6
  67. package/dist/builtin-plugin/ContextReplacementPlugin.js +0 -43
  68. package/dist/builtin-plugin/CopyRspackPlugin.js +0 -21
  69. package/dist/builtin-plugin/CssModulesPlugin.js +0 -6
  70. package/dist/builtin-plugin/DataUriPlugin.js +0 -6
  71. package/dist/builtin-plugin/DefinePlugin.js +0 -44
  72. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.js +0 -6
  73. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.js +0 -6
  74. package/dist/builtin-plugin/DynamicEntryPlugin.js +0 -36
  75. package/dist/builtin-plugin/ElectronTargetPlugin.js +0 -6
  76. package/dist/builtin-plugin/EnableChunkLoadingPlugin.js +0 -6
  77. package/dist/builtin-plugin/EnableLibraryPlugin.js +0 -39
  78. package/dist/builtin-plugin/EnableWasmLoadingPlugin.js +0 -6
  79. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.js +0 -6
  80. package/dist/builtin-plugin/EntryPlugin.js +0 -34
  81. package/dist/builtin-plugin/EvalDevToolModulePlugin.js +0 -6
  82. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.js +0 -16
  83. package/dist/builtin-plugin/ExternalsPlugin.js +0 -51
  84. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.js +0 -6
  85. package/dist/builtin-plugin/FileUriPlugin.js +0 -6
  86. package/dist/builtin-plugin/FlagDependencyExportsPlugin.js +0 -6
  87. package/dist/builtin-plugin/FlagDependencyUsagePlugin.js +0 -6
  88. package/dist/builtin-plugin/HotModuleReplacementPlugin.js +0 -18
  89. package/dist/builtin-plugin/HtmlRspackPlugin.js +0 -285
  90. package/dist/builtin-plugin/HttpExternalsRspackPlugin.js +0 -11
  91. package/dist/builtin-plugin/IgnorePlugin.js +0 -20
  92. package/dist/builtin-plugin/InferAsyncModulesPlugin.js +0 -6
  93. package/dist/builtin-plugin/JavascriptModulesPlugin.js +0 -55
  94. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +0 -9
  95. package/dist/builtin-plugin/JsonModulesPlugin.js +0 -6
  96. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +0 -30
  97. package/dist/builtin-plugin/LimitChunkCountPlugin.js +0 -8
  98. package/dist/builtin-plugin/MangleExportsPlugin.js +0 -6
  99. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.js +0 -6
  100. package/dist/builtin-plugin/ModuleChunkFormatPlugin.js +0 -6
  101. package/dist/builtin-plugin/ModuleConcatenationPlugin.js +0 -6
  102. package/dist/builtin-plugin/NamedChunkIdsPlugin.js +0 -6
  103. package/dist/builtin-plugin/NamedModuleIdsPlugin.js +0 -6
  104. package/dist/builtin-plugin/NaturalChunkIdsPlugin.js +0 -6
  105. package/dist/builtin-plugin/NaturalModuleIdsPlugin.js +0 -6
  106. package/dist/builtin-plugin/NoEmitOnErrorsPlugin.js +0 -6
  107. package/dist/builtin-plugin/NodeTargetPlugin.js +0 -6
  108. package/dist/builtin-plugin/ProgressPlugin.js +0 -15
  109. package/dist/builtin-plugin/ProvidePlugin.js +0 -14
  110. package/dist/builtin-plugin/RealContentHashPlugin.js +0 -6
  111. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.js +0 -6
  112. package/dist/builtin-plugin/RuntimeChunkPlugin.js +0 -6
  113. package/dist/builtin-plugin/RuntimePlugin.js +0 -6
  114. package/dist/builtin-plugin/SideEffectsFlagPlugin.js +0 -6
  115. package/dist/builtin-plugin/SizeLimitsPlugin.js +0 -9
  116. package/dist/builtin-plugin/SourceMapDevToolPlugin.js +0 -14
  117. package/dist/builtin-plugin/SplitChunksPlugin.js +0 -92
  118. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +0 -80
  119. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.js +0 -6
  120. package/dist/builtin-plugin/WebWorkerTemplatePlugin.js +0 -6
  121. package/dist/builtin-plugin/WorkerPlugin.js +0 -31
  122. package/dist/builtin-plugin/base.js +0 -58
  123. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +0 -182
  124. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +0 -2
  125. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +0 -31
  126. package/dist/builtin-plugin/css-extract/index.js +0 -105
  127. package/dist/builtin-plugin/css-extract/loader.js +0 -204
  128. package/dist/builtin-plugin/css-extract/utils.js +0 -51
  129. package/dist/builtin-plugin/index.js +0 -84
  130. package/dist/builtin-plugin/lazy-compilation/backend.js +0 -139
  131. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.js +0 -6
  132. package/dist/builtin-plugin/lazy-compilation/plugin.js +0 -60
  133. package/dist/config/adapter.js +0 -691
  134. package/dist/config/adapterRuleUse.js +0 -107
  135. package/dist/config/browserslistTargetHandler.js +0 -345
  136. package/dist/config/defaults.js +0 -876
  137. package/dist/config/index.js +0 -20
  138. package/dist/config/normalization.js +0 -299
  139. package/dist/config/target.js +0 -318
  140. package/dist/config/types.js +0 -3
  141. package/dist/config/zod.js +0 -1028
  142. package/dist/container/ContainerPlugin.js +0 -50
  143. package/dist/container/ContainerReferencePlugin.js +0 -49
  144. package/dist/container/ModuleFederationPlugin.js +0 -137
  145. package/dist/container/ModuleFederationPluginV1.js +0 -63
  146. package/dist/container/ModuleFederationRuntimePlugin.js +0 -6
  147. package/dist/container/options.js +0 -48
  148. package/dist/error/ConcurrentCompilationError.js +0 -20
  149. package/dist/exports.js +0 -183
  150. package/dist/lib/AbstractMethodError.js +0 -51
  151. package/dist/lib/Cache.js +0 -111
  152. package/dist/lib/CacheFacade.js +0 -321
  153. package/dist/lib/Dependency.js +0 -11
  154. package/dist/lib/EntryOptionPlugin.js +0 -89
  155. package/dist/lib/EnvironmentPlugin.js +0 -57
  156. package/dist/lib/HookWebpackError.js +0 -83
  157. package/dist/lib/IgnoreWarningsPlugin.js +0 -35
  158. package/dist/lib/LoaderOptionsPlugin.js +0 -74
  159. package/dist/lib/LoaderTargetPlugin.js +0 -37
  160. package/dist/lib/ModuleFilenameHelpers.js +0 -83
  161. package/dist/lib/NormalModuleReplacementPlugin.js +0 -85
  162. package/dist/lib/WebpackError.js +0 -20
  163. package/dist/lib/cache/MemoryCachePlugin.js +0 -40
  164. package/dist/lib/cache/getLazyHashedEtag.js +0 -73
  165. package/dist/lib/cache/mergeEtags.js +0 -74
  166. package/dist/lib/formatLocation.js +0 -64
  167. package/dist/loader-runner/LoaderLoadingError.js +0 -19
  168. package/dist/loader-runner/index.js +0 -735
  169. package/dist/loader-runner/loadLoader.js +0 -64
  170. package/dist/logging/Logger.js +0 -143
  171. package/dist/logging/createConsoleLogger.js +0 -176
  172. package/dist/logging/runtime.js +0 -37
  173. package/dist/logging/truncateArgs.js +0 -81
  174. package/dist/node/NodeEnvironmentPlugin.js +0 -50
  175. package/dist/node/NodeTemplatePlugin.js +0 -26
  176. package/dist/node/NodeWatchFileSystem.js +0 -144
  177. package/dist/node/nodeConsole.js +0 -146
  178. package/dist/rspack.js +0 -123
  179. package/dist/rspackOptionsApply.js +0 -274
  180. package/dist/sharing/ConsumeSharedPlugin.js +0 -69
  181. package/dist/sharing/ProvideSharedPlugin.js +0 -50
  182. package/dist/sharing/SharePlugin.js +0 -66
  183. package/dist/sharing/ShareRuntimePlugin.js +0 -26
  184. package/dist/sharing/utils.js +0 -8
  185. package/dist/stats/DefaultStatsFactoryPlugin.js +0 -1173
  186. package/dist/stats/DefaultStatsPresetPlugin.js +0 -305
  187. package/dist/stats/DefaultStatsPrinterPlugin.js +0 -1069
  188. package/dist/stats/StatsFactory.js +0 -167
  189. package/dist/stats/StatsPrinter.js +0 -142
  190. package/dist/stats/statsFactoryUtils.js +0 -341
  191. package/dist/util/ArrayQueue.js +0 -108
  192. package/dist/util/AssetInfo.js +0 -39
  193. package/dist/util/IterableHelpers.js +0 -35
  194. package/dist/util/MergeCaller.js +0 -24
  195. package/dist/util/SizeFormatHelpers.js +0 -24
  196. package/dist/util/SplitChunkSize.js +0 -18
  197. package/dist/util/assertNotNil.js +0 -9
  198. package/dist/util/assetCondition.js +0 -2
  199. package/dist/util/bindingVersionCheck.js +0 -124
  200. package/dist/util/cleverMerge.js +0 -504
  201. package/dist/util/comparators.js +0 -108
  202. package/dist/util/createHash.js +0 -161
  203. package/dist/util/createReadonlyMap.js +0 -29
  204. package/dist/util/fake.js +0 -28
  205. package/dist/util/fs.js +0 -120
  206. package/dist/util/hash/BatchedHash.js +0 -69
  207. package/dist/util/hash/index.js +0 -39
  208. package/dist/util/hash/md4.js +0 -27
  209. package/dist/util/hash/wasm-hash.js +0 -167
  210. package/dist/util/hash/xxhash64.js +0 -27
  211. package/dist/util/identifier.js +0 -330
  212. package/dist/util/index.js +0 -123
  213. package/dist/util/memoize.js +0 -61
  214. package/dist/util/scheme.js +0 -57
  215. package/dist/util/smartGrouping.js +0 -148
  216. package/dist/util/source.js +0 -42
  217. package/dist/util/validate.js +0 -77
  218. package/dist/util/webpack.js +0 -27
  219. /package/dist/{container/default.runtime.js → moduleFederationDefaultRuntime.js} +0 -0
@@ -1,167 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatsFactory = void 0;
4
- const lite_tapable_1 = require("@rspack/lite-tapable");
5
- const comparators_1 = require("../util/comparators");
6
- const smartGrouping_1 = require("../util/smartGrouping");
7
- class StatsFactory {
8
- constructor() {
9
- this.hooks = Object.freeze({
10
- extract: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
11
- "object",
12
- "data",
13
- "context"
14
- ])),
15
- filter: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["item", "context", "index", "unfilteredIndex"])),
16
- sort: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["comparators", "context"])),
17
- filterSorted: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["item", "context", "index", "unfilteredIndex"])),
18
- groupResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["groupConfigs", "context"])),
19
- sortResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["comparators", "context"])),
20
- filterResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["item", "context", "index", "unfilteredIndex"])),
21
- merge: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
22
- "items",
23
- "context"
24
- ])),
25
- result: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncWaterfallHook([
26
- "result",
27
- "context"
28
- ])),
29
- getItemName: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
30
- "item",
31
- "context"
32
- ])),
33
- getItemFactory: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
34
- "item",
35
- "context"
36
- ]))
37
- });
38
- const hooks = this.hooks;
39
- const caches = {};
40
- for (const key of Object.keys(hooks)) {
41
- caches[key] = new Map();
42
- }
43
- this._caches = caches;
44
- this._inCreate = false;
45
- }
46
- _getAllLevelHooks(hookMap, cache, type) {
47
- const cacheEntry = cache.get(type);
48
- if (cacheEntry !== undefined) {
49
- return cacheEntry;
50
- }
51
- const hooks = [];
52
- const typeParts = type.split(".");
53
- for (let i = 0; i < typeParts.length; i++) {
54
- const hook = hookMap.get(typeParts.slice(i).join("."));
55
- if (hook) {
56
- hooks.push(hook);
57
- }
58
- }
59
- cache.set(type, hooks);
60
- return hooks;
61
- }
62
- _forEachLevel(hookMap, cache, type, fn) {
63
- for (const hook of this._getAllLevelHooks(hookMap, cache, type)) {
64
- const result = fn(hook);
65
- if (result !== undefined)
66
- return result;
67
- }
68
- }
69
- _forEachLevelWaterfall(hookMap, cache, type, data, fn) {
70
- return this._getAllLevelHooks(hookMap, cache, type).reduce((data, hook) => {
71
- return fn(hook, data);
72
- }, data);
73
- }
74
- _forEachLevelFilter(hookMap, cache, type, items, fn, forceClone) {
75
- const hooks = this._getAllLevelHooks(hookMap, cache, type);
76
- if (hooks.length === 0)
77
- return forceClone ? items.slice() : items;
78
- let i = 0;
79
- return items.filter((item, idx) => {
80
- for (const hook of hooks) {
81
- const r = fn(hook, item, idx, i);
82
- if (r !== undefined) {
83
- if (r)
84
- i++;
85
- return r;
86
- }
87
- }
88
- i++;
89
- return true;
90
- });
91
- }
92
- create(type, data, baseContext) {
93
- if (this._inCreate) {
94
- return this._create(type, data, baseContext);
95
- }
96
- try {
97
- this._inCreate = true;
98
- return this._create(type, data, baseContext);
99
- }
100
- finally {
101
- for (const key of Object.keys(this._caches))
102
- this._caches[key].clear();
103
- this._inCreate = false;
104
- }
105
- }
106
- _create(type, data, baseContext) {
107
- const context = {
108
- ...baseContext,
109
- type,
110
- [type]: data
111
- };
112
- if (Array.isArray(data)) {
113
- // run filter on unsorted items
114
- const items = this._forEachLevelFilter(this.hooks.filter, this._caches.filter, type, data, (h, r, idx, i) => h.call(r, context, idx, i), true);
115
- // sort items
116
- const comparators = [];
117
- this._forEachLevel(this.hooks.sort, this._caches.sort, type, h => h.call(comparators, context));
118
- if (comparators.length > 0) {
119
- items.sort((0, comparators_1.concatComparators)(...comparators));
120
- }
121
- // run filter on sorted items
122
- const items2 = this._forEachLevelFilter(this.hooks.filterSorted, this._caches.filterSorted, type, items, (h, r, idx, i) => h.call(r, context, idx, i), false);
123
- // for each item
124
- let resultItems = items2.map((item, i) => {
125
- const itemContext = {
126
- ...context,
127
- _index: i
128
- };
129
- // run getItemName
130
- const itemName = this._forEachLevel(this.hooks.getItemName, this._caches.getItemName, `${type}[]`, h => h.call(item, itemContext));
131
- if (itemName)
132
- itemContext[itemName] = item;
133
- const innerType = itemName ? `${type}[].${itemName}` : `${type}[]`;
134
- // run getItemFactory
135
- const itemFactory = this._forEachLevel(this.hooks.getItemFactory, this._caches.getItemFactory, innerType, h => h.call(item, itemContext)) || this;
136
- // run item factory
137
- return itemFactory.create(innerType, item, itemContext);
138
- });
139
- // sort result items
140
- const comparators2 = [];
141
- this._forEachLevel(this.hooks.sortResults, this._caches.sortResults, type, h => h.call(comparators2, context));
142
- if (comparators2.length > 0) {
143
- resultItems.sort((0, comparators_1.concatComparators)(...comparators2));
144
- }
145
- // group result items
146
- const groupConfigs = [];
147
- this._forEachLevel(this.hooks.groupResults, this._caches.groupResults, type, h => h.call(groupConfigs, context));
148
- if (groupConfigs.length > 0) {
149
- resultItems = (0, smartGrouping_1.smartGrouping)(resultItems, groupConfigs);
150
- }
151
- // run filter on sorted result items
152
- const finalResultItems = this._forEachLevelFilter(this.hooks.filterResults, this._caches.filterResults, type, resultItems, (h, r, idx, i) => h.call(r, context, idx, i), false);
153
- // run merge on mapped items
154
- let result = this._forEachLevel(this.hooks.merge, this._caches.merge, type, h => h.call(finalResultItems, context));
155
- if (result === undefined)
156
- result = finalResultItems;
157
- // run result on merged items
158
- return this._forEachLevelWaterfall(this.hooks.result, this._caches.result, type, result, (h, r) => h.call(r, context));
159
- }
160
- const object = {};
161
- // run extract on value
162
- this._forEachLevel(this.hooks.extract, this._caches.extract, type, h => h.call(object, data, context));
163
- // run result on extracted object
164
- return this._forEachLevelWaterfall(this.hooks.result, this._caches.result, type, object, (h, r) => h.call(r, context));
165
- }
166
- }
167
- exports.StatsFactory = StatsFactory;
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatsPrinter = void 0;
4
- const lite_tapable_1 = require("@rspack/lite-tapable");
5
- class StatsPrinter {
6
- constructor() {
7
- this.hooks = Object.freeze({
8
- sortElements: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
9
- "elements",
10
- "context"
11
- ])),
12
- printElements: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
13
- "printedElements",
14
- "context"
15
- ])),
16
- sortItems: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
17
- "items",
18
- "context"
19
- ])),
20
- getItemName: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
21
- "item",
22
- "context"
23
- ])),
24
- printItems: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
25
- "printedItems",
26
- "context"
27
- ])),
28
- print: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
29
- "object",
30
- "context"
31
- ])),
32
- result: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncWaterfallHook([
33
- "result",
34
- "context"
35
- ]))
36
- });
37
- this._levelHookCache = new Map();
38
- this._inPrint = false;
39
- }
40
- /**
41
- * get all level hooks
42
- */
43
- _getAllLevelHooks(hookMap, type) {
44
- // @ts-expect-error
45
- let cache = this._levelHookCache.get(hookMap);
46
- if (cache === undefined) {
47
- cache = new Map();
48
- // @ts-expect-error
49
- this._levelHookCache.set(hookMap, cache);
50
- }
51
- const cacheEntry = cache.get(type);
52
- if (cacheEntry !== undefined) {
53
- return cacheEntry;
54
- }
55
- const hooks = [];
56
- const typeParts = type.split(".");
57
- for (let i = 0; i < typeParts.length; i++) {
58
- const hook = hookMap.get(typeParts.slice(i).join("."));
59
- if (hook) {
60
- hooks.push(hook);
61
- }
62
- }
63
- cache.set(type, hooks);
64
- return hooks;
65
- }
66
- _forEachLevel(hookMap, type, fn) {
67
- for (const hook of this._getAllLevelHooks(hookMap, type)) {
68
- const result = fn(hook);
69
- if (result !== undefined)
70
- return result;
71
- }
72
- }
73
- _forEachLevelWaterfall(hookMap, type, data, fn) {
74
- return this._getAllLevelHooks(hookMap, type).reduce((data, hook) => {
75
- return fn(hook, data);
76
- }, data);
77
- }
78
- print(type, object, baseContext) {
79
- if (this._inPrint) {
80
- return this._print(type, object, baseContext);
81
- }
82
- try {
83
- this._inPrint = true;
84
- return this._print(type, object, baseContext);
85
- }
86
- finally {
87
- this._levelHookCache.clear();
88
- this._inPrint = false;
89
- }
90
- }
91
- _print(type, object, baseContext) {
92
- const context = {
93
- ...baseContext,
94
- type,
95
- [type]: object
96
- };
97
- let printResult = this._forEachLevel(this.hooks.print, type, hook => hook.call(object, context));
98
- if (printResult === undefined) {
99
- if (Array.isArray(object)) {
100
- const sortedItems = object.slice();
101
- this._forEachLevel(this.hooks.sortItems, type, h => h.call(sortedItems, context));
102
- const printedItems = sortedItems.map((item, i) => {
103
- const itemContext = {
104
- ...context,
105
- _index: i
106
- };
107
- const itemName = this._forEachLevel(this.hooks.getItemName, `${type}[]`, h => h.call(item, itemContext));
108
- if (itemName)
109
- itemContext[itemName] = item;
110
- return this.print(itemName ? `${type}[].${itemName}` : `${type}[]`, item, itemContext);
111
- });
112
- printResult = this._forEachLevel(this.hooks.printItems, type, h => h.call(printedItems, context));
113
- if (printResult === undefined) {
114
- const result = printedItems.filter(Boolean);
115
- if (result.length > 0)
116
- printResult = result.join("\n");
117
- }
118
- }
119
- else if (object !== null && typeof object === "object") {
120
- const elements = Object.keys(object).filter(key => object[key] !== undefined);
121
- this._forEachLevel(this.hooks.sortElements, type, h => h.call(elements, context));
122
- const printedElements = elements.map(element => {
123
- const content = this.print(`${type}.${element}`, object[element], {
124
- ...context,
125
- _parent: object,
126
- _element: element,
127
- [element]: object[element]
128
- });
129
- return { element, content };
130
- });
131
- printResult = this._forEachLevel(this.hooks.printElements, type, h => h.call(printedElements, context));
132
- if (printResult === undefined) {
133
- const result = printedElements.map(e => e.content).filter(Boolean);
134
- if (result.length > 0)
135
- printResult = result.join("\n");
136
- }
137
- }
138
- }
139
- return this._forEachLevelWaterfall(this.hooks.result, type, printResult, (h, r) => h.call(r, context));
140
- }
141
- }
142
- exports.StatsPrinter = StatsPrinter;
@@ -1,341 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorsSpaceLimit = exports.resolveStatsMillisecond = exports.mergeToObject = exports.moduleGroup = exports.assetGroup = exports.sortByField = exports.countWithChildren = exports.spaceLimited = exports.collapse = exports.getTotalItems = exports.iterateConfig = exports.uniqueOrderedArray = exports.uniqueArray = void 0;
4
- const comparators_1 = require("../util/comparators");
5
- const uniqueArray = (items, selector) => {
6
- const set = new Set();
7
- for (const item of items) {
8
- for (const i of selector(item)) {
9
- set.add(i);
10
- }
11
- }
12
- return Array.from(set);
13
- };
14
- exports.uniqueArray = uniqueArray;
15
- const uniqueOrderedArray = (items, selector, comparator) => {
16
- return (0, exports.uniqueArray)(items, selector).sort(comparator);
17
- };
18
- exports.uniqueOrderedArray = uniqueOrderedArray;
19
- const iterateConfig = (config, options, fn) => {
20
- for (const hookFor of Object.keys(config)) {
21
- const subConfig = config[hookFor];
22
- for (const option of Object.keys(subConfig)) {
23
- if (option !== "_") {
24
- if (option.startsWith("!")) {
25
- if (
26
- // string cannot be used as key, so use "as"
27
- options[option.slice(1)])
28
- continue;
29
- }
30
- else {
31
- const value = options[option];
32
- if (value === false ||
33
- value === undefined ||
34
- (Array.isArray(value) && value.length === 0))
35
- continue;
36
- }
37
- }
38
- fn(hookFor, subConfig[option]);
39
- }
40
- }
41
- };
42
- exports.iterateConfig = iterateConfig;
43
- const getTotalItems = (children) => {
44
- let count = 0;
45
- for (const child of children) {
46
- if (!child.children && !child.filteredChildren) {
47
- count++;
48
- }
49
- else {
50
- if (child.children)
51
- count += (0, exports.getTotalItems)(child.children);
52
- if (child.filteredChildren)
53
- count += child.filteredChildren;
54
- }
55
- }
56
- return count;
57
- };
58
- exports.getTotalItems = getTotalItems;
59
- const collapse = (children) => {
60
- // After collapse each child must take exactly one line
61
- const newChildren = [];
62
- for (const child of children) {
63
- if (child.children) {
64
- let filteredChildren = child.filteredChildren || 0;
65
- filteredChildren += (0, exports.getTotalItems)(child.children);
66
- newChildren.push({
67
- ...child,
68
- children: undefined,
69
- filteredChildren
70
- });
71
- }
72
- else {
73
- newChildren.push(child);
74
- }
75
- }
76
- return newChildren;
77
- };
78
- exports.collapse = collapse;
79
- const getTotalSize = (children) => {
80
- let size = 0;
81
- for (const child of children) {
82
- size += getItemSize(child);
83
- }
84
- return size;
85
- };
86
- const getItemSize = (item) => {
87
- // Each item takes 1 line
88
- // + the size of the children
89
- // + 1 extra line when it has children and filteredChildren
90
- return !item.children
91
- ? 1
92
- : item.filteredChildren
93
- ? 2 + getTotalSize(item.children)
94
- : 1 + getTotalSize(item.children);
95
- };
96
- const spaceLimited = (itemsAndGroups, max, filteredChildrenLineReserved = false) => {
97
- if (max < 1) {
98
- return {
99
- children: undefined,
100
- filteredChildren: (0, exports.getTotalItems)(itemsAndGroups)
101
- };
102
- }
103
- let children = undefined;
104
- let filteredChildren = undefined;
105
- // This are the groups, which take 1+ lines each
106
- const groups = [];
107
- // The sizes of the groups are stored in groupSizes
108
- const groupSizes = [];
109
- // This are the items, which take 1 line each
110
- const items = [];
111
- // The total of group sizes
112
- let groupsSize = 0;
113
- for (const itemOrGroup of itemsAndGroups) {
114
- // is item
115
- if (!itemOrGroup.children && !itemOrGroup.filteredChildren) {
116
- items.push(itemOrGroup);
117
- }
118
- else {
119
- groups.push(itemOrGroup);
120
- const size = getItemSize(itemOrGroup);
121
- groupSizes.push(size);
122
- groupsSize += size;
123
- }
124
- }
125
- if (groupsSize + items.length <= max) {
126
- // The total size in the current state fits into the max
127
- // keep all
128
- children = groups.length > 0 ? groups.concat(items) : items;
129
- }
130
- else if (groups.length === 0) {
131
- // slice items to max
132
- // inner space marks that lines for filteredChildren already reserved
133
- const limit = max - (filteredChildrenLineReserved ? 0 : 1);
134
- filteredChildren = items.length - limit;
135
- items.length = limit;
136
- children = items;
137
- }
138
- else {
139
- // limit is the size when all groups are collapsed
140
- const limit = groups.length +
141
- (filteredChildrenLineReserved || items.length === 0 ? 0 : 1);
142
- if (limit < max) {
143
- // calculate how much we are over the size limit
144
- // this allows to approach the limit faster
145
- let oversize;
146
- // If each group would take 1 line the total would be below the maximum
147
- // collapse some groups, keep items
148
- while ((oversize =
149
- groupsSize +
150
- items.length +
151
- (filteredChildren && !filteredChildrenLineReserved ? 1 : 0) -
152
- max) > 0) {
153
- // Find the maximum group and process only this one
154
- const maxGroupSize = Math.max(...groupSizes);
155
- if (maxGroupSize < items.length) {
156
- filteredChildren = items.length;
157
- items.length = 0;
158
- continue;
159
- }
160
- for (let i = 0; i < groups.length; i++) {
161
- if (groupSizes[i] === maxGroupSize) {
162
- const group = groups[i];
163
- // run this algorithm recursively and limit the size of the children to
164
- // current size - oversize / number of groups
165
- // So it should always end up being smaller
166
- const headerSize = group.filteredChildren ? 2 : 1;
167
- const limited = (0, exports.spaceLimited)(group.children, maxGroupSize -
168
- // we should use ceil to always feet in max
169
- Math.ceil(oversize / groups.length) -
170
- // we substitute size of group head
171
- headerSize, headerSize === 2);
172
- groups[i] = {
173
- ...group,
174
- children: limited.children,
175
- filteredChildren: limited.filteredChildren
176
- ? (group.filteredChildren || 0) + limited.filteredChildren
177
- : group.filteredChildren
178
- };
179
- const newSize = getItemSize(groups[i]);
180
- groupsSize -= maxGroupSize - newSize;
181
- groupSizes[i] = newSize;
182
- break;
183
- }
184
- }
185
- }
186
- children = groups.concat(items);
187
- }
188
- else if (limit === max) {
189
- // If we have only enough space to show one line per group and one line for the filtered items
190
- // collapse all groups and items
191
- children = (0, exports.collapse)(groups);
192
- filteredChildren = items.length;
193
- }
194
- else {
195
- // If we have no space
196
- // collapse complete group
197
- filteredChildren = (0, exports.getTotalItems)(itemsAndGroups);
198
- }
199
- }
200
- return {
201
- children,
202
- filteredChildren
203
- };
204
- };
205
- exports.spaceLimited = spaceLimited;
206
- const countWithChildren = (compilation, getItems) => {
207
- let count = getItems(compilation, "").length;
208
- for (const child of compilation.children) {
209
- count += (0, exports.countWithChildren)(child, (c, type) => getItems(c, `.children[].compilation${type}`));
210
- }
211
- return count;
212
- };
213
- exports.countWithChildren = countWithChildren;
214
- // remove a prefixed "!" that can be specified to reverse sort order
215
- const normalizeFieldKey = (field) => {
216
- if (field[0] === "!") {
217
- return field.slice(1);
218
- }
219
- return field;
220
- };
221
- // if a field is prefixed by a "!" reverse sort order
222
- const sortOrderRegular = (field) => {
223
- if (field[0] === "!") {
224
- return false;
225
- }
226
- return true;
227
- };
228
- const sortByField = (field) => {
229
- if (!field) {
230
- const noSort = (_a, _b) => 0;
231
- return noSort;
232
- }
233
- const fieldKey = normalizeFieldKey(field);
234
- let sortFn = (0, comparators_1.compareSelect)((m) => m[fieldKey], comparators_1.compareIds);
235
- // if a field is prefixed with a "!" the sort is reversed!
236
- const sortIsRegular = sortOrderRegular(field);
237
- if (!sortIsRegular) {
238
- const oldSortFn = sortFn;
239
- sortFn = (a, b) => oldSortFn(b, a);
240
- }
241
- return sortFn;
242
- };
243
- exports.sortByField = sortByField;
244
- const assetGroup = (children) => {
245
- let size = 0;
246
- for (const asset of children) {
247
- size += asset.size;
248
- }
249
- return {
250
- size
251
- };
252
- };
253
- exports.assetGroup = assetGroup;
254
- const moduleGroup = (children) => {
255
- let size = 0;
256
- const sizes = {};
257
- for (const module of children) {
258
- size += module.size;
259
- for (const key of Object.keys(module.sizes)) {
260
- sizes[key] = (sizes[key] || 0) + module.sizes[key];
261
- }
262
- }
263
- return {
264
- size,
265
- sizes
266
- };
267
- };
268
- exports.moduleGroup = moduleGroup;
269
- const mergeToObject = (items) => {
270
- const obj = Object.create(null);
271
- for (const item of items) {
272
- obj[item.name] = item;
273
- }
274
- return obj;
275
- };
276
- exports.mergeToObject = mergeToObject;
277
- function resolveStatsMillisecond(s) {
278
- return s.secs * 1000 + s.subsecMillis;
279
- }
280
- exports.resolveStatsMillisecond = resolveStatsMillisecond;
281
- const errorsSpaceLimit = (errors, max) => {
282
- let filtered = 0;
283
- // Can not fit into limit
284
- // print only messages
285
- if (errors.length + 1 >= max) {
286
- return {
287
- errors: errors.map(error => {
288
- if (typeof error === "string" || !error.details)
289
- return error;
290
- filtered++;
291
- return { ...error, details: "" };
292
- }),
293
- filtered
294
- };
295
- }
296
- let fullLength = errors.length;
297
- let result = errors;
298
- let i = 0;
299
- for (; i < errors.length; i++) {
300
- const error = errors[i];
301
- if (typeof error !== "string" && error.details) {
302
- const splitted = error.details.split("\n");
303
- const len = splitted.length;
304
- fullLength += len;
305
- if (fullLength > max) {
306
- result = i > 0 ? errors.slice(0, i) : [];
307
- const overLimit = fullLength - max + 1;
308
- const error = errors[i++];
309
- result.push({
310
- ...error,
311
- details: error.details.split("\n").slice(0, -overLimit).join("\n"),
312
- filteredDetails: overLimit
313
- });
314
- filtered = errors.length - i;
315
- for (; i < errors.length; i++) {
316
- const error = errors[i];
317
- if (typeof error === "string" || !error.details)
318
- result.push(error);
319
- result.push({ ...error, details: "" });
320
- }
321
- break;
322
- }
323
- if (fullLength === max) {
324
- result = errors.slice(0, ++i);
325
- filtered = errors.length - i;
326
- for (; i < errors.length; i++) {
327
- const error = errors[i];
328
- if (typeof error === "string" || !error.details)
329
- result.push(error);
330
- result.push({ ...error, details: "" });
331
- }
332
- break;
333
- }
334
- }
335
- }
336
- return {
337
- errors: result,
338
- filtered
339
- };
340
- };
341
- exports.errorsSpaceLimit = errorsSpaceLimit;