webpack 5.31.2 → 5.33.2
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/lib/CaseSensitiveModulesWarning.js +3 -3
- package/lib/Compilation.js +488 -48
- package/lib/DefinePlugin.js +21 -5
- package/lib/EntryOptionPlugin.js +1 -0
- package/lib/FlagDependencyExportsPlugin.js +22 -0
- package/lib/Module.js +1 -1
- package/lib/ModuleGraph.js +24 -0
- package/lib/NormalModule.js +14 -3
- package/lib/NormalModuleFactory.js +15 -1
- package/lib/RuntimeModule.js +5 -1
- package/lib/RuntimePlugin.js +7 -2
- package/lib/WarnCaseSensitiveModulesPlugin.js +15 -9
- package/lib/WebpackOptionsApply.js +3 -1
- package/lib/asset/AssetModulesPlugin.js +13 -0
- package/lib/config/defaults.js +1 -3
- package/lib/config/normalization.js +1 -0
- package/lib/container/RemoteRuntimeModule.js +2 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +191 -39
- package/lib/dependencies/LoaderImportDependency.js +28 -0
- package/lib/dependencies/LoaderPlugin.js +134 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -2
- package/lib/javascript/JavascriptModulesPlugin.js +67 -2
- package/lib/library/AbstractLibraryPlugin.js +26 -8
- package/lib/node/CommonJsChunkLoadingPlugin.js +3 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +3 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +3 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -4
- package/lib/runtime/CompatRuntimeModule.js +1 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/PublicPathRuntimeModule.js +5 -5
- package/lib/runtime/RuntimeIdRuntimeModule.js +1 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +5 -3
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +13 -4
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -5
- package/lib/sharing/ShareRuntimeModule.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +5 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +2 -0
- package/lib/util/AsyncQueue.js +45 -10
- package/lib/util/WeakTupleMap.js +168 -0
- package/lib/util/processAsyncTree.js +3 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +3 -1
- package/lib/web/JsonpChunkLoadingPlugin.js +3 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -2
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +3 -3
- package/schemas/WebpackOptions.json +10 -0
- package/types.d.ts +131 -14
@@ -11,6 +11,7 @@ const HarmonyLinkingError = require("../HarmonyLinkingError");
|
|
11
11
|
const InitFragment = require("../InitFragment");
|
12
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
13
13
|
const Template = require("../Template");
|
14
|
+
const { countIterable } = require("../util/IterableHelpers");
|
14
15
|
const { first, combine } = require("../util/SetHelpers");
|
15
16
|
const makeSerializable = require("../util/makeSerializable");
|
16
17
|
const propertyAccess = require("../util/propertyAccess");
|
@@ -92,6 +93,62 @@ class ExportMode {
|
|
92
93
|
}
|
93
94
|
}
|
94
95
|
|
96
|
+
const determineExportAssignments = (
|
97
|
+
moduleGraph,
|
98
|
+
dependencies,
|
99
|
+
additionalDependency
|
100
|
+
) => {
|
101
|
+
const names = new Set();
|
102
|
+
const dependencyIndices = [];
|
103
|
+
|
104
|
+
if (additionalDependency) {
|
105
|
+
dependencies = dependencies.concat(additionalDependency);
|
106
|
+
}
|
107
|
+
|
108
|
+
for (const dep of dependencies) {
|
109
|
+
const i = dependencyIndices.length;
|
110
|
+
dependencyIndices[i] = names.size;
|
111
|
+
const otherImportedModule = moduleGraph.getModule(dep);
|
112
|
+
if (otherImportedModule) {
|
113
|
+
const exportsInfo = moduleGraph.getExportsInfo(otherImportedModule);
|
114
|
+
for (const exportInfo of exportsInfo.exports) {
|
115
|
+
if (
|
116
|
+
exportInfo.provided === true &&
|
117
|
+
exportInfo.name !== "default" &&
|
118
|
+
!names.has(exportInfo.name)
|
119
|
+
) {
|
120
|
+
names.add(exportInfo.name);
|
121
|
+
dependencyIndices[i] = names.size;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
dependencyIndices.push(names.size);
|
127
|
+
|
128
|
+
return { names: Array.from(names), dependencyIndices };
|
129
|
+
};
|
130
|
+
|
131
|
+
const findDependencyForName = (
|
132
|
+
{ names, dependencyIndices },
|
133
|
+
name,
|
134
|
+
dependencies
|
135
|
+
) => {
|
136
|
+
const dependenciesIt = dependencies[Symbol.iterator]();
|
137
|
+
const dependencyIndicesIt = dependencyIndices[Symbol.iterator]();
|
138
|
+
let dependenciesItResult = dependenciesIt.next();
|
139
|
+
let dependencyIndicesItResult = dependencyIndicesIt.next();
|
140
|
+
if (dependencyIndicesItResult.done) return;
|
141
|
+
for (let i = 0; i < names.length; i++) {
|
142
|
+
while (i >= dependencyIndicesItResult.value) {
|
143
|
+
dependenciesItResult = dependenciesIt.next();
|
144
|
+
dependencyIndicesItResult = dependencyIndicesIt.next();
|
145
|
+
if (dependencyIndicesItResult.done) return;
|
146
|
+
}
|
147
|
+
if (names[i] === name) return dependenciesItResult.value;
|
148
|
+
}
|
149
|
+
return undefined;
|
150
|
+
};
|
151
|
+
|
95
152
|
class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
96
153
|
/**
|
97
154
|
* @param {string} request the request string
|
@@ -99,8 +156,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
99
156
|
* @param {string[]} ids the requested export name of the imported module
|
100
157
|
* @param {string | null} name the export name of for this module
|
101
158
|
* @param {Set<string>} activeExports other named exports in the module
|
102
|
-
* @param {Iterable<HarmonyExportImportedSpecifierDependency>} otherStarExports other star exports in the module
|
159
|
+
* @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency>} otherStarExports other star exports in the module before this import
|
103
160
|
* @param {boolean} strictExportPresence when true, missing exports in the imported module lead to errors instead of warnings
|
161
|
+
* @param {HarmonyStarExportsList} allStarExports all star exports in the module
|
104
162
|
*/
|
105
163
|
constructor(
|
106
164
|
request,
|
@@ -109,7 +167,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
109
167
|
name,
|
110
168
|
activeExports,
|
111
169
|
otherStarExports,
|
112
|
-
strictExportPresence
|
170
|
+
strictExportPresence,
|
171
|
+
allStarExports
|
113
172
|
) {
|
114
173
|
super(request, sourceOrder);
|
115
174
|
|
@@ -118,6 +177,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
118
177
|
this.activeExports = activeExports;
|
119
178
|
this.otherStarExports = otherStarExports;
|
120
179
|
this.strictExportPresence = strictExportPresence;
|
180
|
+
this.allStarExports = allStarExports;
|
181
|
+
this._getMode = this._getMode.bind(this);
|
121
182
|
}
|
122
183
|
|
123
184
|
// TODO webpack 6 remove
|
@@ -162,6 +223,15 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
162
223
|
* @returns {ExportMode} the export mode
|
163
224
|
*/
|
164
225
|
getMode(moduleGraph, runtime) {
|
226
|
+
return moduleGraph.cached(this._getMode, runtime);
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
231
|
+
* @param {RuntimeSpec} runtime the runtime
|
232
|
+
* @returns {ExportMode} the export mode
|
233
|
+
*/
|
234
|
+
_getMode(moduleGraph, runtime) {
|
165
235
|
const name = this.name;
|
166
236
|
const ids = this.getIds(moduleGraph);
|
167
237
|
const parentModule = moduleGraph.getParentModule(this);
|
@@ -300,10 +370,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
300
370
|
checked.has(exportName),
|
301
371
|
false
|
302
372
|
)
|
303
|
-
)
|
304
|
-
|
305
|
-
|
306
|
-
|
373
|
+
);
|
374
|
+
if (hidden !== undefined) {
|
375
|
+
for (const exportName of hidden) {
|
376
|
+
mode.items.push(
|
307
377
|
new NormalReexportItem(
|
308
378
|
exportName,
|
309
379
|
[exportName],
|
@@ -311,8 +381,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
311
381
|
false,
|
312
382
|
true
|
313
383
|
)
|
314
|
-
|
315
|
-
|
384
|
+
);
|
385
|
+
}
|
386
|
+
}
|
316
387
|
|
317
388
|
return mode;
|
318
389
|
}
|
@@ -322,7 +393,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
322
393
|
* @param {RuntimeSpec} runtime the runtime
|
323
394
|
* @param {ExportsInfo} exportsInfo exports info about the current module (optional)
|
324
395
|
* @param {Module} importedModule the imported module (optional)
|
325
|
-
* @returns {{exports?: Set<string>, checked?: Set<string>, ignoredExports: Set<string>, hidden
|
396
|
+
* @returns {{exports?: Set<string>, checked?: Set<string>, ignoredExports: Set<string>, hidden?: Set<string>}} information
|
326
397
|
*/
|
327
398
|
getStarReexports(
|
328
399
|
moduleGraph,
|
@@ -338,10 +409,18 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
338
409
|
exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused;
|
339
410
|
|
340
411
|
const ignoredExports = new Set(["default", ...this.activeExports]);
|
341
|
-
|
342
|
-
|
412
|
+
|
413
|
+
let hiddenExports = undefined;
|
414
|
+
const otherStarExports = this._discoverActiveExportsFromOtherStarExports(
|
415
|
+
moduleGraph
|
343
416
|
);
|
344
|
-
|
417
|
+
if (otherStarExports !== undefined) {
|
418
|
+
hiddenExports = new Set();
|
419
|
+
for (let i = 0; i < otherStarExports.namesSlice; i++) {
|
420
|
+
hiddenExports.add(otherStarExports.names[i]);
|
421
|
+
}
|
422
|
+
for (const e of ignoredExports) hiddenExports.delete(e);
|
423
|
+
}
|
345
424
|
|
346
425
|
if (!noExtraExports && !noExtraImports) {
|
347
426
|
return {
|
@@ -355,7 +434,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
355
434
|
/** @type {Set<string>} */
|
356
435
|
const checked = new Set();
|
357
436
|
/** @type {Set<string>} */
|
358
|
-
const hidden = new Set();
|
437
|
+
const hidden = hiddenExports !== undefined ? new Set() : undefined;
|
359
438
|
|
360
439
|
if (noExtraImports) {
|
361
440
|
for (const exportInfo of exportsInfo.orderedExports) {
|
@@ -366,7 +445,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
366
445
|
name
|
367
446
|
);
|
368
447
|
if (importedExportInfo.provided === false) continue;
|
369
|
-
if (hiddenExports.has(name)) {
|
448
|
+
if (hiddenExports !== undefined && hiddenExports.has(name)) {
|
370
449
|
hidden.add(name);
|
371
450
|
continue;
|
372
451
|
}
|
@@ -381,7 +460,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
381
460
|
if (importedExportInfo.provided === false) continue;
|
382
461
|
const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
|
383
462
|
if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
|
384
|
-
if (hiddenExports.has(name)) {
|
463
|
+
if (hiddenExports !== undefined && hiddenExports.has(name)) {
|
385
464
|
hidden.add(name);
|
386
465
|
continue;
|
387
466
|
}
|
@@ -481,28 +560,43 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
481
560
|
|
482
561
|
/**
|
483
562
|
* @param {ModuleGraph} moduleGraph the module graph
|
484
|
-
* @returns {
|
563
|
+
* @returns {{ names: string[], namesSlice: number, dependencyIndices: number[], dependencyIndex: number } | undefined} exported names and their origin dependency
|
485
564
|
*/
|
486
565
|
_discoverActiveExportsFromOtherStarExports(moduleGraph) {
|
487
|
-
if (!this.otherStarExports)
|
488
|
-
|
489
|
-
|
566
|
+
if (!this.otherStarExports) return undefined;
|
567
|
+
|
568
|
+
const i =
|
569
|
+
"length" in this.otherStarExports
|
570
|
+
? this.otherStarExports.length
|
571
|
+
: countIterable(this.otherStarExports);
|
572
|
+
if (i === 0) return undefined;
|
573
|
+
|
574
|
+
if (this.allStarExports) {
|
575
|
+
const { names, dependencyIndices } = moduleGraph.cached(
|
576
|
+
determineExportAssignments,
|
577
|
+
this.allStarExports.dependencies
|
578
|
+
);
|
490
579
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
for (const exportInfo of exportsInfo.exports) {
|
498
|
-
if (exportInfo.provided === true && !result.has(exportInfo.name)) {
|
499
|
-
result.set(exportInfo.name, otherStarExport);
|
500
|
-
}
|
501
|
-
}
|
502
|
-
}
|
580
|
+
return {
|
581
|
+
names,
|
582
|
+
namesSlice: dependencyIndices[i - 1],
|
583
|
+
dependencyIndices,
|
584
|
+
dependencyIndex: i
|
585
|
+
};
|
503
586
|
}
|
504
587
|
|
505
|
-
|
588
|
+
const { names, dependencyIndices } = moduleGraph.cached(
|
589
|
+
determineExportAssignments,
|
590
|
+
this.otherStarExports,
|
591
|
+
this
|
592
|
+
);
|
593
|
+
|
594
|
+
return {
|
595
|
+
names,
|
596
|
+
namesSlice: dependencyIndices[i - 1],
|
597
|
+
dependencyIndices,
|
598
|
+
dependencyIndex: i
|
599
|
+
};
|
506
600
|
}
|
507
601
|
|
508
602
|
/**
|
@@ -522,7 +616,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
522
616
|
exports: true,
|
523
617
|
from,
|
524
618
|
canMangle: false,
|
525
|
-
excludeExports:
|
619
|
+
excludeExports: mode.hidden
|
620
|
+
? combine(mode.ignored, mode.hidden)
|
621
|
+
: mode.ignored,
|
526
622
|
hideExports: mode.hidden,
|
527
623
|
dependencies: [from.module]
|
528
624
|
};
|
@@ -670,7 +766,15 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
670
766
|
const potentialConflicts = this._discoverActiveExportsFromOtherStarExports(
|
671
767
|
moduleGraph
|
672
768
|
);
|
673
|
-
if (potentialConflicts.
|
769
|
+
if (potentialConflicts && potentialConflicts.namesSlice > 0) {
|
770
|
+
const ownNames = new Set(
|
771
|
+
potentialConflicts.names.slice(
|
772
|
+
potentialConflicts.namesSlice,
|
773
|
+
potentialConflicts.dependencyIndices[
|
774
|
+
potentialConflicts.dependencyIndex
|
775
|
+
]
|
776
|
+
)
|
777
|
+
);
|
674
778
|
const importedModule = moduleGraph.getModule(this);
|
675
779
|
if (importedModule) {
|
676
780
|
const exportsInfo = moduleGraph.getExportsInfo(importedModule);
|
@@ -679,8 +783,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
679
783
|
if (exportInfo.provided !== true) continue;
|
680
784
|
if (exportInfo.name === "default") continue;
|
681
785
|
if (this.activeExports.has(exportInfo.name)) continue;
|
682
|
-
|
683
|
-
|
786
|
+
if (ownNames.has(exportInfo.name)) continue;
|
787
|
+
const conflictingDependency = findDependencyForName(
|
788
|
+
potentialConflicts,
|
789
|
+
exportInfo.name,
|
790
|
+
this.allStarExports
|
791
|
+
? this.allStarExports.dependencies
|
792
|
+
: [...this.otherStarExports, this]
|
684
793
|
);
|
685
794
|
if (!conflictingDependency) continue;
|
686
795
|
const target = exportInfo.getTerminalBinding(moduleGraph);
|
@@ -726,25 +835,29 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
726
835
|
}
|
727
836
|
|
728
837
|
serialize(context) {
|
729
|
-
const { write } = context;
|
838
|
+
const { write, setCircularReference } = context;
|
730
839
|
|
840
|
+
setCircularReference(this);
|
731
841
|
write(this.ids);
|
732
842
|
write(this.name);
|
733
843
|
write(this.activeExports);
|
734
844
|
write(this.otherStarExports);
|
735
845
|
write(this.strictExportPresence);
|
846
|
+
write(this.allStarExports);
|
736
847
|
|
737
848
|
super.serialize(context);
|
738
849
|
}
|
739
850
|
|
740
851
|
deserialize(context) {
|
741
|
-
const { read } = context;
|
852
|
+
const { read, setCircularReference } = context;
|
742
853
|
|
854
|
+
setCircularReference(this);
|
743
855
|
this.ids = read();
|
744
856
|
this.name = read();
|
745
857
|
this.activeExports = read();
|
746
858
|
this.otherStarExports = read();
|
747
859
|
this.strictExportPresence = read();
|
860
|
+
this.allStarExports = read();
|
748
861
|
|
749
862
|
super.deserialize(context);
|
750
863
|
}
|
@@ -948,7 +1061,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
948
1061
|
break;
|
949
1062
|
|
950
1063
|
case "dynamic-reexport": {
|
951
|
-
const ignored =
|
1064
|
+
const ignored = mode.hidden
|
1065
|
+
? combine(mode.ignored, mode.hidden)
|
1066
|
+
: mode.ignored;
|
952
1067
|
const modern =
|
953
1068
|
runtimeTemplate.supportsConst() &&
|
954
1069
|
runtimeTemplate.supportsArrowFunction();
|
@@ -1089,3 +1204,40 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1089
1204
|
return `${name}${propertyAccess(valueKey)}`;
|
1090
1205
|
}
|
1091
1206
|
};
|
1207
|
+
|
1208
|
+
class HarmonyStarExportsList {
|
1209
|
+
constructor() {
|
1210
|
+
/** @type {HarmonyExportImportedSpecifierDependency[]} */
|
1211
|
+
this.dependencies = [];
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
/**
|
1215
|
+
* @param {HarmonyExportImportedSpecifierDependency} dep dependency
|
1216
|
+
* @returns {void}
|
1217
|
+
*/
|
1218
|
+
push(dep) {
|
1219
|
+
this.dependencies.push(dep);
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
slice() {
|
1223
|
+
return this.dependencies.slice();
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
serialize({ write, setCircularReference }) {
|
1227
|
+
setCircularReference(this);
|
1228
|
+
write(this.dependencies);
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
deserialize({ read, setCircularReference }) {
|
1232
|
+
setCircularReference(this);
|
1233
|
+
this.dependencies = read();
|
1234
|
+
}
|
1235
|
+
}
|
1236
|
+
|
1237
|
+
makeSerializable(
|
1238
|
+
HarmonyStarExportsList,
|
1239
|
+
"webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency",
|
1240
|
+
"HarmonyStarExportsList"
|
1241
|
+
);
|
1242
|
+
|
1243
|
+
module.exports.HarmonyStarExportsList = HarmonyStarExportsList;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const ModuleDependency = require("./ModuleDependency");
|
9
|
+
|
10
|
+
class LoaderImportDependency extends ModuleDependency {
|
11
|
+
/**
|
12
|
+
* @param {string} request request string
|
13
|
+
*/
|
14
|
+
constructor(request) {
|
15
|
+
super(request);
|
16
|
+
this.weak = true;
|
17
|
+
}
|
18
|
+
|
19
|
+
get type() {
|
20
|
+
return "loader import";
|
21
|
+
}
|
22
|
+
|
23
|
+
get category() {
|
24
|
+
return "loaderImport";
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
module.exports = LoaderImportDependency;
|
@@ -8,18 +8,45 @@
|
|
8
8
|
const NormalModule = require("../NormalModule");
|
9
9
|
const LazySet = require("../util/LazySet");
|
10
10
|
const LoaderDependency = require("./LoaderDependency");
|
11
|
+
const LoaderImportDependency = require("./LoaderImportDependency");
|
11
12
|
|
13
|
+
/** @typedef {import("../Compilation").DepConstructor} DepConstructor */
|
14
|
+
/** @typedef {import("../Compiler")} Compiler */
|
12
15
|
/** @typedef {import("../Module")} Module */
|
13
16
|
|
14
17
|
/**
|
15
18
|
* @callback LoadModuleCallback
|
16
19
|
* @param {Error=} err error object
|
17
|
-
* @param {string=} source source code
|
20
|
+
* @param {string | Buffer=} source source code
|
18
21
|
* @param {object=} map source map
|
19
22
|
* @param {Module=} module loaded module if successful
|
20
23
|
*/
|
21
24
|
|
25
|
+
/**
|
26
|
+
* @callback ImportModuleCallback
|
27
|
+
* @param {Error=} err error object
|
28
|
+
* @param {any=} exports exports of the evaluated module
|
29
|
+
*/
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @typedef {Object} ImportModuleOptions
|
33
|
+
* @property {string=} layer the target layer
|
34
|
+
* @property {string=} publicPath the target public path
|
35
|
+
*/
|
36
|
+
|
22
37
|
class LoaderPlugin {
|
38
|
+
/**
|
39
|
+
* @param {Object} options options
|
40
|
+
* @param {boolean=} options.enableExecuteModule execute module enabled
|
41
|
+
*/
|
42
|
+
constructor(options = {}) {
|
43
|
+
this._enableExecuteModule = !!options.enableExecuteModule;
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Apply the plugin
|
47
|
+
* @param {Compiler} compiler the compiler instance
|
48
|
+
* @returns {void}
|
49
|
+
*/
|
23
50
|
apply(compiler) {
|
24
51
|
compiler.hooks.compilation.tap(
|
25
52
|
"LoaderPlugin",
|
@@ -28,6 +55,10 @@ class LoaderPlugin {
|
|
28
55
|
LoaderDependency,
|
29
56
|
normalModuleFactory
|
30
57
|
);
|
58
|
+
compilation.dependencyFactories.set(
|
59
|
+
LoaderImportDependency,
|
60
|
+
normalModuleFactory
|
61
|
+
);
|
31
62
|
}
|
32
63
|
);
|
33
64
|
|
@@ -47,7 +78,7 @@ class LoaderPlugin {
|
|
47
78
|
name: request
|
48
79
|
};
|
49
80
|
const factory = compilation.dependencyFactories.get(
|
50
|
-
dep.constructor
|
81
|
+
/** @type {DepConstructor} */ (dep.constructor)
|
51
82
|
);
|
52
83
|
if (factory === undefined) {
|
53
84
|
return callback(
|
@@ -123,6 +154,107 @@ class LoaderPlugin {
|
|
123
154
|
}
|
124
155
|
);
|
125
156
|
};
|
157
|
+
|
158
|
+
if (this._enableExecuteModule) {
|
159
|
+
/**
|
160
|
+
* @param {string} request the request string to load the module from
|
161
|
+
* @param {ImportModuleOptions=} options options
|
162
|
+
* @param {ImportModuleCallback=} callback callback returning the exports
|
163
|
+
* @returns {void}
|
164
|
+
*/
|
165
|
+
const importModule = (request, options, callback) => {
|
166
|
+
const dep = new LoaderImportDependency(request);
|
167
|
+
dep.loc = {
|
168
|
+
name: request
|
169
|
+
};
|
170
|
+
const factory = compilation.dependencyFactories.get(
|
171
|
+
/** @type {DepConstructor} */ (dep.constructor)
|
172
|
+
);
|
173
|
+
if (factory === undefined) {
|
174
|
+
return callback(
|
175
|
+
new Error(
|
176
|
+
`No module factory available for dependency type: ${dep.constructor.name}`
|
177
|
+
)
|
178
|
+
);
|
179
|
+
}
|
180
|
+
compilation.buildQueue.increaseParallelism();
|
181
|
+
compilation.handleModuleCreation(
|
182
|
+
{
|
183
|
+
factory,
|
184
|
+
dependencies: [dep],
|
185
|
+
originModule: loaderContext._module,
|
186
|
+
contextInfo: {
|
187
|
+
issuerLayer: options.layer
|
188
|
+
},
|
189
|
+
context: loaderContext.context,
|
190
|
+
connectOrigin: false
|
191
|
+
},
|
192
|
+
err => {
|
193
|
+
compilation.buildQueue.decreaseParallelism();
|
194
|
+
if (err) {
|
195
|
+
return callback(err);
|
196
|
+
}
|
197
|
+
const referencedModule = moduleGraph.getModule(dep);
|
198
|
+
if (!referencedModule) {
|
199
|
+
return callback(new Error("Cannot load the module"));
|
200
|
+
}
|
201
|
+
compilation.executeModule(
|
202
|
+
referencedModule,
|
203
|
+
{
|
204
|
+
entryOptions: {
|
205
|
+
publicPath: options.publicPath
|
206
|
+
}
|
207
|
+
},
|
208
|
+
(err, result) => {
|
209
|
+
if (err) return callback(err);
|
210
|
+
for (const d of result.fileDependencies) {
|
211
|
+
loaderContext.addDependency(d);
|
212
|
+
}
|
213
|
+
for (const d of result.contextDependencies) {
|
214
|
+
loaderContext.addContextDependency(d);
|
215
|
+
}
|
216
|
+
for (const d of result.missingDependencies) {
|
217
|
+
loaderContext.addMissingDependency(d);
|
218
|
+
}
|
219
|
+
for (const d of result.buildDependencies) {
|
220
|
+
loaderContext.addBuildDependency(d);
|
221
|
+
}
|
222
|
+
if (result.cacheable === false)
|
223
|
+
loaderContext.cacheable(false);
|
224
|
+
for (const [name, { source, info }] of result.assets) {
|
225
|
+
const { buildInfo } = loaderContext._module;
|
226
|
+
if (!buildInfo.assets) {
|
227
|
+
buildInfo.assets = Object.create(null);
|
228
|
+
buildInfo.assetsInfo = new Map();
|
229
|
+
}
|
230
|
+
buildInfo.assets[name] = source;
|
231
|
+
buildInfo.assetsInfo.set(name, info);
|
232
|
+
}
|
233
|
+
callback(null, result.exports);
|
234
|
+
}
|
235
|
+
);
|
236
|
+
}
|
237
|
+
);
|
238
|
+
};
|
239
|
+
|
240
|
+
/**
|
241
|
+
* @param {string} request the request string to load the module from
|
242
|
+
* @param {ImportModuleOptions} options options
|
243
|
+
* @param {ImportModuleCallback=} callback callback returning the exports
|
244
|
+
* @returns {Promise<any> | void} exports
|
245
|
+
*/
|
246
|
+
loaderContext.importModule = (request, options, callback) => {
|
247
|
+
if (!callback) {
|
248
|
+
return new Promise((resolve, reject) => {
|
249
|
+
importModule(request, options || {}, (err, result) => {
|
250
|
+
if (err) reject(err);
|
251
|
+
else resolve(result);
|
252
|
+
});
|
253
|
+
});
|
254
|
+
}
|
255
|
+
return importModule(request, options || {}, callback);
|
256
|
+
};
|
257
|
+
}
|
126
258
|
}
|
127
259
|
);
|
128
260
|
});
|
@@ -29,9 +29,9 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
29
29
|
compilation => {
|
30
30
|
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
31
31
|
"ArrayPushCallbackChunkFormatPlugin",
|
32
|
-
(chunk, set) => {
|
32
|
+
(chunk, set, { chunkGraph }) => {
|
33
33
|
if (chunk.hasRuntime()) return;
|
34
|
-
if (
|
34
|
+
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
35
35
|
set.add(RuntimeGlobals.onChunksLoaded);
|
36
36
|
set.add(RuntimeGlobals.require);
|
37
37
|
}
|
@@ -31,9 +31,9 @@ class CommonJsChunkFormatPlugin {
|
|
31
31
|
compilation => {
|
32
32
|
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
33
33
|
"CommonJsChunkLoadingPlugin",
|
34
|
-
(chunk, set) => {
|
34
|
+
(chunk, set, { chunkGraph }) => {
|
35
35
|
if (chunk.hasRuntime()) return;
|
36
|
-
if (
|
36
|
+
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
37
37
|
set.add(RuntimeGlobals.require);
|
38
38
|
set.add(RuntimeGlobals.startupEntrypoint);
|
39
39
|
set.add(RuntimeGlobals.externalInstallChunk);
|