webpack 5.91.0 → 5.92.0
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/bin/webpack.js +1 -2
- package/lib/APIPlugin.js +6 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +20 -7
- package/lib/ChunkGroup.js +9 -3
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +33 -27
- package/lib/Compiler.js +28 -8
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ContextModule.js +95 -43
- package/lib/DefinePlugin.js +14 -4
- package/lib/Dependency.js +8 -8
- package/lib/DependencyTemplate.js +10 -5
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExternalModule.js +49 -18
- package/lib/FileSystemInfo.js +68 -41
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +2 -3
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/Module.js +11 -12
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +29 -16
- package/lib/ModuleGraph.js +5 -5
- package/lib/MultiCompiler.js +36 -1
- package/lib/NormalModule.js +10 -12
- package/lib/NormalModuleFactory.js +17 -8
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeTemplate.js +22 -18
- package/lib/Stats.js +1 -1
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +16 -1
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/buildChunkGraph.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/cache/ResolverCachePlugin.js +8 -8
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +85 -34
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +43 -17
- package/lib/css/CssGenerator.js +22 -12
- package/lib/css/CssLoadingRuntimeModule.js +8 -5
- package/lib/css/CssModulesPlugin.js +197 -100
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
- package/lib/dependencies/CssUrlDependency.js +5 -4
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportEagerDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +63 -49
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +37 -16
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/nodeConsole.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -76
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -8
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +6 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +3 -3
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +4 -2
- package/lib/util/conventions.js +1 -1
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +15 -15
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +12 -3
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +30 -2
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +213 -81
@@ -6,7 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const { Parser: AcornParser } = require("acorn");
|
9
|
-
const {
|
9
|
+
const { importAttributesOrAssertions } = require("acorn-import-attributes");
|
10
10
|
const { SyncBailHook, HookMap } = require("tapable");
|
11
11
|
const vm = require("vm");
|
12
12
|
const Parser = require("../Parser");
|
@@ -88,7 +88,6 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
88
88
|
/** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
|
89
89
|
/** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
|
90
90
|
/** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
|
91
|
-
/** @typedef {Record<string, any>} Attributes */
|
92
91
|
/**
|
93
92
|
* @template T
|
94
93
|
* @typedef {import("tapable").AsArray<T>} AsArray<T>
|
@@ -100,6 +99,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
100
99
|
/** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */
|
101
100
|
/** @typedef {TODO} OnIdent */
|
102
101
|
|
102
|
+
/** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
|
103
|
+
|
103
104
|
/** @type {string[]} */
|
104
105
|
const EMPTY_ARRAY = [];
|
105
106
|
const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
@@ -108,7 +109,7 @@ const ALLOWED_MEMBER_TYPES_ALL = 0b11;
|
|
108
109
|
|
109
110
|
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
110
111
|
|
111
|
-
const parser = AcornParser.extend(
|
112
|
+
const parser = AcornParser.extend(importAttributesOrAssertions);
|
112
113
|
|
113
114
|
class VariableInfo {
|
114
115
|
/**
|
@@ -128,14 +129,14 @@ class VariableInfo {
|
|
128
129
|
/** @typedef {Omit<AcornOptions, "sourceType" | "ecmaVersion"> & { sourceType: "module" | "script" | "auto", ecmaVersion?: AcornOptions["ecmaVersion"] }} ParseOptions */
|
129
130
|
|
130
131
|
/**
|
131
|
-
* @typedef {
|
132
|
+
* @typedef {object} TagInfo
|
132
133
|
* @property {any} tag
|
133
134
|
* @property {any} data
|
134
135
|
* @property {TagInfo | undefined} next
|
135
136
|
*/
|
136
137
|
|
137
138
|
/**
|
138
|
-
* @typedef {
|
139
|
+
* @typedef {object} ScopeInfo
|
139
140
|
* @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
|
140
141
|
* @property {boolean | "arrow"} topLevelScope
|
141
142
|
* @property {boolean | string} inShorthand
|
@@ -147,6 +148,13 @@ class VariableInfo {
|
|
147
148
|
|
148
149
|
/** @typedef {[number, number]} Range */
|
149
150
|
|
151
|
+
/**
|
152
|
+
* @typedef {object} DestructuringAssignmentProperty
|
153
|
+
* @property {string} id
|
154
|
+
* @property {Range | undefined=} range
|
155
|
+
* @property {boolean | string} shorthand
|
156
|
+
*/
|
157
|
+
|
150
158
|
/**
|
151
159
|
* Helper function for joining two ranges into a single range. This is useful
|
152
160
|
* when working with AST nodes, as it allows you to combine the ranges of child nodes
|
@@ -437,7 +445,7 @@ class JavascriptParser extends Parser {
|
|
437
445
|
this.statementPath = undefined;
|
438
446
|
/** @type {Statement | ModuleDeclaration | Expression | undefined} */
|
439
447
|
this.prevStatement = undefined;
|
440
|
-
/** @type {WeakMap<Expression, Set<
|
448
|
+
/** @type {WeakMap<Expression, Set<DestructuringAssignmentProperty>> | undefined} */
|
441
449
|
this.destructuringAssignmentProperties = undefined;
|
442
450
|
this.currentTagData = undefined;
|
443
451
|
this.magicCommentContext = vm.createContext(undefined, {
|
@@ -605,7 +613,7 @@ class JavascriptParser extends Parser {
|
|
605
613
|
*
|
606
614
|
* import("./" + foo + bar); // webpack will auto evaluate this into import("./foobar")
|
607
615
|
* ```
|
608
|
-
* @param {boolean | number |
|
616
|
+
* @param {boolean | number | bigint | string} value the value to convert to an expression
|
609
617
|
* @param {BinaryExpression | UnaryExpression} expr the expression being evaluated
|
610
618
|
* @param {boolean} sideEffects whether the expression has side effects
|
611
619
|
* @returns {BasicEvaluatedExpression | undefined} the evaluated expression
|
@@ -663,7 +671,7 @@ class JavascriptParser extends Parser {
|
|
663
671
|
* Evaluates a binary expression if and only if it is a const operation (e.g. 1 + 2, "a" + "b", etc.).
|
664
672
|
*
|
665
673
|
* @template T
|
666
|
-
* @param {(leftOperand: T, rightOperand: T) => boolean | number |
|
674
|
+
* @param {(leftOperand: T, rightOperand: T) => boolean | number | bigint | string} operandHandler the handler for the operation (e.g. (a, b) => a + b)
|
667
675
|
* @returns {BasicEvaluatedExpression | undefined} the evaluated expression
|
668
676
|
*/
|
669
677
|
const handleConstOperation = operandHandler => {
|
@@ -1076,7 +1084,7 @@ class JavascriptParser extends Parser {
|
|
1076
1084
|
* Evaluates a UnaryExpression if and only if it is a basic const operator (e.g. +a, -a, ~a).
|
1077
1085
|
*
|
1078
1086
|
* @template T
|
1079
|
-
* @param {(operand: T) => boolean | number |
|
1087
|
+
* @param {(operand: T) => boolean | number | bigint | string} operandHandler handler for the operand
|
1080
1088
|
* @returns {BasicEvaluatedExpression | undefined} evaluated expression
|
1081
1089
|
*/
|
1082
1090
|
const handleConstOperation = operandHandler => {
|
@@ -1701,7 +1709,7 @@ class JavascriptParser extends Parser {
|
|
1701
1709
|
|
1702
1710
|
/**
|
1703
1711
|
* @param {Expression} node node
|
1704
|
-
* @returns {Set<
|
1712
|
+
* @returns {Set<DestructuringAssignmentProperty> | undefined} destructured identifiers
|
1705
1713
|
*/
|
1706
1714
|
destructuringAssignmentPropertiesFor(node) {
|
1707
1715
|
if (!this.destructuringAssignmentProperties) return undefined;
|
@@ -2332,7 +2340,7 @@ class JavascriptParser extends Parser {
|
|
2332
2340
|
// check multiple assignments
|
2333
2341
|
if (this.destructuringAssignmentProperties.has(expression)) {
|
2334
2342
|
const set =
|
2335
|
-
/** @type {Set<
|
2343
|
+
/** @type {Set<DestructuringAssignmentProperty>} */
|
2336
2344
|
(this.destructuringAssignmentProperties.get(expression));
|
2337
2345
|
this.destructuringAssignmentProperties.delete(expression);
|
2338
2346
|
for (const id of set) keys.add(id);
|
@@ -2627,30 +2635,43 @@ class JavascriptParser extends Parser {
|
|
2627
2635
|
|
2628
2636
|
/**
|
2629
2637
|
* @param {ObjectPattern} objectPattern object pattern
|
2630
|
-
* @returns {Set<
|
2638
|
+
* @returns {Set<DestructuringAssignmentProperty> | undefined} set of names or undefined if not all keys are identifiers
|
2631
2639
|
*/
|
2632
2640
|
_preWalkObjectPattern(objectPattern) {
|
2633
|
-
|
2641
|
+
/** @type {Set<DestructuringAssignmentProperty>} */
|
2642
|
+
const props = new Set();
|
2634
2643
|
const properties = objectPattern.properties;
|
2635
2644
|
for (let i = 0; i < properties.length; i++) {
|
2636
2645
|
const property = properties[i];
|
2637
2646
|
if (property.type !== "Property") return;
|
2647
|
+
if (property.shorthand && property.value.type === "Identifier") {
|
2648
|
+
this.scope.inShorthand = property.value.name;
|
2649
|
+
}
|
2638
2650
|
const key = property.key;
|
2639
2651
|
if (key.type === "Identifier") {
|
2640
|
-
|
2652
|
+
props.add({
|
2653
|
+
id: key.name,
|
2654
|
+
range: key.range,
|
2655
|
+
shorthand: this.scope.inShorthand
|
2656
|
+
});
|
2641
2657
|
} else {
|
2642
2658
|
const id = this.evaluateExpression(/** @type {TODO} */ (key));
|
2643
2659
|
const str = id.asString();
|
2644
2660
|
if (str) {
|
2645
|
-
|
2661
|
+
props.add({
|
2662
|
+
id: str,
|
2663
|
+
range: key.range,
|
2664
|
+
shorthand: this.scope.inShorthand
|
2665
|
+
});
|
2646
2666
|
} else {
|
2647
2667
|
// could not evaluate key
|
2648
2668
|
return;
|
2649
2669
|
}
|
2650
2670
|
}
|
2671
|
+
this.scope.inShorthand = false;
|
2651
2672
|
}
|
2652
2673
|
|
2653
|
-
return
|
2674
|
+
return props;
|
2654
2675
|
}
|
2655
2676
|
|
2656
2677
|
/**
|
@@ -26,7 +26,7 @@ const COMMON_LIBRARY_NAME_MESSAGE =
|
|
26
26
|
|
27
27
|
/**
|
28
28
|
* @template T
|
29
|
-
* @typedef {
|
29
|
+
* @typedef {object} LibraryContext
|
30
30
|
* @property {Compilation} compilation
|
31
31
|
* @property {ChunkGraph} chunkGraph
|
32
32
|
* @property {T} options
|
@@ -37,7 +37,7 @@ const COMMON_LIBRARY_NAME_MESSAGE =
|
|
37
37
|
*/
|
38
38
|
class AbstractLibraryPlugin {
|
39
39
|
/**
|
40
|
-
* @param {
|
40
|
+
* @param {object} options options
|
41
41
|
* @param {string} options.pluginName name of the plugin
|
42
42
|
* @param {LibraryType} options.type used library type
|
43
43
|
*/
|
@@ -21,13 +21,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
21
21
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
22
22
|
|
23
23
|
/**
|
24
|
-
* @typedef {
|
24
|
+
* @typedef {object} AmdLibraryPluginOptions
|
25
25
|
* @property {LibraryType} type
|
26
26
|
* @property {boolean=} requireAsWrapper
|
27
27
|
*/
|
28
28
|
|
29
29
|
/**
|
30
|
-
* @typedef {
|
30
|
+
* @typedef {object} AmdLibraryPluginParsed
|
31
31
|
* @property {string} name
|
32
32
|
* @property {string} amdContainer
|
33
33
|
*/
|
@@ -91,7 +91,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
91
91
|
};
|
92
92
|
|
93
93
|
/**
|
94
|
-
* @typedef {
|
94
|
+
* @typedef {object} AssignLibraryPluginOptions
|
95
95
|
* @property {LibraryType} type
|
96
96
|
* @property {string[] | "global"} prefix name prefix
|
97
97
|
* @property {string | false} declare declare name as variable
|
@@ -100,7 +100,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
100
100
|
*/
|
101
101
|
|
102
102
|
/**
|
103
|
-
* @typedef {
|
103
|
+
* @typedef {object} AssignLibraryPluginParsed
|
104
104
|
* @property {string | string[]} name
|
105
105
|
* @property {string | string[] | undefined} export
|
106
106
|
*/
|
@@ -323,7 +323,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
323
323
|
true
|
324
324
|
)};\n`
|
325
325
|
);
|
326
|
-
/** @type {
|
326
|
+
/** @type {string} */
|
327
327
|
let exports = RuntimeGlobals.exports;
|
328
328
|
if (exportAccess) {
|
329
329
|
result.add(
|
@@ -22,12 +22,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
22
22
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
23
23
|
|
24
24
|
/**
|
25
|
-
* @typedef {
|
25
|
+
* @typedef {object} ExportPropertyLibraryPluginParsed
|
26
26
|
* @property {string | string[]} export
|
27
27
|
*/
|
28
28
|
|
29
29
|
/**
|
30
|
-
* @typedef {
|
30
|
+
* @typedef {object} ExportPropertyLibraryPluginOptions
|
31
31
|
* @property {LibraryType} type
|
32
32
|
* @property {boolean} nsObjectUsed the namespace object is used
|
33
33
|
*/
|
@@ -19,12 +19,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
19
19
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
20
20
|
|
21
21
|
/**
|
22
|
-
* @typedef {
|
22
|
+
* @typedef {object} JsonpLibraryPluginOptions
|
23
23
|
* @property {LibraryType} type
|
24
24
|
*/
|
25
25
|
|
26
26
|
/**
|
27
|
-
* @typedef {
|
27
|
+
* @typedef {object} JsonpLibraryPluginParsed
|
28
28
|
* @property {string} name
|
29
29
|
*/
|
30
30
|
|
@@ -23,12 +23,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
23
23
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
24
24
|
|
25
25
|
/**
|
26
|
-
* @typedef {
|
26
|
+
* @typedef {object} ModuleLibraryPluginOptions
|
27
27
|
* @property {LibraryType} type
|
28
28
|
*/
|
29
29
|
|
30
30
|
/**
|
31
|
-
* @typedef {
|
31
|
+
* @typedef {object} ModuleLibraryPluginParsed
|
32
32
|
* @property {string} name
|
33
33
|
*/
|
34
34
|
|
@@ -23,12 +23,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
23
23
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
24
24
|
|
25
25
|
/**
|
26
|
-
* @typedef {
|
26
|
+
* @typedef {object} SystemLibraryPluginOptions
|
27
27
|
* @property {LibraryType} type
|
28
28
|
*/
|
29
29
|
|
30
30
|
/**
|
31
|
-
* @typedef {
|
31
|
+
* @typedef {object} SystemLibraryPluginParsed
|
32
32
|
* @property {string} name
|
33
33
|
*/
|
34
34
|
|
@@ -18,8 +18,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
18
18
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
19
19
|
/** @typedef {import("../Compiler")} Compiler */
|
20
20
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
21
|
+
/** @typedef {import("../ExternalModule").RequestRecord} RequestRecord */
|
21
22
|
/** @typedef {import("../util/Hash")} Hash */
|
22
|
-
/**
|
23
|
+
/**
|
24
|
+
* @template T
|
25
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>}
|
26
|
+
* LibraryContext<T>
|
27
|
+
*/
|
23
28
|
|
24
29
|
/**
|
25
30
|
* @param {string[]} accessor the accessor to convert to path
|
@@ -53,13 +58,13 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
|
|
53
58
|
/** @typedef {string | string[] | LibraryCustomUmdObject} UmdLibraryPluginName */
|
54
59
|
|
55
60
|
/**
|
56
|
-
* @typedef {
|
61
|
+
* @typedef {object} UmdLibraryPluginOptions
|
57
62
|
* @property {LibraryType} type
|
58
63
|
* @property {boolean=} optionalAmdExternalAsGlobal
|
59
64
|
*/
|
60
65
|
|
61
66
|
/**
|
62
|
-
* @typedef {
|
67
|
+
* @typedef {object} UmdLibraryPluginParsed
|
63
68
|
* @property {string | string[]} name
|
64
69
|
* @property {LibraryCustomUmdObject} names
|
65
70
|
* @property {string | LibraryCustomUmdCommentObject} auxiliaryComment
|
@@ -158,24 +163,38 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
158
163
|
});
|
159
164
|
};
|
160
165
|
|
166
|
+
/**
|
167
|
+
* @param {ExternalModule[]} modules external modules
|
168
|
+
* @returns {string} result
|
169
|
+
*/
|
161
170
|
const externalsDepsArray = modules => {
|
162
171
|
return `[${replaceKeys(
|
163
172
|
modules
|
164
173
|
.map(m =>
|
165
174
|
JSON.stringify(
|
166
|
-
typeof m.request === "object"
|
175
|
+
typeof m.request === "object"
|
176
|
+
? /** @type {RequestRecord} */
|
177
|
+
(m.request).amd
|
178
|
+
: m.request
|
167
179
|
)
|
168
180
|
)
|
169
181
|
.join(", ")
|
170
182
|
)}]`;
|
171
183
|
};
|
172
184
|
|
185
|
+
/**
|
186
|
+
* @param {ExternalModule[]} modules external modules
|
187
|
+
* @returns {string} result
|
188
|
+
*/
|
173
189
|
const externalsRootArray = modules => {
|
174
190
|
return replaceKeys(
|
175
191
|
modules
|
176
192
|
.map(m => {
|
177
193
|
let request = m.request;
|
178
|
-
if (typeof request === "object")
|
194
|
+
if (typeof request === "object")
|
195
|
+
request =
|
196
|
+
/** @type {RequestRecord} */
|
197
|
+
(request).root;
|
179
198
|
return `root${accessorToObjectAccess([].concat(request))}`;
|
180
199
|
})
|
181
200
|
.join(", ")
|
@@ -194,7 +213,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
194
213
|
let request = m.request;
|
195
214
|
if (typeof request === "object") {
|
196
215
|
request =
|
197
|
-
/** @type {
|
216
|
+
/** @type {RequestRecord} */
|
198
217
|
(request)[type];
|
199
218
|
}
|
200
219
|
if (request === undefined) {
|
@@ -233,8 +252,14 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
233
252
|
.join(", ");
|
234
253
|
};
|
235
254
|
|
255
|
+
/**
|
256
|
+
* @param {string| string[]} library library name
|
257
|
+
* @returns {string} stringified library name
|
258
|
+
*/
|
236
259
|
const libraryName = library => {
|
237
|
-
return JSON.stringify(
|
260
|
+
return JSON.stringify(
|
261
|
+
replaceKeys(/** @type {string[]} */ ([]).concat(library).pop())
|
262
|
+
);
|
238
263
|
};
|
239
264
|
|
240
265
|
let amdFactory;
|
@@ -313,11 +338,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
313
338
|
" else\n" +
|
314
339
|
" " +
|
315
340
|
replaceKeys(
|
316
|
-
accessorAccess(
|
317
|
-
"root",
|
318
|
-
/** @type {string | string[]} */ (names.root) ||
|
319
|
-
/** @type {string} */ (names.commonjs)
|
320
|
-
)
|
341
|
+
accessorAccess("root", names.root || names.commonjs)
|
321
342
|
) +
|
322
343
|
" = factory(" +
|
323
344
|
externalsRootArray(externals) +
|
@@ -15,7 +15,7 @@ const { LogType } = require("./Logger");
|
|
15
15
|
/** @typedef {function(string, LogTypeEnum, any[]): void} LoggingFunction */
|
16
16
|
|
17
17
|
/**
|
18
|
-
* @typedef {
|
18
|
+
* @typedef {object} LoggerConsole
|
19
19
|
* @property {function(): void} clear
|
20
20
|
* @property {function(): void} trace
|
21
21
|
* @property {(...args: any[]) => void} info
|
@@ -33,7 +33,7 @@ const { LogType } = require("./Logger");
|
|
33
33
|
*/
|
34
34
|
|
35
35
|
/**
|
36
|
-
* @typedef {
|
36
|
+
* @typedef {object} LoggerOptions
|
37
37
|
* @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} level loglevel
|
38
38
|
* @property {FilterTypes|boolean} debug filter for debug logging
|
39
39
|
* @property {LoggerConsole} console the console to log to
|
@@ -11,7 +11,8 @@ const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenc
|
|
11
11
|
/** @typedef {import("../Chunk")} Chunk */
|
12
12
|
/** @typedef {import("../Compiler")} Compiler */
|
13
13
|
|
14
|
-
/**
|
14
|
+
/**
|
15
|
+
* @typedef {object} CommonJsChunkLoadingPluginOptions
|
15
16
|
* @property {boolean} [asyncChunkLoading] enable async chunk loading
|
16
17
|
*/
|
17
18
|
|
@@ -17,7 +17,7 @@ const nodeConsole = require("./nodeConsole");
|
|
17
17
|
|
18
18
|
class NodeEnvironmentPlugin {
|
19
19
|
/**
|
20
|
-
* @param {
|
20
|
+
* @param {object} options options
|
21
21
|
* @param {InfrastructureLogging} options.infrastructureLogging infrastructure logging options
|
22
22
|
*/
|
23
23
|
constructor(options) {
|
@@ -11,7 +11,7 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
13
|
/**
|
14
|
-
* @typedef {
|
14
|
+
* @typedef {object} NodeTemplatePluginOptions
|
15
15
|
* @property {boolean} [asyncChunkLoading] enable async chunk loading
|
16
16
|
*/
|
17
17
|
|
@@ -14,7 +14,7 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
|
|
14
14
|
/** @typedef {import("../Compiler")} Compiler */
|
15
15
|
|
16
16
|
/**
|
17
|
-
* @typedef {
|
17
|
+
* @typedef {object} ReadFileCompileWasmPluginOptions
|
18
18
|
* @property {boolean} [mangleImports] mangle imports
|
19
19
|
*/
|
20
20
|
|
package/lib/node/nodeConsole.js
CHANGED
@@ -11,7 +11,7 @@ const truncateArgs = require("../logging/truncateArgs");
|
|
11
11
|
/** @typedef {import("../logging/createConsoleLogger").LoggerConsole} LoggerConsole */
|
12
12
|
|
13
13
|
/**
|
14
|
-
* @param {
|
14
|
+
* @param {object} options options
|
15
15
|
* @param {boolean=} options.colors colors
|
16
16
|
* @param {boolean=} options.appendOnly append only
|
17
17
|
* @param {NodeJS.WritableStream} options.stream stream
|
@@ -11,7 +11,7 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
13
|
/**
|
14
|
-
* @typedef {
|
14
|
+
* @typedef {object} AggressiveMergingPluginOptions
|
15
15
|
* @property {number=} minSizeReduce minimal size reduction to trigger merging
|
16
16
|
*/
|
17
17
|
|
@@ -26,6 +26,7 @@ const { concatComparators } = require("../util/comparators");
|
|
26
26
|
const createHash = require("../util/createHash");
|
27
27
|
const { makePathsRelative } = require("../util/identifier");
|
28
28
|
const makeSerializable = require("../util/makeSerializable");
|
29
|
+
const { getAllReferences, getPathInAst } = require("../util/mergeScope");
|
29
30
|
const propertyAccess = require("../util/propertyAccess");
|
30
31
|
const { propertyName } = require("../util/propertyName");
|
31
32
|
const {
|
@@ -92,7 +93,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
92
93
|
}
|
93
94
|
|
94
95
|
/**
|
95
|
-
* @typedef {
|
96
|
+
* @typedef {object} ReexportInfo
|
96
97
|
* @property {Module} module
|
97
98
|
* @property {string[]} export
|
98
99
|
*/
|
@@ -100,7 +101,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
100
101
|
/** @typedef {RawBinding | SymbolBinding} Binding */
|
101
102
|
|
102
103
|
/**
|
103
|
-
* @typedef {
|
104
|
+
* @typedef {object} RawBinding
|
104
105
|
* @property {ModuleInfo} info
|
105
106
|
* @property {string} rawName
|
106
107
|
* @property {string=} comment
|
@@ -109,7 +110,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
109
110
|
*/
|
110
111
|
|
111
112
|
/**
|
112
|
-
* @typedef {
|
113
|
+
* @typedef {object} SymbolBinding
|
113
114
|
* @property {ConcatenatedModuleInfo} info
|
114
115
|
* @property {string} name
|
115
116
|
* @property {string=} comment
|
@@ -121,7 +122,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
121
122
|
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo } ModuleInfoOrReference */
|
122
123
|
|
123
124
|
/**
|
124
|
-
* @typedef {
|
125
|
+
* @typedef {object} ConcatenatedModuleInfo
|
125
126
|
* @property {"concatenated"} type
|
126
127
|
* @property {Module} module
|
127
128
|
* @property {number} index
|
@@ -146,7 +147,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
146
147
|
*/
|
147
148
|
|
148
149
|
/**
|
149
|
-
* @typedef {
|
150
|
+
* @typedef {object} ExternalModuleInfo
|
150
151
|
* @property {"external"} type
|
151
152
|
* @property {Module} module
|
152
153
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
@@ -161,7 +162,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
161
162
|
*/
|
162
163
|
|
163
164
|
/**
|
164
|
-
* @typedef {
|
165
|
+
* @typedef {object} ReferenceToModuleInfo
|
165
166
|
* @property {"reference"} type
|
166
167
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
167
168
|
* @property {ConcatenatedModuleInfo | ExternalModuleInfo} target
|
@@ -254,7 +255,7 @@ const joinIterableWithComma = iterable => {
|
|
254
255
|
};
|
255
256
|
|
256
257
|
/**
|
257
|
-
* @typedef {
|
258
|
+
* @typedef {object} ConcatenationEntry
|
258
259
|
* @property {"concatenated" | "external"} type
|
259
260
|
* @property {Module} module
|
260
261
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
@@ -625,72 +626,6 @@ const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
|
|
625
626
|
}
|
626
627
|
};
|
627
628
|
|
628
|
-
/**
|
629
|
-
* @param {Variable} variable variable
|
630
|
-
* @returns {Reference[]} references
|
631
|
-
*/
|
632
|
-
const getAllReferences = variable => {
|
633
|
-
let set = variable.references;
|
634
|
-
// Look for inner scope variables too (like in class Foo { t() { Foo } })
|
635
|
-
const identifiers = new Set(variable.identifiers);
|
636
|
-
for (const scope of variable.scope.childScopes) {
|
637
|
-
for (const innerVar of scope.variables) {
|
638
|
-
if (innerVar.identifiers.some(id => identifiers.has(id))) {
|
639
|
-
set = set.concat(innerVar.references);
|
640
|
-
break;
|
641
|
-
}
|
642
|
-
}
|
643
|
-
}
|
644
|
-
return set;
|
645
|
-
};
|
646
|
-
|
647
|
-
/**
|
648
|
-
* @param {TODO} ast ast
|
649
|
-
* @param {TODO} node node
|
650
|
-
* @returns {TODO} result
|
651
|
-
*/
|
652
|
-
const getPathInAst = (ast, node) => {
|
653
|
-
if (ast === node) {
|
654
|
-
return [];
|
655
|
-
}
|
656
|
-
|
657
|
-
const nr = node.range;
|
658
|
-
|
659
|
-
const enterNode = n => {
|
660
|
-
if (!n) return undefined;
|
661
|
-
const r = n.range;
|
662
|
-
if (r) {
|
663
|
-
if (r[0] <= nr[0] && r[1] >= nr[1]) {
|
664
|
-
const path = getPathInAst(n, node);
|
665
|
-
if (path) {
|
666
|
-
path.push(n);
|
667
|
-
return path;
|
668
|
-
}
|
669
|
-
}
|
670
|
-
}
|
671
|
-
return undefined;
|
672
|
-
};
|
673
|
-
|
674
|
-
if (Array.isArray(ast)) {
|
675
|
-
for (let i = 0; i < ast.length; i++) {
|
676
|
-
const enterResult = enterNode(ast[i]);
|
677
|
-
if (enterResult !== undefined) return enterResult;
|
678
|
-
}
|
679
|
-
} else if (ast && typeof ast === "object") {
|
680
|
-
const keys = Object.keys(ast);
|
681
|
-
for (let i = 0; i < keys.length; i++) {
|
682
|
-
const value = ast[keys[i]];
|
683
|
-
if (Array.isArray(value)) {
|
684
|
-
const pathResult = getPathInAst(value, node);
|
685
|
-
if (pathResult !== undefined) return pathResult;
|
686
|
-
} else if (value && typeof value === "object") {
|
687
|
-
const enterResult = enterNode(value);
|
688
|
-
if (enterResult !== undefined) return enterResult;
|
689
|
-
}
|
690
|
-
}
|
691
|
-
}
|
692
|
-
};
|
693
|
-
|
694
629
|
const TYPES = new Set(["javascript"]);
|
695
630
|
|
696
631
|
class ConcatenatedModule extends Module {
|
@@ -698,7 +633,7 @@ class ConcatenatedModule extends Module {
|
|
698
633
|
* @param {Module} rootModule the root module of the concatenation
|
699
634
|
* @param {Set<Module>} modules all modules in the concatenation (including the root module)
|
700
635
|
* @param {RuntimeSpec} runtime the runtime
|
701
|
-
* @param {
|
636
|
+
* @param {object=} associatedObjectForCache object for caching
|
702
637
|
* @param {string | HashConstructor=} hashFunction hash function to use
|
703
638
|
* @returns {ConcatenatedModule} the module
|
704
639
|
*/
|
@@ -724,7 +659,7 @@ class ConcatenatedModule extends Module {
|
|
724
659
|
}
|
725
660
|
|
726
661
|
/**
|
727
|
-
* @param {
|
662
|
+
* @param {object} options options
|
728
663
|
* @param {string} options.identifier the identifier of the module
|
729
664
|
* @param {Module=} options.rootModule the root module of the concatenation
|
730
665
|
* @param {RuntimeSpec} options.runtime the selected runtime
|
@@ -1098,7 +1033,7 @@ class ConcatenatedModule extends Module {
|
|
1098
1033
|
/**
|
1099
1034
|
* @param {Module} rootModule the root module of the concatenation
|
1100
1035
|
* @param {Set<Module>} modules all modules in the concatenation (including the root module)
|
1101
|
-
* @param {
|
1036
|
+
* @param {object=} associatedObjectForCache object for caching
|
1102
1037
|
* @param {string | HashConstructor=} hashFunction hash function to use
|
1103
1038
|
* @returns {string} the identifier
|
1104
1039
|
*/
|
@@ -21,7 +21,7 @@ const { UsageState } = require("../ExportsInfo");
|
|
21
21
|
/** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
|
22
22
|
|
23
23
|
/**
|
24
|
-
* @typedef {
|
24
|
+
* @typedef {object} StateObject
|
25
25
|
* @property {InnerGraph} innerGraph
|
26
26
|
* @property {TopLevelSymbol=} currentTopLevelSymbol
|
27
27
|
* @property {Map<TopLevelSymbol, Set<UsageCallback>>} usageCallbackMap
|