webpack 5.94.0 → 5.96.0

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 (151) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EnvironmentPlugin.js +3 -2
  19. package/lib/EvalDevToolModulePlugin.js +5 -2
  20. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  21. package/lib/ExternalModule.js +118 -99
  22. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  23. package/lib/FileSystemInfo.js +12 -8
  24. package/lib/Generator.js +5 -4
  25. package/lib/HotModuleReplacementPlugin.js +8 -6
  26. package/lib/IgnorePlugin.js +19 -1
  27. package/lib/LoaderOptionsPlugin.js +3 -1
  28. package/lib/Module.js +9 -8
  29. package/lib/ModuleSourceTypesConstants.js +100 -0
  30. package/lib/NormalModule.js +27 -13
  31. package/lib/NormalModuleFactory.js +38 -22
  32. package/lib/OptionsApply.js +12 -1
  33. package/lib/ProgressPlugin.js +50 -10
  34. package/lib/RawModule.js +3 -4
  35. package/lib/RuntimeModule.js +3 -4
  36. package/lib/RuntimePlugin.js +11 -4
  37. package/lib/RuntimeTemplate.js +13 -42
  38. package/lib/SourceMapDevToolPlugin.js +10 -7
  39. package/lib/TemplatedPathPlugin.js +9 -3
  40. package/lib/Watching.js +2 -2
  41. package/lib/WebpackOptionsApply.js +42 -21
  42. package/lib/asset/AssetGenerator.js +347 -194
  43. package/lib/asset/AssetModulesPlugin.js +2 -1
  44. package/lib/asset/AssetSourceGenerator.js +82 -27
  45. package/lib/asset/RawDataUrlModule.js +5 -4
  46. package/lib/buildChunkGraph.js +79 -62
  47. package/lib/cache/PackFileCacheStrategy.js +69 -31
  48. package/lib/cache/ResolverCachePlugin.js +248 -173
  49. package/lib/config/defaults.js +135 -126
  50. package/lib/container/ContainerEntryModule.js +3 -4
  51. package/lib/container/ContainerPlugin.js +8 -0
  52. package/lib/container/FallbackModule.js +2 -2
  53. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  54. package/lib/container/ModuleFederationPlugin.js +38 -1
  55. package/lib/container/RemoteModule.js +4 -2
  56. package/lib/container/RemoteRuntimeModule.js +4 -2
  57. package/lib/css/CssExportsGenerator.js +16 -12
  58. package/lib/css/CssGenerator.js +22 -16
  59. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  60. package/lib/css/CssModulesPlugin.js +122 -77
  61. package/lib/css/CssParser.js +655 -526
  62. package/lib/css/walkCssTokens.js +1168 -338
  63. package/lib/debug/ProfilingPlugin.js +5 -0
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  66. package/lib/dependencies/ContextDependency.js +6 -1
  67. package/lib/dependencies/ContextElementDependency.js +33 -6
  68. package/lib/dependencies/CssExportDependency.js +3 -3
  69. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  70. package/lib/dependencies/CssUrlDependency.js +33 -3
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  75. package/lib/dependencies/ImportParserPlugin.js +9 -7
  76. package/lib/dependencies/LoaderPlugin.js +19 -0
  77. package/lib/dependencies/SystemPlugin.js +2 -1
  78. package/lib/dependencies/URLPlugin.js +7 -1
  79. package/lib/dependencies/WorkerPlugin.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  81. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  82. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  83. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  84. package/lib/hmr/lazyCompilationBackend.js +1 -7
  85. package/lib/index.js +35 -6
  86. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  87. package/lib/javascript/JavascriptGenerator.js +8 -8
  88. package/lib/javascript/JavascriptModulesPlugin.js +166 -88
  89. package/lib/javascript/JavascriptParser.js +338 -117
  90. package/lib/json/JsonGenerator.js +5 -5
  91. package/lib/library/EnableLibraryPlugin.js +2 -2
  92. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  93. package/lib/library/UmdLibraryPlugin.js +16 -8
  94. package/lib/logging/Logger.js +11 -11
  95. package/lib/logging/createConsoleLogger.js +14 -14
  96. package/lib/logging/truncateArgs.js +1 -1
  97. package/lib/node/NodeWatchFileSystem.js +3 -1
  98. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  99. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  100. package/lib/node/nodeConsole.js +11 -8
  101. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  102. package/lib/optimize/ConcatenatedModule.js +44 -148
  103. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  104. package/lib/optimize/InnerGraphPlugin.js +57 -16
  105. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  106. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  107. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  108. package/lib/optimize/RealContentHashPlugin.js +1 -1
  109. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  110. package/lib/rules/RuleSetCompiler.js +2 -2
  111. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  112. package/lib/schemes/DataUriPlugin.js +1 -1
  113. package/lib/serialization/BinaryMiddleware.js +32 -19
  114. package/lib/serialization/ObjectMiddleware.js +23 -9
  115. package/lib/serialization/SerializerMiddleware.js +3 -2
  116. package/lib/serialization/types.js +2 -2
  117. package/lib/sharing/ConsumeSharedModule.js +2 -3
  118. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  119. package/lib/sharing/ProvideSharedModule.js +2 -3
  120. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  121. package/lib/stats/StatsFactory.js +12 -12
  122. package/lib/stats/StatsPrinter.js +7 -7
  123. package/lib/util/AsyncQueue.js +17 -1
  124. package/lib/util/IterableHelpers.js +1 -1
  125. package/lib/util/LazySet.js +12 -0
  126. package/lib/util/SetHelpers.js +1 -1
  127. package/lib/util/cleverMerge.js +48 -24
  128. package/lib/util/concatenate.js +227 -0
  129. package/lib/util/create-schema-validation.js +22 -9
  130. package/lib/util/deprecation.js +86 -28
  131. package/lib/util/fs.js +10 -10
  132. package/lib/util/hash/wasm-hash.js +12 -1
  133. package/lib/util/magicComment.js +21 -0
  134. package/lib/util/makeSerializable.js +24 -1
  135. package/lib/util/memoize.js +2 -1
  136. package/lib/util/runtime.js +10 -1
  137. package/lib/util/semver.js +130 -23
  138. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  140. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  141. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  142. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  143. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  144. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  145. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  146. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  147. package/package.json +19 -20
  148. package/schemas/WebpackOptions.check.js +1 -1
  149. package/schemas/WebpackOptions.json +12 -2
  150. package/types.d.ts +817 -269
  151. package/lib/util/mergeScope.js +0 -76
package/lib/Module.js CHANGED
@@ -9,6 +9,7 @@ const util = require("util");
9
9
  const ChunkGraph = require("./ChunkGraph");
10
10
  const DependenciesBlock = require("./DependenciesBlock");
11
11
  const ModuleGraph = require("./ModuleGraph");
12
+ const { JS_TYPES } = require("./ModuleSourceTypesConstants");
12
13
  const RuntimeGlobals = require("./RuntimeGlobals");
13
14
  const { first } = require("./util/SetHelpers");
14
15
  const { compareChunksById } = require("./util/comparators");
@@ -23,7 +24,6 @@ const makeSerializable = require("./util/makeSerializable");
23
24
  /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
24
25
  /** @typedef {import("./Compilation")} Compilation */
25
26
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
26
- /** @typedef {import("./Compilation").ValueCacheVersion} ValueCacheVersion */
27
27
  /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
28
28
  /** @typedef {import("./Dependency")} Dependency */
29
29
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
@@ -56,6 +56,8 @@ const makeSerializable = require("./util/makeSerializable");
56
56
  * @property {string=} type the type of source that should be generated
57
57
  */
58
58
 
59
+ /** @typedef {ReadonlySet<string>} SourceTypes */
60
+
59
61
  // TODO webpack 6: compilation will be required in CodeGenerationContext
60
62
  /**
61
63
  * @typedef {object} CodeGenerationContext
@@ -67,7 +69,7 @@ const makeSerializable = require("./util/makeSerializable");
67
69
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
68
70
  * @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
69
71
  * @property {Compilation=} compilation the compilation
70
- * @property {ReadonlySet<string>=} sourceTypes source types
72
+ * @property {SourceTypes=} sourceTypes source types
71
73
  */
72
74
 
73
75
  /**
@@ -114,18 +116,20 @@ const makeSerializable = require("./util/makeSerializable");
114
116
  * @property {LazySet<string>=} contextDependencies
115
117
  * @property {LazySet<string>=} missingDependencies
116
118
  * @property {LazySet<string>=} buildDependencies
117
- * @property {(Map<string, ValueCacheVersion>)=} valueDependencies
119
+ * @property {ValueCacheVersions=} valueDependencies
118
120
  * @property {TODO=} hash
119
121
  * @property {Record<string, Source>=} assets
120
122
  * @property {Map<string, AssetInfo | undefined>=} assetsInfo
121
123
  * @property {(Snapshot | null)=} snapshot
122
124
  */
123
125
 
126
+ /** @typedef {Map<string, string | Set<string>>} ValueCacheVersions */
127
+
124
128
  /**
125
129
  * @typedef {object} NeedBuildContext
126
130
  * @property {Compilation} compilation
127
131
  * @property {FileSystemInfo} fileSystemInfo
128
- * @property {Map<string, string | Set<string>>} valueCacheVersions
132
+ * @property {ValueCacheVersions} valueCacheVersions
129
133
  */
130
134
 
131
135
  /** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
@@ -136,8 +140,6 @@ const makeSerializable = require("./util/makeSerializable");
136
140
  * @property {boolean=} sideEffectFree
137
141
  */
138
142
 
139
- /** @typedef {Set<string>} SourceTypes */
140
-
141
143
  /** @typedef {{ factoryMeta: FactoryMeta | undefined, resolveOptions: ResolveOptions | undefined }} UnsafeCacheData */
142
144
 
143
145
  const EMPTY_RESOLVE_OPTIONS = {};
@@ -145,7 +147,6 @@ const EMPTY_RESOLVE_OPTIONS = {};
145
147
  let debugId = 1000;
146
148
 
147
149
  const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
148
- const DEFAULT_TYPES_JS = new Set(["javascript"]);
149
150
 
150
151
  const deprecatedNeedRebuild = util.deprecate(
151
152
  /**
@@ -873,7 +874,7 @@ class Module extends DependenciesBlock {
873
874
  if (this.source === Module.prototype.source) {
874
875
  return DEFAULT_TYPES_UNKNOWN;
875
876
  }
876
- return DEFAULT_TYPES_JS;
877
+ return JS_TYPES;
877
878
  }
878
879
 
879
880
  /**
@@ -0,0 +1,100 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * @type {ReadonlySet<never>}
10
+ */
11
+ const NO_TYPES = new Set();
12
+
13
+ /**
14
+ * @type {ReadonlySet<"asset">}
15
+ */
16
+ const ASSET_TYPES = new Set(["asset"]);
17
+
18
+ /**
19
+ * @type {ReadonlySet<"asset" | "javascript" | "asset">}
20
+ */
21
+ const ASSET_AND_JS_TYPES = new Set(["asset", "javascript"]);
22
+
23
+ /**
24
+ * @type {ReadonlySet<"css-url" | "asset">}
25
+ */
26
+ const ASSET_AND_CSS_URL_TYPES = new Set(["asset", "css-url"]);
27
+
28
+ /**
29
+ * @type {ReadonlySet<"javascript" | "css-url" | "asset">}
30
+ */
31
+ const ASSET_AND_JS_AND_CSS_URL_TYPES = new Set([
32
+ "asset",
33
+ "javascript",
34
+ "css-url"
35
+ ]);
36
+
37
+ /**
38
+ * @type {ReadonlySet<"javascript">}
39
+ */
40
+ const JS_TYPES = new Set(["javascript"]);
41
+
42
+ /**
43
+ * @type {ReadonlySet<"javascript" | "css-url">}
44
+ */
45
+ const JS_AND_CSS_URL_TYPES = new Set(["javascript", "css-url"]);
46
+
47
+ /**
48
+ * @type {ReadonlySet<"css">}
49
+ */
50
+ const CSS_TYPES = new Set(["css"]);
51
+
52
+ /**
53
+ * @type {ReadonlySet<"css-url">}
54
+ */
55
+ const CSS_URL_TYPES = new Set(["css-url"]);
56
+ /**
57
+ * @type {ReadonlySet<"css-import">}
58
+ */
59
+ const CSS_IMPORT_TYPES = new Set(["css-import"]);
60
+
61
+ /**
62
+ * @type {ReadonlySet<"webassembly">}
63
+ */
64
+ const WEBASSEMBLY_TYPES = new Set(["webassembly"]);
65
+
66
+ /**
67
+ * @type {ReadonlySet<"runtime">}
68
+ */
69
+ const RUNTIME_TYPES = new Set(["runtime"]);
70
+
71
+ /**
72
+ * @type {ReadonlySet<"remote" | "share-init">}
73
+ */
74
+ const REMOTE_AND_SHARE_INIT_TYPES = new Set(["remote", "share-init"]);
75
+
76
+ /**
77
+ * @type {ReadonlySet<"consume-shared">}
78
+ */
79
+ const CONSUME_SHARED_TYPES = new Set(["consume-shared"]);
80
+
81
+ /**
82
+ * @type {ReadonlySet<"share-init">}
83
+ */
84
+ const SHARED_INIT_TYPES = new Set(["share-init"]);
85
+
86
+ module.exports.NO_TYPES = NO_TYPES;
87
+ module.exports.JS_TYPES = JS_TYPES;
88
+ module.exports.JS_AND_CSS_URL_TYPES = JS_AND_CSS_URL_TYPES;
89
+ module.exports.ASSET_TYPES = ASSET_TYPES;
90
+ module.exports.ASSET_AND_JS_TYPES = ASSET_AND_JS_TYPES;
91
+ module.exports.ASSET_AND_CSS_URL_TYPES = ASSET_AND_CSS_URL_TYPES;
92
+ module.exports.ASSET_AND_JS_AND_CSS_URL_TYPES = ASSET_AND_JS_AND_CSS_URL_TYPES;
93
+ module.exports.CSS_TYPES = CSS_TYPES;
94
+ module.exports.CSS_URL_TYPES = CSS_URL_TYPES;
95
+ module.exports.CSS_IMPORT_TYPES = CSS_IMPORT_TYPES;
96
+ module.exports.WEBASSEMBLY_TYPES = WEBASSEMBLY_TYPES;
97
+ module.exports.RUNTIME_TYPES = RUNTIME_TYPES;
98
+ module.exports.REMOTE_AND_SHARE_INIT_TYPES = REMOTE_AND_SHARE_INIT_TYPES;
99
+ module.exports.CONSUME_SHARED_TYPES = CONSUME_SHARED_TYPES;
100
+ module.exports.SHARED_INIT_TYPES = SHARED_INIT_TYPES;
@@ -65,12 +65,13 @@ const memoize = require("./util/memoize");
65
65
  /** @typedef {import("./Module").KnownBuildInfo} KnownBuildInfo */
66
66
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
67
67
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
68
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
68
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
69
69
  /** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
70
70
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
71
71
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
72
72
  /** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes} JavaScriptModuleTypes */
73
73
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
74
+ /** @typedef {import("./NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
74
75
  /** @typedef {import("./Parser")} Parser */
75
76
  /** @typedef {import("./RequestShortener")} RequestShortener */
76
77
  /** @typedef {import("./ResolverFactory").ResolveContext} ResolveContext */
@@ -777,6 +778,10 @@ class NormalModule extends Module {
777
778
  webpack: true,
778
779
  sourceMap: Boolean(this.useSourceMap),
779
780
  mode: options.mode || "production",
781
+ hashFunction: /** @type {TODO} */ (options.output.hashFunction),
782
+ hashDigest: /** @type {string} */ (options.output.hashDigest),
783
+ hashDigestLength: /** @type {number} */ (options.output.hashDigestLength),
784
+ hashSalt: /** @type {string} */ (options.output.hashSalt),
780
785
  _module: this,
781
786
  _compilation: compilation,
782
787
  _compiler: compilation.compiler,
@@ -947,7 +952,7 @@ class NormalModule extends Module {
947
952
  /** @type {LoaderContext<any>} */ (loaderContext)
948
953
  );
949
954
  } catch (err) {
950
- processResult(err);
955
+ processResult(/** @type {Error} */ (err));
951
956
  return;
952
957
  }
953
958
 
@@ -961,6 +966,11 @@ class NormalModule extends Module {
961
966
  resource: this.resource,
962
967
  loaders: this.loaders,
963
968
  context: loaderContext,
969
+ /**
970
+ * @param {LoaderContext<TODO>} loaderContext the loader context
971
+ * @param {string} resourcePath the resource Path
972
+ * @param {(err: Error | null, result?: string | Buffer) => void} callback callback
973
+ */
964
974
  processResource: (loaderContext, resourcePath, callback) => {
965
975
  const resource = loaderContext.resource;
966
976
  const scheme = getScheme(resource);
@@ -1597,24 +1607,28 @@ class NormalModule extends Module {
1597
1607
  super.serialize(context);
1598
1608
  }
1599
1609
 
1610
+ /**
1611
+ * @param {ObjectDeserializerContext} context context
1612
+ * @returns {TODO} Module
1613
+ */
1600
1614
  static deserialize(context) {
1601
1615
  const obj = new NormalModule({
1602
1616
  // will be deserialized by Module
1603
- layer: null,
1617
+ layer: /** @type {EXPECTED_ANY} */ (null),
1604
1618
  type: "",
1605
1619
  // will be filled by updateCacheModule
1606
1620
  resource: "",
1607
1621
  context: "",
1608
- request: null,
1609
- userRequest: null,
1610
- rawRequest: null,
1611
- loaders: null,
1612
- matchResource: null,
1613
- parser: null,
1614
- parserOptions: null,
1615
- generator: null,
1616
- generatorOptions: null,
1617
- resolveOptions: null
1622
+ request: /** @type {EXPECTED_ANY} */ (null),
1623
+ userRequest: /** @type {EXPECTED_ANY} */ (null),
1624
+ rawRequest: /** @type {EXPECTED_ANY} */ (null),
1625
+ loaders: /** @type {EXPECTED_ANY} */ (null),
1626
+ matchResource: /** @type {EXPECTED_ANY} */ (null),
1627
+ parser: /** @type {EXPECTED_ANY} */ (null),
1628
+ parserOptions: /** @type {EXPECTED_ANY} */ (null),
1629
+ generator: /** @type {EXPECTED_ANY} */ (null),
1630
+ generatorOptions: /** @type {EXPECTED_ANY} */ (null),
1631
+ resolveOptions: /** @type {EXPECTED_ANY} */ (null)
1618
1632
  });
1619
1633
  obj.deserialize(context);
1620
1634
  return obj;
@@ -52,8 +52,8 @@ const {
52
52
  /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
53
53
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
54
54
 
55
- /** @typedef {Pick<RuleSetRule, 'type'|'sideEffects'|'parser'|'generator'|'resolve'|'layer'>} ModuleSettings */
56
- /** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
55
+ /** @typedef {Pick<RuleSetRule, 'type' | 'sideEffects' | 'parser' | 'generator' | 'resolve' | 'layer'>} ModuleSettings */
56
+ /** @typedef {Partial<NormalModuleCreateData & { settings: ModuleSettings }>} CreateData */
57
57
 
58
58
  /**
59
59
  * @typedef {object} ResolveData
@@ -68,6 +68,7 @@ const {
68
68
  * @property {LazySet<string>} fileDependencies
69
69
  * @property {LazySet<string>} missingDependencies
70
70
  * @property {LazySet<string>} contextDependencies
71
+ * @property {Module=} ignoredModule
71
72
  * @property {boolean} cacheable allow to use the unsafe cache
72
73
  */
73
74
 
@@ -169,7 +170,9 @@ const mergeGlobalOptions = (globalOptions, type, localOptions) => {
169
170
  let current = "";
170
171
  for (const part of parts) {
171
172
  current = current ? `${current}/${part}` : part;
172
- const options = globalOptions[current];
173
+ const options =
174
+ /** @type {T} */
175
+ (globalOptions[/** @type {keyof T} */ (current)]);
173
176
  if (typeof options === "object") {
174
177
  result =
175
178
  result === undefined ? options : cachedCleverMerge(result, options);
@@ -219,16 +222,19 @@ const ruleSetCompiler = new RuleSetCompiler([
219
222
  new BasicMatcherRulePlugin("issuer"),
220
223
  new BasicMatcherRulePlugin("compiler"),
221
224
  new BasicMatcherRulePlugin("issuerLayer"),
222
- new ObjectMatcherRulePlugin(
223
- "assert",
224
- "assertions",
225
- value => value && /** @type {any} */ (value)._isLegacyAssert !== undefined
226
- ),
227
- new ObjectMatcherRulePlugin(
228
- "with",
229
- "assertions",
230
- value => value && !(/** @type {any} */ (value)._isLegacyAssert)
231
- ),
225
+ new ObjectMatcherRulePlugin("assert", "assertions", value => {
226
+ if (value) {
227
+ return /** @type {any} */ (value)._isLegacyAssert !== undefined;
228
+ }
229
+
230
+ return false;
231
+ }),
232
+ new ObjectMatcherRulePlugin("with", "assertions", value => {
233
+ if (value) {
234
+ return !(/** @type {any} */ (value)._isLegacyAssert);
235
+ }
236
+ return false;
237
+ }),
232
238
  new ObjectMatcherRulePlugin("descriptionData"),
233
239
  new BasicEffectRulePlugin("type"),
234
240
  new BasicEffectRulePlugin("sideEffects"),
@@ -246,7 +252,7 @@ class NormalModuleFactory extends ModuleFactory {
246
252
  * @param {InputFileSystem} param.fs file system
247
253
  * @param {ResolverFactory} param.resolverFactory resolverFactory
248
254
  * @param {ModuleOptions} param.options options
249
- * @param {object=} param.associatedObjectForCache an object to which the cache will be attached
255
+ * @param {object} param.associatedObjectForCache an object to which the cache will be attached
250
256
  * @param {boolean=} param.layers enable layers
251
257
  */
252
258
  constructor({
@@ -277,13 +283,13 @@ class NormalModuleFactory extends ModuleFactory {
277
283
  afterResolve: new AsyncSeriesBailHook(["resolveData"]),
278
284
  /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
279
285
  createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
280
- /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
286
+ /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData]>} */
281
287
  module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
282
- /** @type {HookMap<SyncBailHook<[ParserOptions], Parser>>} */
288
+ /** @type {HookMap<SyncBailHook<[ParserOptions], Parser | void>>} */
283
289
  createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
284
290
  /** @type {HookMap<SyncBailHook<[TODO, ParserOptions], void>>} */
285
291
  parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
286
- /** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator>>} */
292
+ /** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator | void>>} */
287
293
  createGenerator: new HookMap(
288
294
  () => new SyncBailHook(["generatorOptions"])
289
295
  ),
@@ -291,7 +297,7 @@ class NormalModuleFactory extends ModuleFactory {
291
297
  generator: new HookMap(
292
298
  () => new SyncHook(["generator", "generatorOptions"])
293
299
  ),
294
- /** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module>>} */
300
+ /** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module | void>>} */
295
301
  createModuleClass: new HookMap(
296
302
  () => new SyncBailHook(["createData", "resolveData"])
297
303
  )
@@ -374,14 +380,16 @@ class NormalModuleFactory extends ModuleFactory {
374
380
  // TODO webpack 6 make it required and move javascript/wasm/asset properties to own module
375
381
  createdModule = this.hooks.createModuleClass
376
382
  .for(
377
- /** @type {ModuleSettings} */ (createData.settings).type
383
+ /** @type {ModuleSettings} */
384
+ (createData.settings).type
378
385
  )
379
386
  .call(createData, resolveData);
380
387
 
381
388
  if (!createdModule) {
382
389
  createdModule = /** @type {Module} */ (
383
390
  new NormalModule(
384
- /** @type {NormalModuleCreateData} */ (createData)
391
+ /** @type {NormalModuleCreateData} */
392
+ (createData)
385
393
  )
386
394
  );
387
395
  }
@@ -887,12 +895,19 @@ class NormalModuleFactory extends ModuleFactory {
887
895
 
888
896
  // Ignored
889
897
  if (result === false) {
890
- return callback(null, {
898
+ /** @type {ModuleFactoryResult} * */
899
+ const factoryResult = {
891
900
  fileDependencies,
892
901
  missingDependencies,
893
902
  contextDependencies,
894
903
  cacheable: resolveData.cacheable
895
- });
904
+ };
905
+
906
+ if (resolveData.ignoredModule) {
907
+ factoryResult.module = resolveData.ignoredModule;
908
+ }
909
+
910
+ return callback(null, factoryResult);
896
911
  }
897
912
 
898
913
  if (typeof result === "object")
@@ -913,6 +928,7 @@ class NormalModuleFactory extends ModuleFactory {
913
928
  });
914
929
  }
915
930
 
931
+ /** @type {ModuleFactoryResult} * */
916
932
  const factoryResult = {
917
933
  module,
918
934
  fileDependencies,
@@ -5,7 +5,18 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
9
+ /** @typedef {import("./Compiler")} Compiler */
10
+
8
11
  class OptionsApply {
9
- process(options, compiler) {}
12
+ /**
13
+ * @param {WebpackOptions} options options object
14
+ * @param {Compiler} compiler compiler object
15
+ * @returns {WebpackOptions} options object
16
+ */
17
+ process(options, compiler) {
18
+ return options;
19
+ }
10
20
  }
21
+
11
22
  module.exports = OptionsApply;
@@ -15,11 +15,18 @@ const { contextify } = require("./util/identifier");
15
15
  /** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
16
16
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
17
17
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
18
+ /** @typedef {import("./Compilation").FactorizeModuleOptions} FactorizeModuleOptions */
18
19
  /** @typedef {import("./Dependency")} Dependency */
19
20
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
20
21
  /** @typedef {import("./Module")} Module */
22
+ /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
21
23
  /** @typedef {import("./logging/Logger").Logger} Logger */
22
24
 
25
+ /**
26
+ * @template T, K, R
27
+ * @typedef {import("./util/AsyncQueue")<T, K, R>} AsyncQueue
28
+ */
29
+
23
30
  /**
24
31
  * @typedef {object} CountsData
25
32
  * @property {number} modulesCount modules count
@@ -121,6 +128,8 @@ const createDefaultHandler = (profile, logger) => {
121
128
  return defaultHandler;
122
129
  };
123
130
 
131
+ const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
132
+
124
133
  /**
125
134
  * @callback ReportProgress
126
135
  * @param {number} p percentage
@@ -217,7 +226,9 @@ class ProgressPlugin {
217
226
  let lastDependenciesCount = 0;
218
227
  let lastEntriesCount = 0;
219
228
  let modulesCount = 0;
229
+ let skippedModulesCount = 0;
220
230
  let dependenciesCount = 0;
231
+ let skippedDependenciesCount = 0;
221
232
  let entriesCount = 1;
222
233
  let doneModules = 0;
223
234
  let doneDependencies = 0;
@@ -298,7 +309,15 @@ class ProgressPlugin {
298
309
  lastUpdate = Date.now();
299
310
  };
300
311
 
301
- const factorizeAdd = () => {
312
+ /**
313
+ * @template T
314
+ * @param {AsyncQueue<FactorizeModuleOptions, string, Module | ModuleFactoryResult>} factorizeQueue async queue
315
+ * @param {T} _item item
316
+ */
317
+ const factorizeAdd = (factorizeQueue, _item) => {
318
+ if (SKIPPED_QUEUE_CONTEXTS.includes(factorizeQueue.getContext())) {
319
+ skippedDependenciesCount++;
320
+ }
302
321
  dependenciesCount++;
303
322
  if (dependenciesCount < 50 || dependenciesCount % 100 === 0)
304
323
  updateThrottled();
@@ -310,7 +329,15 @@ class ProgressPlugin {
310
329
  updateThrottled();
311
330
  };
312
331
 
313
- const moduleAdd = () => {
332
+ /**
333
+ * @template T
334
+ * @param {AsyncQueue<Module, string, Module>} addModuleQueue async queue
335
+ * @param {T} _item item
336
+ */
337
+ const moduleAdd = (addModuleQueue, _item) => {
338
+ if (SKIPPED_QUEUE_CONTEXTS.includes(addModuleQueue.getContext())) {
339
+ skippedModulesCount++;
340
+ }
314
341
  modulesCount++;
315
342
  if (modulesCount < 50 || modulesCount % 100 === 0) updateThrottled();
316
343
  };
@@ -397,12 +424,19 @@ class ProgressPlugin {
397
424
  if (compilation.compiler.isChild()) return Promise.resolve();
398
425
  return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
399
426
  async oldData => {
427
+ const realModulesCount = modulesCount - skippedModulesCount;
428
+ const realDependenciesCount =
429
+ dependenciesCount - skippedDependenciesCount;
430
+
400
431
  if (
401
432
  !oldData ||
402
- oldData.modulesCount !== modulesCount ||
403
- oldData.dependenciesCount !== dependenciesCount
433
+ oldData.modulesCount !== realModulesCount ||
434
+ oldData.dependenciesCount !== realDependenciesCount
404
435
  ) {
405
- await cache.storePromise({ modulesCount, dependenciesCount });
436
+ await cache.storePromise({
437
+ modulesCount: realModulesCount,
438
+ dependenciesCount: realDependenciesCount
439
+ });
406
440
  }
407
441
  }
408
442
  );
@@ -413,19 +447,25 @@ class ProgressPlugin {
413
447
  lastModulesCount = modulesCount;
414
448
  lastEntriesCount = entriesCount;
415
449
  lastDependenciesCount = dependenciesCount;
416
- modulesCount = dependenciesCount = entriesCount = 0;
450
+ modulesCount =
451
+ skippedModulesCount =
452
+ dependenciesCount =
453
+ skippedDependenciesCount =
454
+ entriesCount =
455
+ 0;
417
456
  doneModules = doneDependencies = doneEntries = 0;
418
457
 
419
- compilation.factorizeQueue.hooks.added.tap(
420
- "ProgressPlugin",
421
- factorizeAdd
458
+ compilation.factorizeQueue.hooks.added.tap("ProgressPlugin", item =>
459
+ factorizeAdd(compilation.factorizeQueue, item)
422
460
  );
423
461
  compilation.factorizeQueue.hooks.result.tap(
424
462
  "ProgressPlugin",
425
463
  factorizeDone
426
464
  );
427
465
 
428
- compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", moduleAdd);
466
+ compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", item =>
467
+ moduleAdd(compilation.addModuleQueue, item)
468
+ );
429
469
  compilation.processDependenciesQueue.hooks.result.tap(
430
470
  "ProgressPlugin",
431
471
  moduleDone
package/lib/RawModule.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JS_TYPES } = require("./ModuleSourceTypesConstants");
10
11
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
11
12
  const makeSerializable = require("./util/makeSerializable");
12
13
 
@@ -16,11 +17,11 @@ const makeSerializable = require("./util/makeSerializable");
16
17
  /** @typedef {import("./Compilation")} Compilation */
17
18
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
18
19
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
20
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
19
21
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
20
22
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
21
23
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
22
24
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
23
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("./RequestShortener")} RequestShortener */
25
26
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
27
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -30,8 +31,6 @@ const makeSerializable = require("./util/makeSerializable");
30
31
  /** @typedef {import("./util/Hash")} Hash */
31
32
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
32
33
 
33
- const TYPES = new Set(["javascript"]);
34
-
35
34
  class RawModule extends Module {
36
35
  /**
37
36
  * @param {string} source source code
@@ -51,7 +50,7 @@ class RawModule extends Module {
51
50
  * @returns {SourceTypes} types available (do not mutate)
52
51
  */
53
52
  getSourceTypes() {
54
- return TYPES;
53
+ return JS_TYPES;
55
54
  }
56
55
 
57
56
  /**
@@ -8,6 +8,7 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const OriginalSource = require("webpack-sources").OriginalSource;
10
10
  const Module = require("./Module");
11
+ const { RUNTIME_TYPES } = require("./ModuleSourceTypesConstants");
11
12
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
@@ -16,18 +17,16 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
16
17
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
17
18
  /** @typedef {import("./Compilation")} Compilation */
18
19
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
20
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
19
21
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
20
22
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
21
23
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
22
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
23
24
  /** @typedef {import("./RequestShortener")} RequestShortener */
24
25
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
25
26
  /** @typedef {import("./WebpackError")} WebpackError */
26
27
  /** @typedef {import("./util/Hash")} Hash */
27
28
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
28
29
 
29
- const TYPES = new Set([WEBPACK_MODULE_TYPE_RUNTIME]);
30
-
31
30
  class RuntimeModule extends Module {
32
31
  /**
33
32
  * @param {string} name a readable name
@@ -127,7 +126,7 @@ class RuntimeModule extends Module {
127
126
  * @returns {SourceTypes} types available (do not mutate)
128
127
  */
129
128
  getSourceTypes() {
130
- return TYPES;
129
+ return RUNTIME_TYPES;
131
130
  }
132
131
 
133
132
  /**