webpack 5.90.2 → 5.90.3
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/Compilation.js +1 -1
- package/lib/ContextModule.js +2 -1
- package/lib/CssModule.js +0 -3
- package/lib/DelegatedModule.js +2 -1
- package/lib/DllModule.js +2 -1
- package/lib/ExternalModule.js +2 -1
- package/lib/Module.js +24 -3
- package/lib/MultiCompiler.js +36 -10
- package/lib/NormalModule.js +236 -85
- package/lib/NormalModuleFactory.js +162 -31
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +2 -0
- package/lib/RuntimeModule.js +2 -1
- package/lib/Stats.js +2 -2
- package/lib/asset/RawDataUrlModule.js +2 -1
- package/lib/buildChunkGraph.js +111 -336
- package/lib/container/ContainerEntryModule.js +2 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/RemoteModule.js +2 -1
- package/lib/css/CssLoadingRuntimeModule.js +1 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +15 -5
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +4 -4
- package/lib/hmr/LazyCompilationPlugin.js +2 -1
- package/lib/optimize/ConcatenatedModule.js +2 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -1
- package/lib/sharing/ProvideSharedModule.js +2 -1
- package/lib/util/memoize.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/webpack.js +5 -3
- package/package.json +1 -1
- package/types.d.ts +122 -78
package/lib/NormalModule.js
CHANGED
@@ -49,7 +49,6 @@ const makeSerializable = require("./util/makeSerializable");
|
|
49
49
|
const memoize = require("./util/memoize");
|
50
50
|
|
51
51
|
/** @typedef {import("webpack-sources").Source} Source */
|
52
|
-
/** @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext} NormalModuleLoaderContext */
|
53
52
|
/** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
|
54
53
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
55
54
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
@@ -58,17 +57,23 @@ const memoize = require("./util/memoize");
|
|
58
57
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
59
58
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
60
59
|
/** @typedef {import("./Generator")} Generator */
|
60
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
61
|
+
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
61
62
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
62
63
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
63
64
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
65
|
+
/** @typedef {import("./Module").KnownBuildInfo} KnownBuildInfo */
|
64
66
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
65
67
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
68
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
69
|
+
/** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
|
66
70
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
67
71
|
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
68
72
|
/** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes} JavaScriptModuleTypes */
|
69
73
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
70
74
|
/** @typedef {import("./Parser")} Parser */
|
71
75
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
76
|
+
/** @typedef {import("./ResolverFactory").ResolveContext} ResolveContext */
|
72
77
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
73
78
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
74
79
|
/** @typedef {import("./logging/Logger").Logger} WebpackLogger */
|
@@ -78,6 +83,11 @@ const memoize = require("./util/memoize");
|
|
78
83
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
79
84
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
80
85
|
|
86
|
+
/** @typedef {{[k: string]: any}} ParserOptions */
|
87
|
+
/** @typedef {{[k: string]: any}} GeneratorOptions */
|
88
|
+
|
89
|
+
/** @typedef {UnsafeCacheData & { parser: undefined | Parser, parserOptions: undefined | ParserOptions, generator: undefined | Generator, generatorOptions: undefined | GeneratorOptions }} NormalModuleUnsafeCacheData */
|
90
|
+
|
81
91
|
/**
|
82
92
|
* @typedef {Object} SourceMap
|
83
93
|
* @property {number} version
|
@@ -212,9 +222,9 @@ makeSerializable(
|
|
212
222
|
* @property {string} context context directory for resolving
|
213
223
|
* @property {string=} matchResource path + query of the matched resource (virtual)
|
214
224
|
* @property {Parser} parser the parser used
|
215
|
-
* @property {
|
225
|
+
* @property {ParserOptions=} parserOptions the options of the parser used
|
216
226
|
* @property {Generator} generator the generator used
|
217
|
-
* @property {
|
227
|
+
* @property {GeneratorOptions=} generatorOptions the options of the generator used
|
218
228
|
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
219
229
|
*/
|
220
230
|
|
@@ -264,9 +274,12 @@ class NormalModule extends Module {
|
|
264
274
|
),
|
265
275
|
needBuild: new AsyncSeriesBailHook(["module", "context"])
|
266
276
|
};
|
267
|
-
compilationHooksMap.set(
|
277
|
+
compilationHooksMap.set(
|
278
|
+
compilation,
|
279
|
+
/** @type {NormalModuleCompilationHooks} */ (hooks)
|
280
|
+
);
|
268
281
|
}
|
269
|
-
return hooks;
|
282
|
+
return /** @type {NormalModuleCompilationHooks} */ (hooks);
|
270
283
|
}
|
271
284
|
|
272
285
|
/**
|
@@ -300,11 +313,13 @@ class NormalModule extends Module {
|
|
300
313
|
this.rawRequest = rawRequest;
|
301
314
|
/** @type {boolean} */
|
302
315
|
this.binary = /^(asset|webassembly)\b/.test(type);
|
303
|
-
/** @type {Parser} */
|
316
|
+
/** @type {undefined | Parser} */
|
304
317
|
this.parser = parser;
|
318
|
+
/** @type {undefined | ParserOptions} */
|
305
319
|
this.parserOptions = parserOptions;
|
306
|
-
/** @type {Generator} */
|
320
|
+
/** @type {undefined | Generator} */
|
307
321
|
this.generator = generator;
|
322
|
+
/** @type {undefined | GeneratorOptions} */
|
308
323
|
this.generatorOptions = generatorOptions;
|
309
324
|
/** @type {string} */
|
310
325
|
this.resource = resource;
|
@@ -319,13 +334,22 @@ class NormalModule extends Module {
|
|
319
334
|
}
|
320
335
|
|
321
336
|
// Info from Build
|
322
|
-
/** @type {
|
337
|
+
/** @type {WebpackError | null} */
|
323
338
|
this.error = null;
|
324
|
-
/**
|
339
|
+
/**
|
340
|
+
* @private
|
341
|
+
* @type {Source | null}
|
342
|
+
*/
|
325
343
|
this._source = null;
|
326
|
-
/**
|
344
|
+
/**
|
345
|
+
* @private
|
346
|
+
* @type {Map<string, number> | undefined}
|
347
|
+
**/
|
327
348
|
this._sourceSizes = undefined;
|
328
|
-
/**
|
349
|
+
/**
|
350
|
+
* @private
|
351
|
+
* @type {undefined | SourceTypes}
|
352
|
+
**/
|
329
353
|
this._sourceTypes = undefined;
|
330
354
|
|
331
355
|
// Cache
|
@@ -419,7 +443,7 @@ class NormalModule extends Module {
|
|
419
443
|
// TODO reconsider this for webpack 6
|
420
444
|
if (this.buildInfo) {
|
421
445
|
if (this._sourceTypes === undefined) this.getSourceTypes();
|
422
|
-
for (const type of this._sourceTypes) {
|
446
|
+
for (const type of /** @type {SourceTypes} */ (this._sourceTypes)) {
|
423
447
|
this.size(type);
|
424
448
|
}
|
425
449
|
}
|
@@ -433,15 +457,22 @@ class NormalModule extends Module {
|
|
433
457
|
/**
|
434
458
|
* Module should be unsafe cached. Get data that's needed for that.
|
435
459
|
* This data will be passed to restoreFromUnsafeCache later.
|
436
|
-
* @returns {
|
460
|
+
* @returns {UnsafeCacheData} cached data
|
437
461
|
*/
|
438
462
|
getUnsafeCacheData() {
|
439
|
-
const data =
|
463
|
+
const data =
|
464
|
+
/** @type {NormalModuleUnsafeCacheData} */
|
465
|
+
(super.getUnsafeCacheData());
|
440
466
|
data.parserOptions = this.parserOptions;
|
441
467
|
data.generatorOptions = this.generatorOptions;
|
442
468
|
return data;
|
443
469
|
}
|
444
470
|
|
471
|
+
/**
|
472
|
+
* restore unsafe cache data
|
473
|
+
* @param {NormalModuleUnsafeCacheData} unsafeCacheData data from getUnsafeCacheData
|
474
|
+
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
475
|
+
*/
|
445
476
|
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
446
477
|
this._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
447
478
|
}
|
@@ -466,8 +497,8 @@ class NormalModule extends Module {
|
|
466
497
|
/**
|
467
498
|
* @param {string} context the compilation context
|
468
499
|
* @param {string} name the asset name
|
469
|
-
* @param {string} content the content
|
470
|
-
* @param {string |
|
500
|
+
* @param {string | Buffer} content the content
|
501
|
+
* @param {(string | SourceMap)=} sourceMap an optional source map
|
471
502
|
* @param {Object=} associatedObjectForCache object for caching
|
472
503
|
* @returns {Source} the created source
|
473
504
|
*/
|
@@ -493,7 +524,11 @@ class NormalModule extends Module {
|
|
493
524
|
return new SourceMapSource(
|
494
525
|
content,
|
495
526
|
name,
|
496
|
-
contextifySourceMap(
|
527
|
+
contextifySourceMap(
|
528
|
+
context,
|
529
|
+
/** @type {SourceMap} */ (sourceMap),
|
530
|
+
associatedObjectForCache
|
531
|
+
)
|
497
532
|
);
|
498
533
|
}
|
499
534
|
}
|
@@ -502,12 +537,14 @@ class NormalModule extends Module {
|
|
502
537
|
}
|
503
538
|
|
504
539
|
/**
|
540
|
+
* @private
|
541
|
+
* @template T
|
505
542
|
* @param {ResolverWithOptions} resolver a resolver
|
506
543
|
* @param {WebpackOptions} options webpack options
|
507
544
|
* @param {Compilation} compilation the compilation
|
508
545
|
* @param {InputFileSystem} fs file system from reading
|
509
546
|
* @param {NormalModuleCompilationHooks} hooks the hooks
|
510
|
-
* @returns {NormalModuleLoaderContext} loader context
|
547
|
+
* @returns {import("../declarations/LoaderContext").NormalModuleLoaderContext<T>} loader context
|
511
548
|
*/
|
512
549
|
_createLoaderContext(resolver, options, compilation, fs, hooks) {
|
513
550
|
const { requestShortener } = compilation.runtimeTemplate;
|
@@ -516,16 +553,19 @@ class NormalModule extends Module {
|
|
516
553
|
if (!currentLoader) return "(not in loader scope)";
|
517
554
|
return requestShortener.shorten(currentLoader.loader);
|
518
555
|
};
|
556
|
+
/**
|
557
|
+
* @returns {ResolveContext} resolve context
|
558
|
+
*/
|
519
559
|
const getResolveContext = () => {
|
520
560
|
return {
|
521
561
|
fileDependencies: {
|
522
|
-
add: d => loaderContext.addDependency(d)
|
562
|
+
add: d => /** @type {TODO} */ (loaderContext).addDependency(d)
|
523
563
|
},
|
524
564
|
contextDependencies: {
|
525
|
-
add: d => loaderContext.addContextDependency(d)
|
565
|
+
add: d => /** @type {TODO} */ (loaderContext).addContextDependency(d)
|
526
566
|
},
|
527
567
|
missingDependencies: {
|
528
|
-
add: d => loaderContext.addMissingDependency(d)
|
568
|
+
add: d => /** @type {TODO} */ (loaderContext).addMissingDependency(d)
|
529
569
|
}
|
530
570
|
};
|
531
571
|
};
|
@@ -542,26 +582,41 @@ class NormalModule extends Module {
|
|
542
582
|
contextify.bindContextCache(this.context, compilation.compiler.root)
|
543
583
|
);
|
544
584
|
const utils = {
|
585
|
+
/**
|
586
|
+
* @param {string} context context
|
587
|
+
* @param {string} request request
|
588
|
+
* @returns {string} result
|
589
|
+
*/
|
545
590
|
absolutify: (context, request) => {
|
546
591
|
return context === this.context
|
547
592
|
? getAbsolutifyInContext()(request)
|
548
593
|
: getAbsolutify()(context, request);
|
549
594
|
},
|
595
|
+
/**
|
596
|
+
* @param {string} context context
|
597
|
+
* @param {string} request request
|
598
|
+
* @returns {string} result
|
599
|
+
*/
|
550
600
|
contextify: (context, request) => {
|
551
601
|
return context === this.context
|
552
602
|
? getContextifyInContext()(request)
|
553
603
|
: getContextify()(context, request);
|
554
604
|
},
|
605
|
+
/**
|
606
|
+
* @param {(string | typeof import("./util/Hash"))=} type type
|
607
|
+
* @returns {Hash} hash
|
608
|
+
*/
|
555
609
|
createHash: type => {
|
556
610
|
return createHash(type || compilation.outputOptions.hashFunction);
|
557
611
|
}
|
558
612
|
};
|
613
|
+
/** @type {import("../declarations/LoaderContext").NormalModuleLoaderContext<T>} */
|
559
614
|
const loaderContext = {
|
560
615
|
version: 2,
|
561
616
|
getOptions: schema => {
|
562
617
|
const loader = this.getCurrentLoader(loaderContext);
|
563
618
|
|
564
|
-
let { options } = loader;
|
619
|
+
let { options } = /** @type {LoaderItem} */ (loader);
|
565
620
|
|
566
621
|
if (typeof options === "string") {
|
567
622
|
if (options.startsWith("{") && options.endsWith("}")) {
|
@@ -649,27 +704,39 @@ class NormalModule extends Module {
|
|
649
704
|
};
|
650
705
|
},
|
651
706
|
emitFile: (name, content, sourceMap, assetInfo) => {
|
652
|
-
|
653
|
-
|
654
|
-
|
707
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
708
|
+
|
709
|
+
if (!buildInfo.assets) {
|
710
|
+
buildInfo.assets = Object.create(null);
|
711
|
+
buildInfo.assetsInfo = new Map();
|
655
712
|
}
|
656
|
-
|
657
|
-
|
713
|
+
|
714
|
+
const assets =
|
715
|
+
/** @type {NonNullable<KnownBuildInfo["assets"]>} */
|
716
|
+
(buildInfo.assets);
|
717
|
+
const assetsInfo =
|
718
|
+
/** @type {NonNullable<KnownBuildInfo["assetsInfo"]>} */
|
719
|
+
(buildInfo.assetsInfo);
|
720
|
+
|
721
|
+
assets[name] = this.createSourceForAsset(
|
722
|
+
/** @type {string} */ (options.context),
|
658
723
|
name,
|
659
724
|
content,
|
660
725
|
sourceMap,
|
661
726
|
compilation.compiler.root
|
662
727
|
);
|
663
|
-
|
728
|
+
assetsInfo.set(name, assetInfo);
|
664
729
|
},
|
665
730
|
addBuildDependency: dep => {
|
666
|
-
|
667
|
-
|
731
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
732
|
+
|
733
|
+
if (buildInfo.buildDependencies === undefined) {
|
734
|
+
buildInfo.buildDependencies = new LazySet();
|
668
735
|
}
|
669
|
-
|
736
|
+
buildInfo.buildDependencies.add(dep);
|
670
737
|
},
|
671
738
|
utils,
|
672
|
-
rootContext: options.context,
|
739
|
+
rootContext: /** @type {string} */ (options.context),
|
673
740
|
webpack: true,
|
674
741
|
sourceMap: !!this.useSourceMap,
|
675
742
|
mode: options.mode || "production",
|
@@ -686,6 +753,12 @@ class NormalModule extends Module {
|
|
686
753
|
return loaderContext;
|
687
754
|
}
|
688
755
|
|
756
|
+
// TODO remove `loaderContext` in webpack@6
|
757
|
+
/**
|
758
|
+
* @param {TODO} loaderContext loader context
|
759
|
+
* @param {number} index index
|
760
|
+
* @returns {LoaderItem | null} loader
|
761
|
+
*/
|
689
762
|
getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
|
690
763
|
if (
|
691
764
|
this.loaders &&
|
@@ -702,7 +775,7 @@ class NormalModule extends Module {
|
|
702
775
|
/**
|
703
776
|
* @param {string} context the compilation context
|
704
777
|
* @param {string | Buffer} content the content
|
705
|
-
* @param {string |
|
778
|
+
* @param {(string | SourceMapSource)=} sourceMap an optional source map
|
706
779
|
* @param {Object=} associatedObjectForCache object for caching
|
707
780
|
* @returns {Source} the created source
|
708
781
|
*/
|
@@ -723,7 +796,11 @@ class NormalModule extends Module {
|
|
723
796
|
return new SourceMapSource(
|
724
797
|
content,
|
725
798
|
contextifySourceUrl(context, identifier, associatedObjectForCache),
|
726
|
-
contextifySourceMap(
|
799
|
+
contextifySourceMap(
|
800
|
+
context,
|
801
|
+
/** @type {TODO} */ (sourceMap),
|
802
|
+
associatedObjectForCache
|
803
|
+
)
|
727
804
|
);
|
728
805
|
}
|
729
806
|
|
@@ -791,7 +868,7 @@ class NormalModule extends Module {
|
|
791
868
|
}
|
792
869
|
|
793
870
|
this._source = this.createSource(
|
794
|
-
options.context,
|
871
|
+
/** @type {string} */ (options.context),
|
795
872
|
this.binary ? asBuffer(source) : asString(source),
|
796
873
|
sourceMap,
|
797
874
|
compilation.compiler.root
|
@@ -806,10 +883,12 @@ class NormalModule extends Module {
|
|
806
883
|
return callback();
|
807
884
|
};
|
808
885
|
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
886
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
887
|
+
|
888
|
+
buildInfo.fileDependencies = new LazySet();
|
889
|
+
buildInfo.contextDependencies = new LazySet();
|
890
|
+
buildInfo.missingDependencies = new LazySet();
|
891
|
+
buildInfo.cacheable = true;
|
813
892
|
|
814
893
|
try {
|
815
894
|
hooks.beforeLoaders.call(this.loaders, this, loaderContext);
|
@@ -819,7 +898,8 @@ class NormalModule extends Module {
|
|
819
898
|
}
|
820
899
|
|
821
900
|
if (this.loaders.length > 0) {
|
822
|
-
|
901
|
+
/** @type {BuildInfo} */
|
902
|
+
(this.buildInfo).buildDependencies = new LazySet();
|
823
903
|
}
|
824
904
|
|
825
905
|
runLoaders(
|
@@ -850,19 +930,37 @@ class NormalModule extends Module {
|
|
850
930
|
undefined;
|
851
931
|
|
852
932
|
if (!result) {
|
853
|
-
|
933
|
+
/** @type {BuildInfo} */
|
934
|
+
(this.buildInfo).cacheable = false;
|
854
935
|
return processResult(
|
855
936
|
err || new Error("No result from loader-runner processing"),
|
856
937
|
null
|
857
938
|
);
|
858
939
|
}
|
859
|
-
|
860
|
-
this.buildInfo
|
861
|
-
|
940
|
+
|
941
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
942
|
+
|
943
|
+
const fileDependencies =
|
944
|
+
/** @type {NonNullable<KnownBuildInfo["fileDependencies"]>} */
|
945
|
+
(buildInfo.fileDependencies);
|
946
|
+
const contextDependencies =
|
947
|
+
/** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
|
948
|
+
(buildInfo.contextDependencies);
|
949
|
+
const missingDependencies =
|
950
|
+
/** @type {NonNullable<KnownBuildInfo["missingDependencies"]>} */
|
951
|
+
(buildInfo.missingDependencies);
|
952
|
+
|
953
|
+
fileDependencies.addAll(result.fileDependencies);
|
954
|
+
contextDependencies.addAll(result.contextDependencies);
|
955
|
+
missingDependencies.addAll(result.missingDependencies);
|
862
956
|
for (const loader of this.loaders) {
|
863
|
-
|
957
|
+
const buildDependencies =
|
958
|
+
/** @type {NonNullable<KnownBuildInfo["buildDependencies"]>} */
|
959
|
+
(buildInfo.buildDependencies);
|
960
|
+
|
961
|
+
buildDependencies.add(loader.loader);
|
864
962
|
}
|
865
|
-
|
963
|
+
buildInfo.cacheable = buildInfo.cacheable && result.cacheable;
|
866
964
|
processResult(err, result.result);
|
867
965
|
}
|
868
966
|
);
|
@@ -879,6 +977,11 @@ class NormalModule extends Module {
|
|
879
977
|
this.addError(error);
|
880
978
|
}
|
881
979
|
|
980
|
+
/**
|
981
|
+
* @param {TODO} rule rule
|
982
|
+
* @param {string} content content
|
983
|
+
* @returns {boolean} result
|
984
|
+
*/
|
882
985
|
applyNoParseRule(rule, content) {
|
883
986
|
// must start with "rule" if rule is a string
|
884
987
|
if (typeof rule === "string") {
|
@@ -892,9 +995,11 @@ class NormalModule extends Module {
|
|
892
995
|
return rule.test(content);
|
893
996
|
}
|
894
997
|
|
895
|
-
|
896
|
-
|
897
|
-
|
998
|
+
/**
|
999
|
+
* @param {TODO} noParseRule no parse rule
|
1000
|
+
* @param {string} request request
|
1001
|
+
* @returns {boolean} check if module should not be parsed, returns "true" if the module should !not! be parsed, returns "false" if the module !must! be parsed
|
1002
|
+
*/
|
898
1003
|
shouldPreventParsing(noParseRule, request) {
|
899
1004
|
// if no noParseRule exists, return false
|
900
1005
|
// the module !must! be parsed.
|
@@ -920,6 +1025,10 @@ class NormalModule extends Module {
|
|
920
1025
|
return false;
|
921
1026
|
}
|
922
1027
|
|
1028
|
+
/**
|
1029
|
+
* @param {Compilation} compilation compilation
|
1030
|
+
* @private
|
1031
|
+
*/
|
923
1032
|
_initBuildHash(compilation) {
|
924
1033
|
const hash = createHash(compilation.outputOptions.hashFunction);
|
925
1034
|
if (this._source) {
|
@@ -928,7 +1037,8 @@ class NormalModule extends Module {
|
|
928
1037
|
}
|
929
1038
|
hash.update("meta");
|
930
1039
|
hash.update(JSON.stringify(this.buildMeta));
|
931
|
-
|
1040
|
+
/** @type {BuildInfo} */
|
1041
|
+
(this.buildInfo).hash = /** @type {string} */ (hash.digest("hex"));
|
932
1042
|
}
|
933
1043
|
|
934
1044
|
/**
|
@@ -974,10 +1084,18 @@ class NormalModule extends Module {
|
|
974
1084
|
return callback();
|
975
1085
|
}
|
976
1086
|
|
1087
|
+
/**
|
1088
|
+
* @param {Error} e error
|
1089
|
+
* @returns {void}
|
1090
|
+
*/
|
977
1091
|
const handleParseError = e => {
|
978
|
-
const source = this._source.source();
|
1092
|
+
const source = /** @type {Source} */ (this._source).source();
|
979
1093
|
const loaders = this.loaders.map(item =>
|
980
|
-
contextify(
|
1094
|
+
contextify(
|
1095
|
+
/** @type {string} */ (options.context),
|
1096
|
+
item.loader,
|
1097
|
+
compilation.compiler.root
|
1098
|
+
)
|
981
1099
|
);
|
982
1100
|
const error = new ModuleParseError(source, e, loaders, this.type);
|
983
1101
|
this.markModuleAsErrored(error);
|
@@ -985,7 +1103,7 @@ class NormalModule extends Module {
|
|
985
1103
|
return callback();
|
986
1104
|
};
|
987
1105
|
|
988
|
-
const handleParseResult =
|
1106
|
+
const handleParseResult = () => {
|
989
1107
|
this.dependencies.sort(
|
990
1108
|
concatComparators(
|
991
1109
|
compareSelect(a => a.loc, compareLocations),
|
@@ -993,7 +1111,9 @@ class NormalModule extends Module {
|
|
993
1111
|
)
|
994
1112
|
);
|
995
1113
|
this._initBuildHash(compilation);
|
996
|
-
this._lastSuccessfulBuildMeta =
|
1114
|
+
this._lastSuccessfulBuildMeta =
|
1115
|
+
/** @type {BuildMeta} */
|
1116
|
+
(this.buildMeta);
|
997
1117
|
return handleBuildDone();
|
998
1118
|
};
|
999
1119
|
|
@@ -1006,12 +1126,17 @@ class NormalModule extends Module {
|
|
1006
1126
|
}
|
1007
1127
|
|
1008
1128
|
const snapshotOptions = compilation.options.snapshot.module;
|
1009
|
-
|
1129
|
+
const { cacheable } = /** @type {BuildInfo} */ (this.buildInfo);
|
1130
|
+
if (!cacheable || !snapshotOptions) {
|
1010
1131
|
return callback();
|
1011
1132
|
}
|
1012
1133
|
// add warning for all non-absolute paths in fileDependencies, etc
|
1013
1134
|
// This makes it easier to find problems with watching and/or caching
|
1135
|
+
/** @type {undefined | Set<string>} */
|
1014
1136
|
let nonAbsoluteDependencies = undefined;
|
1137
|
+
/**
|
1138
|
+
* @param {LazySet<string>} deps deps
|
1139
|
+
*/
|
1015
1140
|
const checkDependencies = deps => {
|
1016
1141
|
for (const dep of deps) {
|
1017
1142
|
if (!ABSOLUTE_PATH_REGEX.test(dep)) {
|
@@ -1028,7 +1153,11 @@ class NormalModule extends Module {
|
|
1028
1153
|
);
|
1029
1154
|
if (absolute !== dep && ABSOLUTE_PATH_REGEX.test(absolute)) {
|
1030
1155
|
(depWithoutGlob !== dep
|
1031
|
-
?
|
1156
|
+
? /** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
|
1157
|
+
(
|
1158
|
+
/** @type {BuildInfo} */ (this.buildInfo)
|
1159
|
+
.contextDependencies
|
1160
|
+
)
|
1032
1161
|
: deps
|
1033
1162
|
).add(absolute);
|
1034
1163
|
}
|
@@ -1038,9 +1167,19 @@ class NormalModule extends Module {
|
|
1038
1167
|
}
|
1039
1168
|
}
|
1040
1169
|
};
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1170
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
1171
|
+
const fileDependencies =
|
1172
|
+
/** @type {NonNullable<KnownBuildInfo["fileDependencies"]>} */
|
1173
|
+
(buildInfo.fileDependencies);
|
1174
|
+
const contextDependencies =
|
1175
|
+
/** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
|
1176
|
+
(buildInfo.contextDependencies);
|
1177
|
+
const missingDependencies =
|
1178
|
+
/** @type {NonNullable<KnownBuildInfo["missingDependencies"]>} */
|
1179
|
+
(buildInfo.missingDependencies);
|
1180
|
+
checkDependencies(fileDependencies);
|
1181
|
+
checkDependencies(missingDependencies);
|
1182
|
+
checkDependencies(contextDependencies);
|
1044
1183
|
if (nonAbsoluteDependencies !== undefined) {
|
1045
1184
|
const InvalidDependenciesModuleWarning =
|
1046
1185
|
getInvalidDependenciesModuleWarning();
|
@@ -1051,19 +1190,19 @@ class NormalModule extends Module {
|
|
1051
1190
|
// convert file/context/missingDependencies into filesystem snapshot
|
1052
1191
|
compilation.fileSystemInfo.createSnapshot(
|
1053
1192
|
startTime,
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1193
|
+
fileDependencies,
|
1194
|
+
contextDependencies,
|
1195
|
+
missingDependencies,
|
1057
1196
|
snapshotOptions,
|
1058
1197
|
(err, snapshot) => {
|
1059
1198
|
if (err) {
|
1060
1199
|
this.markModuleAsErrored(err);
|
1061
1200
|
return;
|
1062
1201
|
}
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1202
|
+
buildInfo.fileDependencies = undefined;
|
1203
|
+
buildInfo.contextDependencies = undefined;
|
1204
|
+
buildInfo.missingDependencies = undefined;
|
1205
|
+
buildInfo.snapshot = snapshot;
|
1067
1206
|
return callback();
|
1068
1207
|
}
|
1069
1208
|
);
|
@@ -1082,15 +1221,16 @@ class NormalModule extends Module {
|
|
1082
1221
|
const noParseRule = options.module && options.module.noParse;
|
1083
1222
|
if (this.shouldPreventParsing(noParseRule, this.request)) {
|
1084
1223
|
// We assume that we need module and exports
|
1085
|
-
|
1224
|
+
/** @type {BuildInfo} */
|
1225
|
+
(this.buildInfo).parsed = false;
|
1086
1226
|
this._initBuildHash(compilation);
|
1087
1227
|
return handleBuildDone();
|
1088
1228
|
}
|
1089
1229
|
|
1090
|
-
let result;
|
1091
1230
|
try {
|
1092
|
-
const source = this._source.source();
|
1093
|
-
|
1231
|
+
const source = /** @type {Source} */ (this._source).source();
|
1232
|
+
/** @type {Parser} */
|
1233
|
+
(this.parser).parse(this._ast || source, {
|
1094
1234
|
source,
|
1095
1235
|
current: this,
|
1096
1236
|
module: this,
|
@@ -1098,10 +1238,10 @@ class NormalModule extends Module {
|
|
1098
1238
|
options: options
|
1099
1239
|
});
|
1100
1240
|
} catch (e) {
|
1101
|
-
handleParseError(e);
|
1241
|
+
handleParseError(/** @type {Error} */ (e));
|
1102
1242
|
return;
|
1103
1243
|
}
|
1104
|
-
handleParseResult(
|
1244
|
+
handleParseResult();
|
1105
1245
|
});
|
1106
1246
|
}
|
1107
1247
|
|
@@ -1110,7 +1250,9 @@ class NormalModule extends Module {
|
|
1110
1250
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
1111
1251
|
*/
|
1112
1252
|
getConcatenationBailoutReason(context) {
|
1113
|
-
return
|
1253
|
+
return /** @type {Generator} */ (
|
1254
|
+
this.generator
|
1255
|
+
).getConcatenationBailoutReason(this, context);
|
1114
1256
|
}
|
1115
1257
|
|
1116
1258
|
/**
|
@@ -1162,11 +1304,13 @@ class NormalModule extends Module {
|
|
1162
1304
|
}
|
1163
1305
|
|
1164
1306
|
/**
|
1165
|
-
* @returns {
|
1307
|
+
* @returns {SourceTypes} types available (do not mutate)
|
1166
1308
|
*/
|
1167
1309
|
getSourceTypes() {
|
1168
1310
|
if (this._sourceTypes === undefined) {
|
1169
|
-
this._sourceTypes = this.generator.getTypes(
|
1311
|
+
this._sourceTypes = /** @type {Generator} */ (this.generator).getTypes(
|
1312
|
+
this
|
1313
|
+
);
|
1170
1314
|
}
|
1171
1315
|
return this._sourceTypes;
|
1172
1316
|
}
|
@@ -1189,7 +1333,9 @@ class NormalModule extends Module {
|
|
1189
1333
|
/** @type {Set<string>} */
|
1190
1334
|
const runtimeRequirements = new Set();
|
1191
1335
|
|
1192
|
-
|
1336
|
+
const { parsed } = /** @type {BuildInfo} */ (this.buildInfo);
|
1337
|
+
|
1338
|
+
if (!parsed) {
|
1193
1339
|
runtimeRequirements.add(RuntimeGlobals.module);
|
1194
1340
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
1195
1341
|
runtimeRequirements.add(RuntimeGlobals.thisAsExports);
|
@@ -1261,15 +1407,16 @@ class NormalModule extends Module {
|
|
1261
1407
|
// always try to build in case of an error
|
1262
1408
|
if (this.error) return callback(null, true);
|
1263
1409
|
|
1410
|
+
const { cacheable, snapshot, valueDependencies } =
|
1411
|
+
/** @type {BuildInfo} */ (this.buildInfo);
|
1412
|
+
|
1264
1413
|
// always build when module is not cacheable
|
1265
|
-
if (!
|
1414
|
+
if (!cacheable) return callback(null, true);
|
1266
1415
|
|
1267
1416
|
// build when there is no snapshot to check
|
1268
|
-
if (!
|
1417
|
+
if (!snapshot) return callback(null, true);
|
1269
1418
|
|
1270
1419
|
// build when valueDependencies have changed
|
1271
|
-
/** @type {Map<string, string | Set<string>>} */
|
1272
|
-
const valueDependencies = this.buildInfo.valueDependencies;
|
1273
1420
|
if (valueDependencies) {
|
1274
1421
|
if (!valueCacheVersions) return callback(null, true);
|
1275
1422
|
for (const [key, value] of valueDependencies) {
|
@@ -1288,7 +1435,7 @@ class NormalModule extends Module {
|
|
1288
1435
|
}
|
1289
1436
|
|
1290
1437
|
// check snapshot for validity
|
1291
|
-
fileSystemInfo.checkSnapshotValid(
|
1438
|
+
fileSystemInfo.checkSnapshotValid(snapshot, (err, valid) => {
|
1292
1439
|
if (err) return callback(err);
|
1293
1440
|
if (!valid) return callback(null, true);
|
1294
1441
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
@@ -1316,7 +1463,10 @@ class NormalModule extends Module {
|
|
1316
1463
|
if (cachedSize !== undefined) {
|
1317
1464
|
return cachedSize;
|
1318
1465
|
}
|
1319
|
-
const size = Math.max(
|
1466
|
+
const size = Math.max(
|
1467
|
+
1,
|
1468
|
+
/** @type {Generator} */ (this.generator).getSize(this, type)
|
1469
|
+
);
|
1320
1470
|
if (this._sourceSizes === undefined) {
|
1321
1471
|
this._sourceSizes = new Map();
|
1322
1472
|
}
|
@@ -1336,7 +1486,8 @@ class NormalModule extends Module {
|
|
1336
1486
|
missingDependencies,
|
1337
1487
|
buildDependencies
|
1338
1488
|
) {
|
1339
|
-
const { snapshot, buildDependencies: buildDeps } =
|
1489
|
+
const { snapshot, buildDependencies: buildDeps } =
|
1490
|
+
/** @type {BuildInfo} */ (this.buildInfo);
|
1340
1491
|
if (snapshot) {
|
1341
1492
|
fileDependencies.addAll(snapshot.getFileIterable());
|
1342
1493
|
contextDependencies.addAll(snapshot.getContextIterable());
|
@@ -1346,7 +1497,7 @@ class NormalModule extends Module {
|
|
1346
1497
|
fileDependencies: fileDeps,
|
1347
1498
|
contextDependencies: contextDeps,
|
1348
1499
|
missingDependencies: missingDeps
|
1349
|
-
} = this.buildInfo;
|
1500
|
+
} = /** @type {BuildInfo} */ (this.buildInfo);
|
1350
1501
|
if (fileDeps !== undefined) fileDependencies.addAll(fileDeps);
|
1351
1502
|
if (contextDeps !== undefined) contextDependencies.addAll(contextDeps);
|
1352
1503
|
if (missingDeps !== undefined) missingDependencies.addAll(missingDeps);
|
@@ -1362,7 +1513,7 @@ class NormalModule extends Module {
|
|
1362
1513
|
* @returns {void}
|
1363
1514
|
*/
|
1364
1515
|
updateHash(hash, context) {
|
1365
|
-
hash.update(this.buildInfo.hash);
|
1516
|
+
hash.update(/** @type {BuildInfo} */ (this.buildInfo).hash);
|
1366
1517
|
this.generator.updateHash(hash, {
|
1367
1518
|
module: this,
|
1368
1519
|
...context
|