webpack 5.80.0 → 5.82.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (135) hide show
  1. package/bin/webpack.js +13 -2
  2. package/lib/AsyncDependenciesBlock.js +8 -0
  3. package/lib/CodeGenerationResults.js +2 -2
  4. package/lib/Compilation.js +4 -2
  5. package/lib/ContextModule.js +8 -0
  6. package/lib/CssModule.js +169 -0
  7. package/lib/DefinePlugin.js +81 -44
  8. package/lib/DelegatedModule.js +5 -0
  9. package/lib/DependenciesBlock.js +8 -0
  10. package/lib/Dependency.js +8 -0
  11. package/lib/DllModule.js +8 -0
  12. package/lib/ExportsInfo.js +3 -0
  13. package/lib/ExternalModule.js +8 -0
  14. package/lib/FileSystemInfo.js +8 -0
  15. package/lib/LoaderOptionsPlugin.js +12 -2
  16. package/lib/Module.js +8 -0
  17. package/lib/ModuleBuildError.js +9 -0
  18. package/lib/ModuleError.js +9 -0
  19. package/lib/ModuleFilenameHelpers.js +113 -4
  20. package/lib/ModuleParseError.js +9 -0
  21. package/lib/ModuleTypeConstants.js +21 -0
  22. package/lib/ModuleWarning.js +9 -0
  23. package/lib/NormalModule.js +8 -0
  24. package/lib/NormalModuleFactory.js +15 -3
  25. package/lib/RawModule.js +8 -0
  26. package/lib/WebpackError.js +8 -0
  27. package/lib/WebpackOptionsApply.js +33 -40
  28. package/lib/asset/RawDataUrlModule.js +8 -0
  29. package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
  30. package/lib/cache/ResolverCachePlugin.js +3 -0
  31. package/lib/config/defaults.js +1 -0
  32. package/lib/config/normalization.js +1 -0
  33. package/lib/container/ContainerEntryModule.js +5 -0
  34. package/lib/container/ContainerExposedDependency.js +9 -0
  35. package/lib/container/FallbackDependency.js +6 -0
  36. package/lib/container/FallbackModule.js +5 -0
  37. package/lib/container/RemoteModule.js +5 -0
  38. package/lib/css/CssGenerator.js +4 -0
  39. package/lib/css/CssLoadingRuntimeModule.js +9 -2
  40. package/lib/css/CssModulesPlugin.js +201 -57
  41. package/lib/css/CssParser.js +270 -147
  42. package/lib/css/walkCssTokens.js +121 -65
  43. package/lib/debug/ProfilingPlugin.js +2 -0
  44. package/lib/dependencies/AMDDefineDependency.js +8 -0
  45. package/lib/dependencies/AMDRequireArrayDependency.js +8 -0
  46. package/lib/dependencies/AMDRequireContextDependency.js +9 -0
  47. package/lib/dependencies/AMDRequireDependency.js +8 -0
  48. package/lib/dependencies/CachedConstDependency.js +8 -0
  49. package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
  50. package/lib/dependencies/CommonJsExportRequireDependency.js +8 -0
  51. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  52. package/lib/dependencies/CommonJsExportsParserPlugin.js +65 -3
  53. package/lib/dependencies/CommonJsFullRequireDependency.js +8 -0
  54. package/lib/dependencies/CommonJsRequireContextDependency.js +9 -0
  55. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  56. package/lib/dependencies/ConstDependency.js +8 -0
  57. package/lib/dependencies/ContextDependency.js +8 -0
  58. package/lib/dependencies/ContextElementDependency.js +8 -0
  59. package/lib/dependencies/CreateScriptUrlDependency.js +8 -0
  60. package/lib/dependencies/CssExportDependency.js +8 -0
  61. package/lib/dependencies/CssImportDependency.js +52 -1
  62. package/lib/dependencies/CssLocalIdentifierDependency.js +8 -0
  63. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +8 -0
  64. package/lib/dependencies/CssUrlDependency.js +8 -0
  65. package/lib/dependencies/DllEntryDependency.js +9 -0
  66. package/lib/dependencies/ExportsInfoDependency.js +5 -0
  67. package/lib/dependencies/HarmonyAcceptDependency.js +8 -0
  68. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +8 -0
  69. package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
  70. package/lib/dependencies/HarmonyExportHeaderDependency.js +8 -0
  71. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +14 -0
  72. package/lib/dependencies/HarmonyExportSpecifierDependency.js +8 -0
  73. package/lib/dependencies/HarmonyImportDependency.js +8 -0
  74. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -0
  75. package/lib/dependencies/HarmonyImportSpecifierDependency.js +8 -0
  76. package/lib/dependencies/ImportContextDependency.js +9 -0
  77. package/lib/dependencies/ImportDependency.js +8 -0
  78. package/lib/dependencies/JsonExportsDependency.js +8 -0
  79. package/lib/dependencies/LocalModuleDependency.js +8 -0
  80. package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
  81. package/lib/dependencies/ModuleDependency.js +8 -0
  82. package/lib/dependencies/ProvidedDependency.js +8 -0
  83. package/lib/dependencies/PureExpressionDependency.js +8 -0
  84. package/lib/dependencies/RequireEnsureDependency.js +8 -0
  85. package/lib/dependencies/RequireHeaderDependency.js +5 -0
  86. package/lib/dependencies/RequireResolveContextDependency.js +9 -0
  87. package/lib/dependencies/RequireResolveHeaderDependency.js +5 -0
  88. package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
  89. package/lib/dependencies/StaticExportsDependency.js +8 -0
  90. package/lib/dependencies/URLDependency.js +8 -0
  91. package/lib/dependencies/UnsupportedDependency.js +8 -0
  92. package/lib/dependencies/WebAssemblyExportImportedDependency.js +8 -0
  93. package/lib/dependencies/WebAssemblyImportDependency.js +8 -0
  94. package/lib/dependencies/WorkerDependency.js +8 -0
  95. package/lib/index.js +1 -0
  96. package/lib/javascript/BasicEvaluatedExpression.js +108 -1
  97. package/lib/javascript/JavascriptParser.js +133 -12
  98. package/lib/json/JsonData.js +25 -0
  99. package/lib/json/JsonGenerator.js +15 -3
  100. package/lib/json/JsonModulesPlugin.js +1 -0
  101. package/lib/json/JsonParser.js +2 -1
  102. package/lib/library/ModuleLibraryPlugin.js +2 -1
  103. package/lib/optimize/RealContentHashPlugin.js +6 -0
  104. package/lib/runtime/AutoPublicPathRuntimeModule.js +6 -1
  105. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  106. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +22 -3
  107. package/lib/schemes/DataUriPlugin.js +4 -0
  108. package/lib/schemes/HttpUriPlugin.js +38 -0
  109. package/lib/serialization/ObjectMiddleware.js +2 -0
  110. package/lib/sharing/ConsumeSharedModule.js +8 -0
  111. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -3
  112. package/lib/sharing/ProvideSharedDependency.js +6 -0
  113. package/lib/sharing/ProvideSharedModule.js +5 -0
  114. package/lib/sharing/ShareRuntimeModule.js +7 -4
  115. package/lib/sharing/utils.js +293 -7
  116. package/lib/stats/DefaultStatsPrinterPlugin.js +25 -0
  117. package/lib/util/LazySet.js +10 -2
  118. package/lib/util/MapHelpers.js +19 -5
  119. package/lib/util/StackedCacheMap.js +6 -0
  120. package/lib/util/StringXor.js +51 -0
  121. package/lib/util/binarySearchBounds.js +49 -0
  122. package/lib/util/compileBooleanMatcher.js +31 -0
  123. package/lib/util/deprecation.js +8 -0
  124. package/lib/util/identifier.js +4 -0
  125. package/lib/util/internalSerializables.js +1 -0
  126. package/lib/util/numberHash.js +75 -21
  127. package/lib/util/propertyAccess.js +5 -0
  128. package/lib/util/semver.js +1 -1
  129. package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
  130. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -0
  131. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  132. package/package.json +4 -5
  133. package/schemas/WebpackOptions.check.js +1 -1
  134. package/schemas/WebpackOptions.json +33 -0
  135. package/types.d.ts +176 -48
package/bin/webpack.js CHANGED
@@ -78,8 +78,19 @@ const runCli = cli => {
78
78
  const pkgPath = require.resolve(`${cli.package}/package.json`);
79
79
  // eslint-disable-next-line node/no-missing-require
80
80
  const pkg = require(pkgPath);
81
- // eslint-disable-next-line node/no-missing-require
82
- require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
81
+
82
+ if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
83
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
84
+ import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
85
+ error => {
86
+ console.error(error);
87
+ process.exitCode = 1;
88
+ }
89
+ );
90
+ } else {
91
+ // eslint-disable-next-line node/no-missing-require
92
+ require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
93
+ }
83
94
  };
84
95
 
85
96
  /**
@@ -15,6 +15,8 @@ const makeSerializable = require("./util/makeSerializable");
15
15
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
16
16
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
17
17
  /** @typedef {import("./Module")} Module */
18
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
18
20
  /** @typedef {import("./util/Hash")} Hash */
19
21
 
20
22
  class AsyncDependenciesBlock extends DependenciesBlock {
@@ -71,6 +73,9 @@ class AsyncDependenciesBlock extends DependenciesBlock {
71
73
  super.updateHash(hash, context);
72
74
  }
73
75
 
76
+ /**
77
+ * @param {ObjectSerializerContext} context context
78
+ */
74
79
  serialize(context) {
75
80
  const { write } = context;
76
81
  write(this.groupOptions);
@@ -79,6 +84,9 @@ class AsyncDependenciesBlock extends DependenciesBlock {
79
84
  super.serialize(context);
80
85
  }
81
86
 
87
+ /**
88
+ * @param {ObjectDeserializerContext} context context
89
+ */
82
90
  deserialize(context) {
83
91
  const { read } = context;
84
92
  this.groupOptions = read();
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { provide } = require("./util/MapHelpers");
8
+ const { getOrInsert } = require("./util/MapHelpers");
9
9
  const { first } = require("./util/SetHelpers");
10
10
  const createHash = require("./util/createHash");
11
11
  const { runtimeToString, RuntimeSpecMap } = require("./util/runtime");
@@ -147,7 +147,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
147
147
  * @returns {void}
148
148
  */
149
149
  add(module, runtime, result) {
150
- const map = provide(this.map, module, () => new RuntimeSpecMap());
150
+ const map = getOrInsert(this.map, module, () => new RuntimeSpecMap());
151
151
  map.set(runtime, result);
152
152
  }
153
153
  }
@@ -61,7 +61,7 @@ const StatsPrinter = require("./stats/StatsPrinter");
61
61
  const { equals: arrayEquals } = require("./util/ArrayHelpers");
62
62
  const AsyncQueue = require("./util/AsyncQueue");
63
63
  const LazySet = require("./util/LazySet");
64
- const { provide } = require("./util/MapHelpers");
64
+ const { getOrInsert } = require("./util/MapHelpers");
65
65
  const WeakTupleMap = require("./util/WeakTupleMap");
66
66
  const { cachedCleverMerge } = require("./util/cleverMerge");
67
67
  const {
@@ -2578,6 +2578,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2578
2578
  p.calculate();
2579
2579
 
2580
2580
  const logger = this.getLogger("webpack.Compilation.ModuleProfile");
2581
+ // Avoid coverage problems due indirect changes
2582
+ /* istanbul ignore next */
2581
2583
  const logByValue = (value, msg) => {
2582
2584
  if (value > 1000) {
2583
2585
  logger.error(msg);
@@ -2618,7 +2620,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2618
2620
  const logByLoadersSummary = (category, getDuration, getParallelism) => {
2619
2621
  const map = new Map();
2620
2622
  for (const [module, profile] of modulesWithProfiles) {
2621
- const list = provide(
2623
+ const list = getOrInsert(
2622
2624
  map,
2623
2625
  module.type + "!" + module.identifier().replace(/(!|^)[^!]*$/, ""),
2624
2626
  () => []
@@ -43,6 +43,8 @@ const makeSerializable = require("./util/makeSerializable");
43
43
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
44
44
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
45
45
  /** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
46
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
47
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
46
48
  /** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
47
49
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
48
50
 
@@ -1151,6 +1153,9 @@ module.exports = webpackEmptyAsyncContext;`;
1151
1153
  return size;
1152
1154
  }
1153
1155
 
1156
+ /**
1157
+ * @param {ObjectSerializerContext} context context
1158
+ */
1154
1159
  serialize(context) {
1155
1160
  const { write } = context;
1156
1161
  write(this._identifier);
@@ -1158,6 +1163,9 @@ module.exports = webpackEmptyAsyncContext;`;
1158
1163
  super.serialize(context);
1159
1164
  }
1160
1165
 
1166
+ /**
1167
+ * @param {ObjectDeserializerContext} context context
1168
+ */
1161
1169
  deserialize(context) {
1162
1170
  const { read } = context;
1163
1171
  this._identifier = read();
@@ -0,0 +1,169 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Krasnoyarov @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const NormalModule = require("./NormalModule");
9
+ const makeSerializable = require("./util/makeSerializable");
10
+
11
+ /** @typedef {import("./Module")} Module */
12
+ /** @typedef {import("./NormalModule").NormalModuleCreateData} NormalModuleCreateData */
13
+ /** @typedef {import("./RequestShortener")} RequestShortener */
14
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
+
17
+ /** @typedef {string|undefined} CssLayer */
18
+ /** @typedef {string|undefined} Supports */
19
+ /** @typedef {string|undefined} Media */
20
+ /** @typedef {[CssLayer?, Supports?, Media?]} InheritanceItem */
21
+ /** @typedef {Array<InheritanceItem>} Inheritance */
22
+
23
+ /** @typedef {NormalModuleCreateData & { cssLayer: CssLayer|null, supports: Supports|null, media: Media|null, inheritance: Inheritance|null }} CSSModuleCreateData */
24
+
25
+ class CssModule extends NormalModule {
26
+ /**
27
+ * @param {CSSModuleCreateData} options options object
28
+ */
29
+ constructor(options) {
30
+ super(options);
31
+
32
+ // Avoid override `layer` for `Module` class, because it is a feature to run module in specific layer
33
+ this.cssLayer = options.cssLayer;
34
+ this.supports = options.supports;
35
+ this.media = options.media;
36
+ this.inheritance = options.inheritance;
37
+ }
38
+
39
+ /**
40
+ * @returns {string} a unique identifier of the module
41
+ */
42
+ identifier() {
43
+ let identifier = super.identifier();
44
+
45
+ if (this.cssLayer) {
46
+ identifier += `|${this.cssLayer}`;
47
+ }
48
+
49
+ if (this.supports) {
50
+ identifier += `|${this.supports}`;
51
+ }
52
+
53
+ if (this.media) {
54
+ identifier += `|${this.media}`;
55
+ }
56
+
57
+ if (this.inheritance) {
58
+ const inheritance = this.inheritance.map(
59
+ (item, index) =>
60
+ `inheritance_${index}|${item[0] || ""}|${item[1] || ""}|${
61
+ item[2] || ""
62
+ }`
63
+ );
64
+
65
+ identifier += `|${inheritance.join("|")}`;
66
+ }
67
+
68
+ return identifier;
69
+ }
70
+
71
+ /**
72
+ * @param {RequestShortener} requestShortener the request shortener
73
+ * @returns {string} a user readable identifier of the module
74
+ */
75
+ readableIdentifier(requestShortener) {
76
+ const readableIdentifier = super.readableIdentifier(requestShortener);
77
+
78
+ let identifier = `css ${readableIdentifier}`;
79
+
80
+ if (this.cssLayer) {
81
+ identifier += ` (layer: ${this.cssLayer})`;
82
+ }
83
+
84
+ if (this.supports) {
85
+ identifier += ` (supports: ${this.supports})`;
86
+ }
87
+
88
+ if (this.media) {
89
+ identifier += ` (media: ${this.media})`;
90
+ }
91
+
92
+ return identifier;
93
+ }
94
+
95
+ /**
96
+ * Assuming this module is in the cache. Update the (cached) module with
97
+ * the fresh module from the factory. Usually updates internal references
98
+ * and properties.
99
+ * @param {Module} module fresh module
100
+ * @returns {void}
101
+ */
102
+ updateCacheModule(module) {
103
+ super.updateCacheModule(module);
104
+ const m = /** @type {CssModule} */ (module);
105
+ this.cssLayer = m.cssLayer;
106
+ this.supports = m.supports;
107
+ this.media = m.media;
108
+ this.inheritance = m.inheritance;
109
+ }
110
+
111
+ /**
112
+ * @param {ObjectSerializerContext} context context
113
+ */
114
+ serialize(context) {
115
+ const { write } = context;
116
+ write(this.cssLayer);
117
+ write(this.supports);
118
+ write(this.media);
119
+ write(this.inheritance);
120
+ super.serialize(context);
121
+ }
122
+
123
+ /**
124
+ * @param {ObjectDeserializerContext} context context
125
+ * @returns {CssModule} the deserialized object
126
+ */
127
+ static deserialize(context) {
128
+ const obj = new CssModule({
129
+ // will be deserialized by Module
130
+ layer: null,
131
+ type: "",
132
+ // will be filled by updateCacheModule
133
+ resource: "",
134
+ context: "",
135
+ request: null,
136
+ userRequest: null,
137
+ rawRequest: null,
138
+ loaders: null,
139
+ matchResource: null,
140
+ parser: null,
141
+ parserOptions: null,
142
+ generator: null,
143
+ generatorOptions: null,
144
+ resolveOptions: null,
145
+ cssLayer: null,
146
+ supports: null,
147
+ media: null,
148
+ inheritance: null
149
+ });
150
+ obj.deserialize(context);
151
+ return obj;
152
+ }
153
+
154
+ /**
155
+ * @param {ObjectDeserializerContext} context context
156
+ */
157
+ deserialize(context) {
158
+ const { read } = context;
159
+ this.cssLayer = read();
160
+ this.supports = read();
161
+ this.media = read();
162
+ this.inheritance = read();
163
+ super.deserialize(context);
164
+ }
165
+ }
166
+
167
+ makeSerializable(CssModule, "webpack/lib/CssModule");
168
+
169
+ module.exports = CssModule;
@@ -26,6 +26,7 @@ const createHash = require("./util/createHash");
26
26
  /** @typedef {import("./NormalModule")} NormalModule */
27
27
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
28
28
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
29
+ /** @typedef {import("./logging/Logger").Logger} Logger */
29
30
 
30
31
  /** @typedef {null|undefined|RegExp|Function|string|number|boolean|bigint|undefined} CodeValuePrimitive */
31
32
  /** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive|RuntimeValue>} CodeValue */
@@ -117,6 +118,7 @@ class RuntimeValue {
117
118
  * @param {Map<string, string | Set<string>>} valueCacheVersions valueCacheVersions
118
119
  * @param {string} key the defined key
119
120
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
121
+ * @param {Logger} logger the logger object
120
122
  * @param {boolean|undefined|null=} asiSafe asi safe (undefined: unknown, null: unneeded)
121
123
  * @param {Set<string>|undefined=} objKeys used keys
122
124
  * @returns {string} code converted to string that evaluates
@@ -127,6 +129,7 @@ const stringifyObj = (
127
129
  valueCacheVersions,
128
130
  key,
129
131
  runtimeTemplate,
132
+ logger,
130
133
  asiSafe,
131
134
  objKeys
132
135
  ) => {
@@ -135,7 +138,15 @@ const stringifyObj = (
135
138
  if (arr) {
136
139
  code = `[${obj
137
140
  .map(code =>
138
- toCode(code, parser, valueCacheVersions, key, runtimeTemplate, null)
141
+ toCode(
142
+ code,
143
+ parser,
144
+ valueCacheVersions,
145
+ key,
146
+ runtimeTemplate,
147
+ logger,
148
+ null
149
+ )
139
150
  )
140
151
  .join(",")}]`;
141
152
  } else {
@@ -150,7 +161,15 @@ const stringifyObj = (
150
161
  return (
151
162
  JSON.stringify(key) +
152
163
  ":" +
153
- toCode(code, parser, valueCacheVersions, key, runtimeTemplate, null)
164
+ toCode(
165
+ code,
166
+ parser,
167
+ valueCacheVersions,
168
+ key,
169
+ runtimeTemplate,
170
+ logger,
171
+ null
172
+ )
154
173
  );
155
174
  })
156
175
  .join(",")}}`;
@@ -175,6 +194,7 @@ const stringifyObj = (
175
194
  * @param {Map<string, string | Set<string>>} valueCacheVersions valueCacheVersions
176
195
  * @param {string} key the defined key
177
196
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
197
+ * @param {Logger} logger the logger object
178
198
  * @param {boolean|undefined|null=} asiSafe asi safe (undefined: unknown, null: unneeded)
179
199
  * @param {Set<string>|undefined=} objKeys used keys
180
200
  * @returns {string} code converted to string that evaluates
@@ -185,51 +205,62 @@ const toCode = (
185
205
  valueCacheVersions,
186
206
  key,
187
207
  runtimeTemplate,
208
+ logger,
188
209
  asiSafe,
189
210
  objKeys
190
211
  ) => {
191
- if (code === null) {
192
- return "null";
193
- }
194
- if (code === undefined) {
195
- return "undefined";
196
- }
197
- if (Object.is(code, -0)) {
198
- return "-0";
199
- }
200
- if (code instanceof RuntimeValue) {
201
- return toCode(
202
- code.exec(parser, valueCacheVersions, key),
203
- parser,
204
- valueCacheVersions,
205
- key,
206
- runtimeTemplate,
207
- asiSafe
208
- );
209
- }
210
- if (code instanceof RegExp && code.toString) {
211
- return code.toString();
212
- }
213
- if (typeof code === "function" && code.toString) {
214
- return "(" + code.toString() + ")";
215
- }
216
- if (typeof code === "object") {
217
- return stringifyObj(
218
- code,
219
- parser,
220
- valueCacheVersions,
221
- key,
222
- runtimeTemplate,
223
- asiSafe,
224
- objKeys
225
- );
226
- }
227
- if (typeof code === "bigint") {
228
- return runtimeTemplate.supportsBigIntLiteral()
229
- ? `${code}n`
230
- : `BigInt("${code}")`;
231
- }
232
- return code + "";
212
+ const transformToCode = () => {
213
+ if (code === null) {
214
+ return "null";
215
+ }
216
+ if (code === undefined) {
217
+ return "undefined";
218
+ }
219
+ if (Object.is(code, -0)) {
220
+ return "-0";
221
+ }
222
+ if (code instanceof RuntimeValue) {
223
+ return toCode(
224
+ code.exec(parser, valueCacheVersions, key),
225
+ parser,
226
+ valueCacheVersions,
227
+ key,
228
+ runtimeTemplate,
229
+ logger,
230
+ asiSafe
231
+ );
232
+ }
233
+ if (code instanceof RegExp && code.toString) {
234
+ return code.toString();
235
+ }
236
+ if (typeof code === "function" && code.toString) {
237
+ return "(" + code.toString() + ")";
238
+ }
239
+ if (typeof code === "object") {
240
+ return stringifyObj(
241
+ code,
242
+ parser,
243
+ valueCacheVersions,
244
+ key,
245
+ runtimeTemplate,
246
+ logger,
247
+ asiSafe,
248
+ objKeys
249
+ );
250
+ }
251
+ if (typeof code === "bigint") {
252
+ return runtimeTemplate.supportsBigIntLiteral()
253
+ ? `${code}n`
254
+ : `BigInt("${code}")`;
255
+ }
256
+ return code + "";
257
+ };
258
+
259
+ const strCode = transformToCode();
260
+
261
+ logger.log(`Replaced "${key}" with "${strCode}"`);
262
+
263
+ return strCode;
233
264
  };
234
265
 
235
266
  const toCacheVersion = code => {
@@ -300,6 +331,7 @@ class DefinePlugin {
300
331
  compiler.hooks.compilation.tap(
301
332
  PLUGIN_NAME,
302
333
  (compilation, { normalModuleFactory }) => {
334
+ const logger = compilation.getLogger("webpack.DefinePlugin");
303
335
  compilation.dependencyTemplates.set(
304
336
  ConstDependency,
305
337
  new ConstDependency.Template()
@@ -421,6 +453,7 @@ class DefinePlugin {
421
453
  compilation.valueCacheVersions,
422
454
  key,
423
455
  runtimeTemplate,
456
+ logger,
424
457
  null
425
458
  )
426
459
  );
@@ -436,6 +469,7 @@ class DefinePlugin {
436
469
  compilation.valueCacheVersions,
437
470
  originalKey,
438
471
  runtimeTemplate,
472
+ logger,
439
473
  !parser.isAsiPosition(expr.range[0]),
440
474
  parser.destructuringAssignmentPropertiesFor(expr)
441
475
  );
@@ -470,6 +504,7 @@ class DefinePlugin {
470
504
  compilation.valueCacheVersions,
471
505
  originalKey,
472
506
  runtimeTemplate,
507
+ logger,
473
508
  null
474
509
  );
475
510
  const typeofCode = isTypeof
@@ -488,6 +523,7 @@ class DefinePlugin {
488
523
  compilation.valueCacheVersions,
489
524
  originalKey,
490
525
  runtimeTemplate,
526
+ logger,
491
527
  null
492
528
  );
493
529
  const typeofCode = isTypeof
@@ -534,6 +570,7 @@ class DefinePlugin {
534
570
  compilation.valueCacheVersions,
535
571
  key,
536
572
  runtimeTemplate,
573
+ logger,
537
574
  !parser.isAsiPosition(expr.range[0]),
538
575
  parser.destructuringAssignmentPropertiesFor(expr)
539
576
  );
@@ -30,6 +30,8 @@ const makeSerializable = require("./util/makeSerializable");
30
30
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
31
31
  /** @typedef {import("./WebpackError")} WebpackError */
32
32
  /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
33
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
34
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
33
35
  /** @typedef {import("./util/Hash")} Hash */
34
36
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
35
37
 
@@ -186,6 +188,9 @@ class DelegatedModule extends Module {
186
188
  super.updateHash(hash, context);
187
189
  }
188
190
 
191
+ /**
192
+ * @param {ObjectSerializerContext} context context
193
+ */
189
194
  serialize(context) {
190
195
  const { write } = context;
191
196
  // constructor
@@ -12,6 +12,8 @@ const makeSerializable = require("./util/makeSerializable");
12
12
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
13
13
  /** @typedef {import("./Dependency")} Dependency */
14
14
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
15
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
17
  /** @typedef {import("./util/Hash")} Hash */
16
18
 
17
19
  /** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
@@ -88,11 +90,17 @@ class DependenciesBlock {
88
90
  }
89
91
  }
90
92
 
93
+ /**
94
+ * @param {ObjectSerializerContext} context context
95
+ */
91
96
  serialize({ write }) {
92
97
  write(this.dependencies);
93
98
  write(this.blocks);
94
99
  }
95
100
 
101
+ /**
102
+ * @param {ObjectDeserializerContext} context context
103
+ */
96
104
  deserialize({ read }) {
97
105
  this.dependencies = read();
98
106
  this.blocks = read();
package/lib/Dependency.js CHANGED
@@ -17,6 +17,8 @@ const memoize = require("./util/memoize");
17
17
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
18
18
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
19
19
  /** @typedef {import("./WebpackError")} WebpackError */
20
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
21
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
22
  /** @typedef {import("./util/Hash")} Hash */
21
23
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
22
24
 
@@ -292,6 +294,9 @@ class Dependency {
292
294
  return getIgnoredModule();
293
295
  }
294
296
 
297
+ /**
298
+ * @param {ObjectSerializerContext} context context
299
+ */
295
300
  serialize({ write }) {
296
301
  write(this.weak);
297
302
  write(this.optional);
@@ -303,6 +308,9 @@ class Dependency {
303
308
  write(this._locN);
304
309
  }
305
310
 
311
+ /**
312
+ * @param {ObjectDeserializerContext} context context
313
+ */
306
314
  deserialize({ read }) {
307
315
  this.weak = read();
308
316
  this.optional = read();
package/lib/DllModule.js CHANGED
@@ -25,6 +25,8 @@ const makeSerializable = require("./util/makeSerializable");
25
25
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
26
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
27
27
  /** @typedef {import("./WebpackError")} WebpackError */
28
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
29
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
28
30
  /** @typedef {import("./util/Hash")} Hash */
29
31
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
30
32
 
@@ -122,11 +124,17 @@ class DllModule extends Module {
122
124
  super.updateHash(hash, context);
123
125
  }
124
126
 
127
+ /**
128
+ * @param {ObjectSerializerContext} context context
129
+ */
125
130
  serialize(context) {
126
131
  context.write(this.name);
127
132
  super.serialize(context);
128
133
  }
129
134
 
135
+ /**
136
+ * @param {ObjectDeserializerContext} context context
137
+ */
130
138
  deserialize(context) {
131
139
  this.name = context.read();
132
140
  super.deserialize(context);
@@ -752,6 +752,9 @@ class ExportsInfo {
752
752
  );
753
753
  }
754
754
 
755
+ /**
756
+ * @param {{ otherProvided: any, otherCanMangleProvide: any, otherTerminalBinding: any, exports: any }} data data
757
+ */
755
758
  restoreProvided({
756
759
  otherProvided,
757
760
  otherCanMangleProvide,
@@ -39,6 +39,8 @@ const { register } = require("./util/serialization");
39
39
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
40
40
  /** @typedef {import("./WebpackError")} WebpackError */
41
41
  /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
42
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
43
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
42
44
  /** @typedef {import("./util/Hash")} Hash */
43
45
  /** @typedef {typeof import("./util/Hash")} HashConstructor */
44
46
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
@@ -733,6 +735,9 @@ class ExternalModule extends Module {
733
735
  super.updateHash(hash, context);
734
736
  }
735
737
 
738
+ /**
739
+ * @param {ObjectSerializerContext} context context
740
+ */
736
741
  serialize(context) {
737
742
  const { write } = context;
738
743
 
@@ -743,6 +748,9 @@ class ExternalModule extends Module {
743
748
  super.serialize(context);
744
749
  }
745
750
 
751
+ /**
752
+ * @param {ObjectDeserializerContext} context context
753
+ */
746
754
  deserialize(context) {
747
755
  const { read } = context;
748
756
 
@@ -18,6 +18,8 @@ const processAsyncTree = require("./util/processAsyncTree");
18
18
 
19
19
  /** @typedef {import("./WebpackError")} WebpackError */
20
20
  /** @typedef {import("./logging/Logger").Logger} Logger */
21
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
22
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
21
23
  /** @typedef {typeof import("./util/Hash")} Hash */
22
24
  /** @typedef {import("./util/fs").IStats} IStats */
23
25
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
@@ -378,6 +380,9 @@ class Snapshot {
378
380
  this.children.add(child);
379
381
  }
380
382
 
383
+ /**
384
+ * @param {ObjectSerializerContext} context context
385
+ */
381
386
  serialize({ write }) {
382
387
  write(this._flags);
383
388
  if (this.hasStartTime()) write(this.startTime);
@@ -395,6 +400,9 @@ class Snapshot {
395
400
  if (this.hasChildren()) write(this.children);
396
401
  }
397
402
 
403
+ /**
404
+ * @param {ObjectDeserializerContext} context context
405
+ */
398
406
  deserialize({ read }) {
399
407
  this._flags = read();
400
408
  if (this.hasStartTime()) this.startTime = read();