webpack 5.59.0 → 5.71.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/README.md +1 -7
- package/hot/lazy-compilation-node.js +3 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/BannerPlugin.js +10 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +1 -2
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +179 -91
- package/lib/Compiler.js +86 -17
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +142 -51
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModule.js +1 -1
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +17 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EntryOptionPlugin.js +2 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExportsInfo.js +4 -4
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +89 -44
- package/lib/Generator.js +3 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +27 -4
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleHashingError.js +29 -0
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +41 -26
- package/lib/NormalModuleFactory.js +42 -37
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +77 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +2 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +57 -11
- package/lib/asset/AssetGenerator.js +193 -63
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +36 -6
- package/lib/cache/PackFileCacheStrategy.js +7 -4
- package/lib/cache/ResolverCachePlugin.js +90 -29
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +41 -6
- package/lib/config/defaults.js +115 -19
- package/lib/config/normalization.js +9 -0
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +440 -0
- package/lib/css/CssModulesPlugin.js +462 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +24 -21
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
- package/lib/dependencies/ContextDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
- package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/hmr/LazyCompilationPlugin.js +54 -26
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +11 -14
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +13 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/JavascriptParser.js +82 -48
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/library/AssignLibraryPlugin.js +39 -15
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
- package/lib/optimize/ConcatenatedModule.js +21 -9
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +77 -14
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
- package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
- package/lib/util/ArrayHelpers.js +30 -0
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +12 -0
- package/lib/util/deprecation.js +10 -2
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +11 -0
- package/lib/util/hash/BatchedHash.js +7 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +5 -139
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +15 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
- package/lib/webpack.js +10 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
- package/module.d.ts +215 -0
- package/package.json +23 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +254 -29
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +628 -179
@@ -0,0 +1,101 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const Dependency = require("../Dependency");
|
9
|
+
const makeSerializable = require("../util/makeSerializable");
|
10
|
+
const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
|
11
|
+
|
12
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
|
+
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
14
|
+
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
15
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
16
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
17
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
18
|
+
|
19
|
+
class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
|
20
|
+
/**
|
21
|
+
* @param {string} name name
|
22
|
+
* @param {[number, number]} range range
|
23
|
+
* @param {string=} prefix prefix
|
24
|
+
* @param {Set<string>=} declaredSet set of declared names (will only be active when in declared set)
|
25
|
+
*/
|
26
|
+
constructor(name, range, prefix = "", declaredSet = undefined) {
|
27
|
+
super(name, range, prefix);
|
28
|
+
this.declaredSet = declaredSet;
|
29
|
+
}
|
30
|
+
|
31
|
+
get type() {
|
32
|
+
return "css self local identifier";
|
33
|
+
}
|
34
|
+
|
35
|
+
get category() {
|
36
|
+
return "self";
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @returns {string | null} an identifier to merge equal requests
|
41
|
+
*/
|
42
|
+
getResourceIdentifier() {
|
43
|
+
return `self`;
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Returns the exported names
|
47
|
+
* @param {ModuleGraph} moduleGraph module graph
|
48
|
+
* @returns {ExportsSpec | undefined} export names
|
49
|
+
*/
|
50
|
+
getExports(moduleGraph) {
|
51
|
+
if (this.declaredSet && !this.declaredSet.has(this.name)) return;
|
52
|
+
return super.getExports(moduleGraph);
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Returns list of exports referenced by this dependency
|
57
|
+
* @param {ModuleGraph} moduleGraph module graph
|
58
|
+
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
59
|
+
* @returns {(string[] | ReferencedExport)[]} referenced exports
|
60
|
+
*/
|
61
|
+
getReferencedExports(moduleGraph, runtime) {
|
62
|
+
if (this.declaredSet && !this.declaredSet.has(this.name))
|
63
|
+
return Dependency.NO_EXPORTS_REFERENCED;
|
64
|
+
return [[this.name]];
|
65
|
+
}
|
66
|
+
|
67
|
+
serialize(context) {
|
68
|
+
const { write } = context;
|
69
|
+
write(this.declaredSet);
|
70
|
+
super.serialize(context);
|
71
|
+
}
|
72
|
+
|
73
|
+
deserialize(context) {
|
74
|
+
const { read } = context;
|
75
|
+
this.declaredSet = read();
|
76
|
+
super.deserialize(context);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
|
81
|
+
CssLocalIdentifierDependency.Template
|
82
|
+
) {
|
83
|
+
/**
|
84
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
85
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
86
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
87
|
+
* @returns {void}
|
88
|
+
*/
|
89
|
+
apply(dependency, source, templateContext) {
|
90
|
+
const dep = /** @type {CssSelfLocalIdentifierDependency} */ (dependency);
|
91
|
+
if (dep.declaredSet && !dep.declaredSet.has(dep.name)) return;
|
92
|
+
super.apply(dependency, source, templateContext);
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
makeSerializable(
|
97
|
+
CssSelfLocalIdentifierDependency,
|
98
|
+
"webpack/lib/dependencies/CssSelfLocalIdentifierDependency"
|
99
|
+
);
|
100
|
+
|
101
|
+
module.exports = CssSelfLocalIdentifierDependency;
|
@@ -0,0 +1,132 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const memoize = require("../util/memoize");
|
10
|
+
const ModuleDependency = require("./ModuleDependency");
|
11
|
+
|
12
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
|
+
/** @typedef {import("../Dependency")} Dependency */
|
15
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
16
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
17
|
+
/** @typedef {import("../Module")} Module */
|
18
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
19
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
20
|
+
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
21
|
+
/** @typedef {import("../util/Hash")} Hash */
|
22
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
23
|
+
|
24
|
+
const getRawDataUrlModule = memoize(() => require("../asset/RawDataUrlModule"));
|
25
|
+
|
26
|
+
class CssUrlDependency extends ModuleDependency {
|
27
|
+
/**
|
28
|
+
* @param {string} request request
|
29
|
+
* @param {[number, number]} range range of the argument
|
30
|
+
* @param {string} cssFunctionKind kind of css function, e. g. url(), image()
|
31
|
+
*/
|
32
|
+
constructor(request, range, cssFunctionKind) {
|
33
|
+
super(request);
|
34
|
+
this.range = range;
|
35
|
+
this.cssFunctionKind = cssFunctionKind;
|
36
|
+
}
|
37
|
+
|
38
|
+
get type() {
|
39
|
+
return "css url()";
|
40
|
+
}
|
41
|
+
|
42
|
+
get category() {
|
43
|
+
return "url";
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @param {string} context context directory
|
48
|
+
* @returns {Module} a module
|
49
|
+
*/
|
50
|
+
createIgnoredModule(context) {
|
51
|
+
const RawDataUrlModule = getRawDataUrlModule();
|
52
|
+
return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
|
53
|
+
}
|
54
|
+
|
55
|
+
serialize(context) {
|
56
|
+
const { write } = context;
|
57
|
+
write(this.cssFunctionKind);
|
58
|
+
super.serialize(context);
|
59
|
+
}
|
60
|
+
|
61
|
+
deserialize(context) {
|
62
|
+
const { read } = context;
|
63
|
+
this.cssFunctionKind = read();
|
64
|
+
super.deserialize(context);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
const cssEscapeString = str => {
|
69
|
+
let countWhiteOrBracket = 0;
|
70
|
+
let countQuotation = 0;
|
71
|
+
let countApostrophe = 0;
|
72
|
+
for (let i = 0; i < str.length; i++) {
|
73
|
+
const cc = str.charCodeAt(i);
|
74
|
+
switch (cc) {
|
75
|
+
case 9: // tab
|
76
|
+
case 10: // nl
|
77
|
+
case 32: // space
|
78
|
+
case 40: // (
|
79
|
+
case 41: // )
|
80
|
+
countWhiteOrBracket++;
|
81
|
+
break;
|
82
|
+
case 34:
|
83
|
+
countQuotation++;
|
84
|
+
break;
|
85
|
+
case 39:
|
86
|
+
countApostrophe++;
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
if (countWhiteOrBracket < 2) {
|
91
|
+
return str.replace(/[\n\t ()'"\\]/g, m => `\\${m}`);
|
92
|
+
} else if (countQuotation <= countApostrophe) {
|
93
|
+
return `"${str.replace(/[\n"\\]/g, m => `\\${m}`)}"`;
|
94
|
+
} else {
|
95
|
+
return `'${str.replace(/[\n'\\]/g, m => `\\${m}`)}'`;
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
100
|
+
ModuleDependency.Template
|
101
|
+
) {
|
102
|
+
/**
|
103
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
104
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
105
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
106
|
+
* @returns {void}
|
107
|
+
*/
|
108
|
+
apply(
|
109
|
+
dependency,
|
110
|
+
source,
|
111
|
+
{ runtime, moduleGraph, runtimeTemplate, codeGenerationResults }
|
112
|
+
) {
|
113
|
+
const dep = /** @type {CssUrlDependency} */ (dependency);
|
114
|
+
|
115
|
+
source.replace(
|
116
|
+
dep.range[0],
|
117
|
+
dep.range[1] - 1,
|
118
|
+
`${dep.cssFunctionKind}(${cssEscapeString(
|
119
|
+
runtimeTemplate.assetUrl({
|
120
|
+
publicPath: "",
|
121
|
+
runtime,
|
122
|
+
module: moduleGraph.getModule(dep),
|
123
|
+
codeGenerationResults
|
124
|
+
})
|
125
|
+
)})`
|
126
|
+
);
|
127
|
+
}
|
128
|
+
};
|
129
|
+
|
130
|
+
makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
|
131
|
+
|
132
|
+
module.exports = CssUrlDependency;
|
@@ -46,6 +46,12 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
|
|
46
46
|
}
|
47
47
|
}
|
48
48
|
switch (property) {
|
49
|
+
case "canMangle": {
|
50
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
51
|
+
const exportInfo = exportsInfo.getExportInfo(exportName);
|
52
|
+
if (exportInfo) return exportInfo.canMangle;
|
53
|
+
return exportsInfo.otherExportsInfo.canMangle;
|
54
|
+
}
|
49
55
|
case "used":
|
50
56
|
return (
|
51
57
|
moduleGraph.getExportsInfo(module).getUsed(exportName, runtime) !==
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
9
9
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
10
|
+
const NullDependency = require("./NullDependency");
|
10
11
|
|
11
12
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
13
|
/** @typedef {import("../Dependency")} Dependency */
|
@@ -28,8 +29,9 @@ makeSerializable(
|
|
28
29
|
"webpack/lib/dependencies/HarmonyAcceptImportDependency"
|
29
30
|
);
|
30
31
|
|
31
|
-
HarmonyAcceptImportDependency.Template =
|
32
|
-
HarmonyImportDependency.Template
|
33
|
-
|
32
|
+
HarmonyAcceptImportDependency.Template =
|
33
|
+
/** @type {typeof HarmonyImportDependency.Template} */ (
|
34
|
+
NullDependency.Template
|
35
|
+
);
|
34
36
|
|
35
37
|
module.exports = HarmonyAcceptImportDependency;
|
@@ -74,14 +74,14 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
|
|
74
74
|
initFragments.push(
|
75
75
|
new InitFragment(
|
76
76
|
runtimeTemplate.supportsArrowFunction()
|
77
|
-
? `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async (__webpack_handle_async_dependencies__) => {\n`
|
78
|
-
: `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async function (__webpack_handle_async_dependencies__) {\n`,
|
77
|
+
? `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n`
|
78
|
+
: `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async function (__webpack_handle_async_dependencies__, __webpack_async_result__) { try {\n`,
|
79
79
|
InitFragment.STAGE_ASYNC_BOUNDARY,
|
80
80
|
0,
|
81
81
|
undefined,
|
82
|
-
|
83
|
-
?
|
84
|
-
|
82
|
+
`\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } }${
|
83
|
+
module.buildMeta.async ? ", 1" : ""
|
84
|
+
});`
|
85
85
|
)
|
86
86
|
);
|
87
87
|
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
10
|
+
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
14
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Dependency for static evaluating import specifier. e.g.
|
18
|
+
* @example
|
19
|
+
* import a from "a";
|
20
|
+
* "x" in a;
|
21
|
+
* a.x !== undefined; // if x value statically analyzable
|
22
|
+
*/
|
23
|
+
class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDependency {
|
24
|
+
constructor(request, sourceOrder, ids, name, range, assertions, operator) {
|
25
|
+
super(request, sourceOrder, ids, name, range, false, assertions);
|
26
|
+
this.operator = operator;
|
27
|
+
}
|
28
|
+
|
29
|
+
get type() {
|
30
|
+
return `evaluated X ${this.operator} harmony import specifier`;
|
31
|
+
}
|
32
|
+
|
33
|
+
serialize(context) {
|
34
|
+
super.serialize(context);
|
35
|
+
const { write } = context;
|
36
|
+
write(this.operator);
|
37
|
+
}
|
38
|
+
|
39
|
+
deserialize(context) {
|
40
|
+
super.deserialize(context);
|
41
|
+
const { read } = context;
|
42
|
+
this.operator = read();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
makeSerializable(
|
47
|
+
HarmonyEvaluatedImportSpecifierDependency,
|
48
|
+
"webpack/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency"
|
49
|
+
);
|
50
|
+
|
51
|
+
HarmonyEvaluatedImportSpecifierDependency.Template = class HarmonyEvaluatedImportSpecifierDependencyTemplate extends (
|
52
|
+
HarmonyImportSpecifierDependency.Template
|
53
|
+
) {
|
54
|
+
/**
|
55
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
56
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
57
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
58
|
+
* @returns {void}
|
59
|
+
*/
|
60
|
+
apply(dependency, source, templateContext) {
|
61
|
+
const dep = /** @type {HarmonyEvaluatedImportSpecifierDependency} */ (
|
62
|
+
dependency
|
63
|
+
);
|
64
|
+
const { moduleGraph, runtime } = templateContext;
|
65
|
+
const connection = moduleGraph.getConnection(dep);
|
66
|
+
// Skip rendering depending when dependency is conditional
|
67
|
+
if (connection && !connection.isTargetActive(runtime)) return;
|
68
|
+
|
69
|
+
const exportsInfo = moduleGraph.getExportsInfo(connection.module);
|
70
|
+
const ids = dep.getIds(moduleGraph);
|
71
|
+
const value = exportsInfo.isExportProvided(ids);
|
72
|
+
|
73
|
+
if (typeof value === "boolean") {
|
74
|
+
source.replace(dep.range[0], dep.range[1] - 1, `${value}`);
|
75
|
+
} else {
|
76
|
+
const usedName = exportsInfo.getUsedName(ids, runtime);
|
77
|
+
|
78
|
+
const code = this._getCodeForIds(
|
79
|
+
dep,
|
80
|
+
source,
|
81
|
+
templateContext,
|
82
|
+
ids.slice(0, -1)
|
83
|
+
);
|
84
|
+
source.replace(
|
85
|
+
dep.range[0],
|
86
|
+
dep.range[1] - 1,
|
87
|
+
`${
|
88
|
+
usedName ? JSON.stringify(usedName[usedName.length - 1]) : '""'
|
89
|
+
} in ${code}`
|
90
|
+
);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
module.exports = HarmonyEvaluatedImportSpecifierDependency;
|
@@ -11,6 +11,7 @@ const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDepe
|
|
11
11
|
const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
|
12
12
|
const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
|
13
13
|
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
14
|
+
const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
14
15
|
const {
|
15
16
|
harmonySpecifierTag,
|
16
17
|
getAssertions
|
@@ -21,10 +22,18 @@ const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency;
|
|
21
22
|
|
22
23
|
module.exports = class HarmonyExportDependencyParserPlugin {
|
23
24
|
constructor(options) {
|
24
|
-
this.
|
25
|
+
this.exportPresenceMode =
|
26
|
+
options.reexportExportsPresence !== undefined
|
27
|
+
? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
|
28
|
+
: options.exportsPresence !== undefined
|
29
|
+
? ExportPresenceModes.fromUserOption(options.exportsPresence)
|
30
|
+
: options.strictExportPresence
|
31
|
+
? ExportPresenceModes.ERROR
|
32
|
+
: ExportPresenceModes.AUTO;
|
25
33
|
}
|
26
34
|
|
27
35
|
apply(parser) {
|
36
|
+
const { exportPresenceMode } = this;
|
28
37
|
parser.hooks.export.tap(
|
29
38
|
"HarmonyExportDependencyParserPlugin",
|
30
39
|
statement => {
|
@@ -128,7 +137,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
128
137
|
name,
|
129
138
|
harmonyNamedExports,
|
130
139
|
null,
|
131
|
-
|
140
|
+
exportPresenceMode,
|
132
141
|
null,
|
133
142
|
settings.assertions
|
134
143
|
);
|
@@ -160,7 +169,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
160
169
|
name,
|
161
170
|
harmonyNamedExports,
|
162
171
|
harmonyStarExports && harmonyStarExports.slice(),
|
163
|
-
|
172
|
+
exportPresenceMode,
|
164
173
|
harmonyStarExports
|
165
174
|
);
|
166
175
|
if (harmonyStarExports) {
|
@@ -40,6 +40,8 @@ const processExportInfo = require("./processExportInfo");
|
|
40
40
|
|
41
41
|
/** @typedef {"missing"|"unused"|"empty-star"|"reexport-dynamic-default"|"reexport-named-default"|"reexport-namespace-object"|"reexport-fake-namespace-object"|"reexport-undefined"|"normal-reexport"|"dynamic-reexport"} ExportModeType */
|
42
42
|
|
43
|
+
const { ExportPresenceModes } = HarmonyImportDependency;
|
44
|
+
|
43
45
|
const idsSymbol = Symbol("HarmonyExportImportedSpecifierDependency.ids");
|
44
46
|
|
45
47
|
class NormalReexportItem {
|
@@ -325,7 +327,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
325
327
|
* @param {string | null} name the export name of for this module
|
326
328
|
* @param {Set<string>} activeExports other named exports in the module
|
327
329
|
* @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency>} otherStarExports other star exports in the module before this import
|
328
|
-
* @param {
|
330
|
+
* @param {number} exportPresenceMode mode of checking export names
|
329
331
|
* @param {HarmonyStarExportsList} allStarExports all star exports in the module
|
330
332
|
* @param {Record<string, any>=} assertions import assertions
|
331
333
|
*/
|
@@ -336,7 +338,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
336
338
|
name,
|
337
339
|
activeExports,
|
338
340
|
otherStarExports,
|
339
|
-
|
341
|
+
exportPresenceMode,
|
340
342
|
allStarExports,
|
341
343
|
assertions
|
342
344
|
) {
|
@@ -346,7 +348,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
346
348
|
this.name = name;
|
347
349
|
this.activeExports = activeExports;
|
348
350
|
this.otherStarExports = otherStarExports;
|
349
|
-
this.
|
351
|
+
this.exportPresenceMode = exportPresenceMode;
|
350
352
|
this.allStarExports = allStarExports;
|
351
353
|
}
|
352
354
|
|
@@ -735,20 +737,29 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
735
737
|
}
|
736
738
|
}
|
737
739
|
|
740
|
+
/**
|
741
|
+
* @param {ModuleGraph} moduleGraph module graph
|
742
|
+
* @returns {number} effective mode
|
743
|
+
*/
|
744
|
+
_getEffectiveExportPresenceLevel(moduleGraph) {
|
745
|
+
if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
|
746
|
+
return this.exportPresenceMode;
|
747
|
+
return moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
|
748
|
+
? ExportPresenceModes.ERROR
|
749
|
+
: ExportPresenceModes.WARN;
|
750
|
+
}
|
751
|
+
|
738
752
|
/**
|
739
753
|
* Returns warnings
|
740
754
|
* @param {ModuleGraph} moduleGraph module graph
|
741
755
|
* @returns {WebpackError[]} warnings
|
742
756
|
*/
|
743
757
|
getWarnings(moduleGraph) {
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
) {
|
748
|
-
return null;
|
758
|
+
const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
|
759
|
+
if (exportsPresence === ExportPresenceModes.WARN) {
|
760
|
+
return this._getErrors(moduleGraph);
|
749
761
|
}
|
750
|
-
|
751
|
-
return this._getErrors(moduleGraph);
|
762
|
+
return null;
|
752
763
|
}
|
753
764
|
|
754
765
|
/**
|
@@ -757,13 +768,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
757
768
|
* @returns {WebpackError[]} errors
|
758
769
|
*/
|
759
770
|
getErrors(moduleGraph) {
|
760
|
-
|
761
|
-
|
762
|
-
moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
|
763
|
-
) {
|
771
|
+
const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
|
772
|
+
if (exportsPresence === ExportPresenceModes.ERROR) {
|
764
773
|
return this._getErrors(moduleGraph);
|
765
774
|
}
|
766
|
-
|
767
775
|
return null;
|
768
776
|
}
|
769
777
|
|
@@ -856,7 +864,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
856
864
|
write(this.name);
|
857
865
|
write(this.activeExports);
|
858
866
|
write(this.otherStarExports);
|
859
|
-
write(this.
|
867
|
+
write(this.exportPresenceMode);
|
860
868
|
write(this.allStarExports);
|
861
869
|
|
862
870
|
super.serialize(context);
|
@@ -870,7 +878,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
870
878
|
this.name = read();
|
871
879
|
this.activeExports = read();
|
872
880
|
this.otherStarExports = read();
|
873
|
-
this.
|
881
|
+
this.exportPresenceMode = read();
|
874
882
|
this.allStarExports = read();
|
875
883
|
|
876
884
|
super.deserialize(context);
|
@@ -145,7 +145,10 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
145
145
|
? `/* unused harmony export ${first(this.unusedExports)} */\n`
|
146
146
|
: "";
|
147
147
|
const definitions = [];
|
148
|
-
|
148
|
+
const orderedExportMap = Array.from(this.exportMap).sort(([a], [b]) =>
|
149
|
+
a < b ? -1 : 1
|
150
|
+
);
|
151
|
+
for (const [key, value] of orderedExportMap) {
|
149
152
|
definitions.push(
|
150
153
|
`\n/* harmony export */ ${JSON.stringify(
|
151
154
|
key
|
@@ -27,6 +27,27 @@ const ModuleDependency = require("./ModuleDependency");
|
|
27
27
|
/** @typedef {import("../util/Hash")} Hash */
|
28
28
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
29
29
|
|
30
|
+
const ExportPresenceModes = {
|
31
|
+
NONE: /** @type {0} */ (0),
|
32
|
+
WARN: /** @type {1} */ (1),
|
33
|
+
AUTO: /** @type {2} */ (2),
|
34
|
+
ERROR: /** @type {3} */ (3),
|
35
|
+
fromUserOption(str) {
|
36
|
+
switch (str) {
|
37
|
+
case "error":
|
38
|
+
return ExportPresenceModes.ERROR;
|
39
|
+
case "warn":
|
40
|
+
return ExportPresenceModes.WARN;
|
41
|
+
case "auto":
|
42
|
+
return ExportPresenceModes.AUTO;
|
43
|
+
case false:
|
44
|
+
return ExportPresenceModes.NONE;
|
45
|
+
default:
|
46
|
+
throw new Error(`Invalid export presence value ${str}`);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
30
51
|
class HarmonyImportDependency extends ModuleDependency {
|
31
52
|
/**
|
32
53
|
*
|
@@ -334,3 +355,5 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
|
334
355
|
return emittedModules.get(referencedModule) || false;
|
335
356
|
}
|
336
357
|
};
|
358
|
+
|
359
|
+
module.exports.ExportPresenceModes = ExportPresenceModes;
|