webpack 5.36.0 → 5.37.1
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 +5 -8
- package/bin/webpack.js +0 -0
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +10 -5
- package/lib/ChunkGraph.js +58 -35
- package/lib/Compilation.js +116 -98
- package/lib/Compiler.js +31 -17
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextReplacementPlugin.js +4 -3
- package/lib/DefinePlugin.js +16 -12
- package/lib/EntryPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/FileSystemInfo.js +25 -31
- package/lib/FlagDependencyExportsPlugin.js +8 -7
- package/lib/FlagDependencyUsagePlugin.js +2 -4
- package/lib/HotModuleReplacementPlugin.js +20 -30
- package/lib/InitFragment.js +21 -6
- package/lib/JavascriptMetaInfoPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -3
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +2 -2
- package/lib/ModuleGraphConnection.js +6 -2
- package/lib/ModuleInfoHeaderPlugin.js +2 -3
- package/lib/MultiCompiler.js +31 -27
- package/lib/NormalModule.js +38 -7
- package/lib/NormalModuleFactory.js +27 -23
- package/lib/RecordIdsPlugin.js +5 -4
- package/lib/ResolverFactory.js +10 -7
- package/lib/RuntimeGlobals.js +7 -0
- package/lib/RuntimePlugin.js +19 -1
- package/lib/SourceMapDevToolPlugin.js +14 -15
- package/lib/Template.js +4 -2
- package/lib/Watching.js +83 -46
- package/lib/WebpackOptionsApply.js +1 -0
- package/lib/asset/AssetGenerator.js +19 -23
- package/lib/buildChunkGraph.js +28 -23
- package/lib/cache/PackFileCacheStrategy.js +77 -13
- package/lib/config/defaults.js +24 -10
- package/lib/config/normalization.js +17 -7
- package/lib/debug/ProfilingPlugin.js +4 -3
- package/lib/dependencies/AMDRequireDependency.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
- package/lib/dependencies/CommonJsPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +10 -8
- package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
- package/lib/dependencies/HarmonyExportInitFragment.js +47 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
- package/lib/dependencies/ImportDependency.js +3 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -4
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
- package/lib/dependencies/RequireEnsureDependency.js +3 -3
- package/lib/dependencies/WorkerDependency.js +6 -6
- package/lib/dependencies/WorkerPlugin.js +47 -20
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/ids/HashedModuleIdsPlugin.js +3 -3
- package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
- package/lib/index.js +5 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
- package/lib/javascript/JavascriptGenerator.js +3 -1
- package/lib/javascript/JavascriptModulesPlugin.js +15 -23
- package/lib/javascript/JavascriptParser.js +10 -8
- package/lib/library/AssignLibraryPlugin.js +4 -2
- package/lib/node/NodeWatchFileSystem.js +19 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
- package/lib/optimize/ConcatenatedModule.js +22 -27
- package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
- package/lib/optimize/InnerGraph.js +9 -11
- package/lib/optimize/InnerGraphPlugin.js +3 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
- package/lib/optimize/RealContentHashPlugin.js +14 -16
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
- package/lib/optimize/SplitChunksPlugin.js +13 -15
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
- package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
- package/lib/serialization/BinaryMiddleware.js +2 -3
- package/lib/serialization/FileMiddleware.js +3 -1
- package/lib/serialization/ObjectMiddleware.js +11 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -3
- package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
- package/lib/stats/StatsFactory.js +2 -1
- package/lib/stats/StatsPrinter.js +3 -3
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/cleverMerge.js +3 -1
- package/lib/util/comparators.js +13 -13
- package/lib/util/fs.js +8 -8
- package/lib/util/identifier.js +2 -1
- package/lib/util/internalSerializables.js +2 -0
- package/lib/validateSchema.js +5 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +6 -5
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
- package/lib/webpack.js +11 -7
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
- package/package.json +9 -6
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +103 -60
- package/types.d.ts +463 -280
@@ -48,6 +48,53 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
48
48
|
this.unusedExports = unusedExports;
|
49
49
|
}
|
50
50
|
|
51
|
+
/**
|
52
|
+
* @param {HarmonyExportInitFragment[]} fragments all fragments to merge
|
53
|
+
* @returns {HarmonyExportInitFragment} merged fragment
|
54
|
+
*/
|
55
|
+
mergeAll(fragments) {
|
56
|
+
let exportMap;
|
57
|
+
let exportMapOwned = false;
|
58
|
+
let unusedExports;
|
59
|
+
let unusedExportsOwned = false;
|
60
|
+
|
61
|
+
for (const fragment of fragments) {
|
62
|
+
if (fragment.exportMap.size !== 0) {
|
63
|
+
if (exportMap === undefined) {
|
64
|
+
exportMap = fragment.exportMap;
|
65
|
+
exportMapOwned = false;
|
66
|
+
} else {
|
67
|
+
if (!exportMapOwned) {
|
68
|
+
exportMap = new Map(exportMap);
|
69
|
+
exportMapOwned = true;
|
70
|
+
}
|
71
|
+
for (const [key, value] of fragment.exportMap) {
|
72
|
+
if (!exportMap.has(key)) exportMap.set(key, value);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
if (fragment.unusedExports.size !== 0) {
|
77
|
+
if (unusedExports === undefined) {
|
78
|
+
unusedExports = fragment.unusedExports;
|
79
|
+
unusedExportsOwned = false;
|
80
|
+
} else {
|
81
|
+
if (!unusedExportsOwned) {
|
82
|
+
unusedExports = new Set(unusedExports);
|
83
|
+
unusedExportsOwned = true;
|
84
|
+
}
|
85
|
+
for (const value of fragment.unusedExports) {
|
86
|
+
unusedExports.add(value);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
return new HarmonyExportInitFragment(
|
92
|
+
this.exportsArgument,
|
93
|
+
exportMap,
|
94
|
+
unusedExports
|
95
|
+
);
|
96
|
+
}
|
97
|
+
|
51
98
|
merge(other) {
|
52
99
|
let exportMap;
|
53
100
|
if (this.exportMap.size === 0) {
|
@@ -152,10 +152,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
152
152
|
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
153
153
|
return true;
|
154
154
|
});
|
155
|
-
const {
|
156
|
-
|
157
|
-
hotAcceptWithoutCallback
|
158
|
-
} = HotModuleReplacementPlugin.getParserHooks(parser);
|
155
|
+
const { hotAcceptCallback, hotAcceptWithoutCallback } =
|
156
|
+
HotModuleReplacementPlugin.getParserHooks(parser);
|
159
157
|
hotAcceptCallback.tap(
|
160
158
|
"HarmonyImportDependencyParserPlugin",
|
161
159
|
(expr, requests) => {
|
@@ -243,12 +243,8 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
243
243
|
*/
|
244
244
|
apply(dependency, source, templateContext) {
|
245
245
|
const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency);
|
246
|
-
const {
|
247
|
-
|
248
|
-
module,
|
249
|
-
runtime,
|
250
|
-
concatenationScope
|
251
|
-
} = templateContext;
|
246
|
+
const { moduleGraph, module, runtime, concatenationScope } =
|
247
|
+
templateContext;
|
252
248
|
const connection = moduleGraph.getConnection(dep);
|
253
249
|
// Skip rendering depending when dependency is conditional
|
254
250
|
if (connection && !connection.isTargetActive(runtime)) return;
|
@@ -287,11 +283,8 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
287
283
|
} else {
|
288
284
|
super.apply(dependency, source, templateContext);
|
289
285
|
|
290
|
-
const {
|
291
|
-
|
292
|
-
initFragments,
|
293
|
-
runtimeRequirements
|
294
|
-
} = templateContext;
|
286
|
+
const { runtimeTemplate, initFragments, runtimeRequirements } =
|
287
|
+
templateContext;
|
295
288
|
|
296
289
|
exportExpr = runtimeTemplate.exportFromImport({
|
297
290
|
moduleGraph,
|
@@ -81,9 +81,9 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
|
|
81
81
|
{ runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
|
82
82
|
) {
|
83
83
|
const dep = /** @type {ImportDependency} */ (dependency);
|
84
|
-
const block = /** @type {AsyncDependenciesBlock} */ (
|
85
|
-
dep
|
86
|
-
)
|
84
|
+
const block = /** @type {AsyncDependenciesBlock} */ (
|
85
|
+
moduleGraph.getParentBlock(dep)
|
86
|
+
);
|
87
87
|
const content = runtimeTemplate.moduleNamespacePromise({
|
88
88
|
chunkGraph,
|
89
89
|
block: block,
|
@@ -36,10 +36,8 @@ class ImportParserPlugin {
|
|
36
36
|
/** @type {RawChunkGroupOptions} */
|
37
37
|
const groupOptions = {};
|
38
38
|
|
39
|
-
const {
|
40
|
-
|
41
|
-
errors: commentErrors
|
42
|
-
} = parser.parseCommentOptions(expr.range);
|
39
|
+
const { options: importOptions, errors: commentErrors } =
|
40
|
+
parser.parseCommentOptions(expr.range);
|
43
41
|
|
44
42
|
if (commentErrors) {
|
45
43
|
for (const e of commentErrors) {
|
@@ -46,9 +46,8 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
46
46
|
? dependenciesExpr.items
|
47
47
|
: [dependenciesExpr];
|
48
48
|
const successExpressionArg = expr.arguments[1];
|
49
|
-
const successExpression =
|
50
|
-
successExpressionArg
|
51
|
-
);
|
49
|
+
const successExpression =
|
50
|
+
getFunctionExpression(successExpressionArg);
|
52
51
|
|
53
52
|
if (successExpression) {
|
54
53
|
parser.walkExpressions(successExpression.expressions);
|
@@ -68,9 +68,9 @@ RequireEnsureDependency.Template = class RequireEnsureDependencyTemplate extends
|
|
68
68
|
{ runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
|
69
69
|
) {
|
70
70
|
const dep = /** @type {RequireEnsureDependency} */ (dependency);
|
71
|
-
const depBlock = /** @type {AsyncDependenciesBlock} */ (
|
72
|
-
dep
|
73
|
-
)
|
71
|
+
const depBlock = /** @type {AsyncDependenciesBlock} */ (
|
72
|
+
moduleGraph.getParentBlock(dep)
|
73
|
+
);
|
74
74
|
const promise = runtimeTemplate.blockPromise({
|
75
75
|
chunkGraph,
|
76
76
|
block: depBlock,
|
@@ -62,12 +62,12 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
|
|
62
62
|
apply(dependency, source, templateContext) {
|
63
63
|
const { chunkGraph, moduleGraph, runtimeRequirements } = templateContext;
|
64
64
|
const dep = /** @type {WorkerDependency} */ (dependency);
|
65
|
-
const block = /** @type {AsyncDependenciesBlock} */ (
|
66
|
-
dependency
|
67
|
-
)
|
68
|
-
const entrypoint = /** @type {Entrypoint} */ (
|
69
|
-
block
|
70
|
-
)
|
65
|
+
const block = /** @type {AsyncDependenciesBlock} */ (
|
66
|
+
moduleGraph.getParentBlock(dependency)
|
67
|
+
);
|
68
|
+
const entrypoint = /** @type {Entrypoint} */ (
|
69
|
+
chunkGraph.getBlockChunkGroup(block)
|
70
|
+
);
|
71
71
|
const chunk = entrypoint.getEntrypointChunk();
|
72
72
|
|
73
73
|
runtimeRequirements.add(RuntimeGlobals.publicPath);
|
@@ -9,12 +9,13 @@ const { pathToFileURL } = require("url");
|
|
9
9
|
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
10
10
|
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
11
11
|
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
12
|
-
const formatLocation = require("../formatLocation");
|
13
12
|
const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
|
14
13
|
const { equals } = require("../util/ArrayHelpers");
|
14
|
+
const createHash = require("../util/createHash");
|
15
15
|
const { contextify } = require("../util/identifier");
|
16
16
|
const EnableWasmLoadingPlugin = require("../wasm/EnableWasmLoadingPlugin");
|
17
17
|
const ConstDependency = require("./ConstDependency");
|
18
|
+
const CreateScriptUrlDependency = require("./CreateScriptUrlDependency");
|
18
19
|
const {
|
19
20
|
harmonySpecifierTag
|
20
21
|
} = require("./HarmonyImportDependencyParserPlugin");
|
@@ -27,6 +28,7 @@ const WorkerDependency = require("./WorkerDependency");
|
|
27
28
|
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
28
29
|
/** @typedef {import("../Compiler")} Compiler */
|
29
30
|
/** @typedef {import("../Entrypoint").EntryOptions} EntryOptions */
|
31
|
+
/** @typedef {import("../Parser").ParserState} ParserState */
|
30
32
|
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
31
33
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
32
34
|
/** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
|
@@ -42,6 +44,9 @@ const DEFAULT_SYNTAX = [
|
|
42
44
|
"Worker from worker_threads"
|
43
45
|
];
|
44
46
|
|
47
|
+
/** @type {WeakMap<ParserState, number>} */
|
48
|
+
const workerIndexMap = new WeakMap();
|
49
|
+
|
45
50
|
class WorkerPlugin {
|
46
51
|
constructor(chunkLoading, wasmLoading) {
|
47
52
|
this._chunkLoading = chunkLoading;
|
@@ -74,6 +79,10 @@ class WorkerPlugin {
|
|
74
79
|
WorkerDependency,
|
75
80
|
new WorkerDependency.Template()
|
76
81
|
);
|
82
|
+
compilation.dependencyTemplates.set(
|
83
|
+
CreateScriptUrlDependency,
|
84
|
+
new CreateScriptUrlDependency.Template()
|
85
|
+
);
|
77
86
|
|
78
87
|
/**
|
79
88
|
* @param {JavascriptParser} parser the parser
|
@@ -177,21 +186,18 @@ class WorkerPlugin {
|
|
177
186
|
spread: hasSpreadInOptions,
|
178
187
|
insertType,
|
179
188
|
insertLocation
|
180
|
-
} =
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
options: importOptions,
|
193
|
-
errors: commentErrors
|
194
|
-
} = parser.parseCommentOptions(expr.range);
|
189
|
+
} = arg2 && arg2.type === "ObjectExpression"
|
190
|
+
? parseObjectExpression(parser, arg2)
|
191
|
+
: {
|
192
|
+
expressions: {},
|
193
|
+
otherElements: [],
|
194
|
+
values: {},
|
195
|
+
spread: false,
|
196
|
+
insertType: arg2 ? "spread" : "argument",
|
197
|
+
insertLocation: arg2 ? arg2.range : arg1.range[1]
|
198
|
+
};
|
199
|
+
const { options: importOptions, errors: commentErrors } =
|
200
|
+
parser.parseCommentOptions(expr.range);
|
195
201
|
|
196
202
|
if (commentErrors) {
|
197
203
|
for (const e of commentErrors) {
|
@@ -264,9 +270,20 @@ class WorkerPlugin {
|
|
264
270
|
}
|
265
271
|
|
266
272
|
if (!entryOptions.runtime) {
|
267
|
-
|
273
|
+
let i = workerIndexMap.get(parser.state) || 0;
|
274
|
+
workerIndexMap.set(parser.state, i + 1);
|
275
|
+
let name = `${cachedContextify(
|
268
276
|
parser.state.module.identifier()
|
269
|
-
)}|${
|
277
|
+
)}|${i}`;
|
278
|
+
const hash = createHash(compilation.outputOptions.hashFunction);
|
279
|
+
hash.update(name);
|
280
|
+
const digest = /** @type {string} */ (
|
281
|
+
hash.digest(compilation.outputOptions.hashDigest)
|
282
|
+
);
|
283
|
+
entryOptions.runtime = digest.slice(
|
284
|
+
0,
|
285
|
+
compilation.outputOptions.hashDigestLength
|
286
|
+
);
|
270
287
|
}
|
271
288
|
|
272
289
|
const block = new AsyncDependenciesBlock({
|
@@ -282,7 +299,14 @@ class WorkerPlugin {
|
|
282
299
|
dep.loc = expr.loc;
|
283
300
|
block.addDependency(dep);
|
284
301
|
parser.state.module.addBlock(block);
|
285
|
-
|
302
|
+
|
303
|
+
if (compilation.outputOptions.trustedTypes) {
|
304
|
+
const dep = new CreateScriptUrlDependency(
|
305
|
+
expr.arguments[0].range
|
306
|
+
);
|
307
|
+
dep.loc = expr.loc;
|
308
|
+
parser.state.module.addDependency(dep);
|
309
|
+
}
|
286
310
|
|
287
311
|
if (expressions.type) {
|
288
312
|
const expr = expressions.type;
|
@@ -314,6 +338,7 @@ class WorkerPlugin {
|
|
314
338
|
parser.state.module.addPresentationalDependency(dep2);
|
315
339
|
}
|
316
340
|
|
341
|
+
parser.walkExpression(expr.callee);
|
317
342
|
for (const key of Object.keys(expressions)) {
|
318
343
|
if (expressions[key]) parser.walkExpression(expressions[key]);
|
319
344
|
}
|
@@ -340,7 +365,9 @@ class WorkerPlugin {
|
|
340
365
|
(call ? parser.hooks.call : parser.hooks.new)
|
341
366
|
.for(harmonySpecifierTag)
|
342
367
|
.tap("WorkerPlugin", expr => {
|
343
|
-
const settings = /** @type {HarmonySettings} */ (
|
368
|
+
const settings = /** @type {HarmonySettings} */ (
|
369
|
+
parser.currentTagData
|
370
|
+
);
|
344
371
|
if (
|
345
372
|
!settings ||
|
346
373
|
settings.source !== source ||
|
@@ -196,8 +196,9 @@ class LazyCompilationProxyModule extends Module {
|
|
196
196
|
const sources = new Map();
|
197
197
|
const runtimeRequirements = new Set();
|
198
198
|
runtimeRequirements.add(RuntimeGlobals.module);
|
199
|
-
const clientDep = /** @type {CommonJsRequireDependency} */ (
|
200
|
-
.dependencies[0]
|
199
|
+
const clientDep = /** @type {CommonJsRequireDependency} */ (
|
200
|
+
this.dependencies[0]
|
201
|
+
);
|
201
202
|
const clientModule = moduleGraph.getModule(clientDep);
|
202
203
|
const block = this.blocks[0];
|
203
204
|
const client = Template.asString([
|
@@ -290,8 +291,9 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|
290
291
|
* @returns {void}
|
291
292
|
*/
|
292
293
|
create(data, callback) {
|
293
|
-
const dependency = /** @type {LazyCompilationDependency} */ (
|
294
|
-
.dependencies[0]
|
294
|
+
const dependency = /** @type {LazyCompilationDependency} */ (
|
295
|
+
data.dependencies[0]
|
296
|
+
);
|
295
297
|
callback(null, {
|
296
298
|
module: dependency.proxyModule.originalModule
|
297
299
|
});
|
@@ -63,9 +63,9 @@ class HashedModuleIdsPlugin {
|
|
63
63
|
const ident = getFullModuleName(module, context, compiler.root);
|
64
64
|
const hash = createHash(options.hashFunction);
|
65
65
|
hash.update(ident || "");
|
66
|
-
const hashId = /** @type {string} */ (
|
67
|
-
options.hashDigest
|
68
|
-
)
|
66
|
+
const hashId = /** @type {string} */ (
|
67
|
+
hash.digest(options.hashDigest)
|
68
|
+
);
|
69
69
|
let len = options.hashDigestLength;
|
70
70
|
while (usedIds.has(hashId.substr(0, len))) len++;
|
71
71
|
const moduleId = hashId.substr(0, len);
|
@@ -98,9 +98,8 @@ class OccurrenceModuleIdsPlugin {
|
|
98
98
|
connections
|
99
99
|
] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
|
100
100
|
if (!originModule) continue;
|
101
|
-
const chunkModules =
|
102
|
-
originModule
|
103
|
-
);
|
101
|
+
const chunkModules =
|
102
|
+
chunkGraph.getNumberOfModuleChunks(originModule);
|
104
103
|
for (const c of connections) {
|
105
104
|
if (!c.isTargetActive(undefined)) continue;
|
106
105
|
if (!c.dependency) continue;
|
package/lib/index.js
CHANGED
@@ -50,9 +50,11 @@ const memoize = require("./util/memoize");
|
|
50
50
|
*/
|
51
51
|
const lazyFunction = factory => {
|
52
52
|
const fac = memoize(factory);
|
53
|
-
const f = /** @type {any} */ (
|
54
|
-
|
55
|
-
|
53
|
+
const f = /** @type {any} */ (
|
54
|
+
(...args) => {
|
55
|
+
return fac()(...args);
|
56
|
+
}
|
57
|
+
);
|
56
58
|
return /** @type {T} */ (f);
|
57
59
|
};
|
58
60
|
|
@@ -47,9 +47,8 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
47
47
|
chunk instanceof HotUpdateChunk ? chunk : null;
|
48
48
|
const globalObject = runtimeTemplate.outputOptions.globalObject;
|
49
49
|
const source = new ConcatSource();
|
50
|
-
const runtimeModules =
|
51
|
-
chunk
|
52
|
-
);
|
50
|
+
const runtimeModules =
|
51
|
+
chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
53
52
|
if (hotUpdateChunk) {
|
54
53
|
const hotUpdateGlobal =
|
55
54
|
runtimeTemplate.outputOptions.hotUpdateGlobal;
|
@@ -83,9 +82,8 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
83
82
|
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
84
83
|
);
|
85
84
|
if (runtimeModules.length > 0 || entries.length > 0) {
|
86
|
-
const strictBailout =
|
87
|
-
renderContext
|
88
|
-
);
|
85
|
+
const strictBailout =
|
86
|
+
hooks.strictRuntimeBailout.call(renderContext);
|
89
87
|
const runtime = new ConcatSource(
|
90
88
|
(runtimeTemplate.supportsArrowFunction()
|
91
89
|
? "__webpack_require__ =>"
|
@@ -51,9 +51,8 @@ class CommonJsChunkFormatPlugin {
|
|
51
51
|
source.add(`exports.modules = `);
|
52
52
|
source.add(modules);
|
53
53
|
source.add(";\n");
|
54
|
-
const runtimeModules =
|
55
|
-
chunk
|
56
|
-
);
|
54
|
+
const runtimeModules =
|
55
|
+
chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
57
56
|
if (runtimeModules.length > 0) {
|
58
57
|
source.add("exports.runtime =\n");
|
59
58
|
source.add(
|
@@ -180,7 +180,9 @@ class JavascriptGenerator extends Generator {
|
|
180
180
|
* @returns {void}
|
181
181
|
*/
|
182
182
|
sourceDependency(module, dependency, initFragments, source, generateContext) {
|
183
|
-
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
183
|
+
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
184
|
+
dependency.constructor
|
185
|
+
);
|
184
186
|
const template = generateContext.dependencyTemplates.get(constructor);
|
185
187
|
if (!template) {
|
186
188
|
throw new Error(
|
@@ -228,10 +228,11 @@ class JavascriptModulesPlugin {
|
|
228
228
|
chunk instanceof HotUpdateChunk ? chunk : null;
|
229
229
|
|
230
230
|
let render;
|
231
|
-
const filenameTemplate =
|
232
|
-
|
233
|
-
|
234
|
-
|
231
|
+
const filenameTemplate =
|
232
|
+
JavascriptModulesPlugin.getChunkFilenameTemplate(
|
233
|
+
chunk,
|
234
|
+
outputOptions
|
235
|
+
);
|
235
236
|
if (hotUpdateChunk) {
|
236
237
|
render = () =>
|
237
238
|
this.renderChunk(
|
@@ -394,9 +395,8 @@ class JavascriptModulesPlugin {
|
|
394
395
|
compilation.hooks.executeModule.tap(
|
395
396
|
"JavascriptModulesPlugin",
|
396
397
|
(options, context) => {
|
397
|
-
const source =
|
398
|
-
"javascript"
|
399
|
-
);
|
398
|
+
const source =
|
399
|
+
options.codeGenerationResult.sources.get("javascript");
|
400
400
|
if (source === undefined) return;
|
401
401
|
const { module, moduleObject } = options;
|
402
402
|
const code = source.source();
|
@@ -468,12 +468,8 @@ class JavascriptModulesPlugin {
|
|
468
468
|
* @returns {Source} the newly generated source from rendering
|
469
469
|
*/
|
470
470
|
renderModule(module, renderContext, hooks, factory) {
|
471
|
-
const {
|
472
|
-
|
473
|
-
chunkGraph,
|
474
|
-
runtimeTemplate,
|
475
|
-
codeGenerationResults
|
476
|
-
} = renderContext;
|
471
|
+
const { chunk, chunkGraph, runtimeTemplate, codeGenerationResults } =
|
472
|
+
renderContext;
|
477
473
|
try {
|
478
474
|
const moduleSource = codeGenerationResults.getSource(
|
479
475
|
module,
|
@@ -699,9 +695,8 @@ class JavascriptModulesPlugin {
|
|
699
695
|
);
|
700
696
|
}
|
701
697
|
|
702
|
-
const runtimeModules =
|
703
|
-
chunk
|
704
|
-
);
|
698
|
+
const runtimeModules =
|
699
|
+
renderContext.chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
705
700
|
|
706
701
|
if (runtimeModules.length > 0) {
|
707
702
|
source.add(
|
@@ -985,9 +980,8 @@ class JavascriptModulesPlugin {
|
|
985
980
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
986
981
|
/** @type {string[]} */
|
987
982
|
const buf2 = [];
|
988
|
-
const runtimeRequirements =
|
989
|
-
chunk
|
990
|
-
);
|
983
|
+
const runtimeRequirements =
|
984
|
+
chunkGraph.getTreeRuntimeRequirements(chunk);
|
991
985
|
buf2.push("// Load entry module and return exports");
|
992
986
|
let i = chunkGraph.getNumberOfEntryModules(chunk);
|
993
987
|
for (const [
|
@@ -1044,10 +1038,8 @@ class JavascriptModulesPlugin {
|
|
1044
1038
|
}
|
1045
1039
|
i--;
|
1046
1040
|
const moduleId = chunkGraph.getModuleId(entryModule);
|
1047
|
-
const entryRuntimeRequirements =
|
1048
|
-
entryModule,
|
1049
|
-
chunk.runtime
|
1050
|
-
);
|
1041
|
+
const entryRuntimeRequirements =
|
1042
|
+
chunkGraph.getModuleRuntimeRequirements(entryModule, chunk.runtime);
|
1051
1043
|
let moduleIdExpr = JSON.stringify(moduleId);
|
1052
1044
|
if (runtimeRequirements.has(RuntimeGlobals.entryModuleId)) {
|
1053
1045
|
moduleIdExpr = `${RuntimeGlobals.entryModuleId} = ${moduleIdExpr}`;
|
@@ -3336,8 +3336,10 @@ class JavascriptParser extends Parser {
|
|
3336
3336
|
if (expr.superClass && !this.isPure(expr.superClass, expr.range[0])) {
|
3337
3337
|
return false;
|
3338
3338
|
}
|
3339
|
-
const items =
|
3340
|
-
|
3339
|
+
const items =
|
3340
|
+
/** @type {(MethodDefinitionNode | PropertyDefinitionNode)[]} */ (
|
3341
|
+
expr.body.body
|
3342
|
+
);
|
3341
3343
|
return items.every(
|
3342
3344
|
item =>
|
3343
3345
|
(!item.computed ||
|
@@ -3623,10 +3625,8 @@ class JavascriptParser extends Parser {
|
|
3623
3625
|
let callee = object.callee;
|
3624
3626
|
let rootMembers = EMPTY_ARRAY;
|
3625
3627
|
if (callee.type === "MemberExpression") {
|
3626
|
-
({
|
3627
|
-
|
3628
|
-
members: rootMembers
|
3629
|
-
} = this.extractMemberExpressionChain(callee));
|
3628
|
+
({ object: callee, members: rootMembers } =
|
3629
|
+
this.extractMemberExpressionChain(callee));
|
3630
3630
|
}
|
3631
3631
|
const rootName = getRootName(callee);
|
3632
3632
|
if (!rootName) return undefined;
|
@@ -3729,5 +3729,7 @@ class JavascriptParser extends Parser {
|
|
3729
3729
|
|
3730
3730
|
module.exports = JavascriptParser;
|
3731
3731
|
module.exports.ALLOWED_MEMBER_TYPES_ALL = ALLOWED_MEMBER_TYPES_ALL;
|
3732
|
-
module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
3733
|
-
|
3732
|
+
module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
|
3733
|
+
ALLOWED_MEMBER_TYPES_EXPRESSION;
|
3734
|
+
module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
|
3735
|
+
ALLOWED_MEMBER_TYPES_CALL_EXPRESSION;
|
@@ -24,8 +24,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
24
24
|
/** @typedef {import("../util/Hash")} Hash */
|
25
25
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
26
26
|
|
27
|
-
const KEYWORD_REGEX =
|
28
|
-
const
|
27
|
+
const KEYWORD_REGEX =
|
28
|
+
/^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
|
29
|
+
const IDENTIFIER_REGEX =
|
30
|
+
/^[\p{L}\p{Nl}$_][\p{L}\p{Nl}$\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$/iu;
|
29
31
|
|
30
32
|
/**
|
31
33
|
* Validates the library name by checking for keywords and valid characters
|
@@ -70,11 +70,12 @@ class NodeWatchFileSystem {
|
|
70
70
|
}
|
71
71
|
this.watcher.once("aggregated", (changes, removals) => {
|
72
72
|
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
73
|
+
const fs = this.inputFileSystem;
|
73
74
|
for (const item of changes) {
|
74
|
-
|
75
|
+
fs.purge(item);
|
75
76
|
}
|
76
77
|
for (const item of removals) {
|
77
|
-
|
78
|
+
fs.purge(item);
|
78
79
|
}
|
79
80
|
}
|
80
81
|
const times = this.watcher.getTimeInfoEntries();
|
@@ -99,10 +100,24 @@ class NodeWatchFileSystem {
|
|
99
100
|
}
|
100
101
|
},
|
101
102
|
getAggregatedRemovals: () => {
|
102
|
-
|
103
|
+
const items = this.watcher && this.watcher.aggregatedRemovals;
|
104
|
+
if (items && this.inputFileSystem && this.inputFileSystem.purge) {
|
105
|
+
const fs = this.inputFileSystem;
|
106
|
+
for (const item of items) {
|
107
|
+
fs.purge(item);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return items;
|
103
111
|
},
|
104
112
|
getAggregatedChanges: () => {
|
105
|
-
|
113
|
+
const items = this.watcher && this.watcher.aggregatedChanges;
|
114
|
+
if (items && this.inputFileSystem && this.inputFileSystem.purge) {
|
115
|
+
const fs = this.inputFileSystem;
|
116
|
+
for (const item of items) {
|
117
|
+
fs.purge(item);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return items;
|
106
121
|
},
|
107
122
|
getFileTimeInfoEntries: () => {
|
108
123
|
if (this.watcher) {
|
@@ -109,10 +109,11 @@ class AggressiveSplittingPlugin {
|
|
109
109
|
// Precompute stuff
|
110
110
|
const nameToModuleMap = new Map();
|
111
111
|
const moduleToNameMap = new Map();
|
112
|
-
const makePathsRelative =
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
const makePathsRelative =
|
113
|
+
identifierUtils.makePathsRelative.bindContextCache(
|
114
|
+
compiler.context,
|
115
|
+
compiler.root
|
116
|
+
);
|
116
117
|
for (const m of compilation.modules) {
|
117
118
|
const name = makePathsRelative(m.identifier());
|
118
119
|
nameToModuleMap.set(name, m);
|