webpack 5.65.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.

Files changed (134) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +33 -0
  3. package/lib/Cache.js +1 -1
  4. package/lib/CacheFacade.js +4 -11
  5. package/lib/Chunk.js +2 -0
  6. package/lib/ChunkGraph.js +1 -2
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +93 -47
  9. package/lib/Compiler.js +57 -3
  10. package/lib/ContextModule.js +100 -41
  11. package/lib/ContextModuleFactory.js +60 -21
  12. package/lib/DelegatedModule.js +1 -1
  13. package/lib/Dependency.js +10 -0
  14. package/lib/DependencyTemplate.js +9 -0
  15. package/lib/DependencyTemplates.js +1 -1
  16. package/lib/DllModule.js +1 -1
  17. package/lib/EvalDevToolModulePlugin.js +16 -1
  18. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  19. package/lib/ExportsInfo.js +4 -4
  20. package/lib/ExternalModule.js +93 -53
  21. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  22. package/lib/FileSystemInfo.js +29 -25
  23. package/lib/Generator.js +2 -0
  24. package/lib/HookWebpackError.js +1 -1
  25. package/lib/Module.js +25 -4
  26. package/lib/ModuleFilenameHelpers.js +5 -1
  27. package/lib/MultiCompiler.js +1 -1
  28. package/lib/MultiWatching.js +1 -1
  29. package/lib/NormalModule.js +9 -5
  30. package/lib/NormalModuleFactory.js +25 -27
  31. package/lib/ProgressPlugin.js +1 -1
  32. package/lib/RawModule.js +1 -1
  33. package/lib/RuntimeGlobals.js +29 -1
  34. package/lib/RuntimeModule.js +1 -1
  35. package/lib/RuntimePlugin.js +50 -0
  36. package/lib/RuntimeTemplate.js +21 -0
  37. package/lib/Template.js +2 -1
  38. package/lib/TemplatedPathPlugin.js +48 -23
  39. package/lib/Watching.js +2 -2
  40. package/lib/WebpackOptionsApply.js +43 -2
  41. package/lib/asset/AssetGenerator.js +67 -26
  42. package/lib/asset/AssetModulesPlugin.js +3 -0
  43. package/lib/asset/RawDataUrlModule.js +148 -0
  44. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  45. package/lib/buildChunkGraph.js +1 -1
  46. package/lib/cache/ResolverCachePlugin.js +81 -29
  47. package/lib/cli.js +44 -3
  48. package/lib/config/defaults.js +86 -7
  49. package/lib/config/normalization.js +5 -0
  50. package/lib/container/ContainerEntryModule.js +4 -2
  51. package/lib/container/FallbackModule.js +4 -4
  52. package/lib/container/RemoteModule.js +4 -2
  53. package/lib/css/CssExportsGenerator.js +139 -0
  54. package/lib/css/CssGenerator.js +109 -0
  55. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  56. package/lib/css/CssModulesPlugin.js +462 -0
  57. package/lib/css/CssParser.js +618 -0
  58. package/lib/css/walkCssTokens.js +659 -0
  59. package/lib/debug/ProfilingPlugin.js +15 -14
  60. package/lib/dependencies/ContextElementDependency.js +8 -2
  61. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  62. package/lib/dependencies/CssExportDependency.js +85 -0
  63. package/lib/dependencies/CssImportDependency.js +75 -0
  64. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  65. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  66. package/lib/dependencies/CssUrlDependency.js +132 -0
  67. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  68. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  69. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  70. package/lib/dependencies/LoaderPlugin.js +2 -2
  71. package/lib/dependencies/URLDependency.js +3 -8
  72. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  73. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  74. package/lib/hmr/lazyCompilationBackend.js +4 -2
  75. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  76. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  77. package/lib/ids/IdHelpers.js +24 -10
  78. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  79. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  80. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  81. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  82. package/lib/index.js +10 -0
  83. package/lib/javascript/JavascriptGenerator.js +1 -0
  84. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  85. package/lib/javascript/StartupHelpers.js +6 -5
  86. package/lib/library/AssignLibraryPlugin.js +34 -5
  87. package/lib/library/EnableLibraryPlugin.js +11 -0
  88. package/lib/node/NodeTargetPlugin.js +1 -0
  89. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  90. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  91. package/lib/optimize/ConcatenatedModule.js +21 -9
  92. package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
  93. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  94. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  95. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  96. package/lib/schemes/HttpUriPlugin.js +32 -11
  97. package/lib/serialization/FileMiddleware.js +44 -9
  98. package/lib/sharing/ConsumeSharedModule.js +4 -2
  99. package/lib/sharing/ProvideSharedModule.js +4 -2
  100. package/lib/sharing/utils.js +1 -1
  101. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  102. package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
  103. package/lib/util/ArrayHelpers.js +18 -4
  104. package/lib/util/AsyncQueue.js +1 -1
  105. package/lib/util/compileBooleanMatcher.js +1 -1
  106. package/lib/util/deterministicGrouping.js +1 -1
  107. package/lib/util/hash/xxhash64.js +2 -2
  108. package/lib/util/identifier.js +65 -44
  109. package/lib/util/internalSerializables.js +11 -0
  110. package/lib/util/nonNumericOnlyHash.js +22 -0
  111. package/lib/util/semver.js +17 -10
  112. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  113. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -2
  114. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  115. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  116. package/package.json +16 -23
  117. package/schemas/WebpackOptions.check.js +1 -1
  118. package/schemas/WebpackOptions.json +96 -1
  119. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  120. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  121. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  122. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  123. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  124. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  125. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  126. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  127. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  128. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  129. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  130. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  131. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  132. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  133. package/schemas/plugins/css/CssParserOptions.json +3 -0
  134. package/types.d.ts +295 -59
@@ -60,9 +60,9 @@ class FallbackModule extends Module {
60
60
  * @returns {string | null} an identifier for library inclusion
61
61
  */
62
62
  libIdent(options) {
63
- return `webpack/container/fallback/${this.requests[0]}/and ${
64
- this.requests.length - 1
65
- } more`;
63
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/fallback/${
64
+ this.requests[0]
65
+ }/and ${this.requests.length - 1} more`;
66
66
  }
67
67
 
68
68
  /**
@@ -76,7 +76,7 @@ class FallbackModule extends Module {
76
76
 
77
77
  /**
78
78
  * @param {NeedBuildContext} context context info
79
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
79
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
80
80
  * @returns {void}
81
81
  */
82
82
  needBuild(context, callback) {
@@ -67,12 +67,14 @@ class RemoteModule extends Module {
67
67
  * @returns {string | null} an identifier for library inclusion
68
68
  */
69
69
  libIdent(options) {
70
- return `webpack/container/remote/${this.request}`;
70
+ return `${this.layer ? `(${this.layer})/` : ""}webpack/container/remote/${
71
+ this.request
72
+ }`;
71
73
  }
72
74
 
73
75
  /**
74
76
  * @param {NeedBuildContext} context context info
75
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
77
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
76
78
  * @returns {void}
77
79
  */
78
80
  needBuild(context, callback) {
@@ -0,0 +1,139 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Sergey Melyukov @smelukov
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
9
+ const { UsageState } = require("../ExportsInfo");
10
+ const Generator = require("../Generator");
11
+ const RuntimeGlobals = require("../RuntimeGlobals");
12
+ const Template = require("../Template");
13
+
14
+ /** @typedef {import("webpack-sources").Source} Source */
15
+ /** @typedef {import("../Dependency")} Dependency */
16
+ /** @typedef {import("../Generator").GenerateContext} GenerateContext */
17
+ /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
18
+ /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
19
+ /** @typedef {import("../NormalModule")} NormalModule */
20
+ /** @typedef {import("../util/Hash")} Hash */
21
+
22
+ const TYPES = new Set(["javascript"]);
23
+
24
+ class CssExportsGenerator extends Generator {
25
+ constructor() {
26
+ super();
27
+ }
28
+
29
+ // TODO add getConcatenationBailoutReason to allow concatenation
30
+ // but how to make it have a module id
31
+
32
+ /**
33
+ * @param {NormalModule} module module for which the code should be generated
34
+ * @param {GenerateContext} generateContext context for generate
35
+ * @returns {Source} generated code
36
+ */
37
+ generate(module, generateContext) {
38
+ const source = new ReplaceSource(new RawSource(""));
39
+ const initFragments = [];
40
+ const cssExports = new Map();
41
+
42
+ generateContext.runtimeRequirements.add(RuntimeGlobals.module);
43
+
44
+ const runtimeRequirements = new Set();
45
+
46
+ const templateContext = {
47
+ runtimeTemplate: generateContext.runtimeTemplate,
48
+ dependencyTemplates: generateContext.dependencyTemplates,
49
+ moduleGraph: generateContext.moduleGraph,
50
+ chunkGraph: generateContext.chunkGraph,
51
+ module,
52
+ runtime: generateContext.runtime,
53
+ runtimeRequirements: runtimeRequirements,
54
+ concatenationScope: generateContext.concatenationScope,
55
+ codeGenerationResults: generateContext.codeGenerationResults,
56
+ initFragments,
57
+ cssExports
58
+ };
59
+
60
+ const handleDependency = dependency => {
61
+ const constructor = /** @type {new (...args: any[]) => Dependency} */ (
62
+ dependency.constructor
63
+ );
64
+ const template = generateContext.dependencyTemplates.get(constructor);
65
+ if (!template) {
66
+ throw new Error(
67
+ "No template for dependency: " + dependency.constructor.name
68
+ );
69
+ }
70
+
71
+ template.apply(dependency, source, templateContext);
72
+ };
73
+ module.dependencies.forEach(handleDependency);
74
+
75
+ if (generateContext.concatenationScope) {
76
+ const source = new ConcatSource();
77
+ const usedIdentifiers = new Set();
78
+ for (const [k, v] of cssExports) {
79
+ let identifier = Template.toIdentifier(k);
80
+ let i = 0;
81
+ while (usedIdentifiers.has(identifier)) {
82
+ identifier = Template.toIdentifier(k + i);
83
+ }
84
+ usedIdentifiers.add(identifier);
85
+ generateContext.concatenationScope.registerExport(k, identifier);
86
+ source.add(
87
+ `${
88
+ generateContext.runtimeTemplate.supportsConst ? "const" : "var"
89
+ } ${identifier} = ${JSON.stringify(v)};\n`
90
+ );
91
+ }
92
+ return source;
93
+ } else {
94
+ const otherUsed =
95
+ generateContext.moduleGraph
96
+ .getExportsInfo(module)
97
+ .otherExportsInfo.getUsed(generateContext.runtime) !==
98
+ UsageState.Unused;
99
+ if (otherUsed) {
100
+ generateContext.runtimeRequirements.add(
101
+ RuntimeGlobals.makeNamespaceObject
102
+ );
103
+ }
104
+ return new RawSource(
105
+ `${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
106
+ module.moduleArgument
107
+ }.exports = {\n${Array.from(
108
+ cssExports,
109
+ ([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
110
+ ).join(",\n")}\n}${otherUsed ? ")" : ""};`
111
+ );
112
+ }
113
+ }
114
+
115
+ /**
116
+ * @param {NormalModule} module fresh module
117
+ * @returns {Set<string>} available types (do not mutate)
118
+ */
119
+ getTypes(module) {
120
+ return TYPES;
121
+ }
122
+
123
+ /**
124
+ * @param {NormalModule} module the module
125
+ * @param {string=} type source type
126
+ * @returns {number} estimate size of the module
127
+ */
128
+ getSize(module, type) {
129
+ return 42;
130
+ }
131
+
132
+ /**
133
+ * @param {Hash} hash hash that will be modified
134
+ * @param {UpdateHashContext} updateHashContext context for updating hash
135
+ */
136
+ updateHash(hash, { module }) {}
137
+ }
138
+
139
+ module.exports = CssExportsGenerator;
@@ -0,0 +1,109 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Sergey Melyukov @smelukov
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { ReplaceSource } = require("webpack-sources");
9
+ const Generator = require("../Generator");
10
+ const InitFragment = require("../InitFragment");
11
+ const RuntimeGlobals = require("../RuntimeGlobals");
12
+
13
+ /** @typedef {import("webpack-sources").Source} Source */
14
+ /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../Generator").GenerateContext} GenerateContext */
16
+ /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
17
+ /** @typedef {import("../NormalModule")} NormalModule */
18
+ /** @typedef {import("../util/Hash")} Hash */
19
+
20
+ const TYPES = new Set(["css"]);
21
+
22
+ class CssGenerator extends Generator {
23
+ constructor() {
24
+ super();
25
+ }
26
+
27
+ /**
28
+ * @param {NormalModule} module module for which the code should be generated
29
+ * @param {GenerateContext} generateContext context for generate
30
+ * @returns {Source} generated code
31
+ */
32
+ generate(module, generateContext) {
33
+ const originalSource = module.originalSource();
34
+ const source = new ReplaceSource(originalSource);
35
+ const initFragments = [];
36
+ const cssExports = new Map();
37
+
38
+ generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
39
+
40
+ const templateContext = {
41
+ runtimeTemplate: generateContext.runtimeTemplate,
42
+ dependencyTemplates: generateContext.dependencyTemplates,
43
+ moduleGraph: generateContext.moduleGraph,
44
+ chunkGraph: generateContext.chunkGraph,
45
+ module,
46
+ runtime: generateContext.runtime,
47
+ runtimeRequirements: generateContext.runtimeRequirements,
48
+ concatenationScope: generateContext.concatenationScope,
49
+ codeGenerationResults: generateContext.codeGenerationResults,
50
+ initFragments,
51
+ cssExports
52
+ };
53
+
54
+ const handleDependency = dependency => {
55
+ const constructor = /** @type {new (...args: any[]) => Dependency} */ (
56
+ dependency.constructor
57
+ );
58
+ const template = generateContext.dependencyTemplates.get(constructor);
59
+ if (!template) {
60
+ throw new Error(
61
+ "No template for dependency: " + dependency.constructor.name
62
+ );
63
+ }
64
+
65
+ template.apply(dependency, source, templateContext);
66
+ };
67
+ module.dependencies.forEach(handleDependency);
68
+ if (module.presentationalDependencies !== undefined)
69
+ module.presentationalDependencies.forEach(handleDependency);
70
+
71
+ if (cssExports.size > 0) {
72
+ const data = generateContext.getData();
73
+ data.set("css-exports", cssExports);
74
+ }
75
+
76
+ return InitFragment.addToSource(source, initFragments, generateContext);
77
+ }
78
+
79
+ /**
80
+ * @param {NormalModule} module fresh module
81
+ * @returns {Set<string>} available types (do not mutate)
82
+ */
83
+ getTypes(module) {
84
+ return TYPES;
85
+ }
86
+
87
+ /**
88
+ * @param {NormalModule} module the module
89
+ * @param {string=} type source type
90
+ * @returns {number} estimate size of the module
91
+ */
92
+ getSize(module, type) {
93
+ const originalSource = module.originalSource();
94
+
95
+ if (!originalSource) {
96
+ return 0;
97
+ }
98
+
99
+ return originalSource.size();
100
+ }
101
+
102
+ /**
103
+ * @param {Hash} hash hash that will be modified
104
+ * @param {UpdateHashContext} updateHashContext context for updating hash
105
+ */
106
+ updateHash(hash, { module }) {}
107
+ }
108
+
109
+ module.exports = CssGenerator;