webpack 5.101.0 → 5.101.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.
package/lib/ChunkGraph.js CHANGED
@@ -1238,6 +1238,48 @@ class ChunkGraph {
1238
1238
  return set;
1239
1239
  }
1240
1240
 
1241
+ /**
1242
+ * @param {Chunk} chunk the chunk
1243
+ * @returns {Iterable<Chunk>} iterable of chunks and include chunks from children entrypoints
1244
+ */
1245
+ getChunkEntryDependOnChunksIterable(chunk) {
1246
+ /** @type {Set<Chunk>} */
1247
+ const set = new Set();
1248
+
1249
+ /** @type {Set<Entrypoint>} */
1250
+ const entrypoints = new Set();
1251
+
1252
+ for (const chunkGroup of chunk.groupsIterable) {
1253
+ if (chunkGroup instanceof Entrypoint) {
1254
+ const queue = [chunkGroup];
1255
+ while (queue.length > 0) {
1256
+ const current = queue.shift();
1257
+ if (current) {
1258
+ entrypoints.add(current);
1259
+
1260
+ let hasChildrenEntrypoint = false;
1261
+ for (const child of current.childrenIterable) {
1262
+ if (child.isInitial()) {
1263
+ hasChildrenEntrypoint = true;
1264
+ queue.push(/** @type {Entrypoint} */ (child));
1265
+ }
1266
+ }
1267
+ // entryChunkB: hasChildrenEntrypoint = true
1268
+ // entryChunkA: dependOn = entryChunkB
1269
+ if (hasChildrenEntrypoint) {
1270
+ const entrypointChunk = current.getEntrypointChunk();
1271
+ if (entrypointChunk !== chunk && !entrypointChunk.hasRuntime()) {
1272
+ // add entryChunkB to set
1273
+ set.add(entrypointChunk);
1274
+ }
1275
+ }
1276
+ }
1277
+ }
1278
+ }
1279
+ }
1280
+ return set;
1281
+ }
1282
+
1241
1283
  /**
1242
1284
  * @param {Chunk} chunk the chunk
1243
1285
  * @returns {boolean} true, when it has dependent chunks
@@ -526,6 +526,21 @@ class Compilation {
526
526
 
527
527
  /** @type {ProcessedAssets | undefined} */
528
528
  const processedAssets = additionalAssetsFn ? new WeakSet() : undefined;
529
+ /**
530
+ * @param {CompilationAssets} assets to be processed by additionalAssetsFn
531
+ * @returns {CompilationAssets} available assets
532
+ */
533
+ const getAvailableAssets = (assets) => {
534
+ /** @type {CompilationAssets} */
535
+ const availableAssets = {};
536
+ for (const file of Object.keys(assets)) {
537
+ // https://github.com/webpack-contrib/compression-webpack-plugin/issues/390
538
+ if (this.assets[file]) {
539
+ availableAssets[file] = assets[file];
540
+ }
541
+ }
542
+ return availableAssets;
543
+ };
529
544
  switch (type) {
530
545
  case "sync":
531
546
  if (additionalAssetsFn) {
@@ -534,7 +549,7 @@ class Compilation {
534
549
  /** @type {ProcessedAssets} */
535
550
  (processedAssets).has(this.assets)
536
551
  ) {
537
- additionalAssetsFn(assets);
552
+ additionalAssetsFn(getAvailableAssets(assets));
538
553
  }
539
554
  });
540
555
  }
@@ -575,7 +590,10 @@ class Compilation {
575
590
  /** @type {ProcessedAssets} */
576
591
  (processedAssets).has(this.assets)
577
592
  ) {
578
- return additionalAssetsFn(assets, callback);
593
+ return additionalAssetsFn(
594
+ getAvailableAssets(assets),
595
+ callback
596
+ );
579
597
  }
580
598
  callback();
581
599
  }
@@ -620,7 +638,7 @@ class Compilation {
620
638
  /** @type {ProcessedAssets} */
621
639
  (processedAssets).has(this.assets)
622
640
  ) {
623
- return additionalAssetsFn(assets);
641
+ return additionalAssetsFn(getAvailableAssets(assets));
624
642
  }
625
643
  return Promise.resolve();
626
644
  });
@@ -3242,6 +3260,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3242
3260
  entry.setRuntimeChunk(chunk);
3243
3261
  }
3244
3262
  }
3263
+
3245
3264
  buildChunkGraph(this, chunkGraphInit);
3246
3265
  this.hooks.afterChunks.call(this.chunks);
3247
3266
  this.logger.timeEnd("create chunks");
@@ -3259,6 +3278,26 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3259
3278
  }
3260
3279
  this.hooks.afterOptimizeChunks.call(this.chunks, this.chunkGroups);
3261
3280
 
3281
+ for (const [
3282
+ name,
3283
+ {
3284
+ options: { dependOn }
3285
+ }
3286
+ ] of this.entries) {
3287
+ if (dependOn) {
3288
+ const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
3289
+ for (const dep of dependOn) {
3290
+ const depEntry = /** @type {Entrypoint} */ (
3291
+ this.entrypoints.get(dep)
3292
+ );
3293
+ const runtimeChunk = depEntry.getRuntimeChunk();
3294
+ if (runtimeChunk) {
3295
+ runtimeChunk.addGroup(entry);
3296
+ }
3297
+ }
3298
+ }
3299
+ }
3300
+
3262
3301
  this.hooks.optimizeTree.callAsync(this.chunks, this.modules, (err) => {
3263
3302
  if (err) {
3264
3303
  return finalCallback(
package/lib/Dependency.js CHANGED
@@ -5,7 +5,6 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const RawModule = require("./RawModule");
9
8
  const memoize = require("./util/memoize");
10
9
 
11
10
  /** @typedef {import("webpack-sources").Source} Source */
@@ -86,6 +85,8 @@ const memoize = require("./util/memoize");
86
85
  const TRANSITIVE = Symbol("transitive");
87
86
 
88
87
  const getIgnoredModule = memoize(() => {
88
+ const RawModule = require("./RawModule");
89
+
89
90
  const module = new RawModule("/* (ignored) */", "ignored", "(ignored)");
90
91
  module.factoryMeta = { sideEffectFree: true };
91
92
  return module;
package/lib/Module.js CHANGED
@@ -115,9 +115,10 @@ const makeSerializable = require("./util/makeSerializable");
115
115
  * @property {boolean=} strictHarmonyModule
116
116
  * @property {boolean=} async
117
117
  * @property {boolean=} sideEffectFree
118
- * @property {Record<string, string>=} exportsFinalName
119
118
  * @property {boolean=} isCSSModule
120
119
  * @property {Record<string, string>=} jsIncompatibleExports
120
+ * @property {Record<string, string>=} exportsFinalName
121
+ * @property {string=} factoryExportsBinding
121
122
  */
122
123
 
123
124
  /**
@@ -8,10 +8,10 @@
8
8
  const util = require("util");
9
9
  const ExportsInfo = require("./ExportsInfo");
10
10
  const ModuleGraphConnection = require("./ModuleGraphConnection");
11
+ const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
11
12
  const SortableSet = require("./util/SortableSet");
12
13
  const WeakTupleMap = require("./util/WeakTupleMap");
13
14
  const { sortWithSourceOrder } = require("./util/comparators");
14
- const memoize = require("./util/memoize");
15
15
 
16
16
  /** @typedef {import("./Compilation").ModuleMemCaches} ModuleMemCaches */
17
17
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
@@ -25,10 +25,6 @@ const memoize = require("./util/memoize");
25
25
  /** @typedef {import("./dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
26
26
  /** @typedef {import("./util/comparators").DependencySourceOrder} DependencySourceOrder */
27
27
 
28
- const getCommonJsSelfReferenceDependency = memoize(() =>
29
- require("./dependencies/CommonJsSelfReferenceDependency")
30
- );
31
-
32
28
  /**
33
29
  * @callback OptimizationBailoutFunction
34
30
  * @param {RequestShortener} requestShortener
@@ -38,66 +34,51 @@ const getCommonJsSelfReferenceDependency = memoize(() =>
38
34
  const EMPTY_SET = new Set();
39
35
 
40
36
  /**
37
+ * @template {Module | null | undefined} T
41
38
  * @param {SortableSet<ModuleGraphConnection>} set input
42
- * @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} mapped by origin module
39
+ * @param {(connection: ModuleGraphConnection) => T} getKey function to extract key from connection
40
+ * @returns {readonly Map<T, readonly ModuleGraphConnection[]>} mapped by key
43
41
  */
44
- const getConnectionsByOriginModule = (set) => {
42
+ const getConnectionsByKey = (set, getKey) => {
45
43
  const map = new Map();
46
- /** @type {Module | 0} */
47
- let lastModule = 0;
44
+ /** @type {T | 0} */
45
+ let lastKey = 0;
48
46
  /** @type {ModuleGraphConnection[] | undefined} */
49
47
  let lastList;
50
48
  for (const connection of set) {
51
- const { originModule } = connection;
52
- if (lastModule === originModule) {
49
+ const key = getKey(connection);
50
+ if (lastKey === key) {
53
51
  /** @type {ModuleGraphConnection[]} */
54
52
  (lastList).push(connection);
55
53
  } else {
56
- lastModule = /** @type {Module} */ (originModule);
57
- const list = map.get(originModule);
54
+ lastKey = key;
55
+ const list = map.get(key);
58
56
  if (list !== undefined) {
59
57
  lastList = list;
60
58
  list.push(connection);
61
59
  } else {
62
60
  const list = [connection];
63
61
  lastList = list;
64
- map.set(originModule, list);
62
+ map.set(key, list);
65
63
  }
66
64
  }
67
65
  }
68
66
  return map;
69
67
  };
70
68
 
69
+ /**
70
+ * @param {SortableSet<ModuleGraphConnection>} set input
71
+ * @returns {readonly Map<Module | undefined | null, readonly ModuleGraphConnection[]>} mapped by origin module
72
+ */
73
+ const getConnectionsByOriginModule = (set) =>
74
+ getConnectionsByKey(set, (connection) => connection.originModule);
75
+
71
76
  /**
72
77
  * @param {SortableSet<ModuleGraphConnection>} set input
73
78
  * @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} mapped by module
74
79
  */
75
- const getConnectionsByModule = (set) => {
76
- const map = new Map();
77
- /** @type {Module | 0} */
78
- let lastModule = 0;
79
- /** @type {ModuleGraphConnection[] | undefined} */
80
- let lastList;
81
- for (const connection of set) {
82
- const { module } = connection;
83
- if (lastModule === module) {
84
- /** @type {ModuleGraphConnection[]} */
85
- (lastList).push(connection);
86
- } else {
87
- lastModule = module;
88
- const list = map.get(module);
89
- if (list !== undefined) {
90
- lastList = list;
91
- list.push(connection);
92
- } else {
93
- const list = [connection];
94
- lastList = list;
95
- map.set(module, list);
96
- }
97
- }
98
- }
99
- return map;
100
- };
80
+ const getConnectionsByModule = (set) =>
81
+ getConnectionsByKey(set, (connection) => connection.module);
101
82
 
102
83
  /** @typedef {SortableSet<ModuleGraphConnection>} IncomingConnections */
103
84
  /** @typedef {SortableSet<ModuleGraphConnection>} OutgoingConnections */
@@ -845,7 +826,7 @@ class ModuleGraph {
845
826
  for (const connection of connections) {
846
827
  if (
847
828
  !connection.dependency ||
848
- connection.dependency instanceof getCommonJsSelfReferenceDependency()
829
+ !(connection.dependency instanceof HarmonyImportDependency)
849
830
  ) {
850
831
  continue;
851
832
  }
@@ -18,6 +18,7 @@ const memoize = require("./util/memoize");
18
18
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
19
19
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
20
20
  /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
21
+ /** @typedef {import("./javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
21
22
  /** @typedef {import("./util/Hash")} Hash */
22
23
 
23
24
  /**
@@ -44,7 +45,7 @@ class ModuleTemplate {
44
45
  /**
45
46
  * @template AdditionalOptions
46
47
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
47
- * @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
48
+ * @param {(source: Source, module: Module, moduleRenderContext: ModuleRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
48
49
  */
49
50
  (options, fn) => {
50
51
  getJavascriptModulesPlugin()
@@ -69,7 +70,7 @@ class ModuleTemplate {
69
70
  /**
70
71
  * @template AdditionalOptions
71
72
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
72
- * @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
73
+ * @param {(source: Source, module: Module, moduleRenderContext: ModuleRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
73
74
  */
74
75
  (options, fn) => {
75
76
  getJavascriptModulesPlugin()
package/lib/Watching.js CHANGED
@@ -187,8 +187,6 @@ class Watching {
187
187
 
188
188
  const compilation = /** @type {Compilation} */ (_compilation);
189
189
 
190
- if (this.invalid) return this._done(null, compilation);
191
-
192
190
  if (this.compiler.hooks.shouldEmit.call(compilation) === false) {
193
191
  return this._done(null, compilation);
194
192
  }
@@ -18,6 +18,8 @@ const NullDependency = require("./NullDependency");
18
18
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
19
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
20
  /** @typedef {import("./HarmonyAcceptImportDependency")} HarmonyAcceptImportDependency */
21
+ /** @typedef {import("../Module")} Module */
22
+ /** @typedef {import("../Module").ModuleId} ModuleId */
21
23
 
22
24
  class HarmonyAcceptDependency extends NullDependency {
23
25
  /**
@@ -84,7 +86,57 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
84
86
  chunkGraph
85
87
  } = templateContext;
86
88
 
87
- /** @type {HarmonyAcceptImportDependency[]} */
89
+ /**
90
+ * @param {Dependency} dependency the dependency to get module id for
91
+ * @returns {ModuleId | null} the module id or null if not found
92
+ */
93
+ const getDependencyModuleId = (dependency) =>
94
+ chunkGraph.getModuleId(
95
+ /** @type {Module} */ (moduleGraph.getModule(dependency))
96
+ );
97
+
98
+ /**
99
+ * @param {Dependency} a the first dependency
100
+ * @param {Dependency} b the second dependency
101
+ * @returns {boolean} true if the dependencies are related
102
+ */
103
+ const isRelatedHarmonyImportDependency = (a, b) =>
104
+ a !== b &&
105
+ b instanceof HarmonyImportDependency &&
106
+ getDependencyModuleId(a) === getDependencyModuleId(b);
107
+
108
+ /**
109
+ * HarmonyAcceptImportDependency lacks a lot of information, such as the defer property.
110
+ * One HarmonyAcceptImportDependency may need to generate multiple ImportStatements.
111
+ * Therefore, we find its original HarmonyImportDependency for code generation.
112
+ * @param {HarmonyAcceptImportDependency} dependency the dependency to get harmony import dependencies for
113
+ * @returns {HarmonyImportDependency[]} array of related harmony import dependencies
114
+ */
115
+ const getHarmonyImportDependencies = (dependency) => {
116
+ const result = [];
117
+ let deferDependency = null;
118
+ let noDeferredDependency = null;
119
+
120
+ for (const d of module.dependencies) {
121
+ if (deferDependency && noDeferredDependency) break;
122
+ if (isRelatedHarmonyImportDependency(dependency, d)) {
123
+ if (d.defer) {
124
+ deferDependency = /** @type {HarmonyImportDependency} */ (d);
125
+ } else {
126
+ noDeferredDependency = /** @type {HarmonyImportDependency} */ (d);
127
+ }
128
+ }
129
+ }
130
+ if (deferDependency) result.push(deferDependency);
131
+ if (noDeferredDependency) result.push(noDeferredDependency);
132
+ if (result.length === 0) {
133
+ // fallback to the original dependency
134
+ result.push(dependency);
135
+ }
136
+ return result;
137
+ };
138
+
139
+ /** @type {HarmonyImportDependency[]} */
88
140
  const syncDeps = [];
89
141
 
90
142
  /** @type {HarmonyAcceptImportDependency[]} */
@@ -96,7 +148,7 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
96
148
  if (connection && moduleGraph.isAsync(connection.module)) {
97
149
  asyncDeps.push(dependency);
98
150
  } else {
99
- syncDeps.push(dependency);
151
+ syncDeps.push(...getHarmonyImportDependencies(dependency));
100
152
  }
101
153
  }
102
154
 
@@ -55,7 +55,12 @@ const getExportsWithDepth = (exportsDepth) =>
55
55
  exports.push({
56
56
  name: key,
57
57
  canMangle: true,
58
- exports: getExportsFromData(data[key], curDepth + 1) || undefined
58
+ exports:
59
+ getExportsFromData(
60
+ /** @type {JsonValue} */
61
+ (data[key]),
62
+ curDepth + 1
63
+ ) || undefined
59
64
  });
60
65
  }
61
66
 
@@ -7,7 +7,6 @@
7
7
 
8
8
  const Dependency = require("../Dependency");
9
9
  const DependencyTemplate = require("../DependencyTemplate");
10
- const RawModule = require("../RawModule");
11
10
 
12
11
  /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
13
12
  /** @typedef {import("../Module")} Module */
@@ -61,6 +60,8 @@ class ModuleDependency extends Dependency {
61
60
  * @returns {Module} ignored module
62
61
  */
63
62
  createIgnoredModule(context) {
63
+ const RawModule = require("../RawModule");
64
+
64
65
  const module = new RawModule(
65
66
  "/* (ignored) */",
66
67
  `ignored|${context}|${this.request}`,
@@ -6,6 +6,10 @@
6
6
 
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
+ const Template = require("../Template");
10
+
11
+ // CompatibilityPlugin renames `__webpack_require__` but doesn’t account for `export { __webpack_require__ }`, so we create a temporary variable to handle it.
12
+ const EXPORT_TEMP_NAME = "__webpack_require_temp__";
9
13
 
10
14
  class ExportWebpackRequireRuntimeModule extends RuntimeModule {
11
15
  constructor() {
@@ -23,7 +27,10 @@ class ExportWebpackRequireRuntimeModule extends RuntimeModule {
23
27
  * @returns {string | null} runtime code
24
28
  */
25
29
  generate() {
26
- return `export default ${RuntimeGlobals.require};`;
30
+ return Template.asString([
31
+ `var ${EXPORT_TEMP_NAME} = ${RuntimeGlobals.require};`,
32
+ `export { ${EXPORT_TEMP_NAME} as ${RuntimeGlobals.require} };`
33
+ ]);
27
34
  }
28
35
  }
29
36
 
@@ -8,13 +8,16 @@
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const { HotUpdateChunk, RuntimeGlobals } = require("..");
10
10
  const Template = require("../Template");
11
+ const {
12
+ createChunkHashHandler,
13
+ getChunkInfo
14
+ } = require("../javascript/ChunkFormatHelpers");
11
15
  const { getAllChunks } = require("../javascript/ChunkHelpers");
12
16
  const {
13
17
  chunkHasJs,
14
18
  getChunkFilenameTemplate,
15
19
  getCompilationHooks
16
20
  } = require("../javascript/JavascriptModulesPlugin");
17
- const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
18
21
  const { getUndoPath } = require("../util/identifier");
19
22
 
20
23
  /** @typedef {import("webpack-sources").Source} Source */
@@ -27,28 +30,6 @@ const { getUndoPath } = require("../util/identifier");
27
30
  /** @typedef {import("../Module")} Module */
28
31
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
29
32
 
30
- /**
31
- * Gets information about a chunk including its entries and runtime chunk
32
- * @param {Chunk} chunk The chunk to get information for
33
- * @param {ChunkGraph} chunkGraph The chunk graph containing the chunk
34
- * @returns {{entries: Array<[Module, Entrypoint | undefined]>, runtimeChunk: Chunk|null}} Object containing chunk entries and runtime chunk
35
- */
36
- function getChunkInfo(chunk, chunkGraph) {
37
- const entries = [
38
- ...chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
39
- ];
40
- const runtimeChunk =
41
- entries.length > 0
42
- ? /** @type {Entrypoint[][]} */
43
- (entries)[0][1].getRuntimeChunk()
44
- : null;
45
-
46
- return {
47
- entries,
48
- runtimeChunk
49
- };
50
- }
51
-
52
33
  /**
53
34
  * @param {Compilation} compilation the compilation instance
54
35
  * @param {Chunk} chunk the chunk
@@ -97,7 +78,7 @@ const getRelativePath = (compilation, chunk, runtimeChunk) => {
97
78
  * @returns {string} the import source
98
79
  */
99
80
  function renderChunkImport(compilation, chunk, namedImport, runtimeChunk) {
100
- return `import ${namedImport ? `* as ${namedImport}` : RuntimeGlobals.require} from ${JSON.stringify(
81
+ return `import ${namedImport ? `* as ${namedImport}` : `{ ${RuntimeGlobals.require} }`} from ${JSON.stringify(
101
82
  getRelativePath(compilation, chunk, runtimeChunk || chunk)
102
83
  )};\n`;
103
84
  }
@@ -168,27 +149,30 @@ class ModuleChunkFormatPlugin {
168
149
  PLUGIN_NAME,
169
150
  (modules, _lastModule, renderContext) => {
170
151
  const { chunk, chunkGraph } = renderContext;
171
- if (!chunk.hasRuntime()) {
172
- return modules;
173
- }
174
- const entryDependentChunks =
175
- chunkGraph.getChunkEntryDependentChunksIterable(chunk);
176
- const sourceWithDependentChunks = withDependentChunks(
177
- /** @type {Set<Chunk>} */ (entryDependentChunks),
178
- chunkGraph,
179
- chunk
180
- );
181
- if (!sourceWithDependentChunks) {
182
- return modules;
183
- }
184
- if (modules.size() === 0) {
185
- return sourceWithDependentChunks;
152
+ if (
153
+ chunkGraph.getNumberOfEntryModules(chunk) > 0 &&
154
+ chunk.hasRuntime()
155
+ ) {
156
+ const entryDependentChunks =
157
+ chunkGraph.getChunkEntryDependentChunksIterable(chunk);
158
+ const sourceWithDependentChunks = withDependentChunks(
159
+ /** @type {Set<Chunk>} */ (entryDependentChunks),
160
+ chunkGraph,
161
+ chunk
162
+ );
163
+ if (!sourceWithDependentChunks) {
164
+ return modules;
165
+ }
166
+ if (modules.size() === 0) {
167
+ return sourceWithDependentChunks;
168
+ }
169
+ const source = new ConcatSource();
170
+ source.add(sourceWithDependentChunks);
171
+ source.add("\n");
172
+ source.add(modules);
173
+ return source;
186
174
  }
187
- const source = new ConcatSource();
188
- source.add(sourceWithDependentChunks);
189
- source.add("\n");
190
- source.add(modules);
191
- return source;
175
+ return modules;
192
176
  }
193
177
  );
194
178
  hooks.renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => {
@@ -238,9 +222,6 @@ class ModuleChunkFormatPlugin {
238
222
  }
239
223
  const final = i + 1 === entries.length;
240
224
  const moduleId = chunkGraph.getModuleId(module);
241
- const entryDependentChunks = /** @type {Set<Chunk>} */ (
242
- chunkGraph.getChunkEntryDependentChunksIterable(chunk)
243
- );
244
225
  const chunks = getAllChunks(
245
226
  /** @type {Entrypoint} */ (entrypoint),
246
227
  /** @type {Chunk} */ (runtimeChunk),
@@ -248,10 +229,7 @@ class ModuleChunkFormatPlugin {
248
229
  );
249
230
  const processChunks = new Set();
250
231
  for (const _chunk of chunks) {
251
- if (
252
- loadedChunks.has(_chunk) ||
253
- entryDependentChunks.has(_chunk)
254
- ) {
232
+ if (loadedChunks.has(_chunk)) {
255
233
  continue;
256
234
  }
257
235
  loadedChunks.add(_chunk);
@@ -287,19 +265,7 @@ class ModuleChunkFormatPlugin {
287
265
  }
288
266
  return source;
289
267
  });
290
- hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, { chunkGraph }) => {
291
- if (chunk.hasRuntime()) return;
292
- const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
293
- hash.update(PLUGIN_NAME);
294
- hash.update("1");
295
- if (runtimeChunk && runtimeChunk.hash) {
296
- // Any change to runtimeChunk should trigger a hash update,
297
- // we shouldn't depend on or inspect its internal implementation.
298
- // import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js";
299
- hash.update(runtimeChunk.hash);
300
- }
301
- updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
302
- });
268
+ hooks.chunkHash.tap(PLUGIN_NAME, createChunkHashHandler(PLUGIN_NAME));
303
269
  });
304
270
  }
305
271
  }
@@ -71,11 +71,8 @@ class ModuleChunkLoadingPlugin {
71
71
  .tap(PLUGIN_NAME, handler);
72
72
  compilation.hooks.runtimeRequirementInTree
73
73
  .for(RuntimeGlobals.externalInstallChunk)
74
- .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
74
+ .tap(PLUGIN_NAME, (chunk) => {
75
75
  if (!isEnabledForChunk(chunk)) return;
76
- // If a chunk contains an entryModule, all exports are determined by the entryModule.
77
- // The ExportWebpackRequireRuntimeModule is for internal use only and not exposed to users.
78
- if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return;
79
76
  compilation.addRuntimeModule(
80
77
  chunk,
81
78
  new ExportWebpackRequireRuntimeModule()
package/lib/index.js CHANGED
@@ -56,6 +56,9 @@ const memoize = require("./util/memoize");
56
56
  /** @typedef {import("./Parser").ParserState} ParserState */
57
57
  /** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */
58
58
  /** @typedef {import("./ResolverFactory").Resolver} Resolver */
59
+ /** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
60
+ /** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */
61
+ /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
59
62
  /** @typedef {import("./Watching")} Watching */
60
63
  /** @typedef {import("./cli").Argument} Argument */
61
64
  /** @typedef {import("./cli").Problem} Problem */
@@ -75,6 +78,8 @@ const memoize = require("./util/memoize");
75
78
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
76
79
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
77
80
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
81
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
82
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
78
83
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
79
84
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
80
85
 
@@ -288,6 +293,9 @@ module.exports = mergeExports(fn, {
288
293
  get Module() {
289
294
  return require("./Module");
290
295
  },
296
+ get ModuleFactory() {
297
+ return require("./ModuleFactory");
298
+ },
291
299
  get ModuleFilenameHelpers() {
292
300
  return require("./ModuleFilenameHelpers");
293
301
  },