webpack 5.51.1 → 5.53.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.

@@ -37,11 +37,9 @@ const LoaderImportDependency = require("./LoaderImportDependency");
37
37
  class LoaderPlugin {
38
38
  /**
39
39
  * @param {Object} options options
40
- * @param {boolean=} options.enableExecuteModule execute module enabled
41
40
  */
42
- constructor(options = {}) {
43
- this._enableExecuteModule = !!options.enableExecuteModule;
44
- }
41
+ constructor(options = {}) {}
42
+
45
43
  /**
46
44
  * Apply the plugin
47
45
  * @param {Compiler} compiler the compiler instance
@@ -155,106 +153,104 @@ class LoaderPlugin {
155
153
  );
156
154
  };
157
155
 
158
- if (this._enableExecuteModule) {
159
- /**
160
- * @param {string} request the request string to load the module from
161
- * @param {ImportModuleOptions=} options options
162
- * @param {ImportModuleCallback=} callback callback returning the exports
163
- * @returns {void}
164
- */
165
- const importModule = (request, options, callback) => {
166
- const dep = new LoaderImportDependency(request);
167
- dep.loc = {
168
- name: request
169
- };
170
- const factory = compilation.dependencyFactories.get(
171
- /** @type {DepConstructor} */ (dep.constructor)
156
+ /**
157
+ * @param {string} request the request string to load the module from
158
+ * @param {ImportModuleOptions=} options options
159
+ * @param {ImportModuleCallback=} callback callback returning the exports
160
+ * @returns {void}
161
+ */
162
+ const importModule = (request, options, callback) => {
163
+ const dep = new LoaderImportDependency(request);
164
+ dep.loc = {
165
+ name: request
166
+ };
167
+ const factory = compilation.dependencyFactories.get(
168
+ /** @type {DepConstructor} */ (dep.constructor)
169
+ );
170
+ if (factory === undefined) {
171
+ return callback(
172
+ new Error(
173
+ `No module factory available for dependency type: ${dep.constructor.name}`
174
+ )
172
175
  );
173
- if (factory === undefined) {
174
- return callback(
175
- new Error(
176
- `No module factory available for dependency type: ${dep.constructor.name}`
177
- )
178
- );
179
- }
180
- compilation.buildQueue.increaseParallelism();
181
- compilation.handleModuleCreation(
182
- {
183
- factory,
184
- dependencies: [dep],
185
- originModule: loaderContext._module,
186
- contextInfo: {
187
- issuerLayer: options.layer
188
- },
189
- context: loaderContext.context,
190
- connectOrigin: false
176
+ }
177
+ compilation.buildQueue.increaseParallelism();
178
+ compilation.handleModuleCreation(
179
+ {
180
+ factory,
181
+ dependencies: [dep],
182
+ originModule: loaderContext._module,
183
+ contextInfo: {
184
+ issuerLayer: options.layer
191
185
  },
192
- err => {
193
- compilation.buildQueue.decreaseParallelism();
194
- if (err) {
195
- return callback(err);
196
- }
197
- const referencedModule = moduleGraph.getModule(dep);
198
- if (!referencedModule) {
199
- return callback(new Error("Cannot load the module"));
200
- }
201
- compilation.executeModule(
202
- referencedModule,
203
- {
204
- entryOptions: {
205
- publicPath: options.publicPath
206
- }
207
- },
208
- (err, result) => {
209
- if (err) return callback(err);
210
- for (const d of result.fileDependencies) {
211
- loaderContext.addDependency(d);
212
- }
213
- for (const d of result.contextDependencies) {
214
- loaderContext.addContextDependency(d);
215
- }
216
- for (const d of result.missingDependencies) {
217
- loaderContext.addMissingDependency(d);
218
- }
219
- for (const d of result.buildDependencies) {
220
- loaderContext.addBuildDependency(d);
221
- }
222
- if (result.cacheable === false)
223
- loaderContext.cacheable(false);
224
- for (const [name, { source, info }] of result.assets) {
225
- const { buildInfo } = loaderContext._module;
226
- if (!buildInfo.assets) {
227
- buildInfo.assets = Object.create(null);
228
- buildInfo.assetsInfo = new Map();
229
- }
230
- buildInfo.assets[name] = source;
231
- buildInfo.assetsInfo.set(name, info);
186
+ context: loaderContext.context,
187
+ connectOrigin: false
188
+ },
189
+ err => {
190
+ compilation.buildQueue.decreaseParallelism();
191
+ if (err) {
192
+ return callback(err);
193
+ }
194
+ const referencedModule = moduleGraph.getModule(dep);
195
+ if (!referencedModule) {
196
+ return callback(new Error("Cannot load the module"));
197
+ }
198
+ compilation.executeModule(
199
+ referencedModule,
200
+ {
201
+ entryOptions: {
202
+ publicPath: options.publicPath
203
+ }
204
+ },
205
+ (err, result) => {
206
+ if (err) return callback(err);
207
+ for (const d of result.fileDependencies) {
208
+ loaderContext.addDependency(d);
209
+ }
210
+ for (const d of result.contextDependencies) {
211
+ loaderContext.addContextDependency(d);
212
+ }
213
+ for (const d of result.missingDependencies) {
214
+ loaderContext.addMissingDependency(d);
215
+ }
216
+ for (const d of result.buildDependencies) {
217
+ loaderContext.addBuildDependency(d);
218
+ }
219
+ if (result.cacheable === false)
220
+ loaderContext.cacheable(false);
221
+ for (const [name, { source, info }] of result.assets) {
222
+ const { buildInfo } = loaderContext._module;
223
+ if (!buildInfo.assets) {
224
+ buildInfo.assets = Object.create(null);
225
+ buildInfo.assetsInfo = new Map();
232
226
  }
233
- callback(null, result.exports);
227
+ buildInfo.assets[name] = source;
228
+ buildInfo.assetsInfo.set(name, info);
234
229
  }
235
- );
236
- }
237
- );
238
- };
230
+ callback(null, result.exports);
231
+ }
232
+ );
233
+ }
234
+ );
235
+ };
239
236
 
240
- /**
241
- * @param {string} request the request string to load the module from
242
- * @param {ImportModuleOptions} options options
243
- * @param {ImportModuleCallback=} callback callback returning the exports
244
- * @returns {Promise<any> | void} exports
245
- */
246
- loaderContext.importModule = (request, options, callback) => {
247
- if (!callback) {
248
- return new Promise((resolve, reject) => {
249
- importModule(request, options || {}, (err, result) => {
250
- if (err) reject(err);
251
- else resolve(result);
252
- });
237
+ /**
238
+ * @param {string} request the request string to load the module from
239
+ * @param {ImportModuleOptions} options options
240
+ * @param {ImportModuleCallback=} callback callback returning the exports
241
+ * @returns {Promise<any> | void} exports
242
+ */
243
+ loaderContext.importModule = (request, options, callback) => {
244
+ if (!callback) {
245
+ return new Promise((resolve, reject) => {
246
+ importModule(request, options || {}, (err, result) => {
247
+ if (err) reject(err);
248
+ else resolve(result);
253
249
  });
254
- }
255
- return importModule(request, options || {}, callback);
256
- };
257
- }
250
+ });
251
+ }
252
+ return importModule(request, options || {}, callback);
253
+ };
258
254
  }
259
255
  );
260
256
  });
@@ -41,6 +41,7 @@ const builtins = [
41
41
  "repl",
42
42
  "stream",
43
43
  "stream/promises",
44
+ "stream/web",
44
45
  "string_decoder",
45
46
  "sys",
46
47
  "timers",
@@ -39,13 +39,28 @@ const comparator = compareSelect(e => e.name, compareStringsNumeric);
39
39
  /**
40
40
  * @param {boolean} deterministic use deterministic names
41
41
  * @param {ExportsInfo} exportsInfo exports info
42
+ * @param {boolean} isNamespace is namespace object
42
43
  * @returns {void}
43
44
  */
44
- const mangleExportsInfo = (deterministic, exportsInfo) => {
45
+ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
45
46
  if (!canMangle(exportsInfo)) return;
46
47
  const usedNames = new Set();
47
48
  /** @type {ExportInfo[]} */
48
49
  const mangleableExports = [];
50
+
51
+ // Avoid to renamed exports that are not provided when
52
+ // 1. it's not a namespace export: non-provided exports can be found in prototype chain
53
+ // 2. there are other provided exports and deterministic mode is chosen:
54
+ // non-provided exports would break the determinism
55
+ let avoidMangleNonProvided = !isNamespace;
56
+ if (!avoidMangleNonProvided && deterministic) {
57
+ for (const exportInfo of exportsInfo.ownedExports) {
58
+ if (exportInfo.provided !== false) {
59
+ avoidMangleNonProvided = true;
60
+ break;
61
+ }
62
+ }
63
+ }
49
64
  for (const exportInfo of exportsInfo.ownedExports) {
50
65
  const name = exportInfo.name;
51
66
  if (!exportInfo.hasUsedName()) {
@@ -59,7 +74,7 @@ const mangleExportsInfo = (deterministic, exportsInfo) => {
59
74
  name.length === 2 &&
60
75
  /^[a-zA-Z_$][a-zA-Z0-9_$]|^[1-9][0-9]/.test(name)) ||
61
76
  // Don't rename exports that are not provided
62
- exportInfo.provided !== true
77
+ (avoidMangleNonProvided && exportInfo.provided !== true)
63
78
  ) {
64
79
  exportInfo.setUsedName(name);
65
80
  usedNames.add(name);
@@ -73,7 +88,7 @@ const mangleExportsInfo = (deterministic, exportsInfo) => {
73
88
  used === UsageState.OnlyPropertiesUsed ||
74
89
  used === UsageState.Unused
75
90
  ) {
76
- mangleExportsInfo(deterministic, exportInfo.exportsInfo);
91
+ mangleExportsInfo(deterministic, exportInfo.exportsInfo, false);
77
92
  }
78
93
  }
79
94
  }
@@ -143,8 +158,10 @@ class MangleExportsPlugin {
143
158
  "MangleExportsPlugin",
144
159
  modules => {
145
160
  for (const module of modules) {
161
+ const isNamespace =
162
+ module.buildMeta && module.buildMeta.exportsType === "namespace";
146
163
  const exportsInfo = moduleGraph.getExportsInfo(module);
147
- mangleExportsInfo(deterministic, exportsInfo);
164
+ mangleExportsInfo(deterministic, exportsInfo, isNamespace);
148
165
  }
149
166
  }
150
167
  );
@@ -1073,7 +1073,7 @@ module.exports = class SplitChunksPlugin {
1073
1073
  "SplitChunksPlugin\n" +
1074
1074
  `Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
1075
1075
  `Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` +
1076
- "Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependsOn).\n" +
1076
+ "Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependOn).\n" +
1077
1077
  'HINT: You can omit "name" to automatically create a name.\n' +
1078
1078
  "BREAKING CHANGE: webpack < 5 used to allow to use an entrypoint as splitChunk. " +
1079
1079
  "This is no longer allowed when the entrypoint is not a parent of the selected modules.\n" +
@@ -30,6 +30,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
30
30
  this.global = global;
31
31
  this.getFilenameForChunk = getFilenameForChunk;
32
32
  this.allChunks = allChunks;
33
+ this.dependentHash = true;
33
34
  }
34
35
 
35
36
  /**
@@ -30,7 +30,7 @@ class RelativeUrlRuntimeModule extends HelperRuntimeModule {
30
30
  `values.toString = values.toJSON = ${runtimeTemplate.returningFunction(
31
31
  "url"
32
32
  )};`,
33
- "for (var key in values) Object.defineProperty(this, key, Object.assign({ enumerable: true, configurable: true, value: values[key] }));"
33
+ "for (var key in values) Object.defineProperty(this, key, { enumerable: true, configurable: true, value: values[key] });"
34
34
  ]),
35
35
  "};",
36
36
  `${RuntimeGlobals.relativeUrl}.prototype = URL.prototype;`
@@ -510,11 +510,11 @@ class ObjectMiddleware extends SerializerMiddleware {
510
510
  } else if (SerializerMiddleware.isLazy(item, this)) {
511
511
  throw new Error("Not implemented");
512
512
  } else {
513
- result.push(
514
- SerializerMiddleware.serializeLazy(item, data =>
515
- this.serialize([data], context)
516
- )
513
+ const data = SerializerMiddleware.serializeLazy(item, data =>
514
+ this.serialize([data], context)
517
515
  );
516
+ SerializerMiddleware.setLazySerializedValue(item, data);
517
+ result.push(data);
518
518
  }
519
519
  } else if (item === undefined) {
520
520
  result.push(ESCAPE, ESCAPE_UNDEFINED);
@@ -164,6 +164,7 @@ module.exports = {
164
164
  DllModule: () => require("../DllModule"),
165
165
  ExternalModule: () => require("../ExternalModule"),
166
166
  FileSystemInfo: () => require("../FileSystemInfo"),
167
+ InitFragment: () => require("../InitFragment"),
167
168
  InvalidDependenciesModuleWarning: () =>
168
169
  require("../InvalidDependenciesModuleWarning"),
169
170
  Module: () => require("../Module"),
@@ -188,6 +189,7 @@ module.exports = {
188
189
  UnsupportedFeatureWarning: () => require("../UnsupportedFeatureWarning"),
189
190
  "util/LazySet": () => require("../util/LazySet"),
190
191
  UnhandledSchemeError: () => require("../UnhandledSchemeError"),
192
+ NodeStuffInWebError: () => require("../NodeStuffInWebError"),
191
193
  WebpackError: () => require("../WebpackError"),
192
194
 
193
195
  "util/registerExternalSerializer": () => {
@@ -6,6 +6,59 @@
6
6
  "use strict";
7
7
 
8
8
  const SAFE_IDENTIFIER = /^[_a-zA-Z$][_a-zA-Z$0-9]*$/;
9
+ const RESERVED_IDENTIFER = new Set([
10
+ "break",
11
+ "case",
12
+ "catch",
13
+ "class",
14
+ "const",
15
+ "continue",
16
+ "debugger",
17
+ "default",
18
+ "delete",
19
+ "do",
20
+ "else",
21
+ "export",
22
+ "extends",
23
+ "finally",
24
+ "for",
25
+ "function",
26
+ "if",
27
+ "import",
28
+ "in",
29
+ "instanceof",
30
+ "new",
31
+ "return",
32
+ "super",
33
+ "switch",
34
+ "this",
35
+ "throw",
36
+ "try",
37
+ "typeof",
38
+ "var",
39
+ "void",
40
+ "while",
41
+ "with",
42
+ "enum",
43
+ // strict mode
44
+ "implements",
45
+ "interface",
46
+ "let",
47
+ "package",
48
+ "private",
49
+ "protected",
50
+ "public",
51
+ "static",
52
+ "yield",
53
+ "yield",
54
+ // module code
55
+ "await",
56
+ // skip future reserved keywords defined under ES1 till ES3
57
+ // additional
58
+ "null",
59
+ "true",
60
+ "false"
61
+ ]);
9
62
 
10
63
  const propertyAccess = (properties, start = 0) => {
11
64
  let str = "";
@@ -13,7 +66,7 @@ const propertyAccess = (properties, start = 0) => {
13
66
  const p = properties[i];
14
67
  if (`${+p}` === p) {
15
68
  str += `[${p}]`;
16
- } else if (SAFE_IDENTIFIER.test(p)) {
69
+ } else if (SAFE_IDENTIFIER.test(p) && !RESERVED_IDENTIFER.has(p)) {
17
70
  str += `.${p}`;
18
71
  } else {
19
72
  str += `[${JSON.stringify(p)}]`;
@@ -111,9 +111,13 @@ module.exports = {
111
111
  );
112
112
  };
113
113
  context.writeSeparate = (value, options) => {
114
- context.write(
115
- SerializerMiddleware.createLazy(value, fileMiddleware, options)
114
+ const lazy = SerializerMiddleware.createLazy(
115
+ value,
116
+ fileMiddleware,
117
+ options
116
118
  );
119
+ context.write(lazy);
120
+ return lazy;
117
121
  };
118
122
  }
119
123
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.51.1",
3
+ "version": "5.53.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",
@@ -39,7 +39,7 @@
39
39
  "@babel/core": "^7.11.1",
40
40
  "@babel/preset-react": "^7.10.4",
41
41
  "@types/es-module-lexer": "^0.4.1",
42
- "@types/jest": "^26.0.24",
42
+ "@types/jest": "^27.0.1",
43
43
  "@types/node": "^15.0.1",
44
44
  "babel-loader": "^8.1.0",
45
45
  "benchmark": "^2.1.4",
@@ -58,7 +58,7 @@
58
58
  "eslint-plugin-jest": "^24.3.6",
59
59
  "eslint-plugin-jsdoc": "^33.0.0",
60
60
  "eslint-plugin-node": "^11.0.0",
61
- "eslint-plugin-prettier": "^3.1.4",
61
+ "eslint-plugin-prettier": "^4.0.0",
62
62
  "file-loader": "^6.0.0",
63
63
  "fork-ts-checker-webpack-plugin": "^6.0.5",
64
64
  "husky": "^6.0.0",
@@ -66,6 +66,7 @@
66
66
  "istanbul": "^0.4.5",
67
67
  "jest": "^27.0.6",
68
68
  "jest-circus": "^27.0.6",
69
+ "jest-cli": "^27.0.6",
69
70
  "jest-diff": "^27.0.2",
70
71
  "jest-junit": "^12.0.0",
71
72
  "json-loader": "^0.5.7",