@rspack/core 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/Compilation.d.ts +21 -8
  2. package/dist/Compilation.js +114 -57
  3. package/dist/Compiler.d.ts +1 -0
  4. package/dist/Compiler.js +29 -24
  5. package/dist/DependenciesBlock.d.ts +8 -0
  6. package/dist/DependenciesBlock.js +30 -0
  7. package/dist/Dependency.d.ts +8 -0
  8. package/dist/Dependency.js +32 -0
  9. package/dist/Module.d.ts +6 -3
  10. package/dist/Module.js +13 -0
  11. package/dist/MultiCompiler.js +10 -6
  12. package/dist/MultiStats.d.ts +1 -1
  13. package/dist/MultiStats.js +19 -16
  14. package/dist/NormalModule.js +3 -4
  15. package/dist/Stats.d.ts +1 -1
  16. package/dist/Template.d.ts +4 -4
  17. package/dist/Template.js +6 -4
  18. package/dist/Watching.js +3 -5
  19. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +11 -10
  20. package/dist/builtin-plugin/DynamicEntryPlugin.js +26 -15
  21. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  22. package/dist/builtin-plugin/ExternalsPlugin.d.ts +4 -4
  23. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +21 -4
  24. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +29 -5
  25. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +4 -6
  26. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +16 -10
  27. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +11 -9
  28. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +28 -17
  29. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +1 -1
  30. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +2 -2
  31. package/dist/builtin-plugin/css-extract/loader.js +1 -2
  32. package/dist/config/adapter.d.ts +2 -2
  33. package/dist/config/defaults.js +9 -6
  34. package/dist/config/zod.d.ts +537 -141
  35. package/dist/config/zod.js +18 -10
  36. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  37. package/dist/exports.d.ts +4 -3
  38. package/dist/exports.js +5 -2
  39. package/dist/lib/Cache.js +6 -4
  40. package/dist/lib/CacheFacade.js +8 -9
  41. package/dist/lib/LoaderOptionsPlugin.d.ts +4 -2
  42. package/dist/lib/LoaderOptionsPlugin.js +0 -2
  43. package/dist/lib/cache/mergeEtags.d.ts +3 -3
  44. package/dist/lib/cache/mergeEtags.js +5 -3
  45. package/dist/loader-runner/index.js +4 -2
  46. package/dist/node/nodeConsole.js +5 -5
  47. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +0 -10
  48. package/dist/stats/DefaultStatsFactoryPlugin.js +130 -90
  49. package/dist/stats/DefaultStatsPresetPlugin.js +17 -18
  50. package/dist/stats/StatsFactory.js +8 -10
  51. package/dist/stats/StatsPrinter.js +3 -4
  52. package/dist/stats/statsFactoryUtils.d.ts +119 -19
  53. package/dist/stats/statsFactoryUtils.js +62 -1
  54. package/dist/util/assertNotNil.d.ts +1 -1
  55. package/dist/util/assetCondition.d.ts +2 -0
  56. package/dist/util/assetCondition.js +2 -0
  57. package/dist/util/cleverMerge.js +5 -4
  58. package/dist/util/createHash.js +10 -5
  59. package/dist/util/hash/wasm-hash.js +5 -4
  60. package/dist/util/identifier.d.ts +4 -4
  61. package/dist/util/identifier.js +10 -10
  62. package/dist/util/memoize.js +3 -2
  63. package/package.json +3 -3
  64. package/dist/builtin-plugin/css-extract/loader-options.json +0 -37
  65. package/dist/builtin-plugin/css-extract/plugin-options.json +0 -79
@@ -114,7 +114,10 @@ const entryDescription = zod_1.z.strictObject({
114
114
  const entryUnnamed = entryItem;
115
115
  const entryObject = zod_1.z.record(entryItem.or(entryDescription));
116
116
  const entryStatic = entryObject.or(entryUnnamed);
117
- const entry = entryStatic.or(zod_1.z.function().returns(entryStatic.or(zod_1.z.promise(entryStatic))));
117
+ const entryDynamic = zod_1.z
118
+ .function()
119
+ .returns(entryStatic.or(zod_1.z.promise(entryStatic)));
120
+ const entry = entryStatic.or(entryDynamic);
118
121
  //#endregion
119
122
  //#region Output
120
123
  const path = zod_1.z.string();
@@ -467,8 +470,7 @@ const allowTarget = zod_1.z.union([
467
470
  "es2019",
468
471
  "es2020",
469
472
  "es2021",
470
- "es2022",
471
- "browserslist"
473
+ "es2022"
472
474
  ]),
473
475
  zod_1.z.literal("node"),
474
476
  zod_1.z.literal("async-node"),
@@ -490,7 +492,9 @@ const allowTarget = zod_1.z.union([
490
492
  zod_1.z.custom(value => typeof value === "string" && /^nwjs\d+\.\d+$/.test(value)),
491
493
  zod_1.z.literal("node-webkit"),
492
494
  zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+$/.test(value)),
493
- zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+\.\d+$/.test(value))
495
+ zod_1.z.custom(value => typeof value === "string" && /^node-webkit\d+\.\d+$/.test(value)),
496
+ zod_1.z.literal("browserslist"),
497
+ zod_1.z.custom(value => typeof value === "string" && /^browserslist:(.+)$/.test(value))
494
498
  ]);
495
499
  const target = zod_1.z.union([zod_1.z.literal(false), allowTarget, allowTarget.array()]);
496
500
  //#endregion
@@ -515,6 +519,7 @@ exports.externalsType = zod_1.z.enum([
515
519
  "system",
516
520
  "promise",
517
521
  "import",
522
+ "module-import",
518
523
  "script",
519
524
  "node-commonjs"
520
525
  ]);
@@ -614,11 +619,11 @@ const devTool = zod_1.z
614
619
  const nodeOptions = zod_1.z.strictObject({
615
620
  __dirname: zod_1.z
616
621
  .boolean()
617
- .or(zod_1.z.enum(["warn-mock", "mock", "eval-only"]))
622
+ .or(zod_1.z.enum(["warn-mock", "mock", "eval-only", "node-module"]))
618
623
  .optional(),
619
624
  __filename: zod_1.z
620
625
  .boolean()
621
- .or(zod_1.z.enum(["warn-mock", "mock", "eval-only"]))
626
+ .or(zod_1.z.enum(["warn-mock", "mock", "eval-only", "node-module"]))
622
627
  .optional(),
623
628
  global: zod_1.z.boolean().or(zod_1.z.literal("warn")).optional()
624
629
  });
@@ -735,11 +740,13 @@ const statsOptions = zod_1.z.strictObject({
735
740
  errorStack: zod_1.z.boolean().optional(),
736
741
  moduleTrace: zod_1.z.boolean().optional(),
737
742
  cachedModules: zod_1.z.boolean().optional(),
738
- cached: zod_1.z.boolean().optional()
743
+ cachedAssets: zod_1.z.boolean().optional(),
744
+ cached: zod_1.z.boolean().optional(),
745
+ errorsSpace: zod_1.z.number().optional(),
746
+ warningsSpace: zod_1.z.number().optional()
739
747
  });
740
748
  const statsValue = zod_1.z.boolean().or(statsPresets).or(statsOptions);
741
749
  const plugin = zod_1.z.union([
742
- zod_1.z.custom(),
743
750
  zod_1.z.custom(),
744
751
  falsy
745
752
  ]);
@@ -779,11 +786,14 @@ const sharedOptimizationSplitChunksCacheGroup = {
779
786
  chunks: optimizationSplitChunksChunks.optional(),
780
787
  defaultSizeTypes: optimizationSplitChunksDefaultSizeTypes.optional(),
781
788
  minChunks: zod_1.z.number().min(1).optional(),
789
+ usedExports: zod_1.z.boolean().optional(),
782
790
  name: optimizationSplitChunksName.optional(),
783
791
  minSize: optimizationSplitChunksSizes.optional(),
784
792
  maxSize: optimizationSplitChunksSizes.optional(),
785
793
  maxAsyncSize: optimizationSplitChunksSizes.optional(),
786
794
  maxInitialSize: optimizationSplitChunksSizes.optional(),
795
+ maxAsyncRequests: zod_1.z.number().optional(),
796
+ maxInitialRequests: zod_1.z.number().optional(),
787
797
  automaticNameDelimiter: zod_1.z.string().optional()
788
798
  };
789
799
  const optimizationSplitChunksCacheGroup = zod_1.z.strictObject({
@@ -806,8 +816,6 @@ const optimizationSplitChunksOptions = zod_1.z.strictObject({
806
816
  cacheGroups: zod_1.z
807
817
  .record(zod_1.z.literal(false).or(optimizationSplitChunksCacheGroup))
808
818
  .optional(),
809
- maxAsyncRequests: zod_1.z.number().optional(),
810
- maxInitialRequests: zod_1.z.number().optional(),
811
819
  fallbackCacheGroup: zod_1.z
812
820
  .strictObject({
813
821
  chunks: optimizationSplitChunksChunks.optional(),
@@ -21,7 +21,7 @@ export type RemotesConfig = {
21
21
  export declare class ContainerReferencePlugin extends RspackBuiltinPlugin {
22
22
  name: BuiltinPluginName;
23
23
  _options: {
24
- remoteType: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "script" | "node-commonjs";
24
+ remoteType: "module" | "global" | "system" | "promise" | "commonjs" | "umd" | "amd" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "module-import" | "script" | "node-commonjs";
25
25
  remotes: [string, {
26
26
  external: string[];
27
27
  shareScope: string;
package/dist/exports.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- declare const rspackVersion: any, webpackVersion: any;
2
- export { rspackVersion, webpackVersion as version };
1
+ declare const rspackVersion: string;
2
+ declare const version: string;
3
+ export { rspackVersion, version };
3
4
  export type { Asset, AssetInfo, Assets, CompilationParams, LogEntry } from "./Compilation";
4
5
  export { Compilation } from "./Compilation";
5
6
  export { Compiler } from "./Compiler";
@@ -14,7 +15,7 @@ export { MultiStats } from "./MultiStats";
14
15
  export { NormalModule } from "./NormalModule";
15
16
  export type { NormalModuleFactory } from "./NormalModuleFactory";
16
17
  export { RuntimeGlobals } from "./RuntimeGlobals";
17
- export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule, StatsWarnings } from "./Stats";
18
+ export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule } from "./Stats";
18
19
  export { Stats } from "./Stats";
19
20
  import * as ModuleFilenameHelpers from "./lib/ModuleFilenameHelpers";
20
21
  export { ModuleFilenameHelpers };
package/dist/exports.js CHANGED
@@ -28,9 +28,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.CssExtractRspackPlugin = exports.EvalDevToolModulePlugin = exports.EvalSourceMapDevToolPlugin = exports.SourceMapDevToolPlugin = exports.CopyRspackPlugin = exports.LightningCssMinimizerRspackPlugin = exports.SwcCssMinimizerRspackPlugin = exports.SwcJsMinimizerRspackPlugin = exports.HtmlRspackPlugin = exports.sharing = exports.container = exports.optimize = exports.webworker = exports.javascript = exports.wasm = exports.library = exports.electron = exports.node = exports.web = exports.NormalModuleReplacementPlugin = exports.LoaderTargetPlugin = exports.LoaderOptionsPlugin = exports.EnvironmentPlugin = exports.HotModuleReplacementPlugin = exports.ExternalsPlugin = exports.DynamicEntryPlugin = exports.EntryPlugin = exports.ProgressPlugin = exports.DefinePlugin = exports.ProvidePlugin = exports.IgnorePlugin = exports.BannerPlugin = exports.EntryOptionPlugin = exports.util = exports.config = exports.sources = exports.WebpackError = exports.Template = exports.ModuleFilenameHelpers = exports.Stats = exports.RuntimeGlobals = exports.NormalModule = exports.MultiStats = exports.WebpackOptionsApply = exports.RspackOptionsApply = exports.MultiCompiler = exports.Compiler = exports.Compilation = exports.version = exports.rspackVersion = void 0;
30
30
  exports.experiments = void 0;
31
- const { version: rspackVersion, webpackVersion } = require("../package.json");
31
+ const package_json_1 = require("../package.json");
32
+ // this is a hack to be compatible with plugin which detect webpack's version
33
+ const rspackVersion = package_json_1.version;
32
34
  exports.rspackVersion = rspackVersion;
33
- exports.version = webpackVersion;
35
+ const version = package_json_1.webpackVersion;
36
+ exports.version = version;
34
37
  var Compilation_1 = require("./Compilation");
35
38
  Object.defineProperty(exports, "Compilation", { enumerable: true, get: function () { return Compilation_1.Compilation; } });
36
39
  var Compiler_1 = require("./Compiler");
package/dist/lib/Cache.js CHANGED
@@ -13,12 +13,13 @@ exports.Cache = void 0;
13
13
  const lite_tapable_1 = require("@rspack/lite-tapable");
14
14
  const HookWebpackError_1 = require("./HookWebpackError");
15
15
  const needCalls = (times, callback) => {
16
+ let leftTimes = times;
16
17
  return err => {
17
- if (--times === 0) {
18
+ if (--leftTimes === 0) {
18
19
  return callback();
19
20
  }
20
- if (err && times > 0) {
21
- times = 0;
21
+ if (err && leftTimes > 0) {
22
+ leftTimes = 0;
22
23
  return callback();
23
24
  }
24
25
  };
@@ -42,11 +43,12 @@ class Cache {
42
43
  */
43
44
  get(identifier, etag, callback) {
44
45
  const gotHandlers = [];
45
- this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
46
+ this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, res) => {
46
47
  if (err) {
47
48
  callback((0, HookWebpackError_1.makeWebpackError)(err, "Cache.hooks.get"));
48
49
  return;
49
50
  }
51
+ let result = res;
50
52
  if (result === null) {
51
53
  result = undefined;
52
54
  }
@@ -63,15 +63,14 @@ class MultiItemCache {
63
63
  /**
64
64
  * @returns promise with the data
65
65
  */
66
- getPromise() {
67
- const next = async (i) => {
68
- const result_1 = await this._items[i].getPromise();
69
- if (result_1 !== undefined)
70
- return result_1;
71
- if (++i < this._items.length)
72
- return next(i);
73
- };
74
- return next(0);
66
+ async getPromise() {
67
+ for (let i = 0; i < this._items.length; i++) {
68
+ const result = await this._items[i].getPromise();
69
+ if (result !== undefined) {
70
+ return result;
71
+ }
72
+ }
73
+ return undefined;
75
74
  }
76
75
  /**
77
76
  * @param data the value to store
@@ -9,9 +9,11 @@
9
9
  */
10
10
  import type { Compiler } from "../Compiler";
11
11
  import type { MatchObject } from "./ModuleFilenameHelpers";
12
- type LoaderOptionsPluginOptions = any;
12
+ type LoaderOptionsPluginOptions = MatchObject & {
13
+ [key: string]: unknown;
14
+ };
13
15
  export declare class LoaderOptionsPlugin {
14
- options: MatchObject;
16
+ options: LoaderOptionsPluginOptions;
15
17
  /**
16
18
  * @param options options object
17
19
  */
@@ -40,8 +40,6 @@ class LoaderOptionsPlugin {
40
40
  * @param options options object
41
41
  */
42
42
  constructor(options = {}) {
43
- if (typeof options !== "object")
44
- options = {};
45
43
  if (!options.test) {
46
44
  options.test = {
47
45
  test: () => true
@@ -9,9 +9,9 @@
9
9
  */
10
10
  import type { Etag } from "../Cache";
11
11
  /**
12
- * @param a first
13
- * @param b second
12
+ * @param first first
13
+ * @param second second
14
14
  * @returns result
15
15
  */
16
- export declare const mergeEtags: (a: Etag, b: Etag) => Etag;
16
+ export declare const mergeEtags: (first: Etag, second: Etag) => Etag;
17
17
  export default mergeEtags;
@@ -26,11 +26,13 @@ class MergedEtag {
26
26
  const dualObjectMap = new WeakMap();
27
27
  const objectStringMap = new WeakMap();
28
28
  /**
29
- * @param a first
30
- * @param b second
29
+ * @param first first
30
+ * @param second second
31
31
  * @returns result
32
32
  */
33
- const mergeEtags = (a, b) => {
33
+ const mergeEtags = (first, second) => {
34
+ let a = first;
35
+ let b = second;
34
36
  if (typeof a === "string") {
35
37
  if (typeof b === "string") {
36
38
  return `${a}|${b}`;
@@ -506,7 +506,8 @@ async function runLoaders(compiler, context) {
506
506
  return compiler._lastCompilation.getLogger([name, resource].filter(Boolean).join("|"));
507
507
  };
508
508
  loaderContext.rootContext = compiler.context;
509
- loaderContext.emitError = function emitError(error) {
509
+ loaderContext.emitError = function emitError(err) {
510
+ let error = err;
510
511
  if (!(error instanceof Error)) {
511
512
  error = new RspackError_1.NonErrorEmittedError(error);
512
513
  }
@@ -521,7 +522,8 @@ async function runLoaders(compiler, context) {
521
522
  severity: binding_1.JsRspackSeverity.Error
522
523
  });
523
524
  };
524
- loaderContext.emitWarning = function emitWarning(warning) {
525
+ loaderContext.emitWarning = function emitWarning(warn) {
526
+ let warning = warn;
525
527
  if (!(warning instanceof Error)) {
526
528
  warning = new RspackError_1.NonErrorEmittedError(warning);
527
529
  }
@@ -42,14 +42,14 @@ function default_1({ colors, appendOnly, stream }) {
42
42
  const indent = (str, prefix, colorPrefix, colorSuffix) => {
43
43
  if (str === "")
44
44
  return str;
45
- prefix = currentIndent + prefix;
45
+ const prefixWithIndent = currentIndent + prefix;
46
46
  if (colors) {
47
- return (prefix +
47
+ return (prefixWithIndent +
48
48
  colorPrefix +
49
49
  str.replace(/\n/g, `${colorSuffix}\n${prefix}${colorPrefix}`) +
50
50
  colorSuffix);
51
51
  }
52
- return prefix + str.replace(/\n/g, `\n${prefix}`);
52
+ return prefixWithIndent + str.replace(/\n/g, `\n${prefix}`);
53
53
  };
54
54
  const clearStatusMessage = () => {
55
55
  if (hasStatusMessage) {
@@ -120,8 +120,8 @@ function default_1({ colors, appendOnly, stream }) {
120
120
  })),
121
121
  status: appendOnly
122
122
  ? writeColored("<s> ", "", "")
123
- : (name, ...args) => {
124
- args = args.filter(Boolean);
123
+ : (name, ...argsWithEmpty) => {
124
+ const args = argsWithEmpty.filter(Boolean);
125
125
  if (name === undefined && args.length === 0) {
126
126
  clearStatusMessage();
127
127
  currentStatusMessage = undefined;
@@ -1,14 +1,4 @@
1
1
  import type { Compiler } from "../Compiler";
2
- /**
3
- * only support below factories:
4
- * - compilation
5
- * - compilation.assets
6
- * - compilation.assets[].asset
7
- * - compilation.chunks
8
- * - compilation.chunks[].chunk
9
- * - compilation.modules
10
- * - compilation.modules[].module
11
- */
12
2
  export declare class DefaultStatsFactoryPlugin {
13
3
  apply(compiler: Compiler): void;
14
4
  }
@@ -102,9 +102,9 @@ const ASSETS_GROUPERS = {
102
102
  // groupByFlag("comparedForEmit");
103
103
  // groupByFlag("isOverSizeLimit");
104
104
  }
105
- // if (groupAssetsByEmitStatus || !options.cachedAssets) {
106
- // groupByFlag("cached", !options.cachedAssets);
107
- // }
105
+ if (groupAssetsByEmitStatus || !options.cachedAssets) {
106
+ groupByFlag("cached", !options.cachedAssets);
107
+ }
108
108
  if (groupAssetsByPath || groupAssetsByExtension) {
109
109
  groupConfigs.push({
110
110
  getKeys: asset => {
@@ -411,16 +411,28 @@ const SORTERS = {
411
411
  "chunk.rootModules": MODULES_SORTER,
412
412
  "chunk.modules": MODULES_SORTER,
413
413
  "module.modules": MODULES_SORTER,
414
- // not support module.reasons (missing Module.identifier())
414
+ "module.reasons": {
415
+ _: comparators => {
416
+ comparators.push((0, comparators_1.compareSelect)((x) => x.moduleIdentifier, compareIds));
417
+ comparators.push((0, comparators_1.compareSelect)((x) => x.resolvedModuleIdentifier, compareIds));
418
+ comparators.push((0, comparators_1.compareSelect)((x) => x.dependency, (0, comparators_1.compareSelect)((x) => x.type, compareIds)
419
+ // concatComparators(
420
+ // compareSelect(
421
+ // /**
422
+ // * @param {Dependency} x dependency
423
+ // * @returns {DependencyLocation} location
424
+ // */
425
+ // x => x.loc,
426
+ // compareLocations
427
+ // ),
428
+ // compareSelect(x => x.type, compareIds)
429
+ // )
430
+ ));
431
+ }
432
+ },
415
433
  "chunk.origins": {
416
434
  _: comparators => {
417
- comparators.push(
418
- // compareSelect(
419
- // origin =>
420
- // origin.module ? chunkGraph.getModuleId(origin.module) : undefined,
421
- // compareIds
422
- // ),
423
- (0, comparators_1.compareSelect)((origin) => origin.loc, compareIds), (0, comparators_1.compareSelect)((origin) => origin.request, compareIds));
435
+ comparators.push((0, comparators_1.compareSelect)((origin) => origin.moduleId, compareIds), (0, comparators_1.compareSelect)((origin) => origin.loc, compareIds), (0, comparators_1.compareSelect)((origin) => origin.request, compareIds));
424
436
  }
425
437
  }
426
438
  };
@@ -749,28 +761,24 @@ const SIMPLE_EXTRACTORS = {
749
761
  },
750
762
  errors: (object, compilation, context, options, factory) => {
751
763
  const { type, cachedGetErrors } = context;
752
- // const rawErrors = cachedGetErrors!(compilation);
764
+ const rawErrors = cachedGetErrors(compilation);
753
765
  const factorizedErrors = factory.create(`${type}.errors`, cachedGetErrors(compilation), context);
754
- // let filtered = 0;
755
- // if (options.errorDetails === "auto" && rawErrors.length >= 3) {
756
- // filtered = rawErrors
757
- // .map(e => typeof e !== "string" && e.details)
758
- // .filter(Boolean).length;
759
- // }
760
- // if (
761
- // options.errorDetails === true ||
762
- // !Number.isFinite(options.errorsSpace)
763
- // ) {
764
- // object.errors = factorizedErrors;
765
- // if (filtered) object.filteredErrorDetailsCount = filtered;
766
- // return;
767
- // }
768
- // const [errors, filteredBySpace] = errorsSpaceLimit(
769
- // factorizedErrors,
770
- // options.errorsSpace
771
- // );
772
- // object.filteredErrorDetailsCount = filtered + filteredBySpace;
773
- object.errors = factorizedErrors;
766
+ let filtered = 0;
767
+ if (options.errorDetails === "auto" && rawErrors.length >= 3) {
768
+ filtered = rawErrors
769
+ .map(e => typeof e !== "string" && e.details)
770
+ .filter(Boolean).length;
771
+ }
772
+ if (options.errorDetails === true ||
773
+ !Number.isFinite(options.errorsSpace)) {
774
+ object.errors = factorizedErrors;
775
+ if (filtered)
776
+ object.filteredErrorDetailsCount = filtered;
777
+ return;
778
+ }
779
+ const { errors, filtered: filteredBySpace } = (0, statsFactoryUtils_1.errorsSpaceLimit)(factorizedErrors, options.errorsSpace);
780
+ object.filteredErrorDetailsCount = filtered + filteredBySpace;
781
+ object.errors = errors;
774
782
  },
775
783
  errorsCount: (object, compilation, { cachedGetErrors }) => {
776
784
  object.errorsCount = (0, statsFactoryUtils_1.countWithChildren)(compilation, c => cachedGetErrors(c));
@@ -778,26 +786,22 @@ const SIMPLE_EXTRACTORS = {
778
786
  warnings: (object, compilation, context, options, factory) => {
779
787
  const { type, cachedGetWarnings } = context;
780
788
  const rawWarnings = factory.create(`${type}.warnings`, cachedGetWarnings(compilation), context);
781
- // let filtered = 0;
782
- // if (options.errorDetails === "auto") {
783
- // filtered = cachedGetWarnings!(compilation)
784
- // .map(e => typeof e !== "string" && e.details)
785
- // .filter(Boolean).length;
786
- // }
787
- // if (
788
- // options.errorDetails === true ||
789
- // !Number.isFinite(options.warningsSpace)
790
- // ) {
791
- // object.warnings = rawWarnings;
792
- // if (filtered) object.filteredWarningDetailsCount = filtered;
793
- // return;
794
- // }
795
- // const [warnings, filteredBySpace] = errorsSpaceLimit(
796
- // rawWarnings,
797
- // options.warningsSpace
798
- // );
799
- // object.filteredWarningDetailsCount = filtered + filteredBySpace;
800
- object.warnings = rawWarnings;
789
+ let filtered = 0;
790
+ if (options.errorDetails === "auto") {
791
+ filtered = cachedGetWarnings(compilation)
792
+ .map(e => typeof e !== "string" && e.details)
793
+ .filter(Boolean).length;
794
+ }
795
+ if (options.errorDetails === true ||
796
+ !Number.isFinite(options.warningsSpace)) {
797
+ object.warnings = rawWarnings;
798
+ if (filtered)
799
+ object.filteredWarningDetailsCount = filtered;
800
+ return;
801
+ }
802
+ const { errors: warnings, filtered: filteredBySpace } = (0, statsFactoryUtils_1.errorsSpaceLimit)(rawWarnings, options.warningsSpace);
803
+ object.filteredWarningDetailsCount = filtered + filteredBySpace;
804
+ object.warnings = warnings;
801
805
  },
802
806
  warningsCount: (object, compilation, context) => {
803
807
  const { cachedGetWarnings } = context;
@@ -821,8 +825,11 @@ const SIMPLE_EXTRACTORS = {
821
825
  related: Object.fromEntries(asset.info.related.map(i => [i.name, i.value]))
822
826
  };
823
827
  // - comparedForEmit
824
- // - cached
825
- Object.assign(object, factory.create(`${context.type}$visible`, asset, context));
828
+ const cached = !object.emitted;
829
+ object.cached = cached;
830
+ if (!cached || options.cachedAssets) {
831
+ Object.assign(object, factory.create(`${context.type}$visible`, asset, context));
832
+ }
826
833
  }
827
834
  },
828
835
  asset$visible: {
@@ -843,6 +850,9 @@ const SIMPLE_EXTRACTORS = {
843
850
  ids: (object, asset) => {
844
851
  object.chunks = asset.chunks;
845
852
  object.auxiliaryChunks = asset.auxiliaryChunks;
853
+ },
854
+ performance: (object, asset) => {
855
+ object.isOverSizeLimit = asset.info.isOverSizeLimit;
846
856
  }
847
857
  },
848
858
  chunkGroup: {
@@ -858,7 +868,10 @@ const SIMPLE_EXTRACTORS = {
858
868
  object.auxiliaryAssets = chunkGroup.auxiliaryAssets;
859
869
  object.auxiliaryAssetsSize = chunkGroup.auxiliaryAssetsSize;
860
870
  object.children = chunkGroup.children;
861
- // - childAssets
871
+ object.childAssets = chunkGroup.childAssets;
872
+ },
873
+ performance: (object, { chunkGroup }) => {
874
+ object.isOverSizeLimit = chunkGroup.isOverSizeLimit;
862
875
  }
863
876
  },
864
877
  module: {
@@ -929,8 +942,10 @@ const SIMPLE_EXTRACTORS = {
929
942
  },
930
943
  reasons: (object, module, context, options, factory) => {
931
944
  const { type } = context;
932
- object.reasons = factory.create(`${type.slice(0, -8)}.reasons`, module.commonAttributes.reasons, context);
933
- // object.filteredReasons
945
+ const groupsReasons = factory.create(`${type.slice(0, -8)}.reasons`, module.commonAttributes.reasons, context);
946
+ const limited = (0, statsFactoryUtils_1.spaceLimited)(groupsReasons, options.reasonsSpace);
947
+ object.reasons = limited.children;
948
+ object.filteredReasons = limited.filteredChildren;
934
949
  },
935
950
  source: (object, module) => {
936
951
  const { commonAttributes } = module;
@@ -997,6 +1012,7 @@ const SIMPLE_EXTRACTORS = {
997
1012
  if (module.moduleDescriptor) {
998
1013
  object.identifier = module.moduleDescriptor.identifier;
999
1014
  object.name = module.moduleDescriptor.name;
1015
+ // - profile
1000
1016
  }
1001
1017
  },
1002
1018
  ids: (object, module) => {
@@ -1011,11 +1027,22 @@ const SIMPLE_EXTRACTORS = {
1011
1027
  }
1012
1028
  object.type = reason.type;
1013
1029
  object.userRequest = reason.userRequest;
1030
+ if (reason.resolvedModuleDescriptor) {
1031
+ object.resolvedModuleIdentifier =
1032
+ reason.resolvedModuleDescriptor.identifier;
1033
+ object.resolvedModule = reason.resolvedModuleDescriptor.name;
1034
+ }
1035
+ // - explanation
1036
+ // - active
1037
+ // - loc
1014
1038
  },
1015
1039
  ids: (object, reason) => {
1016
1040
  object.moduleId = reason.moduleDescriptor
1017
1041
  ? reason.moduleDescriptor.id
1018
1042
  : null;
1043
+ object.resolvedModuleId = reason.resolvedModuleDescriptor
1044
+ ? reason.resolvedModuleDescriptor.id
1045
+ : null;
1019
1046
  }
1020
1047
  },
1021
1048
  chunk: {
@@ -1045,24 +1072,32 @@ const SIMPLE_EXTRACTORS = {
1045
1072
  },
1046
1073
  chunkModules: (object, chunk, context, options, factory) => {
1047
1074
  const { type } = context;
1048
- object.modules = factory.create(`${type}.modules`, chunk.modules, context);
1075
+ const groupedModules = factory.create(`${type}.modules`, chunk.modules, context);
1076
+ const limited = (0, statsFactoryUtils_1.spaceLimited)(groupedModules, options.chunkModulesSpace);
1077
+ object.modules = limited.children;
1078
+ object.filteredModules = limited.filteredChildren;
1049
1079
  },
1050
1080
  chunkOrigins: (object, chunk, context, options, factory) => {
1051
- object.origins = chunk.origins.map(origin => {
1052
- const { moduleDescriptor, loc, request } = origin;
1053
- const statsChunkOrigin = {
1054
- module: moduleDescriptor ? moduleDescriptor.identifier : "",
1055
- moduleIdentifier: moduleDescriptor ? moduleDescriptor.identifier : "",
1056
- moduleName: moduleDescriptor ? moduleDescriptor.name : "",
1057
- moduleId: moduleDescriptor ? moduleDescriptor.id : undefined,
1058
- loc,
1059
- request
1060
- };
1061
- return statsChunkOrigin;
1062
- });
1081
+ const { type } = context;
1082
+ object.origins = factory.create(`${type}.origins`, chunk.origins, context);
1083
+ }
1084
+ },
1085
+ chunkOrigin: {
1086
+ _: (object, origin, context) => {
1087
+ const { moduleDescriptor, loc, request } = origin;
1088
+ const statsChunkOrigin = {
1089
+ module: moduleDescriptor ? moduleDescriptor.identifier : "",
1090
+ moduleIdentifier: moduleDescriptor ? moduleDescriptor.identifier : "",
1091
+ moduleName: moduleDescriptor ? moduleDescriptor.name : "",
1092
+ loc,
1093
+ request
1094
+ };
1095
+ Object.assign(object, statsChunkOrigin);
1096
+ },
1097
+ ids: (object, origin) => {
1098
+ object.moduleId = origin.moduleDescriptor?.id;
1063
1099
  }
1064
1100
  },
1065
- // chunkOrigin
1066
1101
  error: EXTRACT_ERROR,
1067
1102
  warning: EXTRACT_ERROR,
1068
1103
  moduleTraceItem: {
@@ -1081,18 +1116,21 @@ const SIMPLE_EXTRACTORS = {
1081
1116
  object.moduleId = module.moduleDescriptor.id;
1082
1117
  }
1083
1118
  }
1084
- // moduleTraceDependency
1119
+ // - moduleTraceDependency
1120
+ };
1121
+ const FILTER = {
1122
+ "module.reasons": {
1123
+ "!orphanModules": reason => {
1124
+ if (reason.moduleChunks === 0) {
1125
+ return false;
1126
+ }
1127
+ }
1128
+ }
1129
+ };
1130
+ const FILTER_RESULTS = {
1131
+ // Deprecated: "compilation.warnings": {}
1132
+ // Keep this object to retain this phase.
1085
1133
  };
1086
- /**
1087
- * only support below factories:
1088
- * - compilation
1089
- * - compilation.assets
1090
- * - compilation.assets[].asset
1091
- * - compilation.chunks
1092
- * - compilation.chunks[].chunk
1093
- * - compilation.modules
1094
- * - compilation.modules[].module
1095
- */
1096
1134
  class DefaultStatsFactoryPlugin {
1097
1135
  apply(compiler) {
1098
1136
  compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
@@ -1104,14 +1142,16 @@ class DefaultStatsFactoryPlugin {
1104
1142
  .for(hookFor)
1105
1143
  .tap("DefaultStatsFactoryPlugin", (obj, data, ctx) => fn(obj, data, ctx, options, stats));
1106
1144
  });
1107
- // not support filter module.reasons.!orphanModules
1108
- // iterateConfig(FILTER, options, (hookFor, fn) => {
1109
- // stats.hooks.filter
1110
- // .for(hookFor)
1111
- // .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
1112
- // fn(item, ctx, options, idx, i)
1113
- // );
1114
- // });
1145
+ (0, statsFactoryUtils_1.iterateConfig)(FILTER, options, (hookFor, fn) => {
1146
+ stats.hooks.filter
1147
+ .for(hookFor)
1148
+ .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) => fn(item, ctx, options, idx, i));
1149
+ });
1150
+ (0, statsFactoryUtils_1.iterateConfig)(FILTER_RESULTS, options, (hookFor, fn) => {
1151
+ stats.hooks.filterResults
1152
+ .for(hookFor)
1153
+ .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) => fn(item, ctx, options, idx, i));
1154
+ });
1115
1155
  (0, statsFactoryUtils_1.iterateConfig)(SORTERS, options, (hookFor, fn) => {
1116
1156
  stats.hooks.sort
1117
1157
  .for(hookFor)