webpack 5.73.0 → 5.75.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/README.md CHANGED
@@ -8,15 +8,14 @@
8
8
  [![npm][npm]][npm-url]
9
9
 
10
10
  [![node][node]][node-url]
11
- [![deps][deps]][deps-url]
12
11
  [![builds2][builds2]][builds2-url]
13
12
  [![coverage][cover]][cover-url]
14
13
  [![licenses][licenses]][licenses-url]
15
14
  [![PR's welcome][prs]][prs-url]
16
15
 
17
16
  <br>
18
- <a href="https://dependabot.com/compatibility-score.html?dependency-name=webpack&package-manager=npm_and_yarn&new-version=latest">
19
- <img src="https://api.dependabot.com/badges/compatibility_score?dependency-name=webpack&package-manager=npm_and_yarn&version-scheme=semver&target-version=latest">
17
+ <a href="https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates#about-compatibility-scores">
18
+ <img src="https://api.dependabot.com/badges/compatibility_score?dependency-name=webpack&package-manager=npm_and_yarn&previous-version=5.72.1&new-version=5.73.0">
20
19
  </a>
21
20
  <a href="https://npmcharts.com/compare/webpack?minimal=true">
22
21
  <img src="https://img.shields.io/npm/dm/webpack.svg">
@@ -110,6 +109,7 @@ within webpack itself use this plugin interface. This makes webpack very
110
109
  | [mini-css-extract-plugin][mini-css] | ![mini-css-npm] | ![mini-css-size] | Extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. |
111
110
  | [compression-webpack-plugin][compression] | ![compression-npm] | ![compression-size] | Prepares compressed versions of assets to serve them with Content-Encoding |
112
111
  | [html-webpack-plugin][html-plugin] | ![html-plugin-npm] | ![html-plugin-size] | Simplifies creation of HTML files (`index.html`) to serve your bundles |
112
+ | [pug-plugin][pug-plugin] | ![pug-plugin-npm] | ![pug-plugin-size] | Renders Pug files to HTML, extracts JS and CSS from sources specified directly in Pug. |
113
113
 
114
114
  [common-npm]: https://img.shields.io/npm/v/webpack.svg
115
115
  [mini-css]: https://github.com/webpack-contrib/mini-css-extract-plugin
@@ -124,6 +124,9 @@ within webpack itself use this plugin interface. This makes webpack very
124
124
  [html-plugin]: https://github.com/jantimon/html-webpack-plugin
125
125
  [html-plugin-npm]: https://img.shields.io/npm/v/html-webpack-plugin.svg
126
126
  [html-plugin-size]: https://packagephobia.com/badge?p=html-webpack-plugin
127
+ [pug-plugin]: https://github.com/webdiscus/pug-plugin
128
+ [pug-plugin-npm]: https://img.shields.io/npm/v/pug-plugin.svg
129
+ [pug-plugin-size]: https://packagephobia.com/badge?p=pug-plugin
127
130
 
128
131
  ### [Loaders](https://webpack.js.org/loaders/)
129
132
 
@@ -170,18 +173,21 @@ or are automatically applied via regex from your webpack configuration.
170
173
 
171
174
  #### Templating
172
175
 
173
- | Name | Status | Install Size | Description |
174
- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
175
- | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
176
- | <a href="https://github.com/pugjs/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug-npm] | ![pug-size] | Loads Pug templates and returns a function |
177
- | <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
178
- | <a href="https://github.com/posthtml/posthtml-loader"><img width="48" height="48" src="https://posthtml.github.io/posthtml/logo.svg"></a> | ![posthtml-npm] | ![posthtml-size] | Loads and transforms a HTML file using [PostHTML](https://github.com/posthtml/posthtml) |
179
- | <a href="https://github.com/pcardune/handlebars-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/handlebars-1.svg"></a> | ![hbs-npm] | ![hbs-size] | Compiles Handlebars to HTML |
176
+ | Name | Status | Install Size | Description |
177
+ | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
178
+ | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
179
+ | <a href="https://github.com/pugjs/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug-npm] | ![pug-size] | Loads Pug templates and returns a function |
180
+ | <a href="https://github.com/webdiscus/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug3-npm] | ![pug3-size] | Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular |
181
+ | <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
182
+ | <a href="https://github.com/posthtml/posthtml-loader"><img width="48" height="48" src="https://posthtml.github.io/posthtml/logo.svg"></a> | ![posthtml-npm] | ![posthtml-size] | Loads and transforms a HTML file using [PostHTML](https://github.com/posthtml/posthtml) |
183
+ | <a href="https://github.com/pcardune/handlebars-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/handlebars-1.svg"></a> | ![hbs-npm] | ![hbs-size] | Compiles Handlebars to HTML |
180
184
 
181
185
  [html-npm]: https://img.shields.io/npm/v/html-loader.svg
182
186
  [html-size]: https://packagephobia.com/badge?p=html-loader
183
187
  [pug-npm]: https://img.shields.io/npm/v/pug-loader.svg
184
188
  [pug-size]: https://packagephobia.com/badge?p=pug-loader
189
+ [pug3-npm]: https://img.shields.io/npm/v/@webdiscus/pug-loader.svg
190
+ [pug3-size]: https://packagephobia.com/badge?p=@webdiscus/pug-loader
185
191
  [jade-npm]: https://img.shields.io/npm/v/jade-loader.svg
186
192
  [jade-size]: https://packagephobia.com/badge?p=jade-loader
187
193
  [md-npm]: https://img.shields.io/npm/v/markdown-loader.svg
@@ -699,8 +705,6 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
699
705
  [npm-url]: https://npmjs.com/package/webpack
700
706
  [node]: https://img.shields.io/node/v/webpack.svg
701
707
  [node-url]: https://nodejs.org
702
- [deps]: https://img.shields.io/david/webpack/webpack.svg
703
- [deps-url]: https://david-dm.org/webpack/webpack
704
708
  [prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
705
709
  [prs-url]: https://webpack.js.org/contribute/
706
710
  [builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status/webpack.webpack
package/hot/dev-server.js CHANGED
@@ -14,12 +14,20 @@ if (module.hot) {
14
14
  .check(true)
15
15
  .then(function (updatedModules) {
16
16
  if (!updatedModules) {
17
- log("warning", "[HMR] Cannot find update. Need to do a full reload!");
17
+ log(
18
+ "warning",
19
+ "[HMR] Cannot find update. " +
20
+ (typeof window !== "undefined"
21
+ ? "Need to do a full reload!"
22
+ : "Please reload manually!")
23
+ );
18
24
  log(
19
25
  "warning",
20
26
  "[HMR] (Probably because of restarting the webpack-dev-server)"
21
27
  );
22
- window.location.reload();
28
+ if (typeof window !== "undefined") {
29
+ window.location.reload();
30
+ }
23
31
  return;
24
32
  }
25
33
 
@@ -38,10 +46,15 @@ if (module.hot) {
38
46
  if (["abort", "fail"].indexOf(status) >= 0) {
39
47
  log(
40
48
  "warning",
41
- "[HMR] Cannot apply update. Need to do a full reload!"
49
+ "[HMR] Cannot apply update. " +
50
+ (typeof window !== "undefined"
51
+ ? "Need to do a full reload!"
52
+ : "Please reload manually!")
42
53
  );
43
54
  log("warning", "[HMR] " + log.formatError(err));
44
- window.location.reload();
55
+ if (typeof window !== "undefined") {
56
+ window.location.reload();
57
+ }
45
58
  } else {
46
59
  log("warning", "[HMR] Update failed: " + log.formatError(err));
47
60
  }
@@ -33,7 +33,7 @@ const wrapComment = str => {
33
33
  .split("\n")
34
34
  .join("\n * ")
35
35
  .replace(/\s+\n/g, "\n")
36
- .trimRight()}\n */`;
36
+ .trimEnd()}\n */`;
37
37
  };
38
38
 
39
39
  class BannerPlugin {
@@ -1938,7 +1938,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1938
1938
 
1939
1939
  // This avoids deadlocks for circular dependencies
1940
1940
  if (this.processDependenciesQueue.isProcessing(module)) {
1941
- return callback();
1941
+ return callback(null, module);
1942
1942
  }
1943
1943
 
1944
1944
  this.processModuleDependencies(module, err => {
@@ -3192,6 +3192,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3192
3192
  }
3193
3193
 
3194
3194
  _runCodeGenerationJobs(jobs, callback) {
3195
+ if (jobs.length === 0) {
3196
+ return callback();
3197
+ }
3195
3198
  let statModulesFromCache = 0;
3196
3199
  let statModulesGenerated = 0;
3197
3200
  const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
@@ -18,6 +18,7 @@ const { makePathsAbsolute } = require("./util/identifier");
18
18
  /** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */
19
19
  /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
20
20
  /** @typedef {import("./Compiler")} Compiler */
21
+ /** @typedef {import("./NormalModule").SourceMap} SourceMap */
21
22
 
22
23
  /** @type {WeakMap<Source, Source>} */
23
24
  const cache = new WeakMap();
@@ -105,15 +106,15 @@ class EvalSourceMapDevToolPlugin {
105
106
  return result(source);
106
107
  }
107
108
 
108
- /** @type {{ [key: string]: TODO; }} */
109
+ /** @type {SourceMap} */
109
110
  let sourceMap;
110
111
  let content;
111
112
  if (source.sourceAndMap) {
112
113
  const sourceAndMap = source.sourceAndMap(options);
113
- sourceMap = sourceAndMap.map;
114
+ sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
114
115
  content = sourceAndMap.source;
115
116
  } else {
116
- sourceMap = source.map(options);
117
+ sourceMap = /** @type {SourceMap} */ (source.map(options));
117
118
  content = source.source();
118
119
  }
119
120
  if (!sourceMap) {
@@ -152,6 +153,9 @@ class EvalSourceMapDevToolPlugin {
152
153
  }
153
154
  );
154
155
  sourceMap.sources = moduleFilenames;
156
+ if (options.noSources) {
157
+ sourceMap.sourcesContent = undefined;
158
+ }
155
159
  sourceMap.sourceRoot = options.sourceRoot || "";
156
160
  const moduleId = chunkGraph.getModuleId(m);
157
161
  sourceMap.file = `${moduleId}.js`;
@@ -8,6 +8,7 @@
8
8
  const { create: createResolver } = require("enhanced-resolve");
9
9
  const nodeModule = require("module");
10
10
  const asyncLib = require("neo-async");
11
+ const { isAbsolute } = require("path");
11
12
  const AsyncQueue = require("./util/AsyncQueue");
12
13
  const StackedCacheMap = require("./util/StackedCacheMap");
13
14
  const createHash = require("./util/createHash");
@@ -207,6 +208,12 @@ class SnapshotIterable {
207
208
  class Snapshot {
208
209
  constructor() {
209
210
  this._flags = 0;
211
+ /** @type {Iterable<string> | undefined} */
212
+ this._cachedFileIterable = undefined;
213
+ /** @type {Iterable<string> | undefined} */
214
+ this._cachedContextIterable = undefined;
215
+ /** @type {Iterable<string> | undefined} */
216
+ this._cachedMissingIterable = undefined;
210
217
  /** @type {number | undefined} */
211
218
  this.startTime = undefined;
212
219
  /** @type {Map<string, FileSystemInfoEntry | null> | undefined} */
@@ -417,31 +424,43 @@ class Snapshot {
417
424
  * @returns {Iterable<string>} iterable
418
425
  */
419
426
  getFileIterable() {
420
- return this._createIterable(s => [
421
- s.fileTimestamps,
422
- s.fileHashes,
423
- s.fileTshs,
424
- s.managedFiles
425
- ]);
427
+ if (this._cachedFileIterable === undefined) {
428
+ this._cachedFileIterable = this._createIterable(s => [
429
+ s.fileTimestamps,
430
+ s.fileHashes,
431
+ s.fileTshs,
432
+ s.managedFiles
433
+ ]);
434
+ }
435
+ return this._cachedFileIterable;
426
436
  }
427
437
 
428
438
  /**
429
439
  * @returns {Iterable<string>} iterable
430
440
  */
431
441
  getContextIterable() {
432
- return this._createIterable(s => [
433
- s.contextTimestamps,
434
- s.contextHashes,
435
- s.contextTshs,
436
- s.managedContexts
437
- ]);
442
+ if (this._cachedContextIterable === undefined) {
443
+ this._cachedContextIterable = this._createIterable(s => [
444
+ s.contextTimestamps,
445
+ s.contextHashes,
446
+ s.contextTshs,
447
+ s.managedContexts
448
+ ]);
449
+ }
450
+ return this._cachedContextIterable;
438
451
  }
439
452
 
440
453
  /**
441
454
  * @returns {Iterable<string>} iterable
442
455
  */
443
456
  getMissingIterable() {
444
- return this._createIterable(s => [s.missingExistence, s.managedMissing]);
457
+ if (this._cachedMissingIterable === undefined) {
458
+ this._cachedMissingIterable = this._createIterable(s => [
459
+ s.missingExistence,
460
+ s.managedMissing
461
+ ]);
462
+ }
463
+ return this._cachedMissingIterable;
445
464
  }
446
465
  }
447
466
 
@@ -1633,7 +1652,9 @@ class FileSystemInfo {
1633
1652
  let request = relative(this.fs, context, childPath);
1634
1653
  if (request.endsWith(".js")) request = request.slice(0, -3);
1635
1654
  request = request.replace(/\\/g, "/");
1636
- if (!request.startsWith("../")) request = `./${request}`;
1655
+ if (!request.startsWith("../") && !isAbsolute(request)) {
1656
+ request = `./${request}`;
1657
+ }
1637
1658
  push({
1638
1659
  type: RBDT_RESOLVE_CJS_FILE,
1639
1660
  context,
@@ -117,7 +117,7 @@ class NodeStuffPlugin {
117
117
  setConstant(
118
118
  "__filename",
119
119
  "/index.js",
120
- "The __filename is Node.js feature and doesn't present in browser."
120
+ "__filename is a Node.js feature and isn't available in browsers."
121
121
  );
122
122
  break;
123
123
  case true:
@@ -144,7 +144,7 @@ class NodeStuffPlugin {
144
144
  setConstant(
145
145
  "__dirname",
146
146
  "/",
147
- "The __dirname is Node.js feature and doesn't present in browser."
147
+ "__dirname is a Node.js feature and isn't available in browsers."
148
148
  );
149
149
  break;
150
150
  case true:
package/lib/Template.js CHANGED
@@ -217,7 +217,7 @@ class Template {
217
217
  if (Array.isArray(s)) {
218
218
  return s.map(Template.indent).join("\n");
219
219
  } else {
220
- const str = s.trimRight();
220
+ const str = s.trimEnd();
221
221
  if (!str) return "";
222
222
  const ind = str[0] === "\n" ? "" : "\t";
223
223
  return ind + str.replace(/\n([^\n])/g, "\n\t$1");
@@ -160,6 +160,28 @@ class WebpackOptionsApply extends OptionsApply {
160
160
  }
161
161
  : /^(\/\/|https?:\/\/|std:)/
162
162
  ).apply(compiler);
163
+ } else if (options.externalsPresets.node) {
164
+ if (options.experiments.css) {
165
+ //@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
166
+ const ExternalsPlugin = require("./ExternalsPlugin");
167
+ new ExternalsPlugin(
168
+ "module",
169
+ ({ request, dependencyType }, callback) => {
170
+ if (dependencyType === "url") {
171
+ if (/^(\/\/|https?:\/\/)/.test(request))
172
+ return callback(null, `asset ${request}`);
173
+ } else if (dependencyType === "css-import") {
174
+ if (/^(\/\/|https?:\/\/)/.test(request))
175
+ return callback(null, `css-import ${request}`);
176
+ } else if (/^(\/\/|https?:\/\/|std:)/.test(request)) {
177
+ if (/^\.css(\?|$)/.test(request))
178
+ return callback(null, `css-import ${request}`);
179
+ return callback(null, `module ${request}`);
180
+ }
181
+ callback();
182
+ }
183
+ ).apply(compiler);
184
+ }
163
185
  }
164
186
 
165
187
  new ChunkPrefetchPreloadPlugin().apply(compiler);
@@ -508,8 +508,9 @@ const visitModules = (
508
508
  new AsyncDependencyToInitialChunkError(chunkName, module, b.loc)
509
509
  );
510
510
  c = chunkGroup;
511
+ } else {
512
+ c.addOptions(b.groupOptions);
511
513
  }
512
- c.addOptions(b.groupOptions);
513
514
  c.addOrigin(module, b.loc, b.request);
514
515
  }
515
516
  blockConnections.set(b, []);
@@ -485,7 +485,7 @@ const applyJavascriptParserOptionsDefaults = (
485
485
  * @param {boolean} options.cache is caching enabled
486
486
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
487
487
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
488
- * @param {CssExperimentOptions} options.css is css enabled
488
+ * @param {CssExperimentOptions|false} options.css is css enabled
489
489
  * @param {boolean} options.futureDefaults is future defaults enabled
490
490
  * @param {boolean} options.isNode is node target platform
491
491
  * @returns {void}
@@ -1122,7 +1122,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
1122
1122
  * @param {Object} options options
1123
1123
  * @param {boolean} options.production is production
1124
1124
  * @param {boolean} options.development is development
1125
- * @param {CssExperimentOptions} options.css is css enabled
1125
+ * @param {CssExperimentOptions|false} options.css is css enabled
1126
1126
  * @param {boolean} options.records using records
1127
1127
  * @returns {void}
1128
1128
  */
@@ -178,11 +178,10 @@ const getNormalizedWebpackOptions = config => {
178
178
  ),
179
179
  lazyCompilation: optionalNestedConfig(
180
180
  experiments.lazyCompilation,
181
- options =>
182
- options === true ? {} : options === false ? undefined : options
181
+ options => (options === true ? {} : options)
183
182
  ),
184
183
  css: optionalNestedConfig(experiments.css, options =>
185
- options === true ? {} : options === false ? undefined : options
184
+ options === true ? {} : options
186
185
  )
187
186
  })),
188
187
  externals: config.externals,
@@ -65,6 +65,7 @@ class ModuleFederationPlugin {
65
65
  library,
66
66
  filename: options.filename,
67
67
  runtime: options.runtime,
68
+ shareScope: options.shareScope,
68
69
  exposes: options.exposes
69
70
  }).apply(compiler);
70
71
  }
@@ -76,6 +77,7 @@ class ModuleFederationPlugin {
76
77
  ) {
77
78
  new ContainerReferencePlugin({
78
79
  remoteType,
80
+ shareScope: options.shareScope,
79
81
  remotes: options.remotes
80
82
  }).apply(compiler);
81
83
  }
@@ -108,13 +108,15 @@ class CssLoadingRuntimeModule extends RuntimeModule {
108
108
  'link.rel = "stylesheet";',
109
109
  "link.href = url;",
110
110
  crossOriginLoading
111
- ? Template.asString([
112
- "if (link.src.indexOf(window.location.origin + '/') !== 0) {",
113
- Template.indent(
114
- `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
115
- ),
116
- "}"
117
- ])
111
+ ? crossOriginLoading === "use-credentials"
112
+ ? 'link.crossOrigin = "use-credentials";'
113
+ : Template.asString([
114
+ "if (link.src.indexOf(window.location.origin + '/') !== 0) {",
115
+ Template.indent(
116
+ `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
117
+ ),
118
+ "}"
119
+ ])
118
120
  : ""
119
121
  ]);
120
122
 
@@ -196,7 +196,7 @@ class CssParser extends Parser {
196
196
  }
197
197
  if (pos === input.length) break;
198
198
  }
199
- return [pos, text.trimRight()];
199
+ return [pos, text.trimEnd()];
200
200
  };
201
201
  const eatExportName = eatUntil(":};/");
202
202
  const eatExportValue = eatUntil("};/");
@@ -38,7 +38,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
38
38
  apply(parser) {
39
39
  parser.hooks.evaluateIdentifier
40
40
  .for("import.meta.webpackContext")
41
- .tap("HotModuleReplacementPlugin", expr => {
41
+ .tap("ImportMetaContextDependencyParserPlugin", expr => {
42
42
  return evaluateToIdentifier(
43
43
  "import.meta.webpackContext",
44
44
  "import.meta",
@@ -5,19 +5,21 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const Dependency = require("../Dependency");
8
9
  const InitFragment = require("../InitFragment");
9
10
  const makeSerializable = require("../util/makeSerializable");
10
11
  const ModuleDependency = require("./ModuleDependency");
11
12
 
12
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
- /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
15
16
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
16
17
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
17
18
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
18
19
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
20
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
20
21
  /** @typedef {import("../util/Hash")} Hash */
22
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
21
23
 
22
24
  /**
23
25
  * @param {string[]|null} path the property path array
@@ -29,10 +31,16 @@ const pathToString = path =>
29
31
  : "";
30
32
 
31
33
  class ProvidedDependency extends ModuleDependency {
32
- constructor(request, identifier, path, range) {
34
+ /**
35
+ * @param {string} request request
36
+ * @param {string} identifier identifier
37
+ * @param {string[]} ids ids
38
+ * @param {[number, number]} range range
39
+ */
40
+ constructor(request, identifier, ids, range) {
33
41
  super(request);
34
42
  this.identifier = identifier;
35
- this.path = path;
43
+ this.ids = ids;
36
44
  this.range = range;
37
45
  this._hashUpdate = undefined;
38
46
  }
@@ -45,6 +53,18 @@ class ProvidedDependency extends ModuleDependency {
45
53
  return "esm";
46
54
  }
47
55
 
56
+ /**
57
+ * Returns list of exports referenced by this dependency
58
+ * @param {ModuleGraph} moduleGraph module graph
59
+ * @param {RuntimeSpec} runtime the runtime for which the module is analysed
60
+ * @returns {(string[] | ReferencedExport)[]} referenced exports
61
+ */
62
+ getReferencedExports(moduleGraph, runtime) {
63
+ let ids = this.ids;
64
+ if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED;
65
+ return [ids];
66
+ }
67
+
48
68
  /**
49
69
  * Update the hash
50
70
  * @param {Hash} hash hash to be updated
@@ -53,8 +73,7 @@ class ProvidedDependency extends ModuleDependency {
53
73
  */
54
74
  updateHash(hash, context) {
55
75
  if (this._hashUpdate === undefined) {
56
- this._hashUpdate =
57
- this.identifier + (this.path ? this.path.join(",") : "null");
76
+ this._hashUpdate = this.identifier + (this.ids ? this.ids.join(",") : "");
58
77
  }
59
78
  hash.update(this._hashUpdate);
60
79
  }
@@ -62,14 +81,14 @@ class ProvidedDependency extends ModuleDependency {
62
81
  serialize(context) {
63
82
  const { write } = context;
64
83
  write(this.identifier);
65
- write(this.path);
84
+ write(this.ids);
66
85
  super.serialize(context);
67
86
  }
68
87
 
69
88
  deserialize(context) {
70
89
  const { read } = context;
71
90
  this.identifier = read();
72
- this.path = read();
91
+ this.ids = read();
73
92
  super.deserialize(context);
74
93
  }
75
94
  }
@@ -90,6 +109,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
90
109
  dependency,
91
110
  source,
92
111
  {
112
+ runtime,
93
113
  runtimeTemplate,
94
114
  moduleGraph,
95
115
  chunkGraph,
@@ -98,6 +118,9 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
98
118
  }
99
119
  ) {
100
120
  const dep = /** @type {ProvidedDependency} */ (dependency);
121
+ const connection = moduleGraph.getConnection(dep);
122
+ const exportsInfo = moduleGraph.getExportsInfo(connection.module);
123
+ const usedName = exportsInfo.getUsedName(dep.ids, runtime);
101
124
  initFragments.push(
102
125
  new InitFragment(
103
126
  `/* provided dependency */ var ${
@@ -107,7 +130,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
107
130
  chunkGraph,
108
131
  request: dep.request,
109
132
  runtimeRequirements
110
- })}${pathToString(dep.path)};\n`,
133
+ })}${pathToString(/** @type {string[]} */ (usedName))};\n`,
111
134
  InitFragment.STAGE_PROVIDES,
112
135
  1,
113
136
  `provided ${dep.identifier}`
@@ -190,8 +190,10 @@ class WorkerPlugin {
190
190
  } = arg2 && arg2.type === "ObjectExpression"
191
191
  ? parseObjectExpression(parser, arg2)
192
192
  : {
193
+ /** @type {Record<string, Expression | Pattern>} */
193
194
  expressions: {},
194
195
  otherElements: [],
196
+ /** @type {Record<string, any>} */
195
197
  values: {},
196
198
  spread: false,
197
199
  insertType: arg2 ? "spread" : "argument",
@@ -387,7 +387,7 @@ const assignDeterministicIds = (
387
387
 
388
388
  // max 5% fill rate
389
389
  const optimalRange = Math.min(
390
- Math.ceil(items.length * 20) + extraSpace,
390
+ items.length * 20 + extraSpace,
391
391
  Number.MAX_SAFE_INTEGER
392
392
  );
393
393
 
package/lib/index.js CHANGED
@@ -342,6 +342,9 @@ module.exports = mergeExports(fn, {
342
342
  get ModuleDependency() {
343
343
  return require("./dependencies/ModuleDependency");
344
344
  },
345
+ get HarmonyImportDependency() {
346
+ return require("./dependencies/HarmonyImportDependency");
347
+ },
345
348
  get ConstDependency() {
346
349
  return require("./dependencies/ConstDependency");
347
350
  },
@@ -492,6 +495,9 @@ module.exports = mergeExports(fn, {
492
495
  wasm: {
493
496
  get AsyncWebAssemblyModulesPlugin() {
494
497
  return require("./wasm-async/AsyncWebAssemblyModulesPlugin");
498
+ },
499
+ get EnableWasmLoadingPlugin() {
500
+ return require("./wasm/EnableWasmLoadingPlugin");
495
501
  }
496
502
  },
497
503
 
@@ -1447,6 +1447,11 @@ class JavascriptParser extends Parser {
1447
1447
  this.walkExpression(classElement.value);
1448
1448
  this.scope.topLevelScope = wasTopLevel;
1449
1449
  }
1450
+ } else if (classElement.type === "StaticBlock") {
1451
+ const wasTopLevel = this.scope.topLevelScope;
1452
+ this.scope.topLevelScope = false;
1453
+ this.walkBlockStatement(classElement);
1454
+ this.scope.topLevelScope = wasTopLevel;
1450
1455
  }
1451
1456
  }
1452
1457
  }
@@ -1903,7 +1908,7 @@ class JavascriptParser extends Parser {
1903
1908
  !this.hooks.importSpecifier.call(
1904
1909
  statement,
1905
1910
  source,
1906
- specifier.imported.name,
1911
+ specifier.imported.name || specifier.imported.value,
1907
1912
  name
1908
1913
  )
1909
1914
  ) {
@@ -1973,7 +1978,7 @@ class JavascriptParser extends Parser {
1973
1978
  const specifier = statement.specifiers[specifierIndex];
1974
1979
  switch (specifier.type) {
1975
1980
  case "ExportSpecifier": {
1976
- const name = specifier.exported.name;
1981
+ const name = specifier.exported.name || specifier.exported.value;
1977
1982
  if (source) {
1978
1983
  this.hooks.exportImportSpecifier.call(
1979
1984
  statement,