webpack 5.112.0 → 5.112.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.
- package/bin/webpack.js +13 -7
- package/lib/Compilation.js +198 -61
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -47
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +13 -6
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1312 -312
- package/lib/css/syntax-printer.js +1142 -1025
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +4 -8
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +146 -29
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +18 -19
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
|
@@ -34,23 +34,7 @@ const { fileUrlToPath } = require("../util/identifier");
|
|
|
34
34
|
* @property {AbsolutePath=} outputPath Path to the output file e.g. `path.resolve(__dirname, 'profiling/events.json')`. Defaults to `events.json`.
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* Defines the hook type used by this module.
|
|
39
|
-
* @template T, R
|
|
40
|
-
* @typedef {import("tapable").Hook<T, R>} Hook
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Defines the fake hook type used by this module.
|
|
45
|
-
* @template T
|
|
46
|
-
* @typedef {import("../util/deprecation").FakeHook<T>} FakeHook
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Defines the hook map type used by this module.
|
|
51
|
-
* @template T
|
|
52
|
-
* @typedef {import("tapable").HookMap<T>} HookMap
|
|
53
|
-
*/
|
|
37
|
+
/** @import { FakeHookMarker } from "../util/deprecation" */
|
|
54
38
|
|
|
55
39
|
/**
|
|
56
40
|
* Defines the hook interceptor type used by this module.
|
|
@@ -96,8 +80,7 @@ class Profiler {
|
|
|
96
80
|
|
|
97
81
|
try {
|
|
98
82
|
this.session = new /** @type {Inspector} */ (inspector).Session();
|
|
99
|
-
|
|
100
|
-
(this.session).connect();
|
|
83
|
+
this.session.connect();
|
|
101
84
|
} catch (_) {
|
|
102
85
|
this.session = undefined;
|
|
103
86
|
return Promise.resolve();
|
|
@@ -119,7 +102,7 @@ class Profiler {
|
|
|
119
102
|
* Returns promise for the result.
|
|
120
103
|
* @param {string} method method name
|
|
121
104
|
* @param {import("inspector").Profiler.SetSamplingIntervalParameterType=} params params
|
|
122
|
-
* @returns {Promise<
|
|
105
|
+
* @returns {Promise<Partial<import("inspector").Profiler.StopReturnType> | void>} Promise for the result, `{}` for commands without one
|
|
123
106
|
*/
|
|
124
107
|
sendCommand(method, params) {
|
|
125
108
|
if (this.hasSession()) {
|
|
@@ -151,7 +134,9 @@ class Profiler {
|
|
|
151
134
|
* @returns {Promise<{ profile: { startTime: number, endTime: number } }>} profile result
|
|
152
135
|
*/
|
|
153
136
|
stopProfiling() {
|
|
154
|
-
return
|
|
137
|
+
return /** @type {Promise<import("inspector").Profiler.StopReturnType>} */ (
|
|
138
|
+
this.sendCommand("Profiler.stop")
|
|
139
|
+
).then(({ profile }) => {
|
|
155
140
|
const hrtime = process.hrtime();
|
|
156
141
|
const endTime = hrtime[0] * 1000000 + Math.round(hrtime[1] / 1000);
|
|
157
142
|
// Avoid coverage problems due indirect changes
|
|
@@ -406,18 +391,34 @@ class ProfilingPlugin {
|
|
|
406
391
|
}
|
|
407
392
|
}
|
|
408
393
|
|
|
409
|
-
/**
|
|
394
|
+
/**
|
|
395
|
+
* The part of a tapable `HookInterceptor` this plugin sets: it rewraps each tap.
|
|
396
|
+
* @typedef {{ register?(tap: FullTap): FullTap }} TapInterceptor
|
|
397
|
+
*/
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* What intercepting a tapable `Hook` needs of it. Methods, so every hook fits
|
|
401
|
+
* whatever its arguments, result and additional tap options.
|
|
402
|
+
* @typedef {{ intercept(interceptor: TapInterceptor): void, _fakeHook?: undefined }} HookWithInterceptor
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* What intercepting a tapable `HookMap` needs of it, whatever hook it holds.
|
|
407
|
+
* @typedef {{ for(key: string): HookWithInterceptor, intercept(interceptor: { factory?(key: string, hook: HookWithInterceptor): HookWithInterceptor }): void, _fakeHook?: undefined }} HookMapWithInterceptor
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
/** @typedef {Record<string, HookWithInterceptor | HookMapWithInterceptor | FakeHookMarker>} Hooks */
|
|
410
411
|
|
|
411
412
|
/**
|
|
412
413
|
* Intercepts the taps of a hook or every cached and future hook in a hook map.
|
|
413
|
-
* @param {
|
|
414
|
-
* @param {
|
|
414
|
+
* @param {HookWithInterceptor | HookMapWithInterceptor} hook the hook or hook map
|
|
415
|
+
* @param {TapInterceptor} interceptor what intercepts each tap
|
|
415
416
|
* @returns {void}
|
|
416
417
|
*/
|
|
417
418
|
const interceptTaps = (hook, interceptor) => {
|
|
418
419
|
if ("for" in hook) {
|
|
419
420
|
const { _map } =
|
|
420
|
-
/** @type {
|
|
421
|
+
/** @type {HookMapWithInterceptor & { _map: Map<string, HookWithInterceptor> }} */
|
|
421
422
|
(hook);
|
|
422
423
|
for (const cached of _map.values()) {
|
|
423
424
|
cached.intercept(interceptor);
|
|
@@ -425,8 +426,8 @@ const interceptTaps = (hook, interceptor) => {
|
|
|
425
426
|
hook.intercept({
|
|
426
427
|
/**
|
|
427
428
|
* @param {string} key the key the hook is created for
|
|
428
|
-
* @param {
|
|
429
|
-
* @returns {
|
|
429
|
+
* @param {HookWithInterceptor} created the hook created
|
|
430
|
+
* @returns {HookWithInterceptor} the same hook, intercepted
|
|
430
431
|
*/
|
|
431
432
|
factory: (key, created) => {
|
|
432
433
|
created.intercept(interceptor);
|
|
@@ -533,7 +534,25 @@ const interceptAllCssModulesPluginHooks = (compilation, tracer) => {
|
|
|
533
534
|
);
|
|
534
535
|
};
|
|
535
536
|
|
|
536
|
-
/**
|
|
537
|
+
/**
|
|
538
|
+
* A `sync` tap's function, or a `promise` tap's when `R` is a promise.
|
|
539
|
+
* @template {unknown[]} A the hook's arguments
|
|
540
|
+
* @template R what the tap returns
|
|
541
|
+
* @typedef {(...args: A) => R} PluginFunction
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The callback an `async` tap reports its error or result through.
|
|
546
|
+
* @template R the hook's result
|
|
547
|
+
* @typedef {(error?: Error | null, result?: R) => void} TapCallback
|
|
548
|
+
*/
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* An `async` tap's function, the hook's callback after its arguments.
|
|
552
|
+
* @template {unknown[]} A the hook's arguments
|
|
553
|
+
* @template R the hook's result
|
|
554
|
+
* @typedef {(...args: [...A, TapCallback<R>]) => void} AsyncPluginFunction
|
|
555
|
+
*/
|
|
537
556
|
|
|
538
557
|
/**
|
|
539
558
|
* Creates interceptor for.
|
|
@@ -556,7 +575,7 @@ const makeInterceptorFor = (instance, tracer) => (hookName) => ({
|
|
|
556
575
|
: makeNewProfiledTapFn(hookName, tracer, {
|
|
557
576
|
name,
|
|
558
577
|
type,
|
|
559
|
-
fn:
|
|
578
|
+
fn: internalFn
|
|
560
579
|
});
|
|
561
580
|
return { ...tapInfo, fn: newFn };
|
|
562
581
|
}
|
|
@@ -564,20 +583,22 @@ const makeInterceptorFor = (instance, tracer) => (hookName) => ({
|
|
|
564
583
|
|
|
565
584
|
/**
|
|
566
585
|
* Creates new profiled tap fn.
|
|
586
|
+
* @template {unknown[]} A the hook's arguments
|
|
587
|
+
* @template R the hook's result
|
|
567
588
|
* @param {string} hookName Name of the hook to profile.
|
|
568
589
|
* @param {Trace} tracer The trace object.
|
|
569
590
|
* @param {object} options Options for the profiled fn.
|
|
570
591
|
* @param {string} options.name Plugin name
|
|
571
592
|
* @param {"sync" | "async" | "promise"} options.type Plugin type (sync | async | promise)
|
|
572
|
-
* @param {
|
|
573
|
-
* @returns {
|
|
593
|
+
* @param {FullTap["fn"]} options.fn Plugin function, its shape set by `options.type`
|
|
594
|
+
* @returns {FullTap["fn"]} Chainable hooked function.
|
|
574
595
|
*/
|
|
575
596
|
const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
576
597
|
const defaultCategory = ["blink.user_timing"];
|
|
577
598
|
|
|
578
599
|
switch (type) {
|
|
579
600
|
case "promise":
|
|
580
|
-
return (...args) => {
|
|
601
|
+
return /** @type {PluginFunction<A, Promise<R>>} */ (...args) => {
|
|
581
602
|
const id = ++tracer.counter;
|
|
582
603
|
tracer.trace.begin({
|
|
583
604
|
name,
|
|
@@ -585,8 +606,8 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
|
585
606
|
cat: defaultCategory
|
|
586
607
|
});
|
|
587
608
|
const promise =
|
|
588
|
-
/** @type {Promise<
|
|
589
|
-
(fn(...args)
|
|
609
|
+
/** @type {PluginFunction<A, Promise<R>>} */
|
|
610
|
+
(fn)(...args);
|
|
590
611
|
return promise.then((r) => {
|
|
591
612
|
tracer.trace.end({
|
|
592
613
|
name,
|
|
@@ -597,19 +618,20 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
|
597
618
|
});
|
|
598
619
|
};
|
|
599
620
|
case "async":
|
|
600
|
-
return (...args) => {
|
|
621
|
+
return /** @type {AsyncPluginFunction<A, R>} */ (...args) => {
|
|
601
622
|
const id = ++tracer.counter;
|
|
602
623
|
tracer.trace.begin({
|
|
603
624
|
name,
|
|
604
625
|
id,
|
|
605
626
|
cat: defaultCategory
|
|
606
627
|
});
|
|
607
|
-
const callback = args.pop();
|
|
608
|
-
fn(
|
|
609
|
-
|
|
628
|
+
const callback = /** @type {TapCallback<R>} */ (args.pop());
|
|
629
|
+
/** @type {AsyncPluginFunction<A, R>} */ (fn)(
|
|
630
|
+
// `pop()` took the callback off, which the tuple type cannot follow.
|
|
631
|
+
.../** @type {A} */ (/** @type {unknown[]} */ (args)),
|
|
610
632
|
/**
|
|
611
633
|
* Handles the cat callback for this hook.
|
|
612
|
-
* @param {
|
|
634
|
+
* @param {Parameters<TapCallback<R>>} r result
|
|
613
635
|
*/
|
|
614
636
|
(...r) => {
|
|
615
637
|
tracer.trace.end({
|
|
@@ -622,12 +644,12 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
|
622
644
|
);
|
|
623
645
|
};
|
|
624
646
|
case "sync":
|
|
625
|
-
return (...args) => {
|
|
647
|
+
return /** @type {PluginFunction<A, R>} */ (...args) => {
|
|
626
648
|
const id = ++tracer.counter;
|
|
627
649
|
// Do not instrument ourself due to the CPU
|
|
628
650
|
// profile needing to be the last event in the trace.
|
|
629
651
|
if (name === PLUGIN_NAME) {
|
|
630
|
-
return fn(...args);
|
|
652
|
+
return /** @type {PluginFunction<A, R>} */ (fn)(...args);
|
|
631
653
|
}
|
|
632
654
|
|
|
633
655
|
tracer.trace.begin({
|
|
@@ -635,10 +657,10 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
|
635
657
|
id,
|
|
636
658
|
cat: defaultCategory
|
|
637
659
|
});
|
|
638
|
-
/** @type {
|
|
660
|
+
/** @type {R} */
|
|
639
661
|
let r;
|
|
640
662
|
try {
|
|
641
|
-
r = fn(...args);
|
|
663
|
+
r = /** @type {PluginFunction<A, R>} */ (fn)(...args);
|
|
642
664
|
} catch (err) {
|
|
643
665
|
tracer.trace.end({
|
|
644
666
|
name,
|
|
@@ -255,7 +255,7 @@ const dropTrailingMembers = (node, count) => {
|
|
|
255
255
|
|
|
256
256
|
/**
|
|
257
257
|
* Returns code converted to string that evaluates.
|
|
258
|
-
* @param {
|
|
258
|
+
* @param {CodeValue[] | Record<string, CodeValue>} obj obj
|
|
259
259
|
* @param {JavascriptParser} parser Parser
|
|
260
260
|
* @param {ValueCacheVersions} valueCacheVersions valueCacheVersions
|
|
261
261
|
* @param {string} key the defined key
|
|
@@ -376,7 +376,7 @@ const toCode = (
|
|
|
376
376
|
}
|
|
377
377
|
if (typeof code === "object") {
|
|
378
378
|
return stringifyObj(
|
|
379
|
-
code,
|
|
379
|
+
/** @type {CodeValue[] | Record<string, CodeValue>} */ (code),
|
|
380
380
|
parser,
|
|
381
381
|
valueCacheVersions,
|
|
382
382
|
key,
|
|
@@ -675,7 +675,7 @@ const stringifyMergedNode = (merged, node, parser, key, objKeys) => {
|
|
|
675
675
|
}
|
|
676
676
|
const code = `{${keys
|
|
677
677
|
.map((k) => {
|
|
678
|
-
const value =
|
|
678
|
+
const value = node.get(k);
|
|
679
679
|
return `${toPropertyKey(k)}:${
|
|
680
680
|
value instanceof Map
|
|
681
681
|
? stringifyMergedNode(merged, value, parser, k)
|
|
@@ -1115,7 +1115,9 @@ class DefinePlugin {
|
|
|
1115
1115
|
// so scanning that text cannot find every reference.
|
|
1116
1116
|
const hasPreparsedAst =
|
|
1117
1117
|
/** @type {{ _ast: PreparsedAst | null }} */ (
|
|
1118
|
-
/** @type {
|
|
1118
|
+
/** @type {NormalModule | { _ast: PreparsedAst | null }} */ (
|
|
1119
|
+
module
|
|
1120
|
+
)
|
|
1119
1121
|
)._ast !== null;
|
|
1120
1122
|
await resolveAsyncRuntimeValues(
|
|
1121
1123
|
compilation,
|
|
@@ -1139,9 +1141,7 @@ class DefinePlugin {
|
|
|
1139
1141
|
/** @type {ValueCacheVersion} */
|
|
1140
1142
|
(compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
|
|
1141
1143
|
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
|
1142
|
-
const buildInfo =
|
|
1143
|
-
parser.state.module.buildInfo
|
|
1144
|
-
);
|
|
1144
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
1145
1145
|
if (!buildInfo.valueDependencies) {
|
|
1146
1146
|
buildInfo.valueDependencies = new Map();
|
|
1147
1147
|
}
|
|
@@ -1153,9 +1153,7 @@ class DefinePlugin {
|
|
|
1153
1153
|
* @param {string} key key
|
|
1154
1154
|
*/
|
|
1155
1155
|
const addValueDependency = (key) => {
|
|
1156
|
-
const buildInfo =
|
|
1157
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1158
|
-
(parser.state.module.buildInfo);
|
|
1156
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
1159
1157
|
/** @type {NonNullable<NormalModuleBuildInfo["valueDependencies"]>} */
|
|
1160
1158
|
(buildInfo.valueDependencies).set(
|
|
1161
1159
|
VALUE_DEP_PREFIX + key,
|
|
@@ -1229,7 +1227,7 @@ class DefinePlugin {
|
|
|
1229
1227
|
// several DefinePlugins can still be destructured together
|
|
1230
1228
|
const nestedSet = mergedDefinitions.nestedByFinalKey.get(final);
|
|
1231
1229
|
if (!nestedSet || nestedSet.size <= 0) return;
|
|
1232
|
-
for (const nested of
|
|
1230
|
+
for (const nested of nestedSet) {
|
|
1233
1231
|
if (nested && !hooked.has(nested)) {
|
|
1234
1232
|
// only detect the same nested key once
|
|
1235
1233
|
hooked.add(nested);
|
|
@@ -1475,10 +1473,7 @@ class DefinePlugin {
|
|
|
1475
1473
|
parser.hooks.expression.for(key).tap(PLUGIN_NAME, (expr) => {
|
|
1476
1474
|
const valueDependencies =
|
|
1477
1475
|
/** @type {NonNullable<NormalModuleBuildInfo["valueDependencies"]>} */
|
|
1478
|
-
(
|
|
1479
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1480
|
-
(parser.state.module.buildInfo).valueDependencies
|
|
1481
|
-
);
|
|
1476
|
+
(parser.state.module.buildInfo.valueDependencies);
|
|
1482
1477
|
for (const [name, version] of objectValueDependencies) {
|
|
1483
1478
|
valueDependencies.set(name, version);
|
|
1484
1479
|
}
|
|
@@ -281,7 +281,11 @@ class DotenvPlugin {
|
|
|
281
281
|
{
|
|
282
282
|
name: "Dotenv Plugin",
|
|
283
283
|
baseDataPath: "options"
|
|
284
|
-
}
|
|
284
|
+
},
|
|
285
|
+
(options) =>
|
|
286
|
+
require("../../schemas/plugins/define/DotenvPluginOptions.check")(
|
|
287
|
+
options
|
|
288
|
+
)
|
|
285
289
|
);
|
|
286
290
|
});
|
|
287
291
|
const definePlugin = new compiler.webpack.DefinePlugin({});
|
|
@@ -491,6 +495,8 @@ class DotenvPlugin {
|
|
|
491
495
|
* @returns {Env} env variables
|
|
492
496
|
*/
|
|
493
497
|
_getEnv(prefixes, parsed) {
|
|
498
|
+
// Expansion mutates its input, but the cache must retain the raw file values.
|
|
499
|
+
parsed = Object.assign(/** @type {Env} */ (Object.create(null)), parsed);
|
|
494
500
|
// Always expand environment variables (like Vite does)
|
|
495
501
|
// Make a copy of process.env so that dotenv-expand doesn't modify global process.env
|
|
496
502
|
const processEnv = { ...process.env };
|
|
@@ -503,11 +509,9 @@ class DotenvPlugin {
|
|
|
503
509
|
// Prioritize actual env variables from `process.env`, fallback to parsed
|
|
504
510
|
for (const key of keys) {
|
|
505
511
|
if (prefixes.some((prefix) => key.startsWith(prefix))) {
|
|
506
|
-
env[key] =
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
? process.env[key]
|
|
510
|
-
: parsed[key];
|
|
512
|
+
env[key] = Object.prototype.hasOwnProperty.call(process.env, key)
|
|
513
|
+
? /** @type {string} */ (process.env[key])
|
|
514
|
+
: parsed[key];
|
|
511
515
|
}
|
|
512
516
|
}
|
|
513
517
|
|
|
@@ -10,23 +10,25 @@ const DefinePlugin = require("./DefinePlugin");
|
|
|
10
10
|
|
|
11
11
|
/** @import Compiler from "../Compiler" */
|
|
12
12
|
/** @import { CodeValue } from "./DefinePlugin" */
|
|
13
|
+
/** @import { JsonObject } from "../fs/fs" */
|
|
13
14
|
|
|
14
15
|
const PLUGIN_NAME = "EnvironmentPlugin";
|
|
15
16
|
|
|
16
17
|
class EnvironmentPlugin {
|
|
17
18
|
/**
|
|
18
19
|
* Creates an instance of EnvironmentPlugin.
|
|
19
|
-
* @param {(string | string[] |
|
|
20
|
+
* @param {(string | string[] | JsonObject)[]} keys keys
|
|
20
21
|
*/
|
|
21
22
|
constructor(...keys) {
|
|
22
23
|
if (keys.length === 1 && Array.isArray(keys[0])) {
|
|
23
24
|
/** @type {string[]} */
|
|
24
25
|
this.keys = keys[0];
|
|
26
|
+
/** @type {JsonObject} */
|
|
25
27
|
this.defaultValues = {};
|
|
26
28
|
} else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") {
|
|
27
29
|
this.keys = Object.keys(keys[0]);
|
|
28
30
|
this.defaultValues =
|
|
29
|
-
/** @type {
|
|
31
|
+
/** @type {JsonObject} */
|
|
30
32
|
(keys[0]);
|
|
31
33
|
} else {
|
|
32
34
|
this.keys = /** @type {string[]} */ (keys);
|
|
@@ -36,7 +36,6 @@ const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
|
|
|
36
36
|
* } from "../../../declarations/WebpackOptions"
|
|
37
37
|
*/
|
|
38
38
|
/** @import Dependency from "../../graph/Dependency" */
|
|
39
|
-
/** @import { BuildInfo } from "../../module/Module" */
|
|
40
39
|
/** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
|
|
41
40
|
/**
|
|
42
41
|
* @import JavascriptParser, {
|
|
@@ -356,7 +355,7 @@ class AMDDefineDependencyParserPlugin {
|
|
|
356
355
|
}
|
|
357
356
|
DynamicExports.bailout(parser.state);
|
|
358
357
|
recordOptimizationBailout(
|
|
359
|
-
|
|
358
|
+
parser.state.module.buildInfo,
|
|
360
359
|
"AMD bailout: define() prevents static exports analysis"
|
|
361
360
|
);
|
|
362
361
|
/** @type {Identifier[] | null} */
|
|
@@ -39,6 +39,7 @@ const getUnsupportedFeatureWarning = memoize(() =>
|
|
|
39
39
|
* } from "../../../declarations/WebpackOptions"
|
|
40
40
|
*/
|
|
41
41
|
/** @import Dependency, { DependencyLocation } from "../../graph/Dependency" */
|
|
42
|
+
/** @import DependenciesBlock from "../../graph/DependenciesBlock" */
|
|
42
43
|
/** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
|
|
43
44
|
/** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */
|
|
44
45
|
/** @import LocalModule from "./LocalModule" */
|
|
@@ -323,7 +324,9 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
|
323
324
|
dep.loc = parser.getLocation(expr);
|
|
324
325
|
depBlock.addDependency(dep);
|
|
325
326
|
|
|
326
|
-
parser.state.current = /** @type {
|
|
327
|
+
parser.state.current = /** @type {typeof parser.state.current} */ (
|
|
328
|
+
/** @type {DependenciesBlock} */ (depBlock)
|
|
329
|
+
);
|
|
327
330
|
}
|
|
328
331
|
|
|
329
332
|
if (expr.arguments.length === 1) {
|
|
@@ -36,7 +36,6 @@ const {
|
|
|
36
36
|
/** @import ExportsInfo, { ExportInfo } from "../../graph/ExportsInfo" */
|
|
37
37
|
/** @import Module from "../../module/Module" */
|
|
38
38
|
/** @import ModuleGraph from "../../graph/ModuleGraph" */
|
|
39
|
-
/** @import ModuleGraphConnection from "../../graph/ModuleGraphConnection" */
|
|
40
39
|
/** @import { Range } from "../../javascript/JavascriptParser" */
|
|
41
40
|
/** @import { RuntimeSpec } from "../../util/runtime" */
|
|
42
41
|
/** @import CommonJsRequireDependency from "./CommonJsRequireDependency" */
|
|
@@ -576,9 +575,7 @@ CommonJsExportRequireDependency.Template = class CommonJsExportRequireDependency
|
|
|
576
575
|
moduleGraph.getExportsInfo(module).getUsedName(dep.names, runtime)
|
|
577
576
|
);
|
|
578
577
|
|
|
579
|
-
const connection =
|
|
580
|
-
moduleGraph.getConnection(dep)
|
|
581
|
-
);
|
|
578
|
+
const connection = moduleGraph.getConnection(dep);
|
|
582
579
|
// Inactive unused reexport: no module id; drop to a no-op.
|
|
583
580
|
// Missing connection (e.g. IgnorePlugin) must keep the require so it throws.
|
|
584
581
|
if (!used && connection && !connection.isTargetActive(runtime)) {
|
|
@@ -52,7 +52,6 @@ const FUNCTION_PROPERTY_DROP_HEAD =
|
|
|
52
52
|
*/
|
|
53
53
|
/** @import CommonJsRequireDependency from "./CommonJsRequireDependency" */
|
|
54
54
|
/** @import { ExportInfoName } from "../../graph/Dependency" */
|
|
55
|
-
/** @import { BuildInfo } from "../../module/Module" */
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* @import JavascriptParser, {
|
|
@@ -72,11 +71,6 @@ const FUNCTION_PROPERTY_DROP_HEAD =
|
|
|
72
71
|
* } from "./CommonJsObjectExportDependency"
|
|
73
72
|
*/
|
|
74
73
|
/** @import { RequireBindingData } from "./CommonJsImportsParserPlugin" */
|
|
75
|
-
/**
|
|
76
|
-
* @import {
|
|
77
|
-
* JavascriptModuleBuildMeta
|
|
78
|
-
* } from "../../javascript/JavascriptModule"
|
|
79
|
-
*/
|
|
80
74
|
|
|
81
75
|
/**
|
|
82
76
|
* This function takes a generic expression and detects whether it is an ObjectExpression.
|
|
@@ -165,7 +159,7 @@ const getReexportOfPropertyDescriptor = (expr) => {
|
|
|
165
159
|
if (getFn.async || getFn.generator) return;
|
|
166
160
|
// Arrow with expression body: `() => require("./x")`.
|
|
167
161
|
if (getFn.body.type !== "BlockStatement") {
|
|
168
|
-
return { expr:
|
|
162
|
+
return { expr: getFn.body, getter: true };
|
|
169
163
|
}
|
|
170
164
|
// Function body must be exactly `return <expr>;`.
|
|
171
165
|
if (
|
|
@@ -264,15 +258,18 @@ const parseRequireCall = (parser, expr) => {
|
|
|
264
258
|
};
|
|
265
259
|
};
|
|
266
260
|
|
|
261
|
+
/** @typedef {Node extends infer N ? (N extends Node ? N[keyof N] : never) : never} NodeFieldValue */
|
|
262
|
+
|
|
267
263
|
/**
|
|
268
264
|
* Checks if a value is an AST node.
|
|
269
|
-
* @
|
|
270
|
-
* @
|
|
265
|
+
* @template V
|
|
266
|
+
* @param {V} value candidate
|
|
267
|
+
* @returns {value is Extract<V, Node>} true when the value is an AST node
|
|
271
268
|
*/
|
|
272
269
|
const isNode = (value) =>
|
|
273
270
|
typeof value === "object" &&
|
|
274
271
|
value !== null &&
|
|
275
|
-
typeof (/** @type {
|
|
272
|
+
typeof (/** @type {Partial<Node>} */ (value).type) === "string";
|
|
276
273
|
|
|
277
274
|
/** Positional/metadata keys that never hold child AST nodes. */
|
|
278
275
|
const NON_CHILD_KEYS = new Set([
|
|
@@ -337,8 +334,8 @@ const findOwnThisExpression = (body, params) => {
|
|
|
337
334
|
break;
|
|
338
335
|
default: {
|
|
339
336
|
const children =
|
|
340
|
-
/** @type {Record<string,
|
|
341
|
-
(
|
|
337
|
+
/** @type {Node & Record<string, NodeFieldValue>} */
|
|
338
|
+
(node);
|
|
342
339
|
const keys = getChildKeys(node);
|
|
343
340
|
for (let i = 0; i < keys.length; i++) {
|
|
344
341
|
const value = children[keys[i]];
|
|
@@ -462,11 +459,11 @@ class CommonJsExportsParserPlugin {
|
|
|
462
459
|
*/
|
|
463
460
|
const bailoutHint = (reason) => {
|
|
464
461
|
recordOptimizationBailout(
|
|
465
|
-
|
|
462
|
+
parser.state.module.buildInfo,
|
|
466
463
|
`CommonJS bailout: ${reason}`
|
|
467
464
|
);
|
|
468
465
|
};
|
|
469
|
-
/** @type {
|
|
466
|
+
/** @type {JavascriptParser["state"] | undefined} */
|
|
470
467
|
let keptAllExportsForState;
|
|
471
468
|
/**
|
|
472
469
|
* An exported function accessing its own `this` may reach any export
|
|
@@ -547,9 +544,7 @@ class CommonJsExportsParserPlugin {
|
|
|
547
544
|
dep.loc = parser.getLocation(expr);
|
|
548
545
|
dep.optional = Boolean(parser.scope.inTry);
|
|
549
546
|
parser.state.module.addDependency(dep);
|
|
550
|
-
|
|
551
|
-
parser.state.module.buildMeta
|
|
552
|
-
).treatAsCommonJs = true;
|
|
547
|
+
parser.state.module.buildMeta.treatAsCommonJs = true;
|
|
553
548
|
|
|
554
549
|
return true;
|
|
555
550
|
}
|
|
@@ -574,9 +569,7 @@ class CommonJsExportsParserPlugin {
|
|
|
574
569
|
);
|
|
575
570
|
dep.loc = parser.getLocation(expr);
|
|
576
571
|
parser.state.module.addDependency(dep);
|
|
577
|
-
|
|
578
|
-
parser.state.module.buildMeta
|
|
579
|
-
).treatAsCommonJs = true;
|
|
572
|
+
parser.state.module.buildMeta.treatAsCommonJs = true;
|
|
580
573
|
keepAllExportsOnThisAccess(expr.right, base);
|
|
581
574
|
parser.walkExpression(expr.right);
|
|
582
575
|
return true;
|
|
@@ -600,9 +593,7 @@ class CommonJsExportsParserPlugin {
|
|
|
600
593
|
if (object.type !== "ObjectExpression") return;
|
|
601
594
|
|
|
602
595
|
const module = parser.state.module;
|
|
603
|
-
|
|
604
|
-
module.buildMeta
|
|
605
|
-
).treatAsCommonJs = true;
|
|
596
|
+
module.buildMeta.treatAsCommonJs = true;
|
|
606
597
|
// LHS stays as the text `module.exports` (moduleArgument is "module"
|
|
607
598
|
// unless a top-level `module` binding shadows it, which prevents this hook).
|
|
608
599
|
module.addPresentationalDependency(
|
|
@@ -697,7 +688,7 @@ class CommonJsExportsParserPlugin {
|
|
|
697
688
|
parser.hooks.call
|
|
698
689
|
.for("Object.defineProperty")
|
|
699
690
|
.tap(PLUGIN_NAME, (expression) => {
|
|
700
|
-
const expr =
|
|
691
|
+
const expr = expression;
|
|
701
692
|
if (!parser.isStatementLevelExpression(expr)) return;
|
|
702
693
|
if (expr.arguments.length !== 3) return;
|
|
703
694
|
if (expr.arguments[0].type === "SpreadElement") return;
|
|
@@ -747,9 +738,7 @@ class CommonJsExportsParserPlugin {
|
|
|
747
738
|
dep.loc = parser.getLocation(expr);
|
|
748
739
|
dep.optional = Boolean(parser.scope.inTry);
|
|
749
740
|
parser.state.module.addDependency(dep);
|
|
750
|
-
|
|
751
|
-
parser.state.module.buildMeta
|
|
752
|
-
).treatAsCommonJs = true;
|
|
741
|
+
parser.state.module.buildMeta.treatAsCommonJs = true;
|
|
753
742
|
|
|
754
743
|
return true;
|
|
755
744
|
}
|
|
@@ -768,9 +757,7 @@ class CommonJsExportsParserPlugin {
|
|
|
768
757
|
);
|
|
769
758
|
dep.loc = parser.getLocation(expr);
|
|
770
759
|
parser.state.module.addDependency(dep);
|
|
771
|
-
|
|
772
|
-
parser.state.module.buildMeta
|
|
773
|
-
).treatAsCommonJs = true;
|
|
760
|
+
parser.state.module.buildMeta.treatAsCommonJs = true;
|
|
774
761
|
|
|
775
762
|
if (descArg.type === "ObjectExpression") {
|
|
776
763
|
// `value`, `get` and `set` descriptor functions are all called
|
|
@@ -824,9 +811,7 @@ class CommonJsExportsParserPlugin {
|
|
|
824
811
|
);
|
|
825
812
|
dep.loc = parser.getLocation(expr);
|
|
826
813
|
parser.state.module.addDependency(dep);
|
|
827
|
-
|
|
828
|
-
parser.state.module.buildMeta
|
|
829
|
-
).treatAsCommonJs = true;
|
|
814
|
+
parser.state.module.buildMeta.treatAsCommonJs = true;
|
|
830
815
|
|
|
831
816
|
if (call) {
|
|
832
817
|
parser.walkExpressions(call.arguments);
|
|
@@ -189,9 +189,7 @@ const createRequireCallHandler = (
|
|
|
189
189
|
parser,
|
|
190
190
|
expr
|
|
191
191
|
);
|
|
192
|
-
const binding =
|
|
193
|
-
requireBindingData &&
|
|
194
|
-
requireBindingData.get(/** @type {CallExpression} */ (expr));
|
|
192
|
+
const binding = requireBindingData && requireBindingData.get(expr);
|
|
195
193
|
if (binding && !referencedExports) {
|
|
196
194
|
// `const NAME = require(LITERAL)` — let later member-access walks
|
|
197
195
|
// on `NAME` populate the dependency's referenced exports.
|
|
@@ -136,10 +136,10 @@ CommonJsObjectExportDependency.Template = class CommonJsObjectExportDependencyTe
|
|
|
136
136
|
if (!used) {
|
|
137
137
|
// Object spread rewrite needs environment.spread.
|
|
138
138
|
if (!runtimeTemplate.supportsSpread()) return;
|
|
139
|
-
const range =
|
|
139
|
+
const range = dep.range;
|
|
140
140
|
if (FUNCTION_PROPERTY_DROP_HEAD.has(dep.kind)) {
|
|
141
141
|
// Keep the function body so nested dependency replaces stay valid.
|
|
142
|
-
const valueRange =
|
|
142
|
+
const valueRange = dep.valueRange;
|
|
143
143
|
source.replace(
|
|
144
144
|
range[0],
|
|
145
145
|
valueRange[0] - 1,
|
|
@@ -153,7 +153,7 @@ CommonJsObjectExportDependency.Template = class CommonJsObjectExportDependencyTe
|
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
155
|
// keyValue: keep the value's side effects in place.
|
|
156
|
-
const valueRange =
|
|
156
|
+
const valueRange = dep.valueRange;
|
|
157
157
|
if (dep.pure) {
|
|
158
158
|
// spreading null adds nothing; the text stays so nested replaces hold
|
|
159
159
|
source.replace(
|
|
@@ -170,7 +170,7 @@ CommonJsObjectExportDependency.Template = class CommonJsObjectExportDependencyTe
|
|
|
170
170
|
}
|
|
171
171
|
if (used === dep.name) return;
|
|
172
172
|
// Rename the key to the mangled export name.
|
|
173
|
-
const keyRange =
|
|
173
|
+
const keyRange = dep.keyRange;
|
|
174
174
|
if (dep.kind === "shorthand") {
|
|
175
175
|
source.replace(
|
|
176
176
|
keyRange[0],
|
|
@@ -42,7 +42,6 @@ const TopLevelThisParserPlugin = require("./TopLevelThisParserPlugin");
|
|
|
42
42
|
*/
|
|
43
43
|
/** @import Compilation from "../../Compilation" */
|
|
44
44
|
/** @import Compiler from "../../Compiler" */
|
|
45
|
-
/** @import { BuildInfo } from "../../module/Module" */
|
|
46
45
|
/** @import Parser from "../../javascript/JavascriptParser" */
|
|
47
46
|
|
|
48
47
|
const PLUGIN_NAME = "CommonJsPlugin";
|
|
@@ -232,8 +231,7 @@ class CommonJsPlugin {
|
|
|
232
231
|
parser.hooks.expression
|
|
233
232
|
.for(RuntimeGlobals.moduleLoaded)
|
|
234
233
|
.tap(PLUGIN_NAME, (expr) => {
|
|
235
|
-
|
|
236
|
-
(parser.state.module.buildInfo).moduleConcatenationBailout =
|
|
234
|
+
parser.state.module.buildInfo.moduleConcatenationBailout =
|
|
237
235
|
RuntimeGlobals.moduleLoaded;
|
|
238
236
|
const dep = new RuntimeRequirementsDependency([
|
|
239
237
|
RuntimeGlobals.moduleLoaded
|
|
@@ -246,8 +244,7 @@ class CommonJsPlugin {
|
|
|
246
244
|
parser.hooks.expression
|
|
247
245
|
.for(RuntimeGlobals.moduleId)
|
|
248
246
|
.tap(PLUGIN_NAME, (expr) => {
|
|
249
|
-
|
|
250
|
-
(parser.state.module.buildInfo).moduleConcatenationBailout =
|
|
247
|
+
parser.state.module.buildInfo.moduleConcatenationBailout =
|
|
251
248
|
RuntimeGlobals.moduleId;
|
|
252
249
|
const dep = new RuntimeRequirementsDependency([
|
|
253
250
|
RuntimeGlobals.moduleId
|
|
@@ -12,6 +12,7 @@ const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
|
|
|
12
12
|
|
|
13
13
|
/** @import { Expression, SpreadElement } from "estree" */
|
|
14
14
|
/** @import { GroupOptions } from "../../graph/AsyncDependenciesBlock" */
|
|
15
|
+
/** @import DependenciesBlock from "../../graph/DependenciesBlock" */
|
|
15
16
|
/** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
|
|
16
17
|
/** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */
|
|
17
18
|
/** @import { FunctionExpressionResult } from "../helpers/getFunctionExpression" */
|
|
@@ -87,7 +88,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
|
87
88
|
dep.loc = parser.getLocation(expr);
|
|
88
89
|
depBlock.addDependency(dep);
|
|
89
90
|
const old = parser.state.current;
|
|
90
|
-
parser.state.current = /** @type {
|
|
91
|
+
parser.state.current = /** @type {typeof parser.state.current} */ (
|
|
92
|
+
/** @type {DependenciesBlock} */ (depBlock)
|
|
93
|
+
);
|
|
91
94
|
try {
|
|
92
95
|
let failed = false;
|
|
93
96
|
parser.inFunctionScope(true, [], () => {
|