webpack 5.68.0 → 5.69.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/lib/ChunkGraph.js +1 -2
- package/lib/Compilation.js +2 -0
- package/lib/ContextModule.js +79 -24
- package/lib/ContextModuleFactory.js +60 -21
- package/lib/ExportsInfo.js +4 -4
- package/lib/NormalModuleFactory.js +25 -27
- package/lib/ProgressPlugin.js +1 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/asset/AssetGenerator.js +3 -2
- package/lib/buildChunkGraph.js +1 -1
- package/lib/cache/ResolverCachePlugin.js +80 -28
- package/lib/config/defaults.js +7 -2
- package/lib/css/CssLoadingRuntimeModule.js +63 -70
- package/lib/css/CssModulesPlugin.js +2 -1
- package/lib/debug/ProfilingPlugin.js +3 -4
- package/lib/dependencies/ContextElementDependency.js +8 -2
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/index.js +5 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/StartupHelpers.js +3 -2
- package/lib/library/AssignLibraryPlugin.js +8 -2
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +10 -4
- package/lib/schemes/HttpUriPlugin.js +24 -3
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/identifier.js +65 -44
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/package.json +13 -13
- package/types.d.ts +46 -20
@@ -128,6 +128,11 @@ class ResolverCachePlugin {
|
|
128
128
|
fileDependencies: new LazySet(),
|
129
129
|
contextDependencies: new LazySet()
|
130
130
|
};
|
131
|
+
let yieldResult;
|
132
|
+
if (typeof newResolveContext.yield === "function") {
|
133
|
+
yieldResult = [];
|
134
|
+
newResolveContext.yield = obj => yieldResult.push(obj);
|
135
|
+
}
|
131
136
|
const propagate = key => {
|
132
137
|
if (resolveContext[key]) {
|
133
138
|
addAllToSet(resolveContext[key], newResolveContext[key]);
|
@@ -155,15 +160,19 @@ class ResolverCachePlugin {
|
|
155
160
|
snapshotOptions,
|
156
161
|
(err, snapshot) => {
|
157
162
|
if (err) return callback(err);
|
163
|
+
const resolveResult = result || yieldResult;
|
158
164
|
if (!snapshot) {
|
159
|
-
if (
|
165
|
+
if (resolveResult) return callback(null, resolveResult);
|
160
166
|
return callback();
|
161
167
|
}
|
162
|
-
itemCache.store(
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
168
|
+
itemCache.store(
|
169
|
+
new CacheEntry(resolveResult, snapshot),
|
170
|
+
storeErr => {
|
171
|
+
if (storeErr) return callback(storeErr);
|
172
|
+
if (resolveResult) return callback(null, resolveResult);
|
173
|
+
callback();
|
174
|
+
}
|
175
|
+
);
|
167
176
|
}
|
168
177
|
);
|
169
178
|
}
|
@@ -173,6 +182,8 @@ class ResolverCachePlugin {
|
|
173
182
|
factory(type, hook) {
|
174
183
|
/** @type {Map<string, (function(Error=, Object=): void)[]>} */
|
175
184
|
const activeRequests = new Map();
|
185
|
+
/** @type {Map<string, [function(Error=, Object=): void, function(Error=, Object=): void][]>} */
|
186
|
+
const activeRequestsWithYield = new Map();
|
176
187
|
hook.tap(
|
177
188
|
"ResolverCachePlugin",
|
178
189
|
/**
|
@@ -197,29 +208,63 @@ class ResolverCachePlugin {
|
|
197
208
|
if (request._ResolverCachePluginCacheMiss || !fileSystemInfo) {
|
198
209
|
return callback();
|
199
210
|
}
|
200
|
-
const
|
201
|
-
|
202
|
-
|
203
|
-
)}`;
|
204
|
-
|
205
|
-
if (
|
206
|
-
activeRequest.
|
207
|
-
|
211
|
+
const withYield = typeof resolveContext.yield === "function";
|
212
|
+
const identifier = `${type}${
|
213
|
+
withYield ? "|yield" : "|default"
|
214
|
+
}${optionsIdent}${objectToString(request, !cacheWithContext)}`;
|
215
|
+
|
216
|
+
if (withYield) {
|
217
|
+
const activeRequest = activeRequestsWithYield.get(identifier);
|
218
|
+
if (activeRequest) {
|
219
|
+
activeRequest[0].push(callback);
|
220
|
+
activeRequest[1].push(resolveContext.yield);
|
221
|
+
return;
|
222
|
+
}
|
223
|
+
} else {
|
224
|
+
const activeRequest = activeRequests.get(identifier);
|
225
|
+
if (activeRequest) {
|
226
|
+
activeRequest.push(callback);
|
227
|
+
return;
|
228
|
+
}
|
208
229
|
}
|
209
230
|
const itemCache = cache.getItemCache(identifier, null);
|
210
|
-
let callbacks;
|
211
|
-
const done =
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
231
|
+
let callbacks, yields;
|
232
|
+
const done = withYield
|
233
|
+
? (err, result) => {
|
234
|
+
if (callbacks === undefined) {
|
235
|
+
if (err) {
|
236
|
+
callback(err);
|
237
|
+
} else {
|
238
|
+
if (result)
|
239
|
+
for (const r of result) resolveContext.yield(r);
|
240
|
+
callback(null, null);
|
241
|
+
}
|
242
|
+
yields = undefined;
|
243
|
+
callbacks = false;
|
244
|
+
} else {
|
245
|
+
for (let i = 0; i < callbacks.length; i++) {
|
246
|
+
const cb = callbacks[i];
|
247
|
+
const yield_ = yields[i];
|
248
|
+
if (result) for (const r of result) yield_(r);
|
249
|
+
cb(null, null);
|
250
|
+
}
|
251
|
+
activeRequestsWithYield.delete(identifier);
|
252
|
+
yields = undefined;
|
253
|
+
callbacks = false;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
: (err, result) => {
|
257
|
+
if (callbacks === undefined) {
|
258
|
+
callback(err, result);
|
259
|
+
callbacks = false;
|
260
|
+
} else {
|
261
|
+
for (const callback of callbacks) {
|
262
|
+
callback(err, result);
|
263
|
+
}
|
264
|
+
activeRequests.delete(identifier);
|
265
|
+
callbacks = false;
|
266
|
+
}
|
267
|
+
};
|
223
268
|
/**
|
224
269
|
* @param {Error=} err error if any
|
225
270
|
* @param {CacheEntry=} cacheEntry cache entry
|
@@ -276,7 +321,14 @@ class ResolverCachePlugin {
|
|
276
321
|
}
|
277
322
|
};
|
278
323
|
itemCache.get(processCacheResult);
|
279
|
-
if (callbacks === undefined) {
|
324
|
+
if (withYield && callbacks === undefined) {
|
325
|
+
callbacks = [callback];
|
326
|
+
yields = [resolveContext.yield];
|
327
|
+
activeRequestsWithYield.set(
|
328
|
+
identifier,
|
329
|
+
/** @type {[any, any]} */ ([callbacks, yields])
|
330
|
+
);
|
331
|
+
} else if (callbacks === undefined) {
|
280
332
|
callbacks = [callback];
|
281
333
|
activeRequests.set(identifier, callbacks);
|
282
334
|
}
|
package/lib/config/defaults.js
CHANGED
@@ -907,6 +907,7 @@ const applyOutputDefaults = (
|
|
907
907
|
D(output, "strictModuleExceptionHandling", false);
|
908
908
|
|
909
909
|
const optimistic = v => v || v === undefined;
|
910
|
+
const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
|
910
911
|
F(
|
911
912
|
output.environment,
|
912
913
|
"arrowFunction",
|
@@ -920,8 +921,12 @@ const applyOutputDefaults = (
|
|
920
921
|
);
|
921
922
|
F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
|
922
923
|
F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
|
923
|
-
F(output.environment, "dynamicImport", () =>
|
924
|
-
|
924
|
+
F(output.environment, "dynamicImport", () =>
|
925
|
+
conditionallyOptimistic(tp && tp.dynamicImport, output.module)
|
926
|
+
);
|
927
|
+
F(output.environment, "module", () =>
|
928
|
+
conditionallyOptimistic(tp && tp.module, output.module)
|
929
|
+
);
|
925
930
|
|
926
931
|
const { trustedTypes } = output;
|
927
932
|
if (trustedTypes) {
|
@@ -274,78 +274,71 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
274
274
|
"",
|
275
275
|
withLoading
|
276
276
|
? Template.asString([
|
277
|
-
`${fn}.css = ${runtimeTemplate.basicFunction(
|
278
|
-
"
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
277
|
+
`${fn}.css = ${runtimeTemplate.basicFunction("chunkId, promises", [
|
278
|
+
"// css chunk loading",
|
279
|
+
`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
|
280
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
281
|
+
Template.indent([
|
282
|
+
"",
|
283
|
+
'// a Promise means "currently loading".',
|
284
|
+
"if(installedChunkData) {",
|
285
|
+
Template.indent(["promises.push(installedChunkData[2]);"]),
|
286
|
+
"} else {",
|
287
|
+
Template.indent([
|
288
|
+
hasCssMatcher === true
|
289
|
+
? "if(true) { // all chunks have CSS"
|
290
|
+
: `if(${hasCssMatcher("chunkId")}) {`,
|
291
|
+
Template.indent([
|
292
|
+
"// setup Promise in chunk cache",
|
293
|
+
`var promise = new Promise(${runtimeTemplate.expressionFunction(
|
294
|
+
`installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
|
295
|
+
"resolve, reject"
|
296
|
+
)});`,
|
297
|
+
"promises.push(installedChunkData[2] = promise);",
|
298
|
+
"",
|
299
|
+
"// start chunk loading",
|
300
|
+
`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
|
301
|
+
"// create error before stack unwound to get useful stacktrace later",
|
302
|
+
"var error = new Error();",
|
303
|
+
`var loadingEnded = ${runtimeTemplate.basicFunction(
|
304
|
+
"event",
|
305
|
+
[
|
306
|
+
`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
|
296
307
|
Template.indent([
|
297
|
-
"
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
"var errorType = event && event.type;",
|
320
|
-
"var realSrc = event && event.target && event.target.src;",
|
321
|
-
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
|
322
|
-
"error.name = 'ChunkLoadError';",
|
323
|
-
"error.type = errorType;",
|
324
|
-
"error.request = realSrc;",
|
325
|
-
"installedChunkData[1](error);"
|
326
|
-
]),
|
327
|
-
"} else {",
|
328
|
-
Template.indent([
|
329
|
-
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
|
330
|
-
"installedChunkData[0]();"
|
331
|
-
]),
|
332
|
-
"}"
|
333
|
-
]),
|
334
|
-
"}"
|
335
|
-
]),
|
336
|
-
"}"
|
337
|
-
]
|
338
|
-
)};`,
|
339
|
-
"var link = loadStylesheet(chunkId, url, loadingEnded);"
|
308
|
+
"installedChunkData = installedChunks[chunkId];",
|
309
|
+
"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
|
310
|
+
"if(installedChunkData) {",
|
311
|
+
Template.indent([
|
312
|
+
'if(event.type !== "load") {',
|
313
|
+
Template.indent([
|
314
|
+
"var errorType = event && event.type;",
|
315
|
+
"var realSrc = event && event.target && event.target.src;",
|
316
|
+
"error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
|
317
|
+
"error.name = 'ChunkLoadError';",
|
318
|
+
"error.type = errorType;",
|
319
|
+
"error.request = realSrc;",
|
320
|
+
"installedChunkData[1](error);"
|
321
|
+
]),
|
322
|
+
"} else {",
|
323
|
+
Template.indent([
|
324
|
+
`loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
|
325
|
+
"installedChunkData[0]();"
|
326
|
+
]),
|
327
|
+
"}"
|
328
|
+
]),
|
329
|
+
"}"
|
340
330
|
]),
|
341
|
-
"}
|
342
|
-
]
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
331
|
+
"}"
|
332
|
+
]
|
333
|
+
)};`,
|
334
|
+
"var link = loadStylesheet(chunkId, url, loadingEnded);"
|
335
|
+
]),
|
336
|
+
"} else installedChunks[chunkId] = 0;"
|
337
|
+
]),
|
338
|
+
"}"
|
339
|
+
]),
|
340
|
+
"}"
|
341
|
+
])};`
|
349
342
|
])
|
350
343
|
: "// no chunk loading",
|
351
344
|
"",
|
@@ -19,6 +19,7 @@ const { compareModulesByIdentifier } = require("../util/comparators");
|
|
19
19
|
const createSchemaValidation = require("../util/create-schema-validation");
|
20
20
|
const createHash = require("../util/createHash");
|
21
21
|
const memoize = require("../util/memoize");
|
22
|
+
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
22
23
|
const CssExportsGenerator = require("./CssExportsGenerator");
|
23
24
|
const CssGenerator = require("./CssGenerator");
|
24
25
|
const CssParser = require("./CssParser");
|
@@ -201,7 +202,7 @@ class CssModulesPlugin {
|
|
201
202
|
hash.update(chunkGraph.getModuleHash(module, chunk.runtime));
|
202
203
|
}
|
203
204
|
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
204
|
-
chunk.contentHash.css = digest
|
205
|
+
chunk.contentHash.css = nonNumericOnlyHash(digest, hashDigestLength);
|
205
206
|
});
|
206
207
|
compilation.hooks.renderManifest.tap(plugin, (result, options) => {
|
207
208
|
const { chunkGraph } = compilation;
|
@@ -343,7 +343,8 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
|
|
343
343
|
};
|
344
344
|
|
345
345
|
const makeInterceptorFor = (instance, tracer) => hookName => ({
|
346
|
-
register:
|
346
|
+
register: tapInfo => {
|
347
|
+
const { name, type, fn } = tapInfo;
|
347
348
|
const newFn =
|
348
349
|
// Don't tap our own hooks to ensure stream can close cleanly
|
349
350
|
name === pluginName
|
@@ -354,9 +355,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
|
|
354
355
|
fn
|
355
356
|
});
|
356
357
|
return {
|
357
|
-
|
358
|
-
type,
|
359
|
-
context,
|
358
|
+
...tapInfo,
|
360
359
|
fn: newFn
|
361
360
|
};
|
362
361
|
}
|
@@ -53,12 +53,18 @@ class ContextElementDependency extends ModuleDependency {
|
|
53
53
|
}
|
54
54
|
|
55
55
|
serialize(context) {
|
56
|
-
context
|
56
|
+
const { write } = context;
|
57
|
+
write(this._typePrefix);
|
58
|
+
write(this._category);
|
59
|
+
write(this.referencedExports);
|
57
60
|
super.serialize(context);
|
58
61
|
}
|
59
62
|
|
60
63
|
deserialize(context) {
|
61
|
-
|
64
|
+
const { read } = context;
|
65
|
+
this._typePrefix = read();
|
66
|
+
this._category = read();
|
67
|
+
this.referencedExports = read();
|
62
68
|
super.deserialize(context);
|
63
69
|
}
|
64
70
|
}
|
@@ -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) !==
|
package/lib/index.js
CHANGED
@@ -11,6 +11,7 @@ const memoize = require("./util/memoize");
|
|
11
11
|
/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
|
12
12
|
/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
|
13
13
|
/** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
|
14
|
+
/** @typedef {import("../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
|
14
15
|
/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
15
16
|
/** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
|
16
17
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
@@ -26,11 +27,15 @@ const memoize = require("./util/memoize");
|
|
26
27
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
27
28
|
/** @typedef {import("./Compilation").Asset} Asset */
|
28
29
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
30
|
+
/** @typedef {import("./Compilation").EntryOptions} EntryOptions */
|
31
|
+
/** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
|
29
32
|
/** @typedef {import("./MultiStats")} MultiStats */
|
30
33
|
/** @typedef {import("./Parser").ParserState} ParserState */
|
31
34
|
/** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */
|
32
35
|
/** @typedef {import("./ResolverFactory").Resolver} Resolver */
|
33
36
|
/** @typedef {import("./Watching")} Watching */
|
37
|
+
/** @typedef {import("./cli").Argument} Argument */
|
38
|
+
/** @typedef {import("./cli").Problem} Problem */
|
34
39
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
|
35
40
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
|
36
41
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
|
@@ -24,6 +24,7 @@ const { last, someInIterable } = require("../util/IterableHelpers");
|
|
24
24
|
const StringXor = require("../util/StringXor");
|
25
25
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
26
26
|
const createHash = require("../util/createHash");
|
27
|
+
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
27
28
|
const { intersectRuntime } = require("../util/runtime");
|
28
29
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
29
30
|
const JavascriptParser = require("./JavascriptParser");
|
@@ -102,6 +103,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
102
103
|
/**
|
103
104
|
* @typedef {Object} RenderBootstrapContext
|
104
105
|
* @property {Chunk} chunk the chunk
|
106
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
105
107
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
106
108
|
* @property {ModuleGraph} moduleGraph the module graph
|
107
109
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
@@ -331,6 +333,7 @@ class JavascriptModulesPlugin {
|
|
331
333
|
{
|
332
334
|
hash: "0000",
|
333
335
|
chunk,
|
336
|
+
codeGenerationResults: context.codeGenerationResults,
|
334
337
|
chunkGraph: context.chunkGraph,
|
335
338
|
moduleGraph: context.moduleGraph,
|
336
339
|
runtimeTemplate: context.runtimeTemplate
|
@@ -343,6 +346,7 @@ class JavascriptModulesPlugin {
|
|
343
346
|
compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
|
344
347
|
const {
|
345
348
|
chunkGraph,
|
349
|
+
codeGenerationResults,
|
346
350
|
moduleGraph,
|
347
351
|
runtimeTemplate,
|
348
352
|
outputOptions: {
|
@@ -360,6 +364,7 @@ class JavascriptModulesPlugin {
|
|
360
364
|
{
|
361
365
|
hash: "0000",
|
362
366
|
chunk,
|
367
|
+
codeGenerationResults,
|
363
368
|
chunkGraph: compilation.chunkGraph,
|
364
369
|
moduleGraph: compilation.moduleGraph,
|
365
370
|
runtimeTemplate: compilation.runtimeTemplate
|
@@ -372,6 +377,7 @@ class JavascriptModulesPlugin {
|
|
372
377
|
}
|
373
378
|
hooks.chunkHash.call(chunk, hash, {
|
374
379
|
chunkGraph,
|
380
|
+
codeGenerationResults,
|
375
381
|
moduleGraph,
|
376
382
|
runtimeTemplate
|
377
383
|
});
|
@@ -398,7 +404,10 @@ class JavascriptModulesPlugin {
|
|
398
404
|
xor.updateHash(hash);
|
399
405
|
}
|
400
406
|
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
401
|
-
chunk.contentHash.javascript =
|
407
|
+
chunk.contentHash.javascript = nonNumericOnlyHash(
|
408
|
+
digest,
|
409
|
+
hashDigestLength
|
410
|
+
);
|
402
411
|
});
|
403
412
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
404
413
|
"JavascriptModulesPlugin",
|
@@ -974,7 +983,13 @@ class JavascriptModulesPlugin {
|
|
974
983
|
* @returns {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} the generated source of the bootstrap code
|
975
984
|
*/
|
976
985
|
renderBootstrap(renderContext, hooks) {
|
977
|
-
const {
|
986
|
+
const {
|
987
|
+
chunkGraph,
|
988
|
+
codeGenerationResults,
|
989
|
+
moduleGraph,
|
990
|
+
chunk,
|
991
|
+
runtimeTemplate
|
992
|
+
} = renderContext;
|
978
993
|
|
979
994
|
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
980
995
|
|
@@ -1098,8 +1113,18 @@ class JavascriptModulesPlugin {
|
|
1098
1113
|
);
|
1099
1114
|
result.allowInlineStartup = false;
|
1100
1115
|
}
|
1116
|
+
|
1117
|
+
let data;
|
1118
|
+
if (codeGenerationResults.has(entryModule, chunk.runtime)) {
|
1119
|
+
const result = codeGenerationResults.get(
|
1120
|
+
entryModule,
|
1121
|
+
chunk.runtime
|
1122
|
+
);
|
1123
|
+
data = result.data;
|
1124
|
+
}
|
1101
1125
|
if (
|
1102
1126
|
result.allowInlineStartup &&
|
1127
|
+
(!data || !data.get("topLevelDeclarations")) &&
|
1103
1128
|
(!entryModule.buildInfo ||
|
1104
1129
|
!entryModule.buildInfo.topLevelDeclarations)
|
1105
1130
|
) {
|
@@ -14,6 +14,7 @@ const { getAllChunks } = require("./ChunkHelpers");
|
|
14
14
|
/** @typedef {import("../Chunk")} Chunk */
|
15
15
|
/** @typedef {import("../Compilation")} Compilation */
|
16
16
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
|
+
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
17
18
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
18
19
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
19
20
|
/** @typedef {(string|number)[]} EntryItem */
|
@@ -23,7 +24,7 @@ const EXPORT_PREFIX = "var __webpack_exports__ = ";
|
|
23
24
|
/**
|
24
25
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
25
26
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
26
|
-
* @param {
|
27
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
27
28
|
* @param {Chunk} chunk chunk
|
28
29
|
* @param {boolean} passive true: passive startup with on chunks loaded
|
29
30
|
* @returns {string} runtime code
|
@@ -101,7 +102,7 @@ exports.generateEntryStartup = (
|
|
101
102
|
/**
|
102
103
|
* @param {Hash} hash the hash to update
|
103
104
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
104
|
-
* @param {
|
105
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
105
106
|
* @param {Chunk} chunk chunk
|
106
107
|
* @returns {void}
|
107
108
|
*/
|
@@ -222,9 +222,15 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
222
222
|
* @param {LibraryContext<T>} libraryContext context
|
223
223
|
* @returns {string | undefined} bailout reason
|
224
224
|
*/
|
225
|
-
embedInRuntimeBailout(
|
225
|
+
embedInRuntimeBailout(
|
226
|
+
module,
|
227
|
+
{ chunk, codeGenerationResults },
|
228
|
+
{ options, compilation }
|
229
|
+
) {
|
230
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
226
231
|
const topLevelDeclarations =
|
227
|
-
|
232
|
+
(data && data.get("topLevelDeclarations")) ||
|
233
|
+
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
228
234
|
if (!topLevelDeclarations)
|
229
235
|
return "it doesn't tell about top level declarations.";
|
230
236
|
const fullNameResolved = this._getResolvedFullName(
|
@@ -822,10 +822,6 @@ class ConcatenatedModule extends Module {
|
|
822
822
|
const topLevelDeclarations = this.buildInfo.topLevelDeclarations;
|
823
823
|
if (topLevelDeclarations !== undefined) {
|
824
824
|
for (const decl of m.buildInfo.topLevelDeclarations) {
|
825
|
-
// reserved names will always be renamed
|
826
|
-
if (RESERVED_NAMES.has(decl)) continue;
|
827
|
-
// TODO actually this is incorrect since with renaming there could be more
|
828
|
-
// We should do the renaming during build
|
829
825
|
topLevelDeclarations.add(decl);
|
830
826
|
}
|
831
827
|
}
|
@@ -1113,6 +1109,8 @@ class ConcatenatedModule extends Module {
|
|
1113
1109
|
|
1114
1110
|
// List of all used names to avoid conflicts
|
1115
1111
|
const allUsedNames = new Set(RESERVED_NAMES);
|
1112
|
+
// Updated Top level declarations are created by renaming
|
1113
|
+
const topLevelDeclarations = new Set();
|
1116
1114
|
|
1117
1115
|
// List of additional names in scope for module references
|
1118
1116
|
/** @type {Map<string, { usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }>} */
|
@@ -1257,6 +1255,7 @@ class ConcatenatedModule extends Module {
|
|
1257
1255
|
);
|
1258
1256
|
allUsedNames.add(newName);
|
1259
1257
|
info.internalNames.set(name, newName);
|
1258
|
+
topLevelDeclarations.add(newName);
|
1260
1259
|
const source = info.source;
|
1261
1260
|
const allIdentifiers = new Set(
|
1262
1261
|
references.map(r => r.identifier).concat(variable.identifiers)
|
@@ -1283,6 +1282,7 @@ class ConcatenatedModule extends Module {
|
|
1283
1282
|
} else {
|
1284
1283
|
allUsedNames.add(name);
|
1285
1284
|
info.internalNames.set(name, name);
|
1285
|
+
topLevelDeclarations.add(name);
|
1286
1286
|
}
|
1287
1287
|
}
|
1288
1288
|
let namespaceObjectName;
|
@@ -1300,6 +1300,7 @@ class ConcatenatedModule extends Module {
|
|
1300
1300
|
allUsedNames.add(namespaceObjectName);
|
1301
1301
|
}
|
1302
1302
|
info.namespaceObjectName = namespaceObjectName;
|
1303
|
+
topLevelDeclarations.add(namespaceObjectName);
|
1303
1304
|
break;
|
1304
1305
|
}
|
1305
1306
|
case "external": {
|
@@ -1311,6 +1312,7 @@ class ConcatenatedModule extends Module {
|
|
1311
1312
|
);
|
1312
1313
|
allUsedNames.add(externalName);
|
1313
1314
|
info.name = externalName;
|
1315
|
+
topLevelDeclarations.add(externalName);
|
1314
1316
|
break;
|
1315
1317
|
}
|
1316
1318
|
}
|
@@ -1323,6 +1325,7 @@ class ConcatenatedModule extends Module {
|
|
1323
1325
|
);
|
1324
1326
|
allUsedNames.add(externalNameInterop);
|
1325
1327
|
info.interopNamespaceObjectName = externalNameInterop;
|
1328
|
+
topLevelDeclarations.add(externalNameInterop);
|
1326
1329
|
}
|
1327
1330
|
if (
|
1328
1331
|
info.module.buildMeta.exportsType === "default" &&
|
@@ -1336,6 +1339,7 @@ class ConcatenatedModule extends Module {
|
|
1336
1339
|
);
|
1337
1340
|
allUsedNames.add(externalNameInterop);
|
1338
1341
|
info.interopNamespaceObject2Name = externalNameInterop;
|
1342
|
+
topLevelDeclarations.add(externalNameInterop);
|
1339
1343
|
}
|
1340
1344
|
if (
|
1341
1345
|
info.module.buildMeta.exportsType === "dynamic" ||
|
@@ -1349,6 +1353,7 @@ class ConcatenatedModule extends Module {
|
|
1349
1353
|
);
|
1350
1354
|
allUsedNames.add(externalNameInterop);
|
1351
1355
|
info.interopDefaultAccessName = externalNameInterop;
|
1356
|
+
topLevelDeclarations.add(externalNameInterop);
|
1352
1357
|
}
|
1353
1358
|
}
|
1354
1359
|
|
@@ -1618,6 +1623,7 @@ ${defineGetters}`
|
|
1618
1623
|
const data = new Map();
|
1619
1624
|
if (chunkInitFragments.length > 0)
|
1620
1625
|
data.set("chunkInitFragments", chunkInitFragments);
|
1626
|
+
data.set("topLevelDeclarations", topLevelDeclarations);
|
1621
1627
|
|
1622
1628
|
/** @type {CodeGenerationResult} */
|
1623
1629
|
const resultEntry = {
|