webpack 5.85.1 → 5.86.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/APIPlugin.js +150 -99
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGroup.js +10 -6
- package/lib/Compiler.js +1 -2
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/DllModule.js +6 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +15 -8
- package/lib/Module.js +7 -1
- package/lib/ProgressPlugin.js +71 -15
- package/lib/WebpackOptionsApply.js +3 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +13 -6
- package/lib/css/CssModulesPlugin.js +37 -12
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +1 -0
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +4 -4
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +3 -0
- package/lib/serialization/types.js +1 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/types.d.ts +43 -34
package/lib/ProgressPlugin.js
CHANGED
@@ -11,9 +11,20 @@ const NormalModule = require("./NormalModule");
|
|
11
11
|
const createSchemaValidation = require("./util/create-schema-validation");
|
12
12
|
const { contextify } = require("./util/identifier");
|
13
13
|
|
14
|
+
/** @typedef {import("tapable").Tap} Tap */
|
14
15
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
|
15
16
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
|
16
17
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
|
18
|
+
/** @typedef {import("./Dependency")} Dependency */
|
19
|
+
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
20
|
+
/** @typedef {import("./Module")} Module */
|
21
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @typedef {Object} CountsData
|
25
|
+
* @property {number} modulesCount modules count
|
26
|
+
* @property {number} dependenciesCount dependencies count
|
27
|
+
*/
|
17
28
|
|
18
29
|
const validate = createSchemaValidation(
|
19
30
|
require("../schemas/plugins/ProgressPlugin.check.js"),
|
@@ -23,14 +34,31 @@ const validate = createSchemaValidation(
|
|
23
34
|
baseDataPath: "options"
|
24
35
|
}
|
25
36
|
);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param {number} a a
|
40
|
+
* @param {number} b b
|
41
|
+
* @param {number} c c
|
42
|
+
* @returns {number} median
|
43
|
+
*/
|
26
44
|
const median3 = (a, b, c) => {
|
27
45
|
return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
|
28
46
|
};
|
29
47
|
|
48
|
+
/**
|
49
|
+
* @param {boolean | null | undefined} profile need profile
|
50
|
+
* @param {Logger} logger logger
|
51
|
+
* @returns {defaultHandler} default handler
|
52
|
+
*/
|
30
53
|
const createDefaultHandler = (profile, logger) => {
|
31
|
-
/** @type {{ value: string, time: number }[]} */
|
54
|
+
/** @type {{ value: string | undefined, time: number }[]} */
|
32
55
|
const lastStateInfo = [];
|
33
56
|
|
57
|
+
/**
|
58
|
+
* @param {number} percentage percentage
|
59
|
+
* @param {string} msg message
|
60
|
+
* @param {...string} args additional arguments
|
61
|
+
*/
|
34
62
|
const defaultHandler = (percentage, msg, ...args) => {
|
35
63
|
if (profile) {
|
36
64
|
if (percentage === 0) {
|
@@ -95,18 +123,18 @@ const createDefaultHandler = (profile, logger) => {
|
|
95
123
|
|
96
124
|
/**
|
97
125
|
* @callback ReportProgress
|
98
|
-
* @param {number} p
|
99
|
-
* @param {...string}
|
126
|
+
* @param {number} p percentage
|
127
|
+
* @param {...string} args additional arguments
|
100
128
|
* @returns {void}
|
101
129
|
*/
|
102
130
|
|
103
|
-
/** @type {WeakMap<Compiler,ReportProgress>} */
|
131
|
+
/** @type {WeakMap<Compiler, ReportProgress | undefined>} */
|
104
132
|
const progressReporters = new WeakMap();
|
105
133
|
|
106
134
|
class ProgressPlugin {
|
107
135
|
/**
|
108
136
|
* @param {Compiler} compiler the current compiler
|
109
|
-
* @returns {ReportProgress} a progress reporter, if any
|
137
|
+
* @returns {ReportProgress | undefined} a progress reporter, if any
|
110
138
|
*/
|
111
139
|
static getReporter(compiler) {
|
112
140
|
return progressReporters.get(compiler);
|
@@ -288,6 +316,9 @@ class ProgressPlugin {
|
|
288
316
|
};
|
289
317
|
|
290
318
|
// only used when showActiveModules is set
|
319
|
+
/**
|
320
|
+
* @param {Module} module the module
|
321
|
+
*/
|
291
322
|
const moduleBuild = module => {
|
292
323
|
const ident = module.identifier();
|
293
324
|
if (ident) {
|
@@ -297,11 +328,18 @@ class ProgressPlugin {
|
|
297
328
|
}
|
298
329
|
};
|
299
330
|
|
331
|
+
/**
|
332
|
+
* @param {Dependency} entry entry dependency
|
333
|
+
* @param {EntryOptions} options options object
|
334
|
+
*/
|
300
335
|
const entryAdd = (entry, options) => {
|
301
336
|
entriesCount++;
|
302
337
|
if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();
|
303
338
|
};
|
304
339
|
|
340
|
+
/**
|
341
|
+
* @param {Module} module the module
|
342
|
+
*/
|
305
343
|
const moduleDone = module => {
|
306
344
|
doneModules++;
|
307
345
|
if (showActiveModules) {
|
@@ -321,6 +359,10 @@ class ProgressPlugin {
|
|
321
359
|
if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();
|
322
360
|
};
|
323
361
|
|
362
|
+
/**
|
363
|
+
* @param {Dependency} entry entry dependency
|
364
|
+
* @param {EntryOptions} options options object
|
365
|
+
*/
|
324
366
|
const entryDone = (entry, options) => {
|
325
367
|
doneEntries++;
|
326
368
|
update();
|
@@ -330,6 +372,7 @@ class ProgressPlugin {
|
|
330
372
|
.getCache("ProgressPlugin")
|
331
373
|
.getItemCache("counts", null);
|
332
374
|
|
375
|
+
/** @type {Promise<CountsData> | undefined} */
|
333
376
|
let cacheGetPromise;
|
334
377
|
|
335
378
|
compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
|
@@ -352,15 +395,17 @@ class ProgressPlugin {
|
|
352
395
|
|
353
396
|
compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
|
354
397
|
if (compilation.compiler.isChild()) return Promise.resolve();
|
355
|
-
return cacheGetPromise.then(
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
398
|
+
return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
|
399
|
+
async oldData => {
|
400
|
+
if (
|
401
|
+
!oldData ||
|
402
|
+
oldData.modulesCount !== modulesCount ||
|
403
|
+
oldData.dependenciesCount !== dependenciesCount
|
404
|
+
) {
|
405
|
+
await cache.storePromise({ modulesCount, dependenciesCount });
|
406
|
+
}
|
362
407
|
}
|
363
|
-
|
408
|
+
);
|
364
409
|
});
|
365
410
|
|
366
411
|
compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
|
@@ -463,9 +508,9 @@ class ProgressPlugin {
|
|
463
508
|
};
|
464
509
|
const numberOfHooks = Object.keys(hooks).length;
|
465
510
|
Object.keys(hooks).forEach((name, idx) => {
|
466
|
-
const title = hooks[name];
|
511
|
+
const title = hooks[/** @type {keyof typeof hooks} */ (name)];
|
467
512
|
const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
|
468
|
-
compilation.hooks[name].intercept({
|
513
|
+
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
|
469
514
|
name: "ProgressPlugin",
|
470
515
|
call() {
|
471
516
|
handler(percentage, "sealing", title);
|
@@ -500,6 +545,12 @@ class ProgressPlugin {
|
|
500
545
|
handler(0.65, "building");
|
501
546
|
}
|
502
547
|
});
|
548
|
+
/**
|
549
|
+
* @param {TODO} hook hook
|
550
|
+
* @param {number} progress progress from 0 to 1
|
551
|
+
* @param {string} category category
|
552
|
+
* @param {string} name name
|
553
|
+
*/
|
503
554
|
const interceptHook = (hook, progress, category, name) => {
|
504
555
|
hook.intercept({
|
505
556
|
name: "ProgressPlugin",
|
@@ -516,6 +567,9 @@ class ProgressPlugin {
|
|
516
567
|
error() {
|
517
568
|
handler(progress, category, name);
|
518
569
|
},
|
570
|
+
/**
|
571
|
+
* @param {Tap} tap tap
|
572
|
+
*/
|
519
573
|
tap(tap) {
|
520
574
|
progressReporters.set(compiler, (p, ...args) => {
|
521
575
|
handler(progress, category, name, tap.name, ...args);
|
@@ -610,4 +664,6 @@ ProgressPlugin.defaultOptions = {
|
|
610
664
|
entries: true
|
611
665
|
};
|
612
666
|
|
667
|
+
ProgressPlugin.createDefaultHandler = createDefaultHandler;
|
668
|
+
|
613
669
|
module.exports = ProgressPlugin;
|
@@ -368,7 +368,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
368
368
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
369
369
|
new NodeStuffPlugin(options.node).apply(compiler);
|
370
370
|
}
|
371
|
-
new APIPlugin(
|
371
|
+
new APIPlugin({
|
372
|
+
module: options.output.module
|
373
|
+
}).apply(compiler);
|
372
374
|
new ExportsInfoApiPlugin().apply(compiler);
|
373
375
|
new WebpackIsIncludedPlugin().apply(compiler);
|
374
376
|
new ConstPlugin().apply(compiler);
|
@@ -19,6 +19,11 @@ const Template = require("../Template");
|
|
19
19
|
/** @typedef {import("../NormalModule")} NormalModule */
|
20
20
|
/** @typedef {import("../util/Hash")} Hash */
|
21
21
|
|
22
|
+
/**
|
23
|
+
* @template T
|
24
|
+
* @typedef {import("../InitFragment")<T>} InitFragment
|
25
|
+
*/
|
26
|
+
|
22
27
|
const TYPES = new Set(["javascript"]);
|
23
28
|
|
24
29
|
class CssExportsGenerator extends Generator {
|
@@ -36,6 +41,7 @@ class CssExportsGenerator extends Generator {
|
|
36
41
|
*/
|
37
42
|
generate(module, generateContext) {
|
38
43
|
const source = new ReplaceSource(new RawSource(""));
|
44
|
+
/** @type {InitFragment<TODO>[]} */
|
39
45
|
const initFragments = [];
|
40
46
|
const cssExports = new Map();
|
41
47
|
|
@@ -57,6 +63,9 @@ class CssExportsGenerator extends Generator {
|
|
57
63
|
cssExports
|
58
64
|
};
|
59
65
|
|
66
|
+
/**
|
67
|
+
* @param {Dependency} dependency the dependency
|
68
|
+
*/
|
60
69
|
const handleDependency = dependency => {
|
61
70
|
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
62
71
|
dependency.constructor
|
package/lib/css/CssGenerator.js
CHANGED
@@ -30,7 +30,7 @@ class CssGenerator extends Generator {
|
|
30
30
|
* @returns {Source} generated code
|
31
31
|
*/
|
32
32
|
generate(module, generateContext) {
|
33
|
-
const originalSource = module.originalSource();
|
33
|
+
const originalSource = /** @type {Source} */ (module.originalSource());
|
34
34
|
const source = new ReplaceSource(originalSource);
|
35
35
|
/** @type {InitFragment[]} */
|
36
36
|
const initFragments = [];
|
@@ -14,6 +14,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
14
14
|
const { chunkHasCss } = require("./CssModulesPlugin");
|
15
15
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
17
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
18
|
/** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
|
18
19
|
|
19
20
|
/**
|
@@ -67,10 +68,15 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
67
68
|
uniqueName,
|
68
69
|
chunkLoadTimeout: loadTimeout
|
69
70
|
}
|
70
|
-
} = compilation;
|
71
|
+
} = /** @type {Compilation} */ (compilation);
|
71
72
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
72
73
|
const conditionMap = chunkGraph.getChunkConditionMap(
|
73
|
-
chunk,
|
74
|
+
/** @type {Chunk} */ (chunk),
|
75
|
+
/**
|
76
|
+
* @param {Chunk} chunk the chunk
|
77
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
78
|
+
* @returns {boolean} true, if the chunk has css
|
79
|
+
*/
|
74
80
|
(chunk, chunkGraph) =>
|
75
81
|
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
|
76
82
|
);
|
@@ -87,7 +93,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
87
93
|
const initialChunkIdsWithCss = new Set();
|
88
94
|
/** @type {Set<number | string | null>} */
|
89
95
|
const initialChunkIdsWithoutCss = new Set();
|
90
|
-
for (const c of chunk.getAllInitialChunks()) {
|
96
|
+
for (const c of /** @type {Chunk} */ (chunk).getAllInitialChunks()) {
|
91
97
|
(chunkHasCss(c, chunkGraph)
|
92
98
|
? initialChunkIdsWithCss
|
93
99
|
: initialChunkIdsWithoutCss
|
@@ -98,8 +104,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
98
104
|
return null;
|
99
105
|
}
|
100
106
|
|
101
|
-
const { createStylesheet } =
|
102
|
-
|
107
|
+
const { createStylesheet } = CssLoadingRuntimeModule.getCompilationHooks(
|
108
|
+
/** @type {Compilation} */ (compilation)
|
109
|
+
);
|
103
110
|
|
104
111
|
const stateExpression = withHmr
|
105
112
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
|
@@ -239,7 +246,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
239
246
|
"if(!link) {",
|
240
247
|
Template.indent([
|
241
248
|
"needAttach = true;",
|
242
|
-
createStylesheet.call(code, this.chunk)
|
249
|
+
createStylesheet.call(code, /** @type {Chunk} */ (this.chunk))
|
243
250
|
]),
|
244
251
|
"}",
|
245
252
|
`var onLinkComplete = ${runtimeTemplate.basicFunction(
|
@@ -46,6 +46,10 @@ const getCssLoadingRuntimeModule = memoize(() =>
|
|
46
46
|
require("./CssLoadingRuntimeModule")
|
47
47
|
);
|
48
48
|
|
49
|
+
/**
|
50
|
+
* @param {string} name name
|
51
|
+
* @returns {{oneOf: [{$ref: string}], definitions: *}} schema
|
52
|
+
*/
|
49
53
|
const getSchema = name => {
|
50
54
|
const { definitions } = require("../../schemas/WebpackOptions.json");
|
51
55
|
return {
|
@@ -302,6 +306,10 @@ class CssModulesPlugin {
|
|
302
306
|
return result;
|
303
307
|
});
|
304
308
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
309
|
+
/**
|
310
|
+
* @param {Chunk} chunk the chunk
|
311
|
+
* @returns {boolean} true, when enabled
|
312
|
+
*/
|
305
313
|
const isEnabledForChunk = chunk => {
|
306
314
|
const options = chunk.getEntryOptions();
|
307
315
|
const chunkLoading =
|
@@ -311,6 +319,10 @@ class CssModulesPlugin {
|
|
311
319
|
return chunkLoading === "jsonp";
|
312
320
|
};
|
313
321
|
const onceForChunkSet = new WeakSet();
|
322
|
+
/**
|
323
|
+
* @param {Chunk} chunk chunk to check
|
324
|
+
* @param {Set<string>} set runtime requirements
|
325
|
+
*/
|
314
326
|
const handler = (chunk, set) => {
|
315
327
|
if (onceForChunkSet.has(chunk)) return;
|
316
328
|
onceForChunkSet.add(chunk);
|
@@ -361,7 +373,10 @@ class CssModulesPlugin {
|
|
361
373
|
};
|
362
374
|
})
|
363
375
|
.filter(item => item.index !== undefined)
|
364
|
-
.sort(
|
376
|
+
.sort(
|
377
|
+
(a, b) =>
|
378
|
+
/** @type {number} */ (b.index) - /** @type {number} */ (a.index)
|
379
|
+
)
|
365
380
|
.map(item => item.module);
|
366
381
|
|
367
382
|
return { list: sortedModules, set: new Set(sortedModules) };
|
@@ -455,19 +470,25 @@ class CssModulesPlugin {
|
|
455
470
|
return [
|
456
471
|
...this.getModulesInOrder(
|
457
472
|
chunk,
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
473
|
+
/** @type {Iterable<Module>} */
|
474
|
+
(
|
475
|
+
chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
476
|
+
chunk,
|
477
|
+
"css-import",
|
478
|
+
compareModulesByIdentifier
|
479
|
+
)
|
462
480
|
),
|
463
481
|
compilation
|
464
482
|
),
|
465
483
|
...this.getModulesInOrder(
|
466
484
|
chunk,
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
485
|
+
/** @type {Iterable<Module>} */
|
486
|
+
(
|
487
|
+
chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
488
|
+
chunk,
|
489
|
+
"css",
|
490
|
+
compareModulesByIdentifier
|
491
|
+
)
|
471
492
|
),
|
472
493
|
compilation
|
473
494
|
)
|
@@ -498,8 +519,11 @@ class CssModulesPlugin {
|
|
498
519
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
499
520
|
|
500
521
|
let moduleSource =
|
501
|
-
|
502
|
-
|
522
|
+
/** @type {Source} */
|
523
|
+
(
|
524
|
+
codeGenResult.sources.get("css") ||
|
525
|
+
codeGenResult.sources.get("css-import")
|
526
|
+
);
|
503
527
|
|
504
528
|
let inheritance = [[module.cssLayer, module.supports, module.media]];
|
505
529
|
|
@@ -569,7 +593,8 @@ class CssModulesPlugin {
|
|
569
593
|
}${escapeCss(moduleId)}`
|
570
594
|
);
|
571
595
|
} catch (e) {
|
572
|
-
|
596
|
+
/** @type {Error} */
|
597
|
+
(e).message += `\nduring rendering of css ${module.identifier()}`;
|
573
598
|
throw e;
|
574
599
|
}
|
575
600
|
}
|
@@ -937,6 +937,7 @@ class JavascriptModulesPlugin {
|
|
937
937
|
"JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().renderContent plugins should return something"
|
938
938
|
);
|
939
939
|
}
|
940
|
+
|
940
941
|
finalSource = InitFragment.addToSource(
|
941
942
|
finalSource,
|
942
943
|
chunkRenderContext.chunkInitFragments,
|
package/lib/json/JsonData.js
CHANGED
@@ -40,14 +40,14 @@ class JsonData {
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
* @param {Hash} hash hash to be updated
|
43
|
-
* @returns {
|
43
|
+
* @returns {void} the updated hash
|
44
44
|
*/
|
45
45
|
updateHash(hash) {
|
46
46
|
if (this._buffer === undefined && this._data !== undefined) {
|
47
47
|
this._buffer = Buffer.from(JSON.stringify(this._data));
|
48
48
|
}
|
49
49
|
|
50
|
-
if (this._buffer)
|
50
|
+
if (this._buffer) hash.update(this._buffer);
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
package/lib/json/JsonParser.js
CHANGED
@@ -5,16 +5,20 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const parseJson = require("json-parse-even-better-errors");
|
9
8
|
const Parser = require("../Parser");
|
10
9
|
const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
|
10
|
+
const memoize = require("../util/memoize");
|
11
11
|
const JsonData = require("./JsonData");
|
12
12
|
|
13
13
|
/** @typedef {import("../../declarations/plugins/JsonModulesPluginParser").JsonModulesPluginParserOptions} JsonModulesPluginParserOptions */
|
14
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
15
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
14
16
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
15
17
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
16
18
|
/** @typedef {import("./JsonModulesPlugin").RawJsonData} RawJsonData */
|
17
19
|
|
20
|
+
const getParseJson = memoize(() => require("json-parse-even-better-errors"));
|
21
|
+
|
18
22
|
class JsonParser extends Parser {
|
19
23
|
/**
|
20
24
|
* @param {JsonModulesPluginParserOptions} options parser options
|
@@ -36,17 +40,26 @@ class JsonParser extends Parser {
|
|
36
40
|
|
37
41
|
/** @type {NonNullable<JsonModulesPluginParserOptions["parse"]>} */
|
38
42
|
const parseFn =
|
39
|
-
typeof this.options.parse === "function"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
typeof this.options.parse === "function"
|
44
|
+
? this.options.parse
|
45
|
+
: getParseJson();
|
46
|
+
/** @type {Buffer | RawJsonData | undefined} */
|
47
|
+
let data;
|
48
|
+
try {
|
49
|
+
data =
|
50
|
+
typeof source === "object"
|
51
|
+
? source
|
52
|
+
: parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
|
53
|
+
} catch (e) {
|
54
|
+
throw new Error(`Cannot parse JSON: ${/** @type {Error} */ (e).message}`);
|
55
|
+
}
|
56
|
+
const jsonData = new JsonData(/** @type {Buffer | RawJsonData} */ (data));
|
57
|
+
const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
|
58
|
+
buildInfo.jsonData = jsonData;
|
59
|
+
buildInfo.strict = true;
|
60
|
+
const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
|
61
|
+
buildMeta.exportsType = "default";
|
62
|
+
buildMeta.defaultObject =
|
50
63
|
typeof data === "object" ? "redirect-warn" : false;
|
51
64
|
state.module.addDependency(new JsonExportsDependency(jsonData));
|
52
65
|
return state;
|
@@ -40,6 +40,7 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
40
40
|
: globalWasmLoading;
|
41
41
|
return wasmLoading === this._type;
|
42
42
|
};
|
43
|
+
const { importMetaName } = compilation.outputOptions;
|
43
44
|
/**
|
44
45
|
* @type {(path: string) => string}
|
45
46
|
*/
|
@@ -48,7 +49,7 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
48
49
|
Template.asString([
|
49
50
|
"Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
|
50
51
|
Template.indent([
|
51
|
-
`readFile(new URL(${path},
|
52
|
+
`readFile(new URL(${path}, ${importMetaName}.url), (err, buffer) => {`,
|
52
53
|
Template.indent([
|
53
54
|
"if (err) return reject(err);",
|
54
55
|
"",
|
@@ -10,7 +10,15 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
10
10
|
/** @typedef {import("../Chunk")} Chunk */
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
|
+
/**
|
14
|
+
* @typedef {Object} AggressiveMergingPluginOptions
|
15
|
+
* @property {number=} minSizeReduce minimal size reduction to trigger merging
|
16
|
+
*/
|
17
|
+
|
13
18
|
class AggressiveMergingPlugin {
|
19
|
+
/**
|
20
|
+
* @param {AggressiveMergingPluginOptions=} [options] options object
|
21
|
+
*/
|
14
22
|
constructor(options) {
|
15
23
|
if (
|
16
24
|
(options !== undefined && typeof options !== "object") ||
|
@@ -30,6 +30,12 @@ const validate = createSchemaValidation(
|
|
30
30
|
}
|
31
31
|
);
|
32
32
|
|
33
|
+
/**
|
34
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
35
|
+
* @param {Chunk} oldChunk the old chunk
|
36
|
+
* @param {Chunk} newChunk the new chunk
|
37
|
+
* @returns {(module: Module) => void} function to move module between chunks
|
38
|
+
*/
|
33
39
|
const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => {
|
34
40
|
return module => {
|
35
41
|
chunkGraph.disconnectChunkAndModule(oldChunk, module);
|
@@ -92,6 +98,7 @@ class AggressiveSplittingPlugin {
|
|
92
98
|
compilation => {
|
93
99
|
let needAdditionalSeal = false;
|
94
100
|
let newSplits;
|
101
|
+
/** @type {Set<Chunk>} */
|
95
102
|
let fromAggressiveSplittingSet;
|
96
103
|
let chunkSplitDataMap;
|
97
104
|
compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
|
@@ -133,8 +140,8 @@ class AggressiveSplittingPlugin {
|
|
133
140
|
? recordedSplits.concat(newSplits)
|
134
141
|
: recordedSplits;
|
135
142
|
|
136
|
-
const minSize = this.options.minSize;
|
137
|
-
const maxSize = this.options.maxSize;
|
143
|
+
const minSize = /** @type {number} */ (this.options.minSize);
|
144
|
+
const maxSize = /** @type {number} */ (this.options.maxSize);
|
138
145
|
|
139
146
|
const applySplit = splitData => {
|
140
147
|
// Cannot split if id is already taken
|
@@ -21,6 +21,9 @@ class EnsureChunkConditionsPlugin {
|
|
21
21
|
compiler.hooks.compilation.tap(
|
22
22
|
"EnsureChunkConditionsPlugin",
|
23
23
|
compilation => {
|
24
|
+
/**
|
25
|
+
* @param {Iterable<Chunk>} chunks the chunks
|
26
|
+
*/
|
24
27
|
const handler = chunks => {
|
25
28
|
const chunkGraph = compilation.chunkGraph;
|
26
29
|
// These sets are hoisted here to save memory
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/** @typedef {import("../Chunk")} Chunk */
|
9
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
9
10
|
/** @typedef {import("../Compiler")} Compiler */
|
10
11
|
/** @typedef {import("../Module")} Module */
|
11
12
|
|
@@ -61,13 +62,15 @@ class FlagIncludedChunksPlugin {
|
|
61
62
|
for (const chunk of chunks) {
|
62
63
|
let hash = 0;
|
63
64
|
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
64
|
-
hash |= moduleBits.get(module);
|
65
|
+
hash |= /** @type {number} */ (moduleBits.get(module));
|
65
66
|
}
|
66
67
|
chunkModulesHash.set(chunk, hash);
|
67
68
|
}
|
68
69
|
|
69
70
|
for (const chunkA of chunks) {
|
70
|
-
const chunkAHash =
|
71
|
+
const chunkAHash =
|
72
|
+
/** @type {number} */
|
73
|
+
(chunkModulesHash.get(chunkA));
|
71
74
|
const chunkAModulesCount =
|
72
75
|
chunkGraph.getNumberOfChunkModules(chunkA);
|
73
76
|
if (chunkAModulesCount === 0) continue;
|
@@ -81,7 +84,7 @@ class FlagIncludedChunksPlugin {
|
|
81
84
|
bestModule = module;
|
82
85
|
}
|
83
86
|
loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
|
84
|
-
bestModule
|
87
|
+
/** @type {Module} */ (bestModule)
|
85
88
|
)) {
|
86
89
|
// as we iterate the same iterables twice
|
87
90
|
// skip if we find ourselves
|
@@ -100,14 +103,17 @@ class FlagIncludedChunksPlugin {
|
|
100
103
|
// is chunkA in chunkB?
|
101
104
|
|
102
105
|
// we do a cheap check for the hash value
|
103
|
-
const chunkBHash =
|
106
|
+
const chunkBHash =
|
107
|
+
/** @type {number} */
|
108
|
+
(chunkModulesHash.get(chunkB));
|
104
109
|
if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
|
105
110
|
|
106
111
|
// compare all modules
|
107
112
|
for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
|
108
113
|
if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
|
109
114
|
}
|
110
|
-
|
115
|
+
/** @type {ChunkId[]} */
|
116
|
+
(chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
|
111
117
|
}
|
112
118
|
}
|
113
119
|
}
|
@@ -16,7 +16,7 @@ const { UsageState } = require("../ExportsInfo");
|
|
16
16
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
17
17
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
18
18
|
|
19
|
-
/** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true>} InnerGraph */
|
19
|
+
/** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true | undefined>} InnerGraph */
|
20
20
|
/** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
|
21
21
|
|
22
22
|
/**
|
@@ -34,7 +34,7 @@ const topLevelSymbolTag = Symbol("top level symbol");
|
|
34
34
|
|
35
35
|
/**
|
36
36
|
* @param {ParserState} parserState parser state
|
37
|
-
* @returns {State} state
|
37
|
+
* @returns {State | undefined} state
|
38
38
|
*/
|
39
39
|
function getState(parserState) {
|
40
40
|
return parserStateMap.get(parserState);
|
@@ -235,7 +235,7 @@ exports.onUsage = (state, onUsageCallback) => {
|
|
235
235
|
|
236
236
|
/**
|
237
237
|
* @param {ParserState} state parser state
|
238
|
-
* @param {TopLevelSymbol} symbol the symbol
|
238
|
+
* @param {TopLevelSymbol | undefined} symbol the symbol
|
239
239
|
*/
|
240
240
|
exports.setTopLevelSymbol = (state, symbol) => {
|
241
241
|
const innerGraphState = getState(state);
|
@@ -260,7 +260,7 @@ exports.getTopLevelSymbol = state => {
|
|
260
260
|
/**
|
261
261
|
* @param {JavascriptParser} parser parser
|
262
262
|
* @param {string} name name of variable
|
263
|
-
* @returns {TopLevelSymbol} symbol
|
263
|
+
* @returns {TopLevelSymbol | undefined} symbol
|
264
264
|
*/
|
265
265
|
exports.tagTopLevelSymbol = (parser, name) => {
|
266
266
|
const innerGraphState = getState(parser.state);
|