@rspack/core 1.0.0-alpha.3 → 1.0.0-alpha.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 (48) hide show
  1. package/compiled/browserslist/index.js +17 -17
  2. package/compiled/enhanced-resolve/index.js +107 -107
  3. package/compiled/graceful-fs/index.js +8 -8
  4. package/compiled/json-parse-even-better-errors/index.js +2 -2
  5. package/compiled/neo-async/index.js +2 -2
  6. package/compiled/watchpack/index.js +15 -15
  7. package/compiled/webpack-sources/index.js +76 -76
  8. package/compiled/zod/index.js +30 -30
  9. package/compiled/zod-validation-error/index.js +6 -6
  10. package/dist/Compilation.js +2 -3
  11. package/dist/ErrorHelpers.d.ts +16 -7
  12. package/dist/ErrorHelpers.js +34 -33
  13. package/dist/ExecuteModulePlugin.js +1 -1
  14. package/dist/Module.d.ts +1 -2
  15. package/dist/Module.js +2 -6
  16. package/dist/MultiCompiler.js +1 -1
  17. package/dist/ResolverFactory.d.ts +5 -1
  18. package/dist/ResolverFactory.js +7 -1
  19. package/dist/RuntimeGlobals.js +3 -3
  20. package/dist/Stats.js +4 -4
  21. package/dist/Template.js +2 -2
  22. package/dist/builtin-plugin/DefinePlugin.js +2 -2
  23. package/dist/builtin-plugin/EntryPlugin.js +1 -1
  24. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +10 -2
  25. package/dist/builtin-plugin/SwcCssMinimizerPlugin.js +7 -1
  26. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +2 -2
  27. package/dist/builtin-plugin/WorkerPlugin.js +5 -1
  28. package/dist/builtin-plugin/base.js +1 -1
  29. package/dist/builtin-plugin/css-extract/loader.js +3 -3
  30. package/dist/config/adapter.d.ts +1 -1
  31. package/dist/config/adapter.js +20 -9
  32. package/dist/config/adapterRuleUse.js +1 -1
  33. package/dist/config/browserslistTargetHandler.js +1 -1
  34. package/dist/config/defaults.js +4 -3
  35. package/dist/config/zod.d.ts +110 -3
  36. package/dist/config/zod.js +42 -39
  37. package/dist/container/ModuleFederationPlugin.js +2 -2
  38. package/dist/loader-runner/index.js +6 -6
  39. package/dist/logging/runtime.js +1 -1
  40. package/dist/rspack.js +1 -1
  41. package/dist/sharing/ConsumeSharedPlugin.js +1 -1
  42. package/dist/stats/DefaultStatsFactoryPlugin.js +246 -46
  43. package/dist/stats/DefaultStatsPresetPlugin.js +17 -17
  44. package/dist/stats/DefaultStatsPrinterPlugin.js +1 -1
  45. package/dist/stats/statsFactoryUtils.d.ts +15 -0
  46. package/dist/util/identifier.d.ts +65 -62
  47. package/dist/util/identifier.js +30 -55
  48. package/package.json +6 -3
@@ -345,6 +345,7 @@ const reexportExportsPresence = zod_1.z
345
345
  .or(zod_1.z.literal(false));
346
346
  const strictExportPresence = zod_1.z.boolean();
347
347
  const worker = zod_1.z.array(zod_1.z.string()).or(zod_1.z.boolean());
348
+ const overrideStrict = zod_1.z.enum(["strict", "non-strict"]);
348
349
  const javascriptParserOptions = zod_1.z.strictObject({
349
350
  dynamicImportMode: dynamicImportMode.optional(),
350
351
  dynamicImportPreload: dynamicImportPreload.optional(),
@@ -357,7 +358,8 @@ const javascriptParserOptions = zod_1.z.strictObject({
357
358
  importExportsPresence: importExportsPresence.optional(),
358
359
  reexportExportsPresence: reexportExportsPresence.optional(),
359
360
  strictExportPresence: strictExportPresence.optional(),
360
- worker: worker.optional()
361
+ worker: worker.optional(),
362
+ overrideStrict: overrideStrict.optional()
361
363
  });
362
364
  const parserOptionsByModuleTypeKnown = zod_1.z.strictObject({
363
365
  asset: assetParserOptions.optional(),
@@ -442,44 +444,45 @@ const moduleOptions = zod_1.z.strictObject({
442
444
  });
443
445
  //#endregion
444
446
  //#region Target
445
- const allowTarget = zod_1.z
446
- .enum([
447
- "web",
448
- "webworker",
449
- "es3",
450
- "es5",
451
- "es2015",
452
- "es2016",
453
- "es2017",
454
- "es2018",
455
- "es2019",
456
- "es2020",
457
- "es2021",
458
- "es2022",
459
- "browserslist"
460
- ])
461
- .or(zod_1.z.literal("node"))
462
- .or(zod_1.z.literal("async-node"))
463
- .or(zod_1.z.custom(value => typeof value === "string" && /^node\d+$/.test(value)))
464
- .or(zod_1.z.custom(value => typeof value === "string" && /^async-node\d+$/.test(value)))
465
- .or(zod_1.z.custom(value => typeof value === "string" && /^node\d+\.\d+$/.test(value)))
466
- .or(zod_1.z.custom(value => typeof value === "string" && /^async-node\d+\.\d+$/.test(value)))
467
- .or(zod_1.z.literal("electron-main"))
468
- .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-main$/.test(value)))
469
- .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-main$/.test(value)))
470
- .or(zod_1.z.literal("electron-renderer"))
471
- .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-renderer$/.test(value)))
472
- .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-renderer$/.test(value)))
473
- .or(zod_1.z.literal("electron-preload"))
474
- .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-preload$/.test(value)))
475
- .or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-preload$/.test(value)))
476
- .or(zod_1.z.literal("nwjs"))
477
- .or(zod_1.z.custom(value => typeof value === "string" && /^nwjs\d+$/.test(value)))
478
- .or(zod_1.z.custom(value => typeof value === "string" && /^nwjs\d+\.\d+$/.test(value)))
479
- .or(zod_1.z.literal("node-webkit"))
480
- .or(zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+$/.test(value)))
481
- .or(zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+\.\d+$/.test(value)));
482
- const target = zod_1.z.literal(false).or(allowTarget).or(allowTarget.array());
447
+ const allowTarget = zod_1.z.union([
448
+ zod_1.z.enum([
449
+ "web",
450
+ "webworker",
451
+ "es3",
452
+ "es5",
453
+ "es2015",
454
+ "es2016",
455
+ "es2017",
456
+ "es2018",
457
+ "es2019",
458
+ "es2020",
459
+ "es2021",
460
+ "es2022",
461
+ "browserslist"
462
+ ]),
463
+ zod_1.z.literal("node"),
464
+ zod_1.z.literal("async-node"),
465
+ zod_1.z.custom(value => typeof value === "string" && /^node\d+$/.test(value)),
466
+ zod_1.z.custom(value => typeof value === "string" && /^async-node\d+$/.test(value)),
467
+ zod_1.z.custom(value => typeof value === "string" && /^node\d+\.\d+$/.test(value)),
468
+ zod_1.z.custom(value => typeof value === "string" && /^async-node\d+\.\d+$/.test(value)),
469
+ zod_1.z.literal("electron-main"),
470
+ zod_1.z.custom(value => typeof value === "string" && /^electron\d+-main$/.test(value)),
471
+ zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-main$/.test(value)),
472
+ zod_1.z.literal("electron-renderer"),
473
+ zod_1.z.custom(value => typeof value === "string" && /^electron\d+-renderer$/.test(value)),
474
+ zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-renderer$/.test(value)),
475
+ zod_1.z.literal("electron-preload"),
476
+ zod_1.z.custom(value => typeof value === "string" && /^electron\d+-preload$/.test(value)),
477
+ zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-preload$/.test(value)),
478
+ zod_1.z.literal("nwjs"),
479
+ zod_1.z.custom(value => typeof value === "string" && /^nwjs\d+$/.test(value)),
480
+ zod_1.z.custom(value => typeof value === "string" && /^nwjs\d+\.\d+$/.test(value)),
481
+ zod_1.z.literal("node-webkit"),
482
+ zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+$/.test(value)),
483
+ zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+\.\d+$/.test(value))
484
+ ]);
485
+ const target = zod_1.z.union([zod_1.z.literal(false), allowTarget, allowTarget.array()]);
483
486
  //#endregion
484
487
  //#region ExternalsType
485
488
  exports.externalsType = zod_1.z.enum([
@@ -71,8 +71,8 @@ function getRemoteInfos(options) {
71
71
  shareScope: item.shareScope || options.shareScope || "default"
72
72
  }));
73
73
  const remoteInfos = {};
74
- for (let [key, config] of remotes) {
75
- for (let external of config.external) {
74
+ for (const [key, config] of remotes) {
75
+ for (const external of config.external) {
76
76
  const [externalType, externalRequest] = getExternal(external);
77
77
  remoteInfos[key] ??= [];
78
78
  if (externalType === "script") {
@@ -59,10 +59,10 @@ function createLoaderObject(loader, compiler) {
59
59
  obj.query.replace(/#/g, "\u200b#") +
60
60
  obj.fragment,
61
61
  set: value => {
62
- var splittedRequest = (0, identifier_1.parseResourceWithoutFragment)(value.request);
62
+ const splittedRequest = (0, identifier_1.parseResourceWithoutFragment)(value.request);
63
63
  obj.path = splittedRequest.path;
64
64
  obj.query = splittedRequest.query;
65
- obj.fragment = splittedRequest.fragment || "";
65
+ obj.fragment = "";
66
66
  obj.options =
67
67
  obj.options === null
68
68
  ? splittedRequest.query
@@ -231,7 +231,7 @@ const runSyncOrAsync = (0, util_1.promisify)(function runSyncOrAsync(fn, context
231
231
  }
232
232
  catch (e) {
233
233
  // use string for napi getter
234
- let err = e;
234
+ const err = e;
235
235
  if ("hideStack" in err && err.hideStack) {
236
236
  err.hideStack = "true";
237
237
  }
@@ -514,7 +514,7 @@ async function runLoaders(compiler, context) {
514
514
  if (!(error instanceof Error)) {
515
515
  error = new RspackError_1.NonErrorEmittedError(error);
516
516
  }
517
- let hasStack = !!error.stack;
517
+ const hasStack = !!error.stack;
518
518
  error.name = "ModuleError";
519
519
  error.message = `${error.message} (from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
520
520
  !hasStack && Error.captureStackTrace(error);
@@ -529,7 +529,7 @@ async function runLoaders(compiler, context) {
529
529
  if (!(warning instanceof Error)) {
530
530
  warning = new RspackError_1.NonErrorEmittedError(warning);
531
531
  }
532
- let hasStack = !!warning.stack;
532
+ const hasStack = !!warning.stack;
533
533
  warning.name = "ModuleWarning";
534
534
  warning.message = `${warning.message} (from: ${(0, util_2.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
535
535
  hasStack && Error.captureStackTrace(warning);
@@ -686,7 +686,7 @@ async function runLoaders(compiler, context) {
686
686
  currentLoaderObject.normalExecuted = true;
687
687
  if (!fn)
688
688
  continue;
689
- let args = [content, sourceMap, additionalData];
689
+ const args = [content, sourceMap, additionalData];
690
690
  convertArgs(args, !!currentLoaderObject.raw);
691
691
  [content, sourceMap, additionalData] =
692
692
  (await runSyncOrAsync(fn, loaderContext, args)) || [];
@@ -14,7 +14,7 @@ const SyncBailHook = require("tapable/lib/SyncBailHook");
14
14
  const { Logger } = require("./Logger");
15
15
  const createConsoleLogger = require("./createConsoleLogger");
16
16
  /** @type {createConsoleLogger.LoggerOptions} */
17
- let currentDefaultLoggerOptions = {
17
+ const currentDefaultLoggerOptions = {
18
18
  level: "info",
19
19
  debug: false,
20
20
  console
package/dist/rspack.js CHANGED
@@ -68,7 +68,7 @@ function isMultiRspackOptions(o) {
68
68
  }
69
69
  function rspack(options, callback) {
70
70
  try {
71
- for (let o of (0, util_2.asArray)(options)) {
71
+ for (const o of (0, util_2.asArray)(options)) {
72
72
  (0, validate_1.validate)(o, config_1.rspackOptions);
73
73
  }
74
74
  }
@@ -14,7 +14,7 @@ class ConsumeSharedPlugin extends base_1.RspackBuiltinPlugin {
14
14
  consumes: (0, options_1.parseOptions)(options.consumes, (item, key) => {
15
15
  if (Array.isArray(item))
16
16
  throw new Error("Unexpected array in options");
17
- let result = item === key || !(0, utils_1.isRequiredVersion)(item)
17
+ const result = item === key || !(0, utils_1.isRequiredVersion)(item)
18
18
  ? // item is a request/key
19
19
  {
20
20
  import: key,
@@ -57,22 +57,14 @@ const ITEM_NAMES = {
57
57
  "module.issuerPath[]": "moduleIssuer",
58
58
  "module.reasons[]": "moduleReason",
59
59
  "module.modules[]": "module",
60
- "module.children[]": "module"
61
- // "moduleTrace[]": "moduleTraceItem",
60
+ "module.children[]": "module",
61
+ "moduleTrace[]": "moduleTraceItem"
62
62
  // "moduleTraceItem.dependencies[]": "moduleTraceDependency"
63
63
  };
64
- // const MERGER: Record<
65
- // string,
66
- // (
67
- // items: {
68
- // [key: string]: any;
69
- // name: string;
70
- // }[]
71
- // ) => any
72
- // > = {
73
- // "compilation.entrypoints": mergeToObject,
74
- // "compilation.namedChunkGroups": mergeToObject
75
- // };
64
+ const MERGER = {
65
+ "compilation.entrypoints": statsFactoryUtils_1.mergeToObject,
66
+ "compilation.namedChunkGroups": statsFactoryUtils_1.mergeToObject
67
+ };
76
68
  const ASSETS_GROUPERS = {
77
69
  _: (groupConfigs, context, options) => {
78
70
  const groupByFlag = (name, exclude) => {
@@ -149,10 +141,74 @@ const ASSETS_GROUPERS = {
149
141
  }
150
142
  });
151
143
  }
144
+ },
145
+ groupAssetsByInfo: groupConfigs => {
146
+ const groupByAssetInfoFlag = (name) => {
147
+ groupConfigs.push({
148
+ getKeys: asset => {
149
+ return asset.info && asset.info[name] ? ["1"] : undefined;
150
+ },
151
+ // @ts-expect-error
152
+ createGroup: (key, children) => {
153
+ return {
154
+ type: "assets by info",
155
+ info: {
156
+ [name]: !!key
157
+ },
158
+ children,
159
+ ...(0, statsFactoryUtils_1.assetGroup)(children)
160
+ };
161
+ }
162
+ });
163
+ };
164
+ groupByAssetInfoFlag("immutable");
165
+ groupByAssetInfoFlag("development");
166
+ groupByAssetInfoFlag("hotModuleReplacement");
167
+ },
168
+ groupAssetsByChunk: groupConfigs => {
169
+ const groupByNames = (name) => {
170
+ groupConfigs.push({
171
+ getKeys: asset => {
172
+ return asset[name];
173
+ },
174
+ // @ts-expect-error
175
+ createGroup: (key, children) => {
176
+ return {
177
+ type: "assets by chunk",
178
+ [name]: [key],
179
+ children,
180
+ ...(0, statsFactoryUtils_1.assetGroup)(children)
181
+ };
182
+ }
183
+ });
184
+ };
185
+ groupByNames("chunkNames");
186
+ // groupByNames("auxiliaryChunkNames");
187
+ // groupByNames("chunkIdHints");
188
+ // groupByNames("auxiliaryChunkIdHints");
189
+ },
190
+ excludeAssets: (groupConfigs, context, { excludeAssets }) => {
191
+ groupConfigs.push({
192
+ getKeys: asset => {
193
+ const ident = asset.name;
194
+ const excluded = excludeAssets.some(fn => fn(ident, asset));
195
+ if (excluded)
196
+ return ["excluded"];
197
+ },
198
+ getOptions: () => ({
199
+ groupChildren: false,
200
+ force: true
201
+ }),
202
+ // @ts-expect-error
203
+ createGroup: (key, children, assets) => ({
204
+ type: "hidden assets",
205
+ filteredChildren: assets.length,
206
+ ...(0, statsFactoryUtils_1.assetGroup)(children)
207
+ })
208
+ });
152
209
  }
153
- // not support groupAssetsByInfo / groupAssetsByChunk / excludeAssets
154
210
  };
155
- const MODULES_GROUPERS = (_type) => ({
211
+ const MODULES_GROUPERS = (type) => ({
156
212
  _: (groupConfigs, context, options) => {
157
213
  const groupByFlag = (name, type, exclude) => {
158
214
  groupConfigs.push({
@@ -176,7 +232,7 @@ const MODULES_GROUPERS = (_type) => ({
176
232
  }
177
233
  });
178
234
  };
179
- const { groupModulesByCacheStatus, groupModulesByAttributes, groupModulesByType } = options;
235
+ const { groupModulesByCacheStatus, groupModulesByAttributes, groupModulesByType, groupModulesByPath, groupModulesByExtension } = options;
180
236
  if (groupModulesByAttributes) {
181
237
  groupByFlag("errors", "modules with errors");
182
238
  groupByFlag("warnings", "modules with warnings");
@@ -228,9 +284,76 @@ const MODULES_GROUPERS = (_type) => ({
228
284
  }
229
285
  });
230
286
  }
231
- // not support groupModulesByLayer / groupModulesByPath / groupModulesByExtension
287
+ // not support groupModulesByLayer
288
+ if (groupModulesByPath || groupModulesByExtension) {
289
+ groupConfigs.push({
290
+ getKeys: module => {
291
+ if (!module.name)
292
+ return;
293
+ const resource = (0, identifier_1.parseResource)(module.name.split("!").pop()).path;
294
+ const dataUrl = /^data:[^,;]+/.exec(resource);
295
+ if (dataUrl)
296
+ return [dataUrl[0]];
297
+ const extensionMatch = groupModulesByExtension && GROUP_EXTENSION_REGEXP.exec(resource);
298
+ const extension = extensionMatch ? extensionMatch[1] : "";
299
+ const pathMatch = groupModulesByPath && GROUP_PATH_REGEXP.exec(resource);
300
+ const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
301
+ const keys = [];
302
+ if (groupModulesByPath) {
303
+ if (extension)
304
+ keys.push(path.length
305
+ ? `${path.join("/")}/*${extension}`
306
+ : `*${extension}`);
307
+ while (path.length > 0) {
308
+ keys.push(path.join("/") + "/");
309
+ path.pop();
310
+ }
311
+ }
312
+ else {
313
+ if (extension)
314
+ keys.push(`*${extension}`);
315
+ }
316
+ return keys;
317
+ },
318
+ // @ts-expect-error
319
+ createGroup: (key, children, modules) => {
320
+ const isDataUrl = key.startsWith("data:");
321
+ return {
322
+ type: isDataUrl
323
+ ? "modules by mime type"
324
+ : groupModulesByPath
325
+ ? "modules by path"
326
+ : "modules by extension",
327
+ name: isDataUrl ? key.slice(/* 'data:'.length */ 5) : key,
328
+ children,
329
+ ...(0, statsFactoryUtils_1.moduleGroup)(children)
330
+ };
331
+ }
332
+ });
333
+ }
334
+ },
335
+ excludeModules: (groupConfigs, context, { excludeModules }) => {
336
+ groupConfigs.push({
337
+ getKeys: module => {
338
+ const name = module.name;
339
+ if (name) {
340
+ const excluded = excludeModules.some(fn => fn(name, module, type));
341
+ if (excluded)
342
+ return ["1"];
343
+ }
344
+ },
345
+ getOptions: () => ({
346
+ groupChildren: false,
347
+ force: true
348
+ }),
349
+ // @ts-expect-error
350
+ createGroup: (key, children, modules) => ({
351
+ type: "hidden modules",
352
+ filteredChildren: children.length,
353
+ ...(0, statsFactoryUtils_1.moduleGroup)(children)
354
+ })
355
+ });
232
356
  }
233
- // not support excludeModules
234
357
  });
235
358
  const RESULT_GROUPERS = {
236
359
  "compilation.assets": ASSETS_GROUPERS,
@@ -295,6 +418,31 @@ const SORTERS = {
295
418
  }
296
419
  }
297
420
  };
421
+ const EXTRACT_ERROR = {
422
+ _: (object, error) => {
423
+ object.message = error.message;
424
+ object.chunkName = error.chunkName;
425
+ object.chunkEntry = error.chunkEntry;
426
+ object.chunkInitial = error.chunkInitial;
427
+ object.file = error.file;
428
+ object.moduleIdentifier = error.moduleIdentifier;
429
+ object.moduleName = error.moduleName;
430
+ },
431
+ ids: (object, error) => {
432
+ object.chunkId = error.chunkId;
433
+ object.moduleId = error.moduleId;
434
+ },
435
+ moduleTrace: (object, error, context, _, factory) => {
436
+ const { type } = context;
437
+ object.moduleTrace = factory.create(`${type}.moduleTrace`, error.moduleTrace, context);
438
+ },
439
+ errorDetails: (object, error) => {
440
+ object.details = error.details;
441
+ },
442
+ errorStack: (object, error) => {
443
+ object.stack = error.stack;
444
+ }
445
+ };
298
446
  const SIMPLE_EXTRACTORS = {
299
447
  compilation: {
300
448
  _: (object, compilation, context, options) => {
@@ -487,7 +635,7 @@ const SIMPLE_EXTRACTORS = {
487
635
  // compilationFileToChunks
488
636
  // compilationAuxiliaryFileToChunks
489
637
  });
490
- const limited = (0, statsFactoryUtils_1.spaceLimited)(groupedAssets, options.assetsSpace || Infinity);
638
+ const limited = (0, statsFactoryUtils_1.spaceLimited)(groupedAssets, options.assetsSpace || Number.POSITIVE_INFINITY);
491
639
  // object.filteredAssets = limited.filteredChildren;
492
640
  // const limited = spaceLimited(groupedAssets, options.assetsSpace);
493
641
  object.assets = limited.children;
@@ -509,35 +657,46 @@ const SIMPLE_EXTRACTORS = {
509
657
  object.modules = limited.children;
510
658
  object.filteredModules = limited.filteredChildren;
511
659
  },
512
- entrypoints: (object, compilation, context, { chunkGroupAuxiliary, chunkGroupChildren }, _factory) => {
513
- // const { type } = context;
660
+ entrypoints: (object, compilation, context, { entrypoints, chunkGroups, chunkGroupAuxiliary, chunkGroupChildren }, factory) => {
661
+ const { type } = context;
514
662
  const array = context
515
663
  .getInner(compilation)
516
- .getEntrypoints(chunkGroupAuxiliary, chunkGroupChildren);
517
- // object.entrypoints = factory.create(
518
- // `${type}.entrypoints`,
519
- // array,
520
- // context
521
- // );
522
- object.entrypoints = array.reduce((acc, cur) => {
523
- acc[cur.name] = cur;
524
- return acc;
664
+ .getEntrypoints(chunkGroupAuxiliary, chunkGroupChildren)
665
+ .map(entrypoint => ({
666
+ name: entrypoint.name,
667
+ chunkGroup: entrypoint
668
+ }));
669
+ const chunks = Array.from(compilation.chunks).reduce((res, chunk) => {
670
+ res[chunk.id] = chunk;
671
+ return res;
525
672
  }, {});
673
+ if (entrypoints === "auto" && !chunkGroups) {
674
+ if (array.length > 5)
675
+ return;
676
+ if (!chunkGroupChildren &&
677
+ array.every(({ chunkGroup }) => {
678
+ if (chunkGroup.chunks.length !== 1)
679
+ return false;
680
+ const chunk = chunks[chunkGroup.chunks[0]];
681
+ return (chunk &&
682
+ chunk.files.size === 1 &&
683
+ (!chunkGroupAuxiliary || chunk.auxiliaryFiles.size === 0));
684
+ })) {
685
+ return;
686
+ }
687
+ }
688
+ object.entrypoints = factory.create(`${type}.entrypoints`, array, context);
526
689
  },
527
690
  chunkGroups: (object, compilation, context, { chunkGroupAuxiliary, chunkGroupChildren }, factory) => {
528
- // const { type } = context;
691
+ const { type } = context;
529
692
  const namedChunkGroups = context
530
693
  .getInner(compilation)
531
- .getNamedChunkGroups(chunkGroupAuxiliary, chunkGroupChildren);
532
- // object.namedChunkGroups = factory.create(
533
- // `${type}.namedChunkGroups`,
534
- // namedChunkGroups,
535
- // context
536
- // );
537
- object.namedChunkGroups = namedChunkGroups.reduce((acc, cur) => {
538
- acc[cur.name] = cur;
539
- return acc;
540
- }, {});
694
+ .getNamedChunkGroups(chunkGroupAuxiliary, chunkGroupChildren)
695
+ .map(cg => ({
696
+ name: cg.name,
697
+ chunkGroup: cg
698
+ }));
699
+ object.namedChunkGroups = factory.create(`${type}.namedChunkGroups`, namedChunkGroups, context);
541
700
  },
542
701
  errors: (object, compilation, context, _options, _factory) => {
543
702
  const { cachedGetErrors } = context;
@@ -571,15 +730,39 @@ const SIMPLE_EXTRACTORS = {
571
730
  ...asset.info,
572
731
  related: Object.fromEntries(asset.info.related.map(i => [i.name, i.value]))
573
732
  };
733
+ // - comparedForEmit
734
+ // - cached
574
735
  Object.assign(object, factory.create(`${context.type}$visible`, asset, context));
575
736
  }
576
737
  },
577
738
  asset$visible: {
578
739
  _: (object, asset) => {
579
740
  object.chunkNames = asset.chunkNames;
741
+ // - chunkIdHints
742
+ // - auxiliaryChunkNames
743
+ // - auxiliaryChunkIdHints
744
+ // - filteredRelated
580
745
  },
746
+ // relatedAssets
581
747
  ids: (object, asset) => {
582
748
  object.chunks = asset.chunks;
749
+ // - auxiliaryChunks
750
+ }
751
+ },
752
+ chunkGroup: {
753
+ _: (object, { name, chunkGroup }, _context, { chunkGroupMaxAssets }) => {
754
+ object.name = name;
755
+ object.chunks = chunkGroup.chunks;
756
+ object.assets = chunkGroup.assets;
757
+ object.filteredAssets =
758
+ chunkGroup.assets.length <= chunkGroupMaxAssets
759
+ ? 0
760
+ : chunkGroup.assets.length;
761
+ object.assetsSize = chunkGroup.assetsSize;
762
+ object.auxiliaryAssets = chunkGroup.auxiliaryAssets;
763
+ object.auxiliaryAssetsSize = chunkGroup.auxiliaryAssetsSize;
764
+ object.children = chunkGroup.children;
765
+ // - childAssets
583
766
  }
584
767
  },
585
768
  module: {
@@ -635,6 +818,7 @@ const SIMPLE_EXTRACTORS = {
635
818
  reasons: (object, module, context, options, factory) => {
636
819
  const { type } = context;
637
820
  object.reasons = factory.create(`${type.slice(0, -8)}.reasons`, module.reasons, context);
821
+ // object.filteredReasons
638
822
  },
639
823
  source: (object, module) => {
640
824
  object.source = module.source;
@@ -745,7 +929,23 @@ const SIMPLE_EXTRACTORS = {
745
929
  chunkOrigins: (object, chunk, context, options, factory) => {
746
930
  object.origins = chunk.origins;
747
931
  }
932
+ },
933
+ // chunkOrigin
934
+ error: EXTRACT_ERROR,
935
+ warning: EXTRACT_ERROR,
936
+ moduleTraceItem: {
937
+ _: (object, { origin, module }, context, { requestShortener }, factory) => {
938
+ object.originIdentifier = origin.identifier;
939
+ object.originName = origin.name;
940
+ object.moduleIdentifier = module.identifier;
941
+ object.moduleName = module.name;
942
+ },
943
+ ids: (object, { origin, module }) => {
944
+ object.originId = origin.id;
945
+ object.moduleId = module.id;
946
+ }
748
947
  }
948
+ // moduleTraceDependency
749
949
  };
750
950
  /**
751
951
  * only support below factories:
@@ -797,10 +997,10 @@ class DefaultStatsFactoryPlugin {
797
997
  .for(key)
798
998
  .tap("DefaultStatsFactoryPlugin", () => itemName);
799
999
  }
800
- // for (const key of Object.keys(MERGER)) {
801
- // const merger = MERGER[key];
802
- // stats.hooks.merge.for(key).tap("DefaultStatsFactoryPlugin", merger);
803
- // }
1000
+ for (const key of Object.keys(MERGER)) {
1001
+ const merger = MERGER[key];
1002
+ stats.hooks.merge.for(key).tap("DefaultStatsFactoryPlugin", merger);
1003
+ }
804
1004
  });
805
1005
  });
806
1006
  }