webpack 5.42.1 → 5.43.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.

package/bin/webpack.js CHANGED
File without changes
@@ -16,6 +16,7 @@ const StaticExportsDependency = require("./dependencies/StaticExportsDependency"
16
16
  const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
17
17
  const makeSerializable = require("./util/makeSerializable");
18
18
  const propertyAccess = require("./util/propertyAccess");
19
+ const { register } = require("./util/serialization");
19
20
 
20
21
  /** @typedef {import("webpack-sources").Source} Source */
21
22
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
@@ -169,6 +170,8 @@ class ModuleExternalInitFragment extends InitFragment {
169
170
  `external module import ${id}`
170
171
  );
171
172
  this._identifier = identifier;
173
+ this._id = id;
174
+ this._request = request;
172
175
  }
173
176
 
174
177
  getNamespaceIdentifier() {
@@ -176,6 +179,21 @@ class ModuleExternalInitFragment extends InitFragment {
176
179
  }
177
180
  }
178
181
 
182
+ register(
183
+ ModuleExternalInitFragment,
184
+ "webpack/lib/ExternalModule",
185
+ "ModuleExternalInitFragment",
186
+ {
187
+ serialize(obj, { write }) {
188
+ write(obj._id);
189
+ write(obj._request);
190
+ },
191
+ deserialize({ read }) {
192
+ return new ModuleExternalInitFragment(read(), read());
193
+ }
194
+ }
195
+ );
196
+
179
197
  const generateModuleRemapping = (input, exportsInfo, runtime) => {
180
198
  if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
181
199
  const properties = [];
@@ -180,7 +180,11 @@ class FlagDependencyUsagePlugin {
180
180
  b.groupOptions &&
181
181
  b.groupOptions.entryOptions
182
182
  ) {
183
- processModule(b, b.groupOptions.entryOptions.runtime, true);
183
+ processModule(
184
+ b,
185
+ b.groupOptions.entryOptions.runtime || undefined,
186
+ true
187
+ );
184
188
  } else {
185
189
  queue.enqueue(b);
186
190
  }
@@ -39,6 +39,7 @@ class ContainerPlugin {
39
39
  type: "var",
40
40
  name: options.name
41
41
  },
42
+ runtime: options.runtime,
42
43
  filename: options.filename || undefined,
43
44
  exposes: parseOptions(
44
45
  options.exposes,
@@ -60,7 +61,8 @@ class ContainerPlugin {
60
61
  * @returns {void}
61
62
  */
62
63
  apply(compiler) {
63
- const { name, exposes, shareScope, filename, library } = this._options;
64
+ const { name, exposes, shareScope, filename, library, runtime } =
65
+ this._options;
64
66
 
65
67
  compiler.options.output.enabledLibraryTypes.push(library.type);
66
68
 
@@ -73,6 +75,7 @@ class ContainerPlugin {
73
75
  {
74
76
  name,
75
77
  filename,
78
+ runtime,
76
79
  library
77
80
  },
78
81
  error => {
@@ -64,6 +64,7 @@ class ModuleFederationPlugin {
64
64
  name: options.name,
65
65
  library,
66
66
  filename: options.filename,
67
+ runtime: options.runtime,
67
68
  exposes: options.exposes
68
69
  }).apply(compiler);
69
70
  }
@@ -270,7 +270,7 @@ class WorkerPlugin {
270
270
  entryOptions.name = options.name;
271
271
  }
272
272
 
273
- if (!entryOptions.runtime) {
273
+ if (entryOptions.runtime === undefined) {
274
274
  let i = workerIndexMap.get(parser.state) || 0;
275
275
  workerIndexMap.set(parser.state, i + 1);
276
276
  let name = `${cachedContextify(
@@ -0,0 +1,41 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { register } = require("../util/serialization");
9
+
10
+ class JsonData {
11
+ constructor(data) {
12
+ this._buffer = undefined;
13
+ this._data = undefined;
14
+ if (Buffer.isBuffer(data)) {
15
+ this._buffer = data;
16
+ } else {
17
+ this._data = data;
18
+ }
19
+ }
20
+
21
+ get() {
22
+ if (this._data === undefined && this._buffer !== undefined) {
23
+ this._data = JSON.parse(this._buffer.toString());
24
+ }
25
+ return this._data;
26
+ }
27
+ }
28
+
29
+ register(JsonData, "webpack/lib/json/JsonData", null, {
30
+ serialize(obj, { write }) {
31
+ if (obj._buffer === undefined && obj._data !== undefined) {
32
+ obj._buffer = Buffer.from(JSON.stringify(obj._data));
33
+ }
34
+ write(obj._buffer);
35
+ },
36
+ deserialize({ read }) {
37
+ return new JsonData(read());
38
+ }
39
+ });
40
+
41
+ module.exports = JsonData;
@@ -116,7 +116,10 @@ class JsonGenerator extends Generator {
116
116
  * @returns {number} estimate size of the module
117
117
  */
118
118
  getSize(module, type) {
119
- let data = module.buildInfo && module.buildInfo.jsonData;
119
+ let data =
120
+ module.buildInfo &&
121
+ module.buildInfo.jsonData &&
122
+ module.buildInfo.jsonData.get();
120
123
  if (!data) return 0;
121
124
  return stringifySafe(data).length + 10;
122
125
  }
@@ -145,7 +148,10 @@ class JsonGenerator extends Generator {
145
148
  concatenationScope
146
149
  }
147
150
  ) {
148
- const data = module.buildInfo && module.buildInfo.jsonData;
151
+ const data =
152
+ module.buildInfo &&
153
+ module.buildInfo.jsonData &&
154
+ module.buildInfo.jsonData.get();
149
155
  if (data === undefined) {
150
156
  return new RawSource(
151
157
  runtimeTemplate.missingModuleStatement({
@@ -8,6 +8,7 @@
8
8
  const parseJson = require("json-parse-better-errors");
9
9
  const Parser = require("../Parser");
10
10
  const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
11
+ const JsonData = require("./JsonData");
11
12
 
12
13
  /** @typedef {import("../../declarations/plugins/JsonModulesPluginParser").JsonModulesPluginParserOptions} JsonModulesPluginParserOptions */
13
14
  /** @typedef {import("../Parser").ParserState} ParserState */
@@ -41,7 +42,7 @@ class JsonParser extends Parser {
41
42
  ? source
42
43
  : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
43
44
 
44
- state.module.buildInfo.jsonData = data;
45
+ state.module.buildInfo.jsonData = new JsonData(data);
45
46
  state.module.buildInfo.strict = true;
46
47
  state.module.buildMeta.exportsType = "default";
47
48
  state.module.buildMeta.defaultObject =
@@ -45,6 +45,7 @@ const {
45
45
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
46
46
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
47
47
  /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
48
+ /** @template T @typedef {import("../InitFragment")<T>} InitFragment */
48
49
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
49
50
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
50
51
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
@@ -55,6 +56,7 @@ const {
55
56
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
56
57
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
57
58
  /** @typedef {import("../WebpackError")} WebpackError */
59
+ /** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
58
60
  /** @typedef {import("../util/Hash")} Hash */
59
61
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
60
62
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
@@ -104,6 +106,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
104
106
  * @property {Object} ast
105
107
  * @property {Source} internalSource
106
108
  * @property {ReplaceSource} source
109
+ * @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
107
110
  * @property {Iterable<string>} runtimeRequirements
108
111
  * @property {Scope} globalScope
109
112
  * @property {Scope} moduleScope
@@ -1508,6 +1511,8 @@ ${defineGetters}`
1508
1511
  }
1509
1512
  }
1510
1513
 
1514
+ const chunkInitFragments = [];
1515
+
1511
1516
  // evaluate modules in order
1512
1517
  for (const rawInfo of modulesWithInfo) {
1513
1518
  let name;
@@ -1521,6 +1526,9 @@ ${defineGetters}`
1521
1526
  )}\n`
1522
1527
  );
1523
1528
  result.add(info.source);
1529
+ if (info.chunkInitFragments) {
1530
+ for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
1531
+ }
1524
1532
  if (info.runtimeRequirements) {
1525
1533
  for (const r of info.runtimeRequirements) {
1526
1534
  runtimeRequirements.add(r);
@@ -1583,9 +1591,14 @@ ${defineGetters}`
1583
1591
  }
1584
1592
  }
1585
1593
 
1594
+ const data = new Map();
1595
+ if (chunkInitFragments.length > 0)
1596
+ data.set("chunkInitFragments", chunkInitFragments);
1597
+
1586
1598
  /** @type {CodeGenerationResult} */
1587
1599
  const resultEntry = {
1588
1600
  sources: new Map([["javascript", new CachedSource(result)]]),
1601
+ data,
1589
1602
  runtimeRequirements
1590
1603
  };
1591
1604
 
@@ -1626,6 +1639,8 @@ ${defineGetters}`
1626
1639
  concatenationScope
1627
1640
  });
1628
1641
  const source = codeGenResult.sources.get("javascript");
1642
+ const data = codeGenResult.data;
1643
+ const chunkInitFragments = data && data.get("chunkInitFragments");
1629
1644
  const code = source.source().toString();
1630
1645
  let ast;
1631
1646
  try {
@@ -1662,6 +1677,7 @@ ${defineGetters}`
1662
1677
  info.ast = ast;
1663
1678
  info.internalSource = source;
1664
1679
  info.source = resultSource;
1680
+ info.chunkInitFragments = chunkInitFragments;
1665
1681
  info.globalScope = globalScope;
1666
1682
  info.moduleScope = moduleScope;
1667
1683
  } catch (err) {
@@ -27,7 +27,7 @@ class RuntimeChunkPlugin {
27
27
  (_, { name: entryName }) => {
28
28
  if (entryName === undefined) return;
29
29
  const data = compilation.entries.get(entryName);
30
- if (!data.options.runtime && !data.options.dependOn) {
30
+ if (data.options.runtime === undefined && !data.options.dependOn) {
31
31
  // Determine runtime chunk name
32
32
  let name = this.options.name;
33
33
  if (typeof name === "function") {
@@ -225,7 +225,7 @@ class RuleSetCompiler {
225
225
  if (typeof condition === "string") {
226
226
  return {
227
227
  matchWhenEmpty: condition.length === 0,
228
- fn: str => str.startsWith(condition)
228
+ fn: str => typeof str === "string" && str.startsWith(condition)
229
229
  };
230
230
  }
231
231
  if (typeof condition === "function") {
@@ -245,7 +245,7 @@ class RuleSetCompiler {
245
245
  if (condition instanceof RegExp) {
246
246
  return {
247
247
  matchWhenEmpty: condition.test(""),
248
- fn: v => condition.test(v)
248
+ fn: v => typeof v === "string" && condition.test(v)
249
249
  };
250
250
  }
251
251
  if (Array.isArray(condition)) {
@@ -156,6 +156,7 @@ module.exports = {
156
156
  require("../dependencies/WebpackIsIncludedDependency"),
157
157
  "dependencies/WorkerDependency": () =>
158
158
  require("../dependencies/WorkerDependency"),
159
+ "json/JsonData": () => require("../json/JsonData"),
159
160
  "optimize/ConcatenatedModule": () =>
160
161
  require("../optimize/ConcatenatedModule"),
161
162
  DelegatedModule: () => require("../DelegatedModule"),
@@ -9,7 +9,6 @@ const { register } = require("./serialization");
9
9
  class ClassSerializer {
10
10
  constructor(Constructor) {
11
11
  this.Constructor = Constructor;
12
- this.hash = null;
13
12
  }
14
13
 
15
14
  serialize(obj, context) {
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.42.1",
3
+ "version": "5.43.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@types/eslint-scope": "^3.7.0",
9
- "@types/estree": "^0.0.48",
10
- "@webassemblyjs/ast": "1.11.0",
11
- "@webassemblyjs/wasm-edit": "1.11.0",
12
- "@webassemblyjs/wasm-parser": "1.11.0",
9
+ "@types/estree": "^0.0.49",
10
+ "@webassemblyjs/ast": "1.11.1",
11
+ "@webassemblyjs/wasm-edit": "1.11.1",
12
+ "@webassemblyjs/wasm-parser": "1.11.1",
13
13
  "acorn": "^8.4.1",
14
14
  "browserslist": "^4.14.5",
15
15
  "chrome-trace-event": "^1.0.2",
16
16
  "enhanced-resolve": "^5.8.0",
17
- "es-module-lexer": "^0.6.0",
17
+ "es-module-lexer": "^0.7.1",
18
18
  "eslint-scope": "5.1.1",
19
19
  "events": "^3.2.0",
20
20
  "glob-to-regexp": "^0.4.1",