webpack 5.59.1 → 5.62.1

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 (42) hide show
  1. package/hot/lazy-compilation-node.js +3 -1
  2. package/lib/Chunk.js +3 -2
  3. package/lib/Compilation.js +29 -16
  4. package/lib/Compiler.js +13 -11
  5. package/lib/HotModuleReplacementPlugin.js +3 -1
  6. package/lib/NormalModule.js +9 -3
  7. package/lib/WebpackOptionsApply.js +12 -9
  8. package/lib/cache/PackFileCacheStrategy.js +7 -4
  9. package/lib/config/defaults.js +4 -6
  10. package/lib/dependencies/AMDRequireDependency.js +6 -6
  11. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  12. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -1
  13. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  14. package/lib/dependencies/ContextDependency.js +1 -0
  15. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  16. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  17. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  18. package/lib/dependencies/HarmonyImportDependency.js +21 -0
  19. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +17 -4
  20. package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -14
  21. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  22. package/lib/hmr/LazyCompilationPlugin.js +9 -5
  23. package/lib/hmr/lazyCompilationBackend.js +47 -10
  24. package/lib/node/NodeTargetPlugin.js +2 -0
  25. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  26. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  27. package/lib/optimize/SplitChunksPlugin.js +8 -1
  28. package/lib/runtime/AsyncModuleRuntimeModule.js +2 -2
  29. package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
  30. package/lib/sharing/ShareRuntimeModule.js +1 -1
  31. package/lib/util/createHash.js +12 -0
  32. package/lib/util/deprecation.js +10 -2
  33. package/lib/util/hash/BatchedHash.js +7 -4
  34. package/lib/util/hash/md4.js +20 -0
  35. package/lib/util/hash/wasm-hash.js +163 -0
  36. package/lib/util/hash/xxhash64.js +5 -139
  37. package/lib/webpack.js +1 -2
  38. package/module.d.ts +200 -0
  39. package/package.json +12 -10
  40. package/schemas/WebpackOptions.check.js +1 -1
  41. package/schemas/WebpackOptions.json +117 -27
  42. package/types.d.ts +73 -22
@@ -9,7 +9,9 @@ exports.keepAlive = function (options) {
9
9
  var active = options.active;
10
10
  var module = options.module;
11
11
  var response;
12
- var request = require("http").request(
12
+ var request = (
13
+ urlBase.startsWith("https") ? require("https") : require("http")
14
+ ).request(
13
15
  urlBase + data,
14
16
  {
15
17
  agent: false,
package/lib/Chunk.js CHANGED
@@ -63,8 +63,9 @@ let debugId = 1000;
63
63
  class Chunk {
64
64
  /**
65
65
  * @param {string=} name of chunk being created, is optional (for subclasses)
66
+ * @param {boolean} backCompat enable backward-compatibility
66
67
  */
67
- constructor(name) {
68
+ constructor(name, backCompat = true) {
68
69
  /** @type {number | string | null} */
69
70
  this.id = null;
70
71
  /** @type {(number|string)[] | null} */
@@ -84,7 +85,7 @@ class Chunk {
84
85
  /** @type {RuntimeSpec} */
85
86
  this.runtime = undefined;
86
87
  /** @type {Set<string>} */
87
- this.files = new ChunkFilesSet();
88
+ this.files = backCompat ? new ChunkFilesSet() : new Set();
88
89
  /** @type {Set<string>} */
89
90
  this.auxiliaryFiles = new Set();
90
91
  /** @type {boolean} */
@@ -429,6 +429,8 @@ class Compilation {
429
429
  * @param {CompilationParams} params the compilation parameters
430
430
  */
431
431
  constructor(compiler, params) {
432
+ this._backCompat = compiler._backCompat;
433
+
432
434
  const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
433
435
  /** @typedef {{ additionalAssets?: true | Function }} ProcessAssetsAdditionalOptions */
434
436
  /** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
@@ -559,6 +561,7 @@ class Compilation {
559
561
  * @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
560
562
  */
561
563
  const createProcessAssetsHook = (name, stage, getArgs, code) => {
564
+ if (!this._backCompat && code) return undefined;
562
565
  const errorMessage =
563
566
  reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
564
567
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
@@ -983,7 +986,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
983
986
  this.asyncEntrypoints = [];
984
987
  /** @type {Set<Chunk>} */
985
988
  this.chunks = new Set();
986
- arrayToSetDeprecation(this.chunks, "Compilation.chunks");
987
989
  /** @type {ChunkGroup[]} */
988
990
  this.chunkGroups = [];
989
991
  /** @type {Map<string, ChunkGroup>} */
@@ -992,7 +994,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
992
994
  this.namedChunks = new Map();
993
995
  /** @type {Set<Module>} */
994
996
  this.modules = new Set();
995
- arrayToSetDeprecation(this.modules, "Compilation.modules");
997
+ if (this._backCompat) {
998
+ arrayToSetDeprecation(this.chunks, "Compilation.chunks");
999
+ arrayToSetDeprecation(this.modules, "Compilation.modules");
1000
+ }
996
1001
  /** @private @type {Map<string, Module>} */
997
1002
  this._modules = new Map();
998
1003
  this.records = null;
@@ -1286,7 +1291,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1286
1291
  }
1287
1292
  this._modules.set(identifier, module);
1288
1293
  this.modules.add(module);
1289
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1294
+ if (this._backCompat)
1295
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1290
1296
  if (currentProfile !== undefined) {
1291
1297
  currentProfile.markIntegrationEnd();
1292
1298
  }
@@ -1701,7 +1707,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1701
1707
 
1702
1708
  this._modules.set(module.identifier(), module);
1703
1709
  this.modules.add(module);
1704
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1710
+ if (this._backCompat)
1711
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1705
1712
 
1706
1713
  this._handleModuleBuildAndDependencies(
1707
1714
  originModule,
@@ -2777,8 +2784,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2777
2784
  );
2778
2785
  this.chunkGraph = chunkGraph;
2779
2786
 
2780
- for (const module of this.modules) {
2781
- ChunkGraph.setChunkGraphForModule(module, chunkGraph);
2787
+ if (this._backCompat) {
2788
+ for (const module of this.modules) {
2789
+ ChunkGraph.setChunkGraphForModule(module, chunkGraph);
2790
+ }
2782
2791
  }
2783
2792
 
2784
2793
  this.hooks.seal.call();
@@ -3045,14 +3054,16 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3045
3054
  }
3046
3055
  this.hooks.afterProcessAssets.call(this.assets);
3047
3056
  this.logger.timeEnd("process assets");
3048
- this.assets = soonFrozenObjectDeprecation(
3049
- this.assets,
3050
- "Compilation.assets",
3051
- "DEP_WEBPACK_COMPILATION_ASSETS",
3052
- `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3057
+ this.assets = this._backCompat
3058
+ ? soonFrozenObjectDeprecation(
3059
+ this.assets,
3060
+ "Compilation.assets",
3061
+ "DEP_WEBPACK_COMPILATION_ASSETS",
3062
+ `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3053
3063
  Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
3054
3064
  Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
3055
- );
3065
+ )
3066
+ : Object.freeze(this.assets);
3056
3067
 
3057
3068
  this.summarizeDependencies();
3058
3069
  if (shouldRecord) {
@@ -3453,7 +3464,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3453
3464
  */
3454
3465
  addRuntimeModule(chunk, module, chunkGraph = this.chunkGraph) {
3455
3466
  // Deprecated ModuleGraph association
3456
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3467
+ if (this._backCompat)
3468
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3457
3469
 
3458
3470
  // add it to the list
3459
3471
  this.modules.add(module);
@@ -3589,9 +3601,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3589
3601
  return chunk;
3590
3602
  }
3591
3603
  }
3592
- const chunk = new Chunk(name);
3604
+ const chunk = new Chunk(name, this._backCompat);
3593
3605
  this.chunks.add(chunk);
3594
- ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
3606
+ if (this._backCompat)
3607
+ ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
3595
3608
  if (name) {
3596
3609
  this.namedChunks.set(name, chunk);
3597
3610
  }
@@ -4715,7 +4728,7 @@ This prevents using hashes of each other and should be avoided.`);
4715
4728
  this.outputOptions;
4716
4729
  const runtimeTemplate = this.runtimeTemplate;
4717
4730
 
4718
- const chunk = new Chunk("build time chunk");
4731
+ const chunk = new Chunk("build time chunk", this._backCompat);
4719
4732
  chunk.id = chunk.name;
4720
4733
  chunk.ids = [chunk.id];
4721
4734
  chunk.runtime = runtime;
package/lib/Compiler.js CHANGED
@@ -119,8 +119,9 @@ const includesHash = (filename, hashes) => {
119
119
  class Compiler {
120
120
  /**
121
121
  * @param {string} context the compilation path
122
+ * @param {WebpackOptions} options options
122
123
  */
123
- constructor(context) {
124
+ constructor(context, options = /** @type {WebpackOptions} */ ({})) {
124
125
  this.hooks = Object.freeze({
125
126
  /** @type {SyncHook<[]>} */
126
127
  initialize: new SyncHook([]),
@@ -240,8 +241,7 @@ class Compiler {
240
241
 
241
242
  this.infrastructureLogger = undefined;
242
243
 
243
- /** @type {WebpackOptions} */
244
- this.options = /** @type {WebpackOptions} */ ({});
244
+ this.options = options;
245
245
 
246
246
  this.context = context;
247
247
 
@@ -263,6 +263,8 @@ class Compiler {
263
263
  /** @type {boolean} */
264
264
  this.watchMode = false;
265
265
 
266
+ this._backCompat = this.options.experiments.backCompat !== false;
267
+
266
268
  /** @type {Compilation} */
267
269
  this._lastCompilation = undefined;
268
270
  /** @type {NormalModuleFactory} */
@@ -963,7 +965,13 @@ ${other}`);
963
965
  outputOptions,
964
966
  plugins
965
967
  ) {
966
- const childCompiler = new Compiler(this.context);
968
+ const childCompiler = new Compiler(this.context, {
969
+ ...this.options,
970
+ output: {
971
+ ...this.options.output,
972
+ ...outputOptions
973
+ }
974
+ });
967
975
  childCompiler.name = compilerName;
968
976
  childCompiler.outputPath = this.outputPath;
969
977
  childCompiler.inputFileSystem = this.inputFileSystem;
@@ -976,6 +984,7 @@ ${other}`);
976
984
  childCompiler.fsStartTime = this.fsStartTime;
977
985
  childCompiler.cache = this.cache;
978
986
  childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`;
987
+ childCompiler._backCompat = this._backCompat;
979
988
 
980
989
  const relativeCompilerName = makePathsRelative(
981
990
  this.context,
@@ -991,13 +1000,6 @@ ${other}`);
991
1000
  this.records[relativeCompilerName].push((childCompiler.records = {}));
992
1001
  }
993
1002
 
994
- childCompiler.options = {
995
- ...this.options,
996
- output: {
997
- ...this.options.output,
998
- ...outputOptions
999
- }
1000
- };
1001
1003
  childCompiler.parentCompilation = compilation;
1002
1004
  childCompiler.root = this.root;
1003
1005
  if (Array.isArray(plugins)) {
@@ -83,6 +83,7 @@ class HotModuleReplacementPlugin {
83
83
  * @returns {void}
84
84
  */
85
85
  apply(compiler) {
86
+ const { _backCompat: backCompat } = compiler;
86
87
  if (compiler.options.output.strictModuleErrorHandling === undefined)
87
88
  compiler.options.output.strictModuleErrorHandling = true;
88
89
  const runtimeRequirements = [RuntimeGlobals.module];
@@ -597,7 +598,8 @@ class HotModuleReplacementPlugin {
597
598
  (newRuntimeModules && newRuntimeModules.length > 0)
598
599
  ) {
599
600
  const hotUpdateChunk = new HotUpdateChunk();
600
- ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
601
+ if (backCompat)
602
+ ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
601
603
  hotUpdateChunk.id = chunkId;
602
604
  hotUpdateChunk.runtime = newRuntime;
603
605
  if (currentChunk) {
@@ -538,6 +538,9 @@ class NormalModule extends Module {
538
538
  return context === this.context
539
539
  ? getContextifyInContext()(request)
540
540
  : getContextify()(context, request);
541
+ },
542
+ createHash: type => {
543
+ return createHash(type || compilation.outputOptions.hashFunction);
541
544
  }
542
545
  };
543
546
  const loaderContext = {
@@ -793,16 +796,19 @@ class NormalModule extends Module {
793
796
  this.buildInfo.fileDependencies = new LazySet();
794
797
  this.buildInfo.contextDependencies = new LazySet();
795
798
  this.buildInfo.missingDependencies = new LazySet();
796
- if (this.loaders.length > 0) {
797
- this.buildInfo.buildDependencies = new LazySet();
798
- }
799
799
  this.buildInfo.cacheable = true;
800
+
800
801
  try {
801
802
  hooks.beforeLoaders.call(this.loaders, this, loaderContext);
802
803
  } catch (err) {
803
804
  processResult(err);
804
805
  return;
805
806
  }
807
+
808
+ if (this.loaders.length > 0) {
809
+ this.buildInfo.buildDependencies = new LazySet();
810
+ }
811
+
806
812
  runLoaders(
807
813
  {
808
814
  resource: this.resource,
@@ -261,15 +261,18 @@ class WebpackOptionsApply extends OptionsApply {
261
261
  : null;
262
262
  new LazyCompilationPlugin({
263
263
  backend:
264
- (lazyOptions && lazyOptions.backend) ||
265
- require("./hmr/lazyCompilationBackend"),
266
- client:
267
- (lazyOptions && lazyOptions.client) ||
268
- require.resolve(
269
- `../hot/lazy-compilation-${
270
- options.externalsPresets.node ? "node" : "web"
271
- }.js`
272
- ),
264
+ typeof lazyOptions.backend === "function"
265
+ ? lazyOptions.backend
266
+ : require("./hmr/lazyCompilationBackend")({
267
+ ...lazyOptions.backend,
268
+ client:
269
+ (lazyOptions.backend && lazyOptions.backend.client) ||
270
+ require.resolve(
271
+ `../hot/lazy-compilation-${
272
+ options.externalsPresets.node ? "node" : "web"
273
+ }.js`
274
+ )
275
+ }),
273
276
  entries: !lazyOptions || lazyOptions.entries !== false,
274
277
  imports: !lazyOptions || lazyOptions.imports !== false,
275
278
  test: (lazyOptions && lazyOptions.test) || undefined
@@ -782,7 +782,7 @@ class PackContent {
782
782
  this.logger.time(timeMessage);
783
783
  }
784
784
  const value = this.lazy();
785
- if (value instanceof Promise) {
785
+ if ("then" in value) {
786
786
  return value.then(data => {
787
787
  const map = data.map;
788
788
  if (timeMessage) {
@@ -830,7 +830,7 @@ class PackContent {
830
830
  this.logger.time(timeMessage);
831
831
  }
832
832
  const value = this.lazy();
833
- if (value instanceof Promise) {
833
+ if ("then" in value) {
834
834
  return value.then(data => {
835
835
  if (timeMessage) {
836
836
  this.logger.timeEnd(timeMessage);
@@ -918,7 +918,7 @@ class PackContent {
918
918
  }
919
919
  const value = this.lazy();
920
920
  this.outdated = false;
921
- if (value instanceof Promise) {
921
+ if ("then" in value) {
922
922
  // Move to state B1
923
923
  this.lazy = write(() =>
924
924
  value.then(data => {
@@ -991,7 +991,10 @@ class PackFileCacheStrategy {
991
991
  allowCollectingMemory,
992
992
  compression
993
993
  }) {
994
- this.fileSerializer = createFileSerializer(fs);
994
+ this.fileSerializer = createFileSerializer(
995
+ fs,
996
+ compiler.options.output.hashFunction
997
+ );
995
998
  this.fileSystemInfo = new FileSystemInfo(fs, {
996
999
  managedPaths: snapshot.managedPaths,
997
1000
  immutablePaths: snapshot.immutablePaths,
@@ -265,15 +265,15 @@ const applyWebpackOptionsDefaults = options => {
265
265
  * @returns {void}
266
266
  */
267
267
  const applyExperimentsDefaults = (experiments, { production, development }) => {
268
- D(experiments, "topLevelAwait", false);
268
+ D(experiments, "futureDefaults", false);
269
+ D(experiments, "backCompat", !experiments.futureDefaults);
270
+ D(experiments, "topLevelAwait", experiments.futureDefaults);
269
271
  D(experiments, "syncWebAssembly", false);
270
- D(experiments, "asyncWebAssembly", false);
272
+ D(experiments, "asyncWebAssembly", experiments.futureDefaults);
271
273
  D(experiments, "outputModule", false);
272
- D(experiments, "asset", false);
273
274
  D(experiments, "layers", false);
274
275
  D(experiments, "lazyCompilation", undefined);
275
276
  D(experiments, "buildHttp", undefined);
276
- D(experiments, "futureDefaults", false);
277
277
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
278
278
 
279
279
  if (typeof experiments.buildHttp === "object") {
@@ -442,8 +442,6 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
442
442
  D(parserOptions, "wrappedContextRegExp", /.*/);
443
443
  D(parserOptions, "wrappedContextRecursive", true);
444
444
  D(parserOptions, "wrappedContextCritical", false);
445
-
446
- D(parserOptions, "strictExportPresence", false);
447
445
  D(parserOptions, "strictThisContextOnImports", false);
448
446
  };
449
447
 
@@ -90,7 +90,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
90
90
  // has array range but no function range
91
91
  if (dep.arrayRange && !dep.functionRange) {
92
92
  const startBlock = `${promise}.then(function() {`;
93
- const endBlock = `;}).catch(${RuntimeGlobals.uncaughtErrorHandler})`;
93
+ const endBlock = `;})['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
94
94
  runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
95
95
 
96
96
  source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
@@ -103,7 +103,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
103
103
  // has function range but no array range
104
104
  if (dep.functionRange && !dep.arrayRange) {
105
105
  const startBlock = `${promise}.then((`;
106
- const endBlock = `).bind(exports, __webpack_require__, exports, module)).catch(${RuntimeGlobals.uncaughtErrorHandler})`;
106
+ const endBlock = `).bind(exports, __webpack_require__, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
107
107
  runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
108
108
 
109
109
  source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
@@ -118,7 +118,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
118
118
  const startBlock = `${promise}.then(function() { `;
119
119
  const errorRangeBlock = `}${
120
120
  dep.functionBindThis ? ".bind(this)" : ""
121
- }).catch(`;
121
+ })['catch'](`;
122
122
  const endBlock = `${dep.errorCallbackBindThis ? ".bind(this)" : ""})`;
123
123
 
124
124
  source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
@@ -150,9 +150,9 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
150
150
  // has array range, function range, but no errorCallbackRange
151
151
  if (dep.arrayRange && dep.functionRange) {
152
152
  const startBlock = `${promise}.then(function() { `;
153
- const endBlock = `}${dep.functionBindThis ? ".bind(this)" : ""}).catch(${
154
- RuntimeGlobals.uncaughtErrorHandler
155
- })`;
153
+ const endBlock = `}${
154
+ dep.functionBindThis ? ".bind(this)" : ""
155
+ })['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
156
156
  runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
157
157
 
158
158
  source.replace(dep.outerRange[0], dep.arrayRange[0] - 1, startBlock);
@@ -117,7 +117,11 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
117
117
  const comment = equals(usedImported, ids)
118
118
  ? ""
119
119
  : Template.toNormalComment(propertyAccess(ids)) + " ";
120
- requireExpr += `${comment}${propertyAccess(usedImported)}`;
120
+ const access = `${comment}${propertyAccess(usedImported)}`;
121
+ requireExpr =
122
+ dep.asiSafe === true
123
+ ? `(${requireExpr}${access})`
124
+ : `${requireExpr}${access}`;
121
125
  }
122
126
  }
123
127
  source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
@@ -141,7 +141,9 @@ class CommonJsImportsParserPlugin {
141
141
  regExp: options.unknownContextRegExp,
142
142
  mode: "sync"
143
143
  },
144
- expr.range
144
+ expr.range,
145
+ undefined,
146
+ parser.scope.inShorthand
145
147
  );
146
148
  dep.critical =
147
149
  options.unknownContextCritical &&
@@ -10,11 +10,13 @@ const ContextDependency = require("./ContextDependency");
10
10
  const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
11
11
 
12
12
  class CommonJsRequireContextDependency extends ContextDependency {
13
- constructor(options, range, valueRange) {
13
+ constructor(options, range, valueRange, inShorthand) {
14
14
  super(options);
15
15
 
16
16
  this.range = range;
17
17
  this.valueRange = valueRange;
18
+ // inShorthand must be serialized by subclasses that use it
19
+ this.inShorthand = inShorthand;
18
20
  }
19
21
 
20
22
  get type() {
@@ -26,6 +28,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
26
28
 
27
29
  write(this.range);
28
30
  write(this.valueRange);
31
+ write(this.inShorthand);
29
32
 
30
33
  super.serialize(context);
31
34
  }
@@ -35,6 +38,7 @@ class CommonJsRequireContextDependency extends ContextDependency {
35
38
 
36
39
  this.range = read();
37
40
  this.valueRange = read();
41
+ this.inShorthand = read();
38
42
 
39
43
  super.deserialize(context);
40
44
  }
@@ -47,6 +47,7 @@ class ContextDependency extends Dependency {
47
47
  this.request = undefined;
48
48
  this.range = undefined;
49
49
  this.valueRange = undefined;
50
+ this.inShorthand = undefined;
50
51
  // TODO refactor this
51
52
  this.replaces = undefined;
52
53
  }
@@ -24,13 +24,16 @@ class ContextDependencyTemplateAsRequireCall extends ContextDependency.Template
24
24
  { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
25
25
  ) {
26
26
  const dep = /** @type {ContextDependency} */ (dependency);
27
- const moduleExports = runtimeTemplate.moduleExports({
27
+ let moduleExports = runtimeTemplate.moduleExports({
28
28
  module: moduleGraph.getModule(dep),
29
29
  chunkGraph,
30
30
  request: dep.request,
31
31
  runtimeRequirements
32
32
  });
33
33
 
34
+ if (dep.inShorthand) {
35
+ moduleExports = `${dep.inShorthand}: ${moduleExports}`;
36
+ }
34
37
  if (moduleGraph.getModule(dep)) {
35
38
  if (dep.valueRange) {
36
39
  if (Array.isArray(dep.replaces)) {
@@ -11,6 +11,7 @@ const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDepe
11
11
  const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
12
12
  const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
13
13
  const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
14
+ const { ExportPresenceModes } = require("./HarmonyImportDependency");
14
15
  const {
15
16
  harmonySpecifierTag,
16
17
  getAssertions
@@ -21,10 +22,18 @@ const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency;
21
22
 
22
23
  module.exports = class HarmonyExportDependencyParserPlugin {
23
24
  constructor(options) {
24
- this.strictExportPresence = options.strictExportPresence;
25
+ this.exportPresenceMode =
26
+ options.reexportExportPresence !== undefined
27
+ ? ExportPresenceModes.fromUserOption(options.reexportExportPresence)
28
+ : options.exportPresence !== undefined
29
+ ? ExportPresenceModes.fromUserOption(options.exportPresence)
30
+ : options.strictExportPresence
31
+ ? ExportPresenceModes.ERROR
32
+ : ExportPresenceModes.AUTO;
25
33
  }
26
34
 
27
35
  apply(parser) {
36
+ const { exportPresenceMode } = this;
28
37
  parser.hooks.export.tap(
29
38
  "HarmonyExportDependencyParserPlugin",
30
39
  statement => {
@@ -128,7 +137,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
128
137
  name,
129
138
  harmonyNamedExports,
130
139
  null,
131
- this.strictExportPresence,
140
+ exportPresenceMode,
132
141
  null,
133
142
  settings.assertions
134
143
  );
@@ -160,7 +169,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
160
169
  name,
161
170
  harmonyNamedExports,
162
171
  harmonyStarExports && harmonyStarExports.slice(),
163
- this.strictExportPresence,
172
+ exportPresenceMode,
164
173
  harmonyStarExports
165
174
  );
166
175
  if (harmonyStarExports) {
@@ -40,6 +40,8 @@ const processExportInfo = require("./processExportInfo");
40
40
 
41
41
  /** @typedef {"missing"|"unused"|"empty-star"|"reexport-dynamic-default"|"reexport-named-default"|"reexport-namespace-object"|"reexport-fake-namespace-object"|"reexport-undefined"|"normal-reexport"|"dynamic-reexport"} ExportModeType */
42
42
 
43
+ const { ExportPresenceModes } = HarmonyImportDependency;
44
+
43
45
  const idsSymbol = Symbol("HarmonyExportImportedSpecifierDependency.ids");
44
46
 
45
47
  class NormalReexportItem {
@@ -325,7 +327,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
325
327
  * @param {string | null} name the export name of for this module
326
328
  * @param {Set<string>} activeExports other named exports in the module
327
329
  * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency>} otherStarExports other star exports in the module before this import
328
- * @param {boolean} strictExportPresence when true, missing exports in the imported module lead to errors instead of warnings
330
+ * @param {number} exportPresenceMode mode of checking export names
329
331
  * @param {HarmonyStarExportsList} allStarExports all star exports in the module
330
332
  * @param {Record<string, any>=} assertions import assertions
331
333
  */
@@ -336,7 +338,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
336
338
  name,
337
339
  activeExports,
338
340
  otherStarExports,
339
- strictExportPresence,
341
+ exportPresenceMode,
340
342
  allStarExports,
341
343
  assertions
342
344
  ) {
@@ -346,7 +348,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
346
348
  this.name = name;
347
349
  this.activeExports = activeExports;
348
350
  this.otherStarExports = otherStarExports;
349
- this.strictExportPresence = strictExportPresence;
351
+ this.exportPresenceMode = exportPresenceMode;
350
352
  this.allStarExports = allStarExports;
351
353
  }
352
354
 
@@ -735,20 +737,29 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
735
737
  }
736
738
  }
737
739
 
740
+ /**
741
+ * @param {ModuleGraph} moduleGraph module graph
742
+ * @returns {number} effective mode
743
+ */
744
+ _getEffectiveExportPresenceLevel(moduleGraph) {
745
+ if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
746
+ return this.exportPresenceMode;
747
+ return moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
748
+ ? ExportPresenceModes.ERROR
749
+ : ExportPresenceModes.WARN;
750
+ }
751
+
738
752
  /**
739
753
  * Returns warnings
740
754
  * @param {ModuleGraph} moduleGraph module graph
741
755
  * @returns {WebpackError[]} warnings
742
756
  */
743
757
  getWarnings(moduleGraph) {
744
- if (
745
- this.strictExportPresence ||
746
- moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
747
- ) {
748
- return null;
758
+ const exportPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
759
+ if (exportPresence === ExportPresenceModes.WARN) {
760
+ return this._getErrors(moduleGraph);
749
761
  }
750
-
751
- return this._getErrors(moduleGraph);
762
+ return null;
752
763
  }
753
764
 
754
765
  /**
@@ -757,13 +768,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
757
768
  * @returns {WebpackError[]} errors
758
769
  */
759
770
  getErrors(moduleGraph) {
760
- if (
761
- this.strictExportPresence ||
762
- moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
763
- ) {
771
+ const exportPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
772
+ if (exportPresence === ExportPresenceModes.ERROR) {
764
773
  return this._getErrors(moduleGraph);
765
774
  }
766
-
767
775
  return null;
768
776
  }
769
777
 
@@ -856,7 +864,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
856
864
  write(this.name);
857
865
  write(this.activeExports);
858
866
  write(this.otherStarExports);
859
- write(this.strictExportPresence);
867
+ write(this.exportPresenceMode);
860
868
  write(this.allStarExports);
861
869
 
862
870
  super.serialize(context);
@@ -870,7 +878,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
870
878
  this.name = read();
871
879
  this.activeExports = read();
872
880
  this.otherStarExports = read();
873
- this.strictExportPresence = read();
881
+ this.exportPresenceMode = read();
874
882
  this.allStarExports = read();
875
883
 
876
884
  super.deserialize(context);