webpack 5.77.0 → 5.78.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/bin/webpack.js +0 -0
- package/lib/APIPlugin.js +25 -18
- package/lib/CompatibilityPlugin.js +53 -52
- package/lib/ConstPlugin.js +22 -15
- package/lib/ContextModule.js +3 -2
- package/lib/DefinePlugin.js +44 -36
- package/lib/DelegatedModule.js +2 -1
- package/lib/DllModule.js +2 -1
- package/lib/ErrorHelpers.js +61 -22
- package/lib/ExportsInfoApiPlugin.js +16 -9
- package/lib/ExternalModule.js +2 -1
- package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
- package/lib/FlagDependencyExportsPlugin.js +336 -348
- package/lib/FlagDependencyUsagePlugin.js +6 -8
- package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
- package/lib/HotModuleReplacementPlugin.js +50 -45
- package/lib/JavascriptMetaInfoPlugin.js +16 -9
- package/lib/ModuleTypeConstants.js +50 -0
- package/lib/NodeStuffPlugin.js +35 -31
- package/lib/NormalModule.js +2 -1
- package/lib/NormalModuleFactory.js +7 -1
- package/lib/ProvidePlugin.js +17 -10
- package/lib/RawModule.js +2 -1
- package/lib/RequireJsStuffPlugin.js +15 -15
- package/lib/UseStrictPlugin.js +15 -8
- package/lib/WebpackIsIncludedPlugin.js +16 -9
- package/lib/config/defaults.js +16 -8
- package/lib/config/normalization.js +4 -0
- package/lib/container/ContainerEntryModule.js +2 -1
- package/lib/css/CssParser.js +22 -2
- package/lib/debug/ProfilingPlugin.js +20 -12
- package/lib/dependencies/AMDPlugin.js +26 -20
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
- package/lib/dependencies/CommonJsPlugin.js +29 -25
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
- package/lib/dependencies/ImportMetaPlugin.js +26 -20
- package/lib/dependencies/ImportPlugin.js +14 -7
- package/lib/dependencies/RequireContextPlugin.js +12 -6
- package/lib/dependencies/RequireEnsurePlugin.js +13 -7
- package/lib/dependencies/RequireIncludePlugin.js +11 -5
- package/lib/dependencies/SystemPlugin.js +21 -15
- package/lib/dependencies/URLPlugin.js +15 -9
- package/lib/dependencies/WorkerPlugin.js +14 -8
- package/lib/javascript/JavascriptModulesPlugin.js +157 -164
- package/lib/json/JsonModulesPlugin.js +13 -5
- package/lib/library/AmdLibraryPlugin.js +22 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/optimize/ConcatenatedModule.js +2 -1
- package/lib/optimize/InnerGraphPlugin.js +47 -46
- package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
- package/lib/sharing/ConsumeSharedPlugin.js +4 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +40 -40
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +18 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
- package/types.d.ts +10 -0
package/lib/RawModule.js
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const { OriginalSource, RawSource } = require("webpack-sources");
|
9
9
|
const Module = require("./Module");
|
10
|
+
const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
|
10
11
|
const makeSerializable = require("./util/makeSerializable");
|
11
12
|
|
12
13
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -35,7 +36,7 @@ class RawModule extends Module {
|
|
35
36
|
* @param {ReadonlySet<string>=} runtimeRequirements runtime requirements needed for the source code
|
36
37
|
*/
|
37
38
|
constructor(source, identifier, readableIdentifier, runtimeRequirements) {
|
38
|
-
super(
|
39
|
+
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
39
40
|
this.sourceStr = source;
|
40
41
|
this.identifierStr = identifier || this.sourceStr;
|
41
42
|
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
|
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
11
|
+
} = require("./ModuleTypeConstants");
|
8
12
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
9
13
|
const ConstDependency = require("./dependencies/ConstDependency");
|
10
14
|
const {
|
@@ -13,6 +17,8 @@ const {
|
|
13
17
|
|
14
18
|
/** @typedef {import("./Compiler")} Compiler */
|
15
19
|
|
20
|
+
const PLUGIN_NAME = "RequireJsStuffPlugin";
|
21
|
+
|
16
22
|
module.exports = class RequireJsStuffPlugin {
|
17
23
|
/**
|
18
24
|
* Apply the plugin
|
@@ -21,7 +27,7 @@ module.exports = class RequireJsStuffPlugin {
|
|
21
27
|
*/
|
22
28
|
apply(compiler) {
|
23
29
|
compiler.hooks.compilation.tap(
|
24
|
-
|
30
|
+
PLUGIN_NAME,
|
25
31
|
(compilation, { normalModuleFactory }) => {
|
26
32
|
compilation.dependencyTemplates.set(
|
27
33
|
ConstDependency,
|
@@ -37,27 +43,21 @@ module.exports = class RequireJsStuffPlugin {
|
|
37
43
|
|
38
44
|
parser.hooks.call
|
39
45
|
.for("require.config")
|
40
|
-
.tap(
|
41
|
-
"RequireJsStuffPlugin",
|
42
|
-
toConstantDependency(parser, "undefined")
|
43
|
-
);
|
46
|
+
.tap(PLUGIN_NAME, toConstantDependency(parser, "undefined"));
|
44
47
|
parser.hooks.call
|
45
48
|
.for("requirejs.config")
|
46
|
-
.tap(
|
47
|
-
"RequireJsStuffPlugin",
|
48
|
-
toConstantDependency(parser, "undefined")
|
49
|
-
);
|
49
|
+
.tap(PLUGIN_NAME, toConstantDependency(parser, "undefined"));
|
50
50
|
|
51
51
|
parser.hooks.expression
|
52
52
|
.for("require.version")
|
53
53
|
.tap(
|
54
|
-
|
54
|
+
PLUGIN_NAME,
|
55
55
|
toConstantDependency(parser, JSON.stringify("0.0.0"))
|
56
56
|
);
|
57
57
|
parser.hooks.expression
|
58
58
|
.for("requirejs.onError")
|
59
59
|
.tap(
|
60
|
-
|
60
|
+
PLUGIN_NAME,
|
61
61
|
toConstantDependency(
|
62
62
|
parser,
|
63
63
|
RuntimeGlobals.uncaughtErrorHandler,
|
@@ -66,11 +66,11 @@ module.exports = class RequireJsStuffPlugin {
|
|
66
66
|
);
|
67
67
|
};
|
68
68
|
normalModuleFactory.hooks.parser
|
69
|
-
.for(
|
70
|
-
.tap(
|
69
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
70
|
+
.tap(PLUGIN_NAME, handler);
|
71
71
|
normalModuleFactory.hooks.parser
|
72
|
-
.for(
|
73
|
-
.tap(
|
72
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
73
|
+
.tap(PLUGIN_NAME, handler);
|
74
74
|
}
|
75
75
|
);
|
76
76
|
}
|
package/lib/UseStrictPlugin.js
CHANGED
@@ -5,10 +5,17 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
11
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
12
|
+
} = require("./ModuleTypeConstants");
|
8
13
|
const ConstDependency = require("./dependencies/ConstDependency");
|
9
14
|
|
10
15
|
/** @typedef {import("./Compiler")} Compiler */
|
11
16
|
|
17
|
+
const PLUGIN_NAME = "UseStrictPlugin";
|
18
|
+
|
12
19
|
class UseStrictPlugin {
|
13
20
|
/**
|
14
21
|
* Apply the plugin
|
@@ -17,10 +24,10 @@ class UseStrictPlugin {
|
|
17
24
|
*/
|
18
25
|
apply(compiler) {
|
19
26
|
compiler.hooks.compilation.tap(
|
20
|
-
|
27
|
+
PLUGIN_NAME,
|
21
28
|
(compilation, { normalModuleFactory }) => {
|
22
29
|
const handler = parser => {
|
23
|
-
parser.hooks.program.tap(
|
30
|
+
parser.hooks.program.tap(PLUGIN_NAME, ast => {
|
24
31
|
const firstNode = ast.body[0];
|
25
32
|
if (
|
26
33
|
firstNode &&
|
@@ -40,14 +47,14 @@ class UseStrictPlugin {
|
|
40
47
|
};
|
41
48
|
|
42
49
|
normalModuleFactory.hooks.parser
|
43
|
-
.for(
|
44
|
-
.tap(
|
50
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
51
|
+
.tap(PLUGIN_NAME, handler);
|
45
52
|
normalModuleFactory.hooks.parser
|
46
|
-
.for(
|
47
|
-
.tap(
|
53
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
54
|
+
.tap(PLUGIN_NAME, handler);
|
48
55
|
normalModuleFactory.hooks.parser
|
49
|
-
.for(
|
50
|
-
.tap(
|
56
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
57
|
+
.tap(PLUGIN_NAME, handler);
|
51
58
|
}
|
52
59
|
);
|
53
60
|
}
|
@@ -6,6 +6,11 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const IgnoreErrorModuleFactory = require("./IgnoreErrorModuleFactory");
|
9
|
+
const {
|
10
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
11
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
12
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
13
|
+
} = require("./ModuleTypeConstants");
|
9
14
|
const WebpackIsIncludedDependency = require("./dependencies/WebpackIsIncludedDependency");
|
10
15
|
const {
|
11
16
|
toConstantDependency
|
@@ -16,6 +21,8 @@ const {
|
|
16
21
|
/** @typedef {import("./Module")} Module */
|
17
22
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
18
23
|
|
24
|
+
const PLUGIN_NAME = "WebpackIsIncludedPlugin";
|
25
|
+
|
19
26
|
class WebpackIsIncludedPlugin {
|
20
27
|
/**
|
21
28
|
* @param {Compiler} compiler the compiler instance
|
@@ -23,7 +30,7 @@ class WebpackIsIncludedPlugin {
|
|
23
30
|
*/
|
24
31
|
apply(compiler) {
|
25
32
|
compiler.hooks.compilation.tap(
|
26
|
-
|
33
|
+
PLUGIN_NAME,
|
27
34
|
(compilation, { normalModuleFactory }) => {
|
28
35
|
compilation.dependencyFactories.set(
|
29
36
|
WebpackIsIncludedDependency,
|
@@ -41,7 +48,7 @@ class WebpackIsIncludedPlugin {
|
|
41
48
|
const handler = parser => {
|
42
49
|
parser.hooks.call
|
43
50
|
.for("__webpack_is_included__")
|
44
|
-
.tap(
|
51
|
+
.tap(PLUGIN_NAME, expr => {
|
45
52
|
if (
|
46
53
|
expr.type !== "CallExpression" ||
|
47
54
|
expr.arguments.length !== 1 ||
|
@@ -64,19 +71,19 @@ class WebpackIsIncludedPlugin {
|
|
64
71
|
parser.hooks.typeof
|
65
72
|
.for("__webpack_is_included__")
|
66
73
|
.tap(
|
67
|
-
|
74
|
+
PLUGIN_NAME,
|
68
75
|
toConstantDependency(parser, JSON.stringify("function"))
|
69
76
|
);
|
70
77
|
};
|
71
78
|
normalModuleFactory.hooks.parser
|
72
|
-
.for(
|
73
|
-
.tap(
|
79
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
80
|
+
.tap(PLUGIN_NAME, handler);
|
74
81
|
normalModuleFactory.hooks.parser
|
75
|
-
.for(
|
76
|
-
.tap(
|
82
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
83
|
+
.tap(PLUGIN_NAME, handler);
|
77
84
|
normalModuleFactory.hooks.parser
|
78
|
-
.for(
|
79
|
-
.tap(
|
85
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
86
|
+
.tap(PLUGIN_NAME, handler);
|
80
87
|
}
|
81
88
|
);
|
82
89
|
}
|
package/lib/config/defaults.js
CHANGED
@@ -7,6 +7,14 @@
|
|
7
7
|
|
8
8
|
const fs = require("fs");
|
9
9
|
const path = require("path");
|
10
|
+
const {
|
11
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
12
|
+
JSON_MODULE_TYPE,
|
13
|
+
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
14
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
15
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
16
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC
|
17
|
+
} = require("../ModuleTypeConstants");
|
10
18
|
const Template = require("../Template");
|
11
19
|
const { cleverMerge } = require("../util/cleverMerge");
|
12
20
|
const {
|
@@ -517,7 +525,7 @@ const applyModuleDefaults = (
|
|
517
525
|
|
518
526
|
A(module, "defaultRules", () => {
|
519
527
|
const esm = {
|
520
|
-
type:
|
528
|
+
type: JAVASCRIPT_MODULE_TYPE_ESM,
|
521
529
|
resolve: {
|
522
530
|
byDependency: {
|
523
531
|
esm: {
|
@@ -527,21 +535,21 @@ const applyModuleDefaults = (
|
|
527
535
|
}
|
528
536
|
};
|
529
537
|
const commonjs = {
|
530
|
-
type:
|
538
|
+
type: JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
531
539
|
};
|
532
540
|
/** @type {RuleSetRules} */
|
533
541
|
const rules = [
|
534
542
|
{
|
535
543
|
mimetype: "application/node",
|
536
|
-
type:
|
544
|
+
type: JAVASCRIPT_MODULE_TYPE_AUTO
|
537
545
|
},
|
538
546
|
{
|
539
547
|
test: /\.json$/i,
|
540
|
-
type:
|
548
|
+
type: JSON_MODULE_TYPE
|
541
549
|
},
|
542
550
|
{
|
543
551
|
mimetype: "application/json",
|
544
|
-
type:
|
552
|
+
type: JSON_MODULE_TYPE
|
545
553
|
},
|
546
554
|
{
|
547
555
|
test: /\.mjs$/i,
|
@@ -574,7 +582,7 @@ const applyModuleDefaults = (
|
|
574
582
|
];
|
575
583
|
if (asyncWebAssembly) {
|
576
584
|
const wasm = {
|
577
|
-
type:
|
585
|
+
type: WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
578
586
|
rules: [
|
579
587
|
{
|
580
588
|
descriptionData: {
|
@@ -596,7 +604,7 @@ const applyModuleDefaults = (
|
|
596
604
|
});
|
597
605
|
} else if (syncWebAssembly) {
|
598
606
|
const wasm = {
|
599
|
-
type:
|
607
|
+
type: WEBASSEMBLY_MODULE_TYPE_SYNC,
|
600
608
|
rules: [
|
601
609
|
{
|
602
610
|
descriptionData: {
|
@@ -667,7 +675,7 @@ const applyModuleDefaults = (
|
|
667
675
|
},
|
668
676
|
{
|
669
677
|
assert: { type: "json" },
|
670
|
-
type:
|
678
|
+
type: JSON_MODULE_TYPE
|
671
679
|
}
|
672
680
|
);
|
673
681
|
return rules;
|
@@ -340,6 +340,10 @@ const getNormalizedWebpackOptions = config => {
|
|
340
340
|
output.auxiliaryComment !== undefined
|
341
341
|
? output.auxiliaryComment
|
342
342
|
: libraryBase.auxiliaryComment,
|
343
|
+
amdContainer:
|
344
|
+
output.amdContainer !== undefined
|
345
|
+
? output.amdContainer
|
346
|
+
: libraryBase.amdContainer,
|
343
347
|
export:
|
344
348
|
output.libraryExport !== undefined
|
345
349
|
? output.libraryExport
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const { OriginalSource, RawSource } = require("webpack-sources");
|
9
9
|
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
10
10
|
const Module = require("../Module");
|
11
|
+
const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("../ModuleTypeConstants");
|
11
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
12
13
|
const Template = require("../Template");
|
13
14
|
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
|
@@ -44,7 +45,7 @@ class ContainerEntryModule extends Module {
|
|
44
45
|
* @param {string} shareScope name of the share scope
|
45
46
|
*/
|
46
47
|
constructor(name, exposes, shareScope) {
|
47
|
-
super(
|
48
|
+
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
48
49
|
this._name = name;
|
49
50
|
this._exposes = exposes;
|
50
51
|
this._shareScope = shareScope;
|
package/lib/css/CssParser.js
CHANGED
@@ -138,6 +138,7 @@ class CssParser extends Parser {
|
|
138
138
|
let singleClassSelector = undefined;
|
139
139
|
let lastIdentifier = undefined;
|
140
140
|
const modeStack = [];
|
141
|
+
let awaitRightParenthesis = false;
|
141
142
|
const isTopLevelLocal = () =>
|
142
143
|
modeData === "local" ||
|
143
144
|
(this.defaultMode === "local" && modeData === undefined);
|
@@ -296,6 +297,7 @@ class CssParser extends Parser {
|
|
296
297
|
module.addDependency(dep);
|
297
298
|
}
|
298
299
|
};
|
300
|
+
const eatAtRuleNested = eatUntil("{};/");
|
299
301
|
const eatKeyframes = eatUntil("{};/");
|
300
302
|
const eatNameInVar = eatUntil(",)};/");
|
301
303
|
walkCssTokens(source, {
|
@@ -380,6 +382,18 @@ class CssParser extends Parser {
|
|
380
382
|
modeNestingLevel = 1;
|
381
383
|
return pos + 1;
|
382
384
|
}
|
385
|
+
if (name === "@media" || name === "@supports") {
|
386
|
+
let pos = end;
|
387
|
+
const [newPos] = eatText(input, pos, eatAtRuleNested);
|
388
|
+
pos = newPos;
|
389
|
+
if (pos === input.length) return pos;
|
390
|
+
if (input.charCodeAt(pos) !== CC_LEFT_CURLY) {
|
391
|
+
throw new Error(
|
392
|
+
`Unexpected ${input[pos]} at ${pos} during parsing of @media or @supports (expected '{')`
|
393
|
+
);
|
394
|
+
}
|
395
|
+
return pos + 1;
|
396
|
+
}
|
383
397
|
return end;
|
384
398
|
},
|
385
399
|
semicolon: (input, start, end) => {
|
@@ -511,6 +525,9 @@ class CssParser extends Parser {
|
|
511
525
|
rightParenthesis: (input, start, end) => {
|
512
526
|
switch (mode) {
|
513
527
|
case CSS_MODE_TOP_LEVEL: {
|
528
|
+
if (awaitRightParenthesis) {
|
529
|
+
awaitRightParenthesis = false;
|
530
|
+
}
|
514
531
|
const newModeData = modeStack.pop();
|
515
532
|
if (newModeData !== false) {
|
516
533
|
modeData = newModeData;
|
@@ -561,6 +578,7 @@ class CssParser extends Parser {
|
|
561
578
|
const dep = new ConstDependency("", [start, end]);
|
562
579
|
module.addPresentationalDependency(dep);
|
563
580
|
} else {
|
581
|
+
awaitRightParenthesis = true;
|
564
582
|
modeStack.push(false);
|
565
583
|
}
|
566
584
|
break;
|
@@ -597,8 +615,10 @@ class CssParser extends Parser {
|
|
597
615
|
comma: (input, start, end) => {
|
598
616
|
switch (mode) {
|
599
617
|
case CSS_MODE_TOP_LEVEL:
|
600
|
-
|
601
|
-
|
618
|
+
if (!awaitRightParenthesis) {
|
619
|
+
modeData = undefined;
|
620
|
+
modeStack.length = 0;
|
621
|
+
}
|
602
622
|
break;
|
603
623
|
case CSS_MODE_IN_LOCAL_RULE:
|
604
624
|
processDeclarationValueDone(input, start);
|
@@ -5,6 +5,14 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const { Tracer } = require("chrome-trace-event");
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
11
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
12
|
+
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
13
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC,
|
14
|
+
JSON_MODULE_TYPE
|
15
|
+
} = require("../ModuleTypeConstants");
|
8
16
|
const createSchemaValidation = require("../util/create-schema-validation");
|
9
17
|
const { dirname, mkdirpSync } = require("../util/fs");
|
10
18
|
|
@@ -182,7 +190,7 @@ const createTrace = (fs, outputPath) => {
|
|
182
190
|
};
|
183
191
|
};
|
184
192
|
|
185
|
-
const
|
193
|
+
const PLUGIN_NAME = "ProfilingPlugin";
|
186
194
|
|
187
195
|
class ProfilingPlugin {
|
188
196
|
/**
|
@@ -216,7 +224,7 @@ class ProfilingPlugin {
|
|
216
224
|
});
|
217
225
|
|
218
226
|
compiler.hooks.compilation.tap(
|
219
|
-
|
227
|
+
PLUGIN_NAME,
|
220
228
|
(compilation, { normalModuleFactory, contextModuleFactory }) => {
|
221
229
|
interceptAllHooksFor(compilation, tracer, "Compilation");
|
222
230
|
interceptAllHooksFor(
|
@@ -237,7 +245,7 @@ class ProfilingPlugin {
|
|
237
245
|
// We need to write out the CPU profile when we are all done.
|
238
246
|
compiler.hooks.done.tapAsync(
|
239
247
|
{
|
240
|
-
name:
|
248
|
+
name: PLUGIN_NAME,
|
241
249
|
stage: Infinity
|
242
250
|
},
|
243
251
|
(stats, callback) => {
|
@@ -312,18 +320,18 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
|
312
320
|
|
313
321
|
const interceptAllParserHooks = (moduleFactory, tracer) => {
|
314
322
|
const moduleTypes = [
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
323
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
324
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
325
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
326
|
+
JSON_MODULE_TYPE,
|
327
|
+
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
328
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC
|
321
329
|
];
|
322
330
|
|
323
331
|
moduleTypes.forEach(moduleType => {
|
324
332
|
moduleFactory.hooks.parser
|
325
333
|
.for(moduleType)
|
326
|
-
.tap(
|
334
|
+
.tap(PLUGIN_NAME, (parser, parserOpts) => {
|
327
335
|
interceptAllHooksFor(parser, tracer, "Parser");
|
328
336
|
});
|
329
337
|
});
|
@@ -347,7 +355,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
|
|
347
355
|
const { name, type, fn } = tapInfo;
|
348
356
|
const newFn =
|
349
357
|
// Don't tap our own hooks to ensure stream can close cleanly
|
350
|
-
name ===
|
358
|
+
name === PLUGIN_NAME
|
351
359
|
? fn
|
352
360
|
: makeNewProfiledTapFn(hookName, tracer, {
|
353
361
|
name,
|
@@ -418,7 +426,7 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
418
426
|
const id = ++tracer.counter;
|
419
427
|
// Do not instrument ourself due to the CPU
|
420
428
|
// profile needing to be the last event in the trace.
|
421
|
-
if (name ===
|
429
|
+
if (name === PLUGIN_NAME) {
|
422
430
|
return fn(...args);
|
423
431
|
}
|
424
432
|
|
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
11
|
+
} = require("../ModuleTypeConstants");
|
8
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
13
|
const {
|
10
14
|
approve,
|
@@ -31,6 +35,8 @@ const UnsupportedDependency = require("./UnsupportedDependency");
|
|
31
35
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
32
36
|
/** @typedef {import("../Compiler")} Compiler */
|
33
37
|
|
38
|
+
const PLUGIN_NAME = "AMDPlugin";
|
39
|
+
|
34
40
|
class AMDPlugin {
|
35
41
|
/**
|
36
42
|
* @param {Record<string, any>} amdOptions the AMD options
|
@@ -47,7 +53,7 @@ class AMDPlugin {
|
|
47
53
|
apply(compiler) {
|
48
54
|
const amdOptions = this.amdOptions;
|
49
55
|
compiler.hooks.compilation.tap(
|
50
|
-
|
56
|
+
PLUGIN_NAME,
|
51
57
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
52
58
|
compilation.dependencyTemplates.set(
|
53
59
|
AMDRequireDependency,
|
@@ -94,25 +100,25 @@ class AMDPlugin {
|
|
94
100
|
|
95
101
|
compilation.hooks.runtimeRequirementInModule
|
96
102
|
.for(RuntimeGlobals.amdDefine)
|
97
|
-
.tap(
|
103
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
98
104
|
set.add(RuntimeGlobals.require);
|
99
105
|
});
|
100
106
|
|
101
107
|
compilation.hooks.runtimeRequirementInModule
|
102
108
|
.for(RuntimeGlobals.amdOptions)
|
103
|
-
.tap(
|
109
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
104
110
|
set.add(RuntimeGlobals.requireScope);
|
105
111
|
});
|
106
112
|
|
107
113
|
compilation.hooks.runtimeRequirementInTree
|
108
114
|
.for(RuntimeGlobals.amdDefine)
|
109
|
-
.tap(
|
115
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
110
116
|
compilation.addRuntimeModule(chunk, new AMDDefineRuntimeModule());
|
111
117
|
});
|
112
118
|
|
113
119
|
compilation.hooks.runtimeRequirementInTree
|
114
120
|
.for(RuntimeGlobals.amdOptions)
|
115
|
-
.tap(
|
121
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
116
122
|
compilation.addRuntimeModule(
|
117
123
|
chunk,
|
118
124
|
new AMDOptionsRuntimeModule(amdOptions)
|
@@ -126,7 +132,7 @@ class AMDPlugin {
|
|
126
132
|
parser.hooks.expression
|
127
133
|
.for(optionExpr)
|
128
134
|
.tap(
|
129
|
-
|
135
|
+
PLUGIN_NAME,
|
130
136
|
toConstantDependency(parser, RuntimeGlobals.amdOptions, [
|
131
137
|
RuntimeGlobals.amdOptions
|
132
138
|
])
|
@@ -134,16 +140,16 @@ class AMDPlugin {
|
|
134
140
|
parser.hooks.evaluateIdentifier
|
135
141
|
.for(optionExpr)
|
136
142
|
.tap(
|
137
|
-
|
143
|
+
PLUGIN_NAME,
|
138
144
|
evaluateToIdentifier(optionExpr, rootName, getMembers, true)
|
139
145
|
);
|
140
146
|
parser.hooks.evaluateTypeof
|
141
147
|
.for(optionExpr)
|
142
|
-
.tap(
|
148
|
+
.tap(PLUGIN_NAME, evaluateToString("object"));
|
143
149
|
parser.hooks.typeof
|
144
150
|
.for(optionExpr)
|
145
151
|
.tap(
|
146
|
-
|
152
|
+
PLUGIN_NAME,
|
147
153
|
toConstantDependency(parser, JSON.stringify("object"))
|
148
154
|
);
|
149
155
|
};
|
@@ -161,7 +167,7 @@ class AMDPlugin {
|
|
161
167
|
() => []
|
162
168
|
);
|
163
169
|
|
164
|
-
parser.hooks.expression.for("define").tap(
|
170
|
+
parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => {
|
165
171
|
const dep = new ConstDependency(
|
166
172
|
RuntimeGlobals.amdDefine,
|
167
173
|
expr.range,
|
@@ -174,14 +180,14 @@ class AMDPlugin {
|
|
174
180
|
parser.hooks.typeof
|
175
181
|
.for("define")
|
176
182
|
.tap(
|
177
|
-
|
183
|
+
PLUGIN_NAME,
|
178
184
|
toConstantDependency(parser, JSON.stringify("function"))
|
179
185
|
);
|
180
186
|
parser.hooks.evaluateTypeof
|
181
187
|
.for("define")
|
182
|
-
.tap(
|
183
|
-
parser.hooks.canRename.for("define").tap(
|
184
|
-
parser.hooks.rename.for("define").tap(
|
188
|
+
.tap(PLUGIN_NAME, evaluateToString("function"));
|
189
|
+
parser.hooks.canRename.for("define").tap(PLUGIN_NAME, approve);
|
190
|
+
parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => {
|
185
191
|
const dep = new ConstDependency(
|
186
192
|
RuntimeGlobals.amdDefine,
|
187
193
|
expr.range,
|
@@ -194,20 +200,20 @@ class AMDPlugin {
|
|
194
200
|
parser.hooks.typeof
|
195
201
|
.for("require")
|
196
202
|
.tap(
|
197
|
-
|
203
|
+
PLUGIN_NAME,
|
198
204
|
toConstantDependency(parser, JSON.stringify("function"))
|
199
205
|
);
|
200
206
|
parser.hooks.evaluateTypeof
|
201
207
|
.for("require")
|
202
|
-
.tap(
|
208
|
+
.tap(PLUGIN_NAME, evaluateToString("function"));
|
203
209
|
};
|
204
210
|
|
205
211
|
normalModuleFactory.hooks.parser
|
206
|
-
.for(
|
207
|
-
.tap(
|
212
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
213
|
+
.tap(PLUGIN_NAME, handler);
|
208
214
|
normalModuleFactory.hooks.parser
|
209
|
-
.for(
|
210
|
-
.tap(
|
215
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
216
|
+
.tap(PLUGIN_NAME, handler);
|
211
217
|
}
|
212
218
|
);
|
213
219
|
}
|
@@ -444,13 +444,14 @@ class CommonJsImportsParserPlugin {
|
|
444
444
|
|
445
445
|
if (!options.createRequire) return;
|
446
446
|
|
447
|
-
let moduleName;
|
447
|
+
let moduleName = [];
|
448
448
|
let specifierName;
|
449
449
|
|
450
450
|
if (options.createRequire === true) {
|
451
|
-
moduleName = "module";
|
451
|
+
moduleName = ["module", "node:module"];
|
452
452
|
specifierName = "createRequire";
|
453
453
|
} else {
|
454
|
+
let moduleName;
|
454
455
|
const match = /^(.*) from (.*)$/.exec(options.createRequire);
|
455
456
|
if (match) {
|
456
457
|
[, specifierName, moduleName] = match;
|
@@ -545,7 +546,7 @@ class CommonJsImportsParserPlugin {
|
|
545
546
|
},
|
546
547
|
(statement, source) => {
|
547
548
|
if (
|
548
|
-
source
|
549
|
+
!moduleName.includes(source) ||
|
549
550
|
statement.specifiers.length !== 1 ||
|
550
551
|
statement.specifiers[0].type !== "ImportSpecifier" ||
|
551
552
|
statement.specifiers[0].imported.type !== "Identifier" ||
|
@@ -570,7 +571,7 @@ class CommonJsImportsParserPlugin {
|
|
570
571
|
stage: -10
|
571
572
|
},
|
572
573
|
(statement, source, id, name) => {
|
573
|
-
if (source
|
574
|
+
if (!moduleName.includes(source) || id !== specifierName) return;
|
574
575
|
parser.tagVariable(name, createRequireSpecifierTag);
|
575
576
|
return true;
|
576
577
|
}
|