webpack 5.89.0 → 5.90.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 +3 -0
- package/bin/webpack.js +1 -3
- package/hot/log.js +0 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/ChunkGraph.js +1 -1
- package/lib/CleanPlugin.js +12 -12
- package/lib/Compilation.js +25 -16
- package/lib/Compiler.js +13 -0
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ContextModule.js +4 -4
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DependencyTemplate.js +3 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EvalDevToolModulePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +1 -1
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +47 -12
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +20 -3
- package/lib/FlagDependencyExportsPlugin.js +1 -1
- package/lib/Generator.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/LibManifestPlugin.js +4 -1
- package/lib/Module.js +2 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleInfoHeaderPlugin.js +1 -1
- package/lib/MultiStats.js +2 -2
- package/lib/NodeStuffPlugin.js +48 -0
- package/lib/NormalModule.js +13 -11
- package/lib/NormalModuleFactory.js +7 -7
- package/lib/RuntimeTemplate.js +15 -11
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +4 -3
- package/lib/asset/AssetModulesPlugin.js +2 -3
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +12 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/cache/ResolverCachePlugin.js +2 -2
- package/lib/config/browserslistTargetHandler.js +24 -5
- package/lib/config/defaults.js +87 -52
- package/lib/config/normalization.js +17 -18
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/css/CssExportsGenerator.js +14 -1
- package/lib/css/CssGenerator.js +14 -1
- package/lib/css/CssLoadingRuntimeModule.js +23 -23
- package/lib/css/CssModulesPlugin.js +68 -32
- package/lib/css/CssParser.js +8 -3
- package/lib/debug/ProfilingPlugin.js +2 -2
- package/lib/dependencies/CachedConstDependency.js +8 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +98 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +124 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +4 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
- package/lib/dependencies/ImportDependency.js +26 -6
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +12 -4
- package/lib/dependencies/RequireIncludeDependency.js +1 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +7 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
- package/lib/hmr/lazyCompilationBackend.js +4 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptGenerator.js +16 -1
- package/lib/javascript/JavascriptModulesPlugin.js +33 -33
- package/lib/javascript/JavascriptParser.js +8 -0
- package/lib/json/JsonGenerator.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +5 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +39 -39
- package/lib/logging/createConsoleLogger.js +1 -19
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/nodeConsole.js +1 -5
- package/lib/optimize/ConcatenatedModule.js +7 -7
- package/lib/optimize/InnerGraphPlugin.js +9 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
- package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -16
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/FileMiddleware.js +4 -4
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/sharing/ConsumeSharedPlugin.js +5 -5
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +2 -2
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +24 -28
- package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
- package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
- package/lib/util/cleverMerge.js +4 -4
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +2 -2
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/runtime.js +18 -1
- package/lib/util/semver.js +19 -24
- package/lib/util/smartGrouping.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +23 -23
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +140 -32
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +172 -20
package/README.md
CHANGED
@@ -38,6 +38,9 @@
|
|
38
38
|
<a href="https://twitter.com/Webpack">
|
39
39
|
<img src="https://img.shields.io/twitter/follow/Webpack?style=social">
|
40
40
|
</a>
|
41
|
+
<a href="https://discord.gg/Tt5cKVwx">
|
42
|
+
<img src="https://img.shields.io/discord/1180618526436888586?label=discord&logo=discord&logoColor=white&style=flat">
|
43
|
+
</a>
|
41
44
|
<h1>webpack</h1>
|
42
45
|
<p>
|
43
46
|
Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
|
package/bin/webpack.js
CHANGED
@@ -76,11 +76,10 @@ const isInstalled = packageName => {
|
|
76
76
|
const runCli = cli => {
|
77
77
|
const path = require("path");
|
78
78
|
const pkgPath = require.resolve(`${cli.package}/package.json`);
|
79
|
-
// eslint-disable-next-line node/no-missing-require
|
80
79
|
const pkg = require(pkgPath);
|
81
80
|
|
82
81
|
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
|
83
|
-
// eslint-disable-next-line
|
82
|
+
// eslint-disable-next-line n/no-unsupported-features/es-syntax
|
84
83
|
import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
|
85
84
|
error => {
|
86
85
|
console.error(error);
|
@@ -88,7 +87,6 @@ const runCli = cli => {
|
|
88
87
|
}
|
89
88
|
);
|
90
89
|
} else {
|
91
|
-
// eslint-disable-next-line node/no-missing-require
|
92
90
|
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
|
93
91
|
}
|
94
92
|
};
|
package/hot/log.js
CHANGED
@@ -45,11 +45,9 @@ module.exports = function (level, msg) {
|
|
45
45
|
}
|
46
46
|
};
|
47
47
|
|
48
|
-
/* eslint-disable node/no-unsupported-features/node-builtins */
|
49
48
|
var group = console.group || dummy;
|
50
49
|
var groupCollapsed = console.groupCollapsed || dummy;
|
51
50
|
var groupEnd = console.groupEnd || dummy;
|
52
|
-
/* eslint-enable node/no-unsupported-features/node-builtins */
|
53
51
|
|
54
52
|
module.exports.group = logGroup(group);
|
55
53
|
|
package/lib/APIPlugin.js
CHANGED
package/lib/ChunkGraph.js
CHANGED
@@ -1539,7 +1539,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1539
1539
|
return withConnections
|
1540
1540
|
? BigInt(
|
1541
1541
|
`0x${this._getModuleGraphHashWithConnections(cgm, module, runtime)}`
|
1542
|
-
|
1542
|
+
)
|
1543
1543
|
: this._getModuleGraphHashBigInt(cgm, module, runtime);
|
1544
1544
|
}
|
1545
1545
|
|
package/lib/CleanPlugin.js
CHANGED
@@ -328,18 +328,18 @@ class CleanPlugin {
|
|
328
328
|
typeof keep === "function"
|
329
329
|
? keep
|
330
330
|
: typeof keep === "string"
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
331
|
+
? /**
|
332
|
+
* @param {string} path path
|
333
|
+
* @returns {boolean} true, if the path should be kept
|
334
|
+
*/
|
335
|
+
path => path.startsWith(keep)
|
336
|
+
: typeof keep === "object" && keep.test
|
337
|
+
? /**
|
338
|
+
* @param {string} path path
|
339
|
+
* @returns {boolean} true, if the path should be kept
|
340
|
+
*/
|
341
|
+
path => keep.test(path)
|
342
|
+
: () => false;
|
343
343
|
|
344
344
|
// We assume that no external modification happens while the compiler is active
|
345
345
|
// So we can store the old assets and only diff to them to avoid fs access on
|
package/lib/Compilation.js
CHANGED
@@ -885,6 +885,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
885
885
|
this.resolverFactory = compiler.resolverFactory;
|
886
886
|
this.inputFileSystem = compiler.inputFileSystem;
|
887
887
|
this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
|
888
|
+
unmanagedPaths: compiler.unmanagedPaths,
|
888
889
|
managedPaths: compiler.managedPaths,
|
889
890
|
immutablePaths: compiler.immutablePaths,
|
890
891
|
logger: this.getLogger("webpack.FileSystemInfo"),
|
@@ -1177,9 +1178,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1177
1178
|
};
|
1178
1179
|
if (this.hooks.log.call(name, logEntry) === undefined) {
|
1179
1180
|
if (logEntry.type === LogType.profileEnd) {
|
1180
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
1181
1181
|
if (typeof console.profileEnd === "function") {
|
1182
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
1183
1182
|
console.profileEnd(`[${name}] ${logEntry.args[0]}`);
|
1184
1183
|
}
|
1185
1184
|
}
|
@@ -1192,9 +1191,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1192
1191
|
}
|
1193
1192
|
logEntries.push(logEntry);
|
1194
1193
|
if (logEntry.type === LogType.profile) {
|
1195
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
1196
1194
|
if (typeof console.profile === "function") {
|
1197
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
1198
1195
|
console.profile(`[${name}] ${logEntry.args[0]}`);
|
1199
1196
|
}
|
1200
1197
|
}
|
@@ -1725,6 +1722,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1725
1722
|
originModule,
|
1726
1723
|
module,
|
1727
1724
|
true,
|
1725
|
+
false,
|
1728
1726
|
callback
|
1729
1727
|
);
|
1730
1728
|
}
|
@@ -1744,6 +1742,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1744
1742
|
* @property {string=} context
|
1745
1743
|
* @property {boolean=} recursive recurse into dependencies of the created module
|
1746
1744
|
* @property {boolean=} connectOrigin connect the resolved module with the origin module
|
1745
|
+
* @property {boolean=} checkCycle check the cycle dependencies of the created module
|
1747
1746
|
*/
|
1748
1747
|
|
1749
1748
|
/**
|
@@ -1759,7 +1758,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1759
1758
|
contextInfo,
|
1760
1759
|
context,
|
1761
1760
|
recursive = true,
|
1762
|
-
connectOrigin = recursive
|
1761
|
+
connectOrigin = recursive,
|
1762
|
+
checkCycle = !recursive
|
1763
1763
|
},
|
1764
1764
|
callback
|
1765
1765
|
) {
|
@@ -1880,6 +1880,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1880
1880
|
originModule,
|
1881
1881
|
module,
|
1882
1882
|
recursive,
|
1883
|
+
checkCycle,
|
1883
1884
|
callback
|
1884
1885
|
);
|
1885
1886
|
});
|
@@ -1887,10 +1888,16 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1887
1888
|
);
|
1888
1889
|
}
|
1889
1890
|
|
1890
|
-
_handleModuleBuildAndDependencies(
|
1891
|
+
_handleModuleBuildAndDependencies(
|
1892
|
+
originModule,
|
1893
|
+
module,
|
1894
|
+
recursive,
|
1895
|
+
checkCycle,
|
1896
|
+
callback
|
1897
|
+
) {
|
1891
1898
|
// Check for cycles when build is trigger inside another build
|
1892
1899
|
let creatingModuleDuringBuildSet = undefined;
|
1893
|
-
if (
|
1900
|
+
if (checkCycle && this.buildQueue.isProcessing(originModule)) {
|
1894
1901
|
// Track build dependency
|
1895
1902
|
creatingModuleDuringBuildSet =
|
1896
1903
|
this.creatingModuleDuringBuild.get(originModule);
|
@@ -1988,8 +1995,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1988
1995
|
context: context
|
1989
1996
|
? context
|
1990
1997
|
: originModule
|
1991
|
-
|
1992
|
-
|
1998
|
+
? originModule.context
|
1999
|
+
: this.compiler.context,
|
1993
2000
|
dependencies: dependencies
|
1994
2001
|
},
|
1995
2002
|
(err, result) => {
|
@@ -2668,9 +2675,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2668
2675
|
loaders
|
2669
2676
|
? `${
|
2670
2677
|
modules.length
|
2671
|
-
|
2678
|
+
} x ${moduleType} with ${this.requestShortener.shorten(
|
2672
2679
|
loaders
|
2673
|
-
|
2680
|
+
)}`
|
2674
2681
|
: `${modules.length} x ${moduleType}`
|
2675
2682
|
}`
|
2676
2683
|
);
|
@@ -3078,7 +3085,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3078
3085
|
`BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
|
3079
3086
|
Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
|
3080
3087
|
Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
|
3081
|
-
|
3088
|
+
)
|
3082
3089
|
: Object.freeze(this.assets);
|
3083
3090
|
|
3084
3091
|
this.summarizeDependencies();
|
@@ -3341,6 +3348,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3341
3348
|
dependencyTemplates,
|
3342
3349
|
runtimeTemplate,
|
3343
3350
|
runtime,
|
3351
|
+
runtimes,
|
3344
3352
|
codeGenerationResults: results,
|
3345
3353
|
compilation: this
|
3346
3354
|
});
|
@@ -4584,8 +4592,8 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4584
4592
|
(typeof file === "string"
|
4585
4593
|
? file
|
4586
4594
|
: typeof filenameTemplate === "string"
|
4587
|
-
|
4588
|
-
|
4595
|
+
? filenameTemplate
|
4596
|
+
: "");
|
4589
4597
|
|
4590
4598
|
this.errors.push(new ChunkRenderError(chunk, filename, err));
|
4591
4599
|
inTry = false;
|
@@ -4607,7 +4615,7 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4607
4615
|
? {
|
4608
4616
|
...pathAndInfo.info,
|
4609
4617
|
...fileManifest.info
|
4610
|
-
|
4618
|
+
}
|
4611
4619
|
: pathAndInfo.info;
|
4612
4620
|
}
|
4613
4621
|
|
@@ -4927,7 +4935,8 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4927
4935
|
hashFunction,
|
4928
4936
|
runtimeTemplate,
|
4929
4937
|
hashDigest,
|
4930
|
-
hashDigestLength
|
4938
|
+
hashDigestLength,
|
4939
|
+
errors
|
4931
4940
|
);
|
4932
4941
|
}
|
4933
4942
|
|
package/lib/Compiler.js
CHANGED
@@ -228,6 +228,8 @@ class Compiler {
|
|
228
228
|
/** @type {Set<string | RegExp>} */
|
229
229
|
this.managedPaths = new Set();
|
230
230
|
/** @type {Set<string | RegExp>} */
|
231
|
+
this.unmanagedPaths = new Set();
|
232
|
+
/** @type {Set<string | RegExp>} */
|
231
233
|
this.immutablePaths = new Set();
|
232
234
|
|
233
235
|
/** @type {ReadonlySet<string> | undefined} */
|
@@ -381,6 +383,17 @@ class Compiler {
|
|
381
383
|
// e.g. move compilation specific info from Modules into ModuleGraph
|
382
384
|
_cleanupLastCompilation() {
|
383
385
|
if (this._lastCompilation !== undefined) {
|
386
|
+
for (const childCompilation of this._lastCompilation.children) {
|
387
|
+
for (const module of childCompilation.modules) {
|
388
|
+
ChunkGraph.clearChunkGraphForModule(module);
|
389
|
+
ModuleGraph.clearModuleGraphForModule(module);
|
390
|
+
module.cleanupForCache();
|
391
|
+
}
|
392
|
+
for (const chunk of childCompilation.chunks) {
|
393
|
+
ChunkGraph.clearChunkGraphForChunk(chunk);
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
384
397
|
for (const module of this._lastCompilation.modules) {
|
385
398
|
ChunkGraph.clearChunkGraphForModule(module);
|
386
399
|
ModuleGraph.clearModuleGraphForModule(module);
|
@@ -114,8 +114,8 @@ class ConcatenationScope {
|
|
114
114
|
const asiSafeFlag = asiSafe
|
115
115
|
? "_asiSafe1"
|
116
116
|
: asiSafe === false
|
117
|
-
|
118
|
-
|
117
|
+
? "_asiSafe0"
|
118
|
+
: "";
|
119
119
|
const exportData = ids
|
120
120
|
? Buffer.from(JSON.stringify(ids), "utf-8").toString("hex")
|
121
121
|
: "ns";
|
package/lib/ContextModule.js
CHANGED
@@ -509,8 +509,8 @@ class ContextModule extends Module {
|
|
509
509
|
this.context
|
510
510
|
? [this.context]
|
511
511
|
: typeof this.options.resource === "string"
|
512
|
-
|
513
|
-
|
512
|
+
? [this.options.resource]
|
513
|
+
: /** @type {string[]} */ (this.options.resource),
|
514
514
|
null,
|
515
515
|
SNAPSHOT_OPTIONS,
|
516
516
|
(err, snapshot) => {
|
@@ -947,8 +947,8 @@ module.exports = webpackAsyncContext;`;
|
|
947
947
|
const requestPrefix = hasNoChunk
|
948
948
|
? "Promise.resolve()"
|
949
949
|
: hasMultipleOrNoChunks
|
950
|
-
|
951
|
-
|
950
|
+
? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
|
951
|
+
: `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
|
952
952
|
const returnModuleObject = this.getReturnModuleObjectSource(
|
953
953
|
fakeMap,
|
954
954
|
true,
|
@@ -160,7 +160,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
160
160
|
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
161
161
|
"dependencyType",
|
162
162
|
dependencies[0].category
|
163
|
-
|
163
|
+
)
|
164
164
|
: resolveOptions
|
165
165
|
);
|
166
166
|
const loaderResolver = this.resolverFactory.get("loader");
|
@@ -26,10 +26,12 @@
|
|
26
26
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
27
27
|
* @property {Set<string>} runtimeRequirements the requirements for runtime
|
28
28
|
* @property {Module} module current module
|
29
|
-
* @property {RuntimeSpec} runtime current
|
29
|
+
* @property {RuntimeSpec} runtime current runtime, for which code is generated
|
30
|
+
* @property {RuntimeSpec[]} [runtimes] current runtimes, for which code is generated
|
30
31
|
* @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
|
31
32
|
* @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
|
32
33
|
* @property {CodeGenerationResults} codeGenerationResults the code generation results
|
34
|
+
* @property {InitFragment<GenerateContext>[]} chunkInitFragments chunkInitFragments
|
33
35
|
*/
|
34
36
|
|
35
37
|
/**
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Gengkun He @ahabhgk
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("./WebpackError");
|
9
|
+
const makeSerializable = require("./util/makeSerializable");
|
10
|
+
|
11
|
+
/** @typedef {import("./Module")} Module */
|
12
|
+
/** @typedef {import("./Compilation")} Compilation */
|
13
|
+
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
14
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
15
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
16
|
+
/** @typedef {"asyncWebAssembly" | "topLevelAwait" | "external promise" | "external script" | "external import" | "external module"} Feature */
|
17
|
+
|
18
|
+
class EnvironmentNotSupportAsyncWarning extends WebpackError {
|
19
|
+
/**
|
20
|
+
* Creates an instance of EnvironmentNotSupportAsyncWarning.
|
21
|
+
* @param {Module} module module
|
22
|
+
* @param {Feature} feature feature
|
23
|
+
*/
|
24
|
+
constructor(module, feature) {
|
25
|
+
const message = `The generated code contains 'async/await' because this module is using "${feature}".
|
26
|
+
However, your target environment does not appear to support 'async/await'.
|
27
|
+
As a result, the code may not run as expected or may cause runtime errors.`;
|
28
|
+
super(message);
|
29
|
+
|
30
|
+
this.name = "EnvironmentNotSupportAsyncWarning";
|
31
|
+
this.module = module;
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Creates an instance of EnvironmentNotSupportAsyncWarning.
|
36
|
+
* @param {Module} module module
|
37
|
+
* @param {RuntimeTemplate} runtimeTemplate compilation
|
38
|
+
* @param {Feature} feature feature
|
39
|
+
*/
|
40
|
+
static check(module, runtimeTemplate, feature) {
|
41
|
+
if (!runtimeTemplate.supportsAsyncFunction()) {
|
42
|
+
module.addWarning(new EnvironmentNotSupportAsyncWarning(module, feature));
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
makeSerializable(
|
48
|
+
EnvironmentNotSupportAsyncWarning,
|
49
|
+
"webpack/lib/EnvironmentNotSupportAsyncWarning"
|
50
|
+
);
|
51
|
+
|
52
|
+
module.exports = EnvironmentNotSupportAsyncWarning;
|
@@ -48,12 +48,12 @@ class ExportsInfoApiPlugin {
|
|
48
48
|
/** @type {Range} */ (expr.range),
|
49
49
|
members.slice(0, -1),
|
50
50
|
members[members.length - 1]
|
51
|
-
|
51
|
+
)
|
52
52
|
: new ExportsInfoDependency(
|
53
53
|
/** @type {Range} */ (expr.range),
|
54
54
|
null,
|
55
55
|
members[0]
|
56
|
-
|
56
|
+
);
|
57
57
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
58
58
|
parser.state.module.addDependency(dep);
|
59
59
|
return true;
|
package/lib/ExternalModule.js
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const { OriginalSource, RawSource } = require("webpack-sources");
|
9
9
|
const ConcatenationScope = require("./ConcatenationScope");
|
10
|
+
const EnvironmentNotSupportAsyncWarning = require("./EnvironmentNotSupportAsyncWarning");
|
10
11
|
const { UsageState } = require("./ExportsInfo");
|
11
12
|
const InitFragment = require("./InitFragment");
|
12
13
|
const Module = require("./Module");
|
@@ -217,7 +218,12 @@ register(
|
|
217
218
|
}
|
218
219
|
);
|
219
220
|
|
220
|
-
const generateModuleRemapping = (
|
221
|
+
const generateModuleRemapping = (
|
222
|
+
input,
|
223
|
+
exportsInfo,
|
224
|
+
runtime,
|
225
|
+
runtimeTemplate
|
226
|
+
) => {
|
221
227
|
if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
|
222
228
|
const properties = [];
|
223
229
|
for (const exportInfo of exportsInfo.orderedExports) {
|
@@ -235,9 +241,9 @@ const generateModuleRemapping = (input, exportsInfo, runtime) => {
|
|
235
241
|
}
|
236
242
|
}
|
237
243
|
properties.push(
|
238
|
-
`[${JSON.stringify(used)}]:
|
239
|
-
exportInfo.name
|
240
|
-
|
244
|
+
`[${JSON.stringify(used)}]: ${runtimeTemplate.returningFunction(
|
245
|
+
`${input}${propertyAccess([exportInfo.name])}`
|
246
|
+
)}`
|
241
247
|
);
|
242
248
|
}
|
243
249
|
return `x({ ${properties.join(", ")} })`;
|
@@ -248,21 +254,21 @@ const generateModuleRemapping = (input, exportsInfo, runtime) => {
|
|
248
254
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
249
255
|
* @param {ExportsInfo} exportsInfo exports info of this module
|
250
256
|
* @param {RuntimeSpec} runtime the runtime
|
251
|
-
* @param {
|
257
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
252
258
|
* @returns {SourceData} the generated source
|
253
259
|
*/
|
254
260
|
const getSourceForModuleExternal = (
|
255
261
|
moduleAndSpecifiers,
|
256
262
|
exportsInfo,
|
257
263
|
runtime,
|
258
|
-
|
264
|
+
runtimeTemplate
|
259
265
|
) => {
|
260
266
|
if (!Array.isArray(moduleAndSpecifiers))
|
261
267
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
262
268
|
const initFragment = new ModuleExternalInitFragment(
|
263
269
|
moduleAndSpecifiers[0],
|
264
270
|
undefined,
|
265
|
-
hashFunction
|
271
|
+
runtimeTemplate.outputOptions.hashFunction
|
266
272
|
);
|
267
273
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
268
274
|
moduleAndSpecifiers,
|
@@ -271,12 +277,19 @@ const getSourceForModuleExternal = (
|
|
271
277
|
const moduleRemapping = generateModuleRemapping(
|
272
278
|
baseAccess,
|
273
279
|
exportsInfo,
|
274
|
-
runtime
|
280
|
+
runtime,
|
281
|
+
runtimeTemplate
|
275
282
|
);
|
276
283
|
let expression = moduleRemapping || baseAccess;
|
277
284
|
return {
|
278
285
|
expression,
|
279
|
-
init: `var x =
|
286
|
+
init: `var x = ${runtimeTemplate.basicFunction(
|
287
|
+
"y",
|
288
|
+
`var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x`
|
289
|
+
)} \nvar y = ${runtimeTemplate.returningFunction(
|
290
|
+
runtimeTemplate.returningFunction("x"),
|
291
|
+
"x"
|
292
|
+
)}`,
|
280
293
|
runtimeRequirements: moduleRemapping
|
281
294
|
? RUNTIME_REQUIREMENTS_FOR_MODULE
|
282
295
|
: undefined,
|
@@ -355,7 +368,7 @@ const getSourceForAmdOrUmdExternal = (
|
|
355
368
|
externalVariable,
|
356
369
|
Array.isArray(request) ? request.join(".") : request,
|
357
370
|
runtimeTemplate
|
358
|
-
|
371
|
+
)
|
359
372
|
: undefined,
|
360
373
|
expression: externalVariable
|
361
374
|
};
|
@@ -491,6 +504,11 @@ class ExternalModule extends Module {
|
|
491
504
|
}
|
492
505
|
} else {
|
493
506
|
this.buildMeta.async = true;
|
507
|
+
EnvironmentNotSupportAsyncWarning.check(
|
508
|
+
this,
|
509
|
+
compilation.runtimeTemplate,
|
510
|
+
"external module"
|
511
|
+
);
|
494
512
|
if (!Array.isArray(request) || request.length === 1) {
|
495
513
|
this.buildMeta.exportsType = "namespace";
|
496
514
|
canMangle = false;
|
@@ -498,11 +516,28 @@ class ExternalModule extends Module {
|
|
498
516
|
}
|
499
517
|
break;
|
500
518
|
case "script":
|
519
|
+
this.buildMeta.async = true;
|
520
|
+
EnvironmentNotSupportAsyncWarning.check(
|
521
|
+
this,
|
522
|
+
compilation.runtimeTemplate,
|
523
|
+
"external script"
|
524
|
+
);
|
525
|
+
break;
|
501
526
|
case "promise":
|
502
527
|
this.buildMeta.async = true;
|
528
|
+
EnvironmentNotSupportAsyncWarning.check(
|
529
|
+
this,
|
530
|
+
compilation.runtimeTemplate,
|
531
|
+
"external promise"
|
532
|
+
);
|
503
533
|
break;
|
504
534
|
case "import":
|
505
535
|
this.buildMeta.async = true;
|
536
|
+
EnvironmentNotSupportAsyncWarning.check(
|
537
|
+
this,
|
538
|
+
compilation.runtimeTemplate,
|
539
|
+
"external import"
|
540
|
+
);
|
506
541
|
if (!Array.isArray(request) || request.length === 1) {
|
507
542
|
this.buildMeta.exportsType = "namespace";
|
508
543
|
canMangle = false;
|
@@ -569,7 +604,7 @@ class ExternalModule extends Module {
|
|
569
604
|
? getSourceForCommonJsExternalInNodeModule(
|
570
605
|
request,
|
571
606
|
runtimeTemplate.outputOptions.importMetaName
|
572
|
-
|
607
|
+
)
|
573
608
|
: getSourceForCommonJsExternal(request);
|
574
609
|
case "amd":
|
575
610
|
case "amd-require":
|
@@ -610,7 +645,7 @@ class ExternalModule extends Module {
|
|
610
645
|
request,
|
611
646
|
moduleGraph.getExportsInfo(this),
|
612
647
|
runtime,
|
613
|
-
runtimeTemplate
|
648
|
+
runtimeTemplate
|
614
649
|
);
|
615
650
|
}
|
616
651
|
case "var":
|
package/lib/FileSystemInfo.js
CHANGED
@@ -729,7 +729,8 @@ class SnapshotOptimization {
|
|
729
729
|
}
|
730
730
|
|
731
731
|
const parseString = str => {
|
732
|
-
if (str[0] === "'"
|
732
|
+
if (str[0] === "'" || str[0] === "`")
|
733
|
+
str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
|
733
734
|
return JSON.parse(str);
|
734
735
|
};
|
735
736
|
|
@@ -898,6 +899,7 @@ class FileSystemInfo {
|
|
898
899
|
/**
|
899
900
|
* @param {InputFileSystem} fs file system
|
900
901
|
* @param {Object} options options
|
902
|
+
* @param {Iterable<string | RegExp>=} options.unmanagedPaths paths that are not managed by a package manager and the contents are subject to change
|
901
903
|
* @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
|
902
904
|
* @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
|
903
905
|
* @param {Logger=} options.logger logger used to log invalid snapshots
|
@@ -906,6 +908,7 @@ class FileSystemInfo {
|
|
906
908
|
constructor(
|
907
909
|
fs,
|
908
910
|
{
|
911
|
+
unmanagedPaths = [],
|
909
912
|
managedPaths = [],
|
910
913
|
immutablePaths = [],
|
911
914
|
logger,
|
@@ -1040,6 +1043,14 @@ class FileSystemInfo {
|
|
1040
1043
|
parallelism: 10,
|
1041
1044
|
processor: this._getManagedItemDirectoryInfo.bind(this)
|
1042
1045
|
});
|
1046
|
+
const _unmanagedPaths = Array.from(unmanagedPaths);
|
1047
|
+
this.unmanagedPathsWithSlash = /** @type {string[]} */ (
|
1048
|
+
_unmanagedPaths.filter(p => typeof p === "string")
|
1049
|
+
).map(p => join(fs, p, "_").slice(0, -1));
|
1050
|
+
this.unmanagedPathsRegExps = /** @type {RegExp[]} */ (
|
1051
|
+
_unmanagedPaths.filter(p => typeof p !== "string")
|
1052
|
+
);
|
1053
|
+
|
1043
1054
|
this.managedPaths = Array.from(managedPaths);
|
1044
1055
|
this.managedPathsWithSlash = /** @type {string[]} */ (
|
1045
1056
|
this.managedPaths.filter(p => typeof p === "string")
|
@@ -1733,7 +1744,7 @@ class FileSystemInfo {
|
|
1733
1744
|
type: RBDT_RESOLVE_ESM_FILE,
|
1734
1745
|
context,
|
1735
1746
|
path: dependency,
|
1736
|
-
expected: undefined,
|
1747
|
+
expected: imp.d > -1 ? false : undefined,
|
1737
1748
|
issuer: job
|
1738
1749
|
});
|
1739
1750
|
} catch (e) {
|
@@ -2028,6 +2039,12 @@ class FileSystemInfo {
|
|
2028
2039
|
}
|
2029
2040
|
};
|
2030
2041
|
const checkManaged = (path, managedSet) => {
|
2042
|
+
for (const unmanagedPath of this.unmanagedPathsRegExps) {
|
2043
|
+
if (unmanagedPath.test(path)) return false;
|
2044
|
+
}
|
2045
|
+
for (const unmanagedPath of this.unmanagedPathsWithSlash) {
|
2046
|
+
if (path.startsWith(unmanagedPath)) return false;
|
2047
|
+
}
|
2031
2048
|
for (const immutablePath of this.immutablePathsRegExps) {
|
2032
2049
|
if (immutablePath.test(path)) {
|
2033
2050
|
managedSet.add(path);
|
@@ -3346,7 +3363,7 @@ class FileSystemInfo {
|
|
3346
3363
|
: {
|
3347
3364
|
...timestamp,
|
3348
3365
|
...hash
|
3349
|
-
|
3366
|
+
};
|
3350
3367
|
this._contextTshs.set(path, result);
|
3351
3368
|
callback(null, result);
|
3352
3369
|
};
|
package/lib/Generator.js
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
28
28
|
* @property {Set<string>} runtimeRequirements the requirements for runtime
|
29
29
|
* @property {RuntimeSpec} runtime the runtime
|
30
|
+
* @property {RuntimeSpec[]} [runtimes] the runtimes
|
30
31
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
31
32
|
* @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
32
33
|
* @property {string} type which kind of code should be generated
|