webpack 5.69.1 → 5.72.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 (84) hide show
  1. package/hot/poll.js +1 -1
  2. package/hot/signal.js +1 -1
  3. package/lib/BannerPlugin.js +12 -4
  4. package/lib/Chunk.js +1 -1
  5. package/lib/ChunkGraph.js +93 -6
  6. package/lib/ChunkGroup.js +1 -1
  7. package/lib/CleanPlugin.js +64 -18
  8. package/lib/Compilation.js +51 -25
  9. package/lib/Compiler.js +16 -3
  10. package/lib/ConstPlugin.js +2 -2
  11. package/lib/ContextModule.js +121 -34
  12. package/lib/ContextModuleFactory.js +65 -25
  13. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  14. package/lib/Dependency.js +7 -0
  15. package/lib/EntryOptionPlugin.js +1 -0
  16. package/lib/ErrorHelpers.js +2 -2
  17. package/lib/ExportsInfo.js +1 -1
  18. package/lib/ExternalModuleFactoryPlugin.js +4 -4
  19. package/lib/FileSystemInfo.js +8 -0
  20. package/lib/Generator.js +1 -0
  21. package/lib/LoaderOptionsPlugin.js +1 -1
  22. package/lib/Module.js +3 -0
  23. package/lib/ModuleFilenameHelpers.js +3 -3
  24. package/lib/ModuleHashingError.js +29 -0
  25. package/lib/NodeStuffPlugin.js +10 -0
  26. package/lib/NormalModule.js +26 -20
  27. package/lib/NormalModuleFactory.js +17 -10
  28. package/lib/ProgressPlugin.js +3 -4
  29. package/lib/RuntimePlugin.js +18 -0
  30. package/lib/RuntimeTemplate.js +1 -0
  31. package/lib/WebpackOptionsApply.js +2 -0
  32. package/lib/asset/AssetGenerator.js +155 -40
  33. package/lib/asset/AssetParser.js +1 -0
  34. package/lib/asset/AssetSourceGenerator.js +31 -6
  35. package/lib/asset/AssetSourceParser.js +1 -0
  36. package/lib/cache/PackFileCacheStrategy.js +8 -4
  37. package/lib/cache/ResolverCachePlugin.js +89 -28
  38. package/lib/config/browserslistTargetHandler.js +3 -5
  39. package/lib/config/defaults.js +9 -1
  40. package/lib/config/normalization.js +1 -0
  41. package/lib/container/RemoteRuntimeModule.js +8 -7
  42. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  43. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  44. package/lib/dependencies/ContextElementDependency.js +33 -1
  45. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  46. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  47. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  48. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +127 -43
  49. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -8
  50. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  51. package/lib/dependencies/ImportContextDependency.js +0 -2
  52. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  53. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  54. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  55. package/lib/dependencies/LoaderPlugin.js +2 -0
  56. package/lib/dependencies/RequireContextDependency.js +0 -16
  57. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  58. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
  59. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  60. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  61. package/lib/ids/HashedModuleIdsPlugin.js +2 -2
  62. package/lib/ids/IdHelpers.js +1 -1
  63. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  64. package/lib/javascript/JavascriptParser.js +66 -40
  65. package/lib/library/UmdLibraryPlugin.js +5 -3
  66. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
  67. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
  68. package/lib/optimize/ConcatenatedModule.js +2 -1
  69. package/lib/optimize/ModuleConcatenationPlugin.js +20 -1
  70. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  71. package/lib/schemes/HttpUriPlugin.js +44 -3
  72. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  73. package/lib/util/internalSerializables.js +4 -0
  74. package/lib/web/JsonpChunkLoadingRuntimeModule.js +17 -6
  75. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
  76. package/module.d.ts +15 -0
  77. package/package.json +2 -2
  78. package/schemas/WebpackOptions.check.js +1 -1
  79. package/schemas/WebpackOptions.json +17 -1
  80. package/schemas/plugins/BannerPlugin.check.js +1 -1
  81. package/schemas/plugins/BannerPlugin.json +4 -0
  82. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  83. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  84. package/types.d.ts +202 -84
@@ -15,12 +15,33 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
15
15
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
+ /** @typedef {import("../Chunk")} Chunk */
19
+
18
20
  class RequireChunkLoadingRuntimeModule extends RuntimeModule {
19
21
  constructor(runtimeRequirements) {
20
22
  super("require chunk loading", RuntimeModule.STAGE_ATTACH);
21
23
  this.runtimeRequirements = runtimeRequirements;
22
24
  }
23
25
 
26
+ /**
27
+ * @private
28
+ * @param {Chunk} chunk chunk
29
+ * @param {string} rootOutputDir root output directory
30
+ * @returns {string} generated code
31
+ */
32
+ _generateBaseUri(chunk, rootOutputDir) {
33
+ const options = chunk.getEntryOptions();
34
+ if (options && options.baseUri) {
35
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
36
+ }
37
+
38
+ return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
39
+ rootOutputDir !== "./"
40
+ ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
41
+ : "__filename"
42
+ });`;
43
+ }
44
+
24
45
  /**
25
46
  * @returns {string} runtime code
26
47
  */
@@ -67,13 +88,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
67
88
 
68
89
  return Template.asString([
69
90
  withBaseURI
70
- ? Template.asString([
71
- `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
72
- rootOutputDir !== "./"
73
- ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
74
- : "__filename"
75
- });`
76
- ])
91
+ ? this._generateBaseUri(chunk, rootOutputDir)
77
92
  : "// no baseURI",
78
93
  "",
79
94
  "// object to store loaded chunks",
@@ -1669,7 +1669,8 @@ ${defineGetters}`
1669
1669
  chunkGraph,
1670
1670
  runtime,
1671
1671
  concatenationScope,
1672
- codeGenerationResults
1672
+ codeGenerationResults,
1673
+ sourceTypes: TYPES
1673
1674
  });
1674
1675
  const source = codeGenResult.sources.get("javascript");
1675
1676
  const data = codeGenResult.data;
@@ -58,6 +58,11 @@ class ModuleConcatenationPlugin {
58
58
  apply(compiler) {
59
59
  const { _backCompat: backCompat } = compiler;
60
60
  compiler.hooks.compilation.tap("ModuleConcatenationPlugin", compilation => {
61
+ if (compilation.moduleMemCaches) {
62
+ throw new Error(
63
+ "optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect"
64
+ );
65
+ }
61
66
  const moduleGraph = compilation.moduleGraph;
62
67
  const bailoutReasonMap = new Map();
63
68
 
@@ -425,7 +430,21 @@ class ModuleConcatenationPlugin {
425
430
  for (const chunk of chunkGraph.getModuleChunksIterable(
426
431
  rootModule
427
432
  )) {
428
- chunkGraph.disconnectChunkAndModule(chunk, m);
433
+ const sourceTypes = chunkGraph.getChunkModuleSourceTypes(
434
+ chunk,
435
+ m
436
+ );
437
+ if (sourceTypes.size === 1) {
438
+ chunkGraph.disconnectChunkAndModule(chunk, m);
439
+ } else {
440
+ const newSourceTypes = new Set(sourceTypes);
441
+ newSourceTypes.delete("javascript");
442
+ chunkGraph.setChunkModuleSourceTypes(
443
+ chunk,
444
+ m,
445
+ newSourceTypes
446
+ );
447
+ }
429
448
  }
430
449
  }
431
450
  }
@@ -0,0 +1,31 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const RuntimeGlobals = require("../RuntimeGlobals");
9
+ const RuntimeModule = require("../RuntimeModule");
10
+
11
+ class BaseUriRuntimeModule extends RuntimeModule {
12
+ constructor() {
13
+ super("base uri", RuntimeModule.STAGE_ATTACH);
14
+ }
15
+
16
+ /**
17
+ * @returns {string} runtime code
18
+ */
19
+ generate() {
20
+ const { chunk } = this;
21
+
22
+ const options = chunk.getEntryOptions();
23
+ return `${RuntimeGlobals.baseURI} = ${
24
+ options.baseUri === undefined
25
+ ? "undefined"
26
+ : JSON.stringify(options.baseUri)
27
+ };`;
28
+ }
29
+ }
30
+
31
+ module.exports = BaseUriRuntimeModule;
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const EventEmitter = require("events");
8
9
  const { extname, basename } = require("path");
9
10
  const { URL } = require("url");
10
11
  const { createGunzip, createBrotliDecompress, createInflate } = require("zlib");
@@ -19,6 +20,44 @@ const memoize = require("../util/memoize");
19
20
 
20
21
  const getHttp = memoize(() => require("http"));
21
22
  const getHttps = memoize(() => require("https"));
23
+ const proxyFetch = (request, proxy) => (url, options, callback) => {
24
+ const eventEmitter = new EventEmitter();
25
+ const doRequest = socket =>
26
+ request
27
+ .get(url, { ...options, ...(socket && { socket }) }, callback)
28
+ .on("error", eventEmitter.emit.bind(eventEmitter, "error"));
29
+
30
+ if (proxy) {
31
+ const { hostname: host, port } = new URL(proxy);
32
+
33
+ getHttp()
34
+ .request({
35
+ host, // IP address of proxy server
36
+ port, // port of proxy server
37
+ method: "CONNECT",
38
+ path: url.host
39
+ })
40
+ .on("connect", (res, socket) => {
41
+ if (res.statusCode === 200) {
42
+ // connected to proxy server
43
+ doRequest(socket);
44
+ }
45
+ })
46
+ .on("error", err => {
47
+ eventEmitter.emit(
48
+ "error",
49
+ new Error(
50
+ `Failed to connect to proxy server "${proxy}": ${err.message}`
51
+ )
52
+ );
53
+ })
54
+ .end();
55
+ } else {
56
+ doRequest();
57
+ }
58
+
59
+ return eventEmitter;
60
+ };
22
61
 
23
62
  /** @type {(() => void)[] | undefined} */
24
63
  let inProgressWrite = undefined;
@@ -274,6 +313,7 @@ class HttpUriPlugin {
274
313
  this._upgrade = options.upgrade;
275
314
  this._frozen = options.frozen;
276
315
  this._allowedUris = options.allowedUris;
316
+ this._proxy = options.proxy;
277
317
  }
278
318
 
279
319
  /**
@@ -282,15 +322,16 @@ class HttpUriPlugin {
282
322
  * @returns {void}
283
323
  */
284
324
  apply(compiler) {
325
+ const proxy =
326
+ this._proxy || process.env["http_proxy"] || process.env["HTTP_PROXY"];
285
327
  const schemes = [
286
328
  {
287
329
  scheme: "http",
288
- fetch: (url, options, callback) => getHttp().get(url, options, callback)
330
+ fetch: proxyFetch(getHttp(), proxy)
289
331
  },
290
332
  {
291
333
  scheme: "https",
292
- fetch: (url, options, callback) =>
293
- getHttps().get(url, options, callback)
334
+ fetch: proxyFetch(getHttps(), proxy)
294
335
  }
295
336
  ];
296
337
  let lockfileCache;
@@ -2155,7 +2155,7 @@ const RESULT_GROUPERS = {
2155
2155
  // remove a prefixed "!" that can be specified to reverse sort order
2156
2156
  const normalizeFieldKey = field => {
2157
2157
  if (field[0] === "!") {
2158
- return field.substr(1);
2158
+ return field.slice(1);
2159
2159
  }
2160
2160
  return field;
2161
2161
  };
@@ -103,6 +103,8 @@ module.exports = {
103
103
  require("../dependencies/HarmonyImportSideEffectDependency"),
104
104
  "dependencies/HarmonyImportSpecifierDependency": () =>
105
105
  require("../dependencies/HarmonyImportSpecifierDependency"),
106
+ "dependencies/HarmonyEvaluatedImportSpecifierDependency": () =>
107
+ require("../dependencies/HarmonyEvaluatedImportSpecifierDependency"),
106
108
  "dependencies/ImportContextDependency": () =>
107
109
  require("../dependencies/ImportContextDependency"),
108
110
  "dependencies/ImportDependency": () =>
@@ -126,6 +128,8 @@ module.exports = {
126
128
  require("../dependencies/ImportMetaHotAcceptDependency"),
127
129
  "dependencies/ImportMetaHotDeclineDependency": () =>
128
130
  require("../dependencies/ImportMetaHotDeclineDependency"),
131
+ "dependencies/ImportMetaContextDependency": () =>
132
+ require("../dependencies/ImportMetaContextDependency"),
129
133
  "dependencies/ProvidedDependency": () =>
130
134
  require("../dependencies/ProvidedDependency"),
131
135
  "dependencies/PureExpressionDependency": () =>
@@ -51,6 +51,20 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
51
51
  this._runtimeRequirements = runtimeRequirements;
52
52
  }
53
53
 
54
+ /**
55
+ * @private
56
+ * @param {Chunk} chunk chunk
57
+ * @returns {string} generated code
58
+ */
59
+ _generateBaseUri(chunk) {
60
+ const options = chunk.getEntryOptions();
61
+ if (options && options.baseUri) {
62
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
63
+ } else {
64
+ return `${RuntimeGlobals.baseURI} = document.baseURI || self.location.href;`;
65
+ }
66
+ }
67
+
54
68
  /**
55
69
  * @returns {string} runtime code
56
70
  */
@@ -103,11 +117,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
103
117
  : undefined;
104
118
 
105
119
  return Template.asString([
106
- withBaseURI
107
- ? Template.asString([
108
- `${RuntimeGlobals.baseURI} = document.baseURI || self.location.href;`
109
- ])
110
- : "// no baseURI",
120
+ withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
111
121
  "",
112
122
  "// object to store loaded and loading chunks",
113
123
  "// undefined = chunk not loaded, null = chunk preloaded/prefetched",
@@ -276,8 +286,9 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
276
286
  ? Template.asString([
277
287
  "var currentUpdatedModulesList;",
278
288
  "var waitingUpdateResolves = {};",
279
- "function loadUpdateChunk(chunkId) {",
289
+ "function loadUpdateChunk(chunkId, updatedModulesList) {",
280
290
  Template.indent([
291
+ "currentUpdatedModulesList = updatedModulesList;",
281
292
  `return new Promise(${runtimeTemplate.basicFunction(
282
293
  "resolve, reject",
283
294
  [
@@ -15,6 +15,8 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
15
15
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
+ /** @typedef {import("../Chunk")} Chunk */
19
+
18
20
  class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
19
21
  constructor(runtimeRequirements, withCreateScriptUrl) {
20
22
  super("importScripts chunk loading", RuntimeModule.STAGE_ATTACH);
@@ -22,6 +24,33 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
22
24
  this._withCreateScriptUrl = withCreateScriptUrl;
23
25
  }
24
26
 
27
+ /**
28
+ * @private
29
+ * @param {Chunk} chunk chunk
30
+ * @returns {string} generated code
31
+ */
32
+ _generateBaseUri(chunk) {
33
+ const options = chunk.getEntryOptions();
34
+ if (options && options.baseUri) {
35
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
36
+ }
37
+ const outputName = this.compilation.getPath(
38
+ getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
39
+ {
40
+ chunk,
41
+ contentHashType: "javascript"
42
+ }
43
+ );
44
+ const rootOutputDir = getUndoPath(
45
+ outputName,
46
+ this.compilation.outputOptions.path,
47
+ false
48
+ );
49
+ return `${RuntimeGlobals.baseURI} = self.location + ${JSON.stringify(
50
+ rootOutputDir ? "/../" + rootOutputDir : ""
51
+ )};`;
52
+ }
53
+
25
54
  /**
26
55
  * @returns {string} runtime code
27
56
  */
@@ -55,31 +84,12 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
55
84
  );
56
85
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
57
86
 
58
- const outputName = this.compilation.getPath(
59
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
60
- {
61
- chunk,
62
- contentHashType: "javascript"
63
- }
64
- );
65
- const rootOutputDir = getUndoPath(
66
- outputName,
67
- this.compilation.outputOptions.path,
68
- false
69
- );
70
-
71
87
  const stateExpression = withHmr
72
88
  ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_importScripts`
73
89
  : undefined;
74
90
 
75
91
  return Template.asString([
76
- withBaseURI
77
- ? Template.asString([
78
- `${RuntimeGlobals.baseURI} = self.location + ${JSON.stringify(
79
- rootOutputDir ? "/../" + rootOutputDir : ""
80
- )};`
81
- ])
82
- : "// no baseURI",
92
+ withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
83
93
  "",
84
94
  "// object to store loaded chunks",
85
95
  '// "1" means "already loaded"',
package/module.d.ts CHANGED
@@ -129,6 +129,7 @@ declare namespace webpack {
129
129
  used: boolean;
130
130
  provideInfo: boolean | null | undefined;
131
131
  useInfo: boolean | null | undefined;
132
+ canMangle: boolean;
132
133
  }
133
134
 
134
135
  interface ExportsInfo {
@@ -147,6 +148,20 @@ interface ImportMeta {
147
148
  url: string;
148
149
  webpack: number;
149
150
  webpackHot: webpack.Hot;
151
+ webpackContext: (
152
+ request: string,
153
+ options?: {
154
+ recursive?: boolean;
155
+ regExp?: RegExp;
156
+ include?: RegExp;
157
+ exclude?: RegExp;
158
+ preload?: boolean | number;
159
+ prefetch?: boolean | number;
160
+ chunkName?: string;
161
+ exports?: string | string[][];
162
+ mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
163
+ }
164
+ ) => webpack.Context;
150
165
  }
151
166
 
152
167
  declare const __resourceQuery: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.69.1",
3
+ "version": "5.72.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",
@@ -14,7 +14,7 @@
14
14
  "acorn-import-assertions": "^1.7.6",
15
15
  "browserslist": "^4.14.5",
16
16
  "chrome-trace-event": "^1.0.2",
17
- "enhanced-resolve": "^5.8.3",
17
+ "enhanced-resolve": "^5.9.2",
18
18
  "es-module-lexer": "^0.9.0",
19
19
  "eslint-scope": "5.1.1",
20
20
  "events": "^3.2.0",