webpack 5.102.1 → 5.103.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.
Files changed (118) hide show
  1. package/README.md +121 -134
  2. package/lib/CompatibilityPlugin.js +25 -2
  3. package/lib/Compilation.js +25 -2
  4. package/lib/ConcatenationScope.js +0 -15
  5. package/lib/CssModule.js +6 -1
  6. package/lib/DefinePlugin.js +11 -11
  7. package/lib/Dependency.js +8 -1
  8. package/lib/DependencyTemplate.js +1 -0
  9. package/lib/DotenvPlugin.js +457 -0
  10. package/lib/EnvironmentPlugin.js +19 -16
  11. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  12. package/lib/ExportsInfo.js +6 -2
  13. package/lib/ExternalModule.js +20 -28
  14. package/lib/ExternalModuleFactoryPlugin.js +10 -8
  15. package/lib/ExternalsPlugin.js +2 -1
  16. package/lib/ManifestPlugin.js +235 -0
  17. package/lib/Module.js +3 -0
  18. package/lib/ModuleGraph.js +2 -1
  19. package/lib/ModuleSourceTypesConstants.js +0 -6
  20. package/lib/MultiCompiler.js +1 -1
  21. package/lib/NodeStuffPlugin.js +419 -121
  22. package/lib/NormalModule.js +17 -16
  23. package/lib/RuntimeGlobals.js +22 -4
  24. package/lib/RuntimePlugin.js +27 -6
  25. package/lib/RuntimeTemplate.js +115 -56
  26. package/lib/SourceMapDevToolPlugin.js +20 -0
  27. package/lib/WebpackOptionsApply.js +33 -9
  28. package/lib/asset/AssetBytesGenerator.js +1 -1
  29. package/lib/asset/AssetGenerator.js +1 -2
  30. package/lib/asset/AssetSourceGenerator.js +1 -1
  31. package/lib/config/browserslistTargetHandler.js +5 -0
  32. package/lib/config/defaults.js +98 -18
  33. package/lib/config/normalization.js +2 -1
  34. package/lib/config/target.js +6 -0
  35. package/lib/css/CssGenerator.js +283 -57
  36. package/lib/css/CssLoadingRuntimeModule.js +2 -0
  37. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  38. package/lib/css/CssModulesPlugin.js +84 -34
  39. package/lib/css/CssParser.js +1174 -667
  40. package/lib/css/walkCssTokens.js +97 -0
  41. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  42. package/lib/dependencies/CommonJsPlugin.js +12 -0
  43. package/lib/dependencies/CssIcssExportDependency.js +247 -8
  44. package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
  45. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
  46. package/lib/dependencies/CssIcssImportDependency.js +60 -54
  47. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
  48. package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
  49. package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
  50. package/lib/dependencies/CssImportDependency.js +15 -5
  51. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  52. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
  53. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  54. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  55. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  56. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
  57. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
  58. package/lib/dependencies/HarmonyImportDependency.js +23 -27
  59. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  60. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  61. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  62. package/lib/dependencies/ImportDependency.js +8 -2
  63. package/lib/dependencies/ImportEagerDependency.js +6 -3
  64. package/lib/dependencies/ImportMetaPlugin.js +97 -9
  65. package/lib/dependencies/ImportParserPlugin.js +19 -21
  66. package/lib/dependencies/ImportPhase.js +121 -0
  67. package/lib/dependencies/ImportWeakDependency.js +6 -3
  68. package/lib/dependencies/ModuleDependency.js +5 -1
  69. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  70. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  71. package/lib/hmr/LazyCompilationPlugin.js +1 -0
  72. package/lib/ids/IdHelpers.js +4 -1
  73. package/lib/index.js +6 -0
  74. package/lib/javascript/ChunkHelpers.js +16 -5
  75. package/lib/javascript/JavascriptGenerator.js +101 -101
  76. package/lib/javascript/JavascriptModulesPlugin.js +23 -13
  77. package/lib/javascript/JavascriptParser.js +142 -38
  78. package/lib/json/JsonParser.js +7 -1
  79. package/lib/library/ModuleLibraryPlugin.js +0 -10
  80. package/lib/library/SystemLibraryPlugin.js +4 -0
  81. package/lib/library/UmdLibraryPlugin.js +1 -1
  82. package/lib/node/NodeTargetPlugin.js +9 -1
  83. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  84. package/lib/optimize/ConcatenatedModule.js +161 -135
  85. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  86. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  87. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  88. package/lib/util/comparators.js +4 -3
  89. package/lib/util/internalSerializables.js +4 -4
  90. package/lib/util/jsonParseEvenBetterErrors.js +10 -0
  91. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  92. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
  93. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
  94. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  95. package/lib/webpack.js +85 -82
  96. package/module.d.ts +5 -0
  97. package/package.json +16 -14
  98. package/schemas/WebpackOptions.check.js +1 -1
  99. package/schemas/WebpackOptions.json +109 -27
  100. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  101. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  102. package/schemas/plugins/ManifestPlugin.json +98 -0
  103. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  104. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  105. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  106. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  107. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  108. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  109. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  110. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  111. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  112. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  113. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  114. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  115. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  116. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  117. package/types.d.ts +560 -293
  118. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
@@ -5,40 +5,84 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const WebpackError = require("../WebpackError");
8
9
  const makeSerializable = require("../util/makeSerializable");
9
- const CssIcssExportDependency = require("./CssIcssExportDependency");
10
- const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
11
- const ModuleDependency = require("./ModuleDependency");
10
+ const CssImportDependency = require("./CssImportDependency");
12
11
 
13
12
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
13
  /** @typedef {import("../Dependency")} Dependency */
15
14
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
16
15
  /** @typedef {import("../Module")} Module */
16
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
17
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
17
18
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
18
19
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
20
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
21
+ /** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
22
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
20
23
 
21
- class CssIcssImportDependency extends ModuleDependency {
24
+ class CssIcssImportDependency extends CssImportDependency {
22
25
  /**
23
26
  * Example of dependency:
24
27
  *
25
- *:import('./style.css') { IMPORTED_NAME: v-primary }
28
+ * :import('./style.css') { IMPORTED_NAME: v-primary }
26
29
  * @param {string} request request request path which needs resolving
27
- * @param {string} exportName export name
28
30
  * @param {Range} range the range of dependency
31
+ * @param {"local" | "global"} mode mode of the parsed CSS
32
+ * @param {string} name importName name
29
33
  */
30
- constructor(request, exportName, range) {
31
- super(request);
32
- this.exportName = exportName;
33
- this.range = range;
34
+ constructor(request, range, mode, name) {
35
+ super(request, range, mode);
36
+ this.name = name;
34
37
  }
35
38
 
36
39
  get type() {
37
40
  return "css :import";
38
41
  }
39
42
 
40
- get category() {
41
- return "css-import";
43
+ /**
44
+ * @returns {string | null} an identifier to merge equal requests
45
+ */
46
+ getResourceIdentifier() {
47
+ return `${super.getResourceIdentifier()}|mode${this.mode}|name${this.name}`;
48
+ }
49
+
50
+ /**
51
+ * Returns list of exports referenced by this dependency
52
+ * @param {ModuleGraph} moduleGraph module graph
53
+ * @param {RuntimeSpec} runtime the runtime for which the module is analysed
54
+ * @returns {ReferencedExports} referenced exports
55
+ */
56
+ getReferencedExports(moduleGraph, runtime) {
57
+ return [
58
+ {
59
+ name: [this.name],
60
+ canMangle: true
61
+ }
62
+ ];
63
+ }
64
+
65
+ /**
66
+ * Returns warnings
67
+ * @param {ModuleGraph} moduleGraph module graph
68
+ * @returns {WebpackError[] | null | undefined} warnings
69
+ */
70
+ getWarnings(moduleGraph) {
71
+ const module = moduleGraph.getModule(this);
72
+
73
+ if (
74
+ module &&
75
+ !moduleGraph.getExportsInfo(module).isExportProvided(this.name)
76
+ ) {
77
+ const error = new WebpackError(
78
+ `Referenced name "${this.name}" in "${this.userRequest}" not found`
79
+ );
80
+ error.module = module;
81
+
82
+ return [error];
83
+ }
84
+
85
+ return null;
42
86
  }
43
87
 
44
88
  /**
@@ -46,8 +90,7 @@ class CssIcssImportDependency extends ModuleDependency {
46
90
  */
47
91
  serialize(context) {
48
92
  const { write } = context;
49
- write(this.range);
50
- write(this.exportName);
93
+ write(this.name);
51
94
  super.serialize(context);
52
95
  }
53
96
 
@@ -56,14 +99,13 @@ class CssIcssImportDependency extends ModuleDependency {
56
99
  */
57
100
  deserialize(context) {
58
101
  const { read } = context;
59
- this.range = read();
60
- this.exportName = read();
102
+ this.name = read();
61
103
  super.deserialize(context);
62
104
  }
63
105
  }
64
106
 
65
107
  CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends (
66
- ModuleDependency.Template
108
+ CssImportDependency.Template
67
109
  ) {
68
110
  /**
69
111
  * @param {Dependency} dependency the dependency for which the template should be applied
@@ -72,43 +114,7 @@ CssIcssImportDependency.Template = class CssIcssImportDependencyTemplate extends
72
114
  * @returns {void}
73
115
  */
74
116
  apply(dependency, source, templateContext) {
75
- const dep = /** @type {CssIcssImportDependency} */ (dependency);
76
- const { range } = dep;
77
- const module =
78
- /** @type {Module} */
79
- (templateContext.moduleGraph.getModule(dep));
80
- let value;
81
-
82
- for (const item of module.dependencies) {
83
- if (
84
- item instanceof CssLocalIdentifierDependency &&
85
- dep.exportName === item.name
86
- ) {
87
- value = CssLocalIdentifierDependency.Template.getIdentifier(
88
- item,
89
- dep.exportName,
90
- {
91
- ...templateContext,
92
- module
93
- }
94
- );
95
- break;
96
- } else if (
97
- item instanceof CssIcssExportDependency &&
98
- dep.exportName === item.name
99
- ) {
100
- value = item.value;
101
- break;
102
- }
103
- }
104
-
105
- if (!value) {
106
- throw new Error(
107
- `Imported '${dep.exportName}' name from '${dep.request}' not found`
108
- );
109
- }
110
-
111
- source.replace(range[0], range[1], value);
117
+ // We remove everything in CSS parser
112
118
  }
113
119
  };
114
120
 
@@ -0,0 +1,61 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const CssIcssExportDependency = require("./CssIcssExportDependency");
10
+
11
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
+ /** @typedef {import("../Dependency")} Dependency */
13
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
14
+ /** @typedef {import("../css/CssParser").Range} Range */
15
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
+
18
+ class CssIcssLocalIdentifierDependency extends CssIcssExportDependency {
19
+ /**
20
+ * @param {string} name name
21
+ * @param {Range} range range
22
+ * @param {string=} prefix prefix
23
+ */
24
+ constructor(name, range, prefix = "") {
25
+ super(name, name, undefined, range);
26
+ this.prefix = prefix;
27
+ this.interpolationMode = CssIcssExportDependency.INTERPOLATION_MODE.VALUE;
28
+ this.exportMode = CssIcssExportDependency.EXPORT_MODE.ONCE;
29
+ }
30
+
31
+ get type() {
32
+ return "css local identifier";
33
+ }
34
+
35
+ /**
36
+ * @param {ObjectSerializerContext} context context
37
+ */
38
+ serialize(context) {
39
+ const { write } = context;
40
+ write(this.prefix);
41
+ super.serialize(context);
42
+ }
43
+
44
+ /**
45
+ * @param {ObjectDeserializerContext} context context
46
+ */
47
+ deserialize(context) {
48
+ const { read } = context;
49
+ this.prefix = read();
50
+ super.deserialize(context);
51
+ }
52
+ }
53
+
54
+ CssIcssLocalIdentifierDependency.Template = CssIcssExportDependency.Template;
55
+
56
+ makeSerializable(
57
+ CssIcssLocalIdentifierDependency,
58
+ "webpack/lib/dependencies/CssLocalIdentifierDependency"
59
+ );
60
+
61
+ module.exports = CssIcssLocalIdentifierDependency;
@@ -6,9 +6,12 @@
6
6
  "use strict";
7
7
 
8
8
  const Dependency = require("../Dependency");
9
+ const WebpackError = require("../WebpackError");
9
10
  const makeSerializable = require("../util/makeSerializable");
10
- const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
11
+ const CssIcssExportDependency = require("./CssIcssExportDependency");
12
+ const CssLocalIdentifierDependency = require("./CssIcssLocalIdentifierDependency");
11
13
 
14
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
12
15
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
16
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14
17
  /** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
@@ -18,17 +21,36 @@ const CssLocalIdentifierDependency = require("./CssLocalIdentifierDependency");
18
21
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
19
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
23
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
24
+ /** @typedef {import("../CssModule")} CssModule */
25
+ /** @typedef {import("../css/CssGenerator")} CssGenerator */
21
26
 
22
- class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
27
+ class CssIcssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
23
28
  /**
24
29
  * @param {string} name name
30
+ * @param {string | undefined} referencedExport referenced export name
25
31
  * @param {Range} range range
26
32
  * @param {string=} prefix prefix
27
33
  * @param {Set<string>=} declaredSet set of declared names (will only be active when in declared set)
34
+ * @param {string=} reexport reexport name
28
35
  */
29
- constructor(name, range, prefix = "", declaredSet = undefined) {
36
+ constructor(
37
+ name,
38
+ referencedExport,
39
+ range,
40
+ prefix = "",
41
+ declaredSet = undefined,
42
+ reexport = undefined
43
+ ) {
30
44
  super(name, range, prefix);
31
45
  this.declaredSet = declaredSet;
46
+ this.referencedExport = referencedExport;
47
+ this.reexport = reexport;
48
+ this.interpolationMode = referencedExport
49
+ ? CssIcssExportDependency.INTERPOLATION_MODE.NONE
50
+ : CssIcssExportDependency.INTERPOLATION_MODE.VALUE;
51
+ this.exportMode = referencedExport
52
+ ? CssIcssExportDependency.EXPORT_MODE.APPEND
53
+ : CssIcssExportDependency.EXPORT_MODE.ONCE;
32
54
  }
33
55
 
34
56
  get type() {
@@ -52,7 +74,12 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
52
74
  * @returns {ExportsSpec | undefined} export names
53
75
  */
54
76
  getExports(moduleGraph) {
55
- if (this.declaredSet && !this.declaredSet.has(this.name)) return;
77
+ if (
78
+ (this.declaredSet && !this.declaredSet.has(this.name)) ||
79
+ this.referencedExport
80
+ ) {
81
+ return;
82
+ }
56
83
  return super.getExports(moduleGraph);
57
84
  }
58
85
 
@@ -66,7 +93,39 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
66
93
  if (this.declaredSet && !this.declaredSet.has(this.name)) {
67
94
  return Dependency.NO_EXPORTS_REFERENCED;
68
95
  }
69
- return [[this.name]];
96
+ return [
97
+ {
98
+ name: [this.referencedExport || this.name],
99
+ canMangle: true
100
+ }
101
+ ];
102
+ }
103
+
104
+ /**
105
+ * Returns warnings
106
+ * @param {ModuleGraph} moduleGraph module graph
107
+ * @returns {WebpackError[] | null | undefined} warnings
108
+ */
109
+ getWarnings(moduleGraph) {
110
+ if (this.referencedExport && !this.reexport) {
111
+ const module = moduleGraph.getModule(this);
112
+
113
+ if (
114
+ module &&
115
+ !moduleGraph
116
+ .getExportsInfo(module)
117
+ .isExportProvided(this.referencedExport)
118
+ ) {
119
+ const error = new WebpackError(
120
+ `Self-referencing name "${this.referencedExport}" not found`
121
+ );
122
+ error.module = module;
123
+
124
+ return [error];
125
+ }
126
+ }
127
+
128
+ return null;
70
129
  }
71
130
 
72
131
  /**
@@ -75,6 +134,7 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
75
134
  serialize(context) {
76
135
  const { write } = context;
77
136
  write(this.declaredSet);
137
+ write(this.referencedExport);
78
138
  super.serialize(context);
79
139
  }
80
140
 
@@ -84,11 +144,12 @@ class CssSelfLocalIdentifierDependency extends CssLocalIdentifierDependency {
84
144
  deserialize(context) {
85
145
  const { read } = context;
86
146
  this.declaredSet = read();
147
+ this.referencedExport = read();
87
148
  super.deserialize(context);
88
149
  }
89
150
  }
90
151
 
91
- CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
152
+ CssIcssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependencyTemplate extends (
92
153
  CssLocalIdentifierDependency.Template
93
154
  ) {
94
155
  /**
@@ -98,15 +159,32 @@ CssSelfLocalIdentifierDependency.Template = class CssSelfLocalIdentifierDependen
98
159
  * @returns {void}
99
160
  */
100
161
  apply(dependency, source, templateContext) {
101
- const dep = /** @type {CssSelfLocalIdentifierDependency} */ (dependency);
162
+ const dep =
163
+ /** @type {CssIcssSelfLocalIdentifierDependency} */
164
+ (dependency);
102
165
  if (dep.declaredSet && !dep.declaredSet.has(dep.name)) return;
166
+ if (dep.referencedExport) {
167
+ const { module: m, moduleGraph, cssData } = templateContext;
168
+ const module = /** @type {CssModule} */ (m);
169
+
170
+ if (
171
+ !dep.reexport &&
172
+ !moduleGraph
173
+ .getExportsInfo(module)
174
+ .isExportProvided(dep.referencedExport)
175
+ ) {
176
+ return;
177
+ }
178
+
179
+ dep.value = cssData.exports.get(dep.referencedExport) || "";
180
+ }
103
181
  super.apply(dependency, source, templateContext);
104
182
  }
105
183
  };
106
184
 
107
185
  makeSerializable(
108
- CssSelfLocalIdentifierDependency,
109
- "webpack/lib/dependencies/CssSelfLocalIdentifierDependency"
186
+ CssIcssSelfLocalIdentifierDependency,
187
+ "webpack/lib/dependencies/CssIcssSelfLocalIdentifierDependency"
110
188
  );
111
189
 
112
- module.exports = CssSelfLocalIdentifierDependency;
190
+ module.exports = CssIcssSelfLocalIdentifierDependency;
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const makeSerializable = require("../util/makeSerializable");
9
+ const CssIcssExportDependency = require("./CssIcssExportDependency");
9
10
  const NullDependency = require("./NullDependency");
10
11
 
11
12
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -24,19 +25,21 @@ const NullDependency = require("./NullDependency");
24
25
  class CssIcssSymbolDependency extends NullDependency {
25
26
  /**
26
27
  * @param {string} name name
27
- * @param {string} value value
28
+ * @param {string} symbol symbol
28
29
  * @param {Range} range range
30
+ * @param {boolean=} isReference true when is reference, otherwise false
29
31
  */
30
- constructor(name, value, range) {
32
+ constructor(name, symbol, range, isReference) {
31
33
  super();
32
34
  this.name = name;
33
- this.value = value;
35
+ this.symbol = symbol;
34
36
  this.range = range;
37
+ this.isReference = isReference;
35
38
  this._hashUpdate = undefined;
36
39
  }
37
40
 
38
41
  get type() {
39
- return "css @value identifier";
42
+ return "css symbol identifier";
40
43
  }
41
44
 
42
45
  get category() {
@@ -56,23 +59,6 @@ class CssIcssSymbolDependency extends NullDependency {
56
59
  hash.update(this._hashUpdate);
57
60
  }
58
61
 
59
- /**
60
- * Returns the exported names
61
- * @param {ModuleGraph} moduleGraph module graph
62
- * @returns {ExportsSpec | undefined} export names
63
- */
64
- getExports(moduleGraph) {
65
- return {
66
- exports: [
67
- {
68
- name: this.name,
69
- canMangle: true
70
- }
71
- ],
72
- dependencies: undefined
73
- };
74
- }
75
-
76
62
  /**
77
63
  * Returns list of exports referenced by this dependency
78
64
  * @param {ModuleGraph} moduleGraph module graph
@@ -80,7 +66,7 @@ class CssIcssSymbolDependency extends NullDependency {
80
66
  * @returns {ReferencedExports} referenced exports
81
67
  */
82
68
  getReferencedExports(moduleGraph, runtime) {
83
- return [[this.name]];
69
+ return [[this.symbol]];
84
70
  }
85
71
 
86
72
  /**
@@ -89,8 +75,10 @@ class CssIcssSymbolDependency extends NullDependency {
89
75
  serialize(context) {
90
76
  const { write } = context;
91
77
  write(this.name);
78
+ write(this.symbol);
92
79
  write(this.value);
93
80
  write(this.range);
81
+ write(this.isReference);
94
82
  super.serialize(context);
95
83
  }
96
84
 
@@ -100,13 +88,15 @@ class CssIcssSymbolDependency extends NullDependency {
100
88
  deserialize(context) {
101
89
  const { read } = context;
102
90
  this.name = read();
91
+ this.symbol = read();
103
92
  this.value = read();
104
93
  this.range = read();
94
+ this.isReference = read();
105
95
  super.deserialize(context);
106
96
  }
107
97
  }
108
98
 
109
- CssIcssSymbolDependency.Template = class CssValueAtRuleDependencyTemplate extends (
99
+ CssIcssSymbolDependency.Template = class CssIcssSymbolDependencyTemplate extends (
110
100
  NullDependency.Template
111
101
  ) {
112
102
  /**
@@ -115,12 +105,24 @@ CssIcssSymbolDependency.Template = class CssValueAtRuleDependencyTemplate extend
115
105
  * @param {DependencyTemplateContext} templateContext the context object
116
106
  * @returns {void}
117
107
  */
118
- apply(dependency, source, { cssData }) {
119
- const dep = /** @type {CssIcssSymbolDependency} */ (dependency);
120
-
121
- source.replace(dep.range[0], dep.range[1] - 1, dep.value);
122
-
123
- cssData.exports.set(dep.name, dep.value);
108
+ apply(dependency, source, templateContext) {
109
+ if (templateContext.type === "css") {
110
+ const dep = /** @type {CssIcssSymbolDependency} */ (dependency);
111
+ /** @type {string | undefined} */
112
+ const value = dep.isReference
113
+ ? CssIcssExportDependency.Template.findReference(
114
+ dep.symbol,
115
+ templateContext
116
+ )
117
+ : dep.symbol;
118
+
119
+ if (!value) {
120
+ // TODO generate warning
121
+ return;
122
+ }
123
+
124
+ source.replace(dep.range[0], dep.range[1] - 1, value);
125
+ }
124
126
  }
125
127
  };
126
128
 
@@ -21,13 +21,15 @@ class CssImportDependency extends ModuleDependency {
21
21
  * \@import url("landscape.css") layer(forms) screen and (orientation: landscape) screen and (orientation: landscape);
22
22
  * @param {string} request request
23
23
  * @param {Range} range range of the argument
24
- * @param {string | undefined} layer layer
25
- * @param {string | undefined} supports list of supports conditions
26
- * @param {string | undefined} media list of media conditions
24
+ * @param {"local" | "global"=} mode mode of the parsed CSS
25
+ * @param {string=} layer layer
26
+ * @param {string=} supports list of supports conditions
27
+ * @param {string=} media list of media conditions
27
28
  */
28
- constructor(request, range, layer, supports, media) {
29
+ constructor(request, range, mode, layer, supports, media) {
29
30
  super(request);
30
31
  this.range = range;
32
+ this.mode = mode;
31
33
  this.layer = layer;
32
34
  this.supports = supports;
33
35
  this.media = media;
@@ -38,7 +40,7 @@ class CssImportDependency extends ModuleDependency {
38
40
  }
39
41
 
40
42
  get category() {
41
- return "css-import";
43
+ return `css-import${this.mode ? `-${this.mode}-module` : ""}`;
42
44
  }
43
45
 
44
46
  /**
@@ -47,6 +49,10 @@ class CssImportDependency extends ModuleDependency {
47
49
  getResourceIdentifier() {
48
50
  let str = `context${this._context || ""}|module${this.request}`;
49
51
 
52
+ if (this.mode) {
53
+ str += `|mode${this.mode}`;
54
+ }
55
+
50
56
  if (this.layer) {
51
57
  str += `|layer${this.layer}`;
52
58
  }
@@ -67,6 +73,8 @@ class CssImportDependency extends ModuleDependency {
67
73
  */
68
74
  serialize(context) {
69
75
  const { write } = context;
76
+ write(this.range);
77
+ write(this.mode);
70
78
  write(this.layer);
71
79
  write(this.supports);
72
80
  write(this.media);
@@ -78,6 +86,8 @@ class CssImportDependency extends ModuleDependency {
78
86
  */
79
87
  deserialize(context) {
80
88
  const { read } = context;
89
+ this.range = read();
90
+ this.mode = read();
81
91
  this.layer = read();
82
92
  this.supports = read();
83
93
  this.media = read();
@@ -99,7 +99,7 @@ class ExternalModuleInitFragment extends InitFragment {
99
99
 
100
100
  return `import ${importsString} from ${JSON.stringify(
101
101
  this.importedModule
102
- )};`;
102
+ )};\n`;
103
103
  }
104
104
 
105
105
  /**
@@ -0,0 +1,95 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const DependencyTemplate = require("../DependencyTemplate");
9
+ const makeSerializable = require("../util/makeSerializable");
10
+ const ExternalModuleInitFragment = require("./ExternalModuleInitFragment");
11
+ const NullDependency = require("./NullDependency");
12
+
13
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
+ /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
17
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
18
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
19
+
20
+ class ExternalModuleInitFragmentDependency extends NullDependency {
21
+ /**
22
+ * @param {string} module module
23
+ * @param {{ name: string, value: string }[]} importSpecifiers import specifiers
24
+ * @param {string | undefined} defaultImport default import
25
+ */
26
+ constructor(module, importSpecifiers, defaultImport) {
27
+ super();
28
+ this.importedModule = module;
29
+ this.specifiers = importSpecifiers;
30
+ this.default = defaultImport;
31
+ }
32
+
33
+ /**
34
+ * @returns {string} hash update
35
+ */
36
+ _createHashUpdate() {
37
+ return `${this.importedModule}${JSON.stringify(this.specifiers)}${
38
+ this.default || "null"
39
+ }`;
40
+ }
41
+
42
+ /**
43
+ * @param {ObjectSerializerContext} context context
44
+ */
45
+ serialize(context) {
46
+ const { write } = context;
47
+ write(this.importedModule);
48
+ write(this.specifiers);
49
+ write(this.default);
50
+ }
51
+
52
+ /**
53
+ * @param {ObjectDeserializerContext} context context
54
+ */
55
+ deserialize(context) {
56
+ const { read } = context;
57
+ this.importedModule = read();
58
+ this.specifiers = read();
59
+ this.default = read();
60
+ }
61
+ }
62
+
63
+ makeSerializable(
64
+ ExternalModuleInitFragmentDependency,
65
+ "webpack/lib/dependencies/ExternalModuleConstDependency"
66
+ );
67
+
68
+ ExternalModuleInitFragmentDependency.Template = class ExternalModuleConstDependencyTemplate extends (
69
+ DependencyTemplate
70
+ ) {
71
+ /**
72
+ * @param {Dependency} dependency the dependency for which the template should be applied
73
+ * @param {ReplaceSource} source the current replace source which can be modified
74
+ * @param {DependencyTemplateContext} templateContext the context object
75
+ * @returns {void}
76
+ */
77
+ apply(dependency, source, templateContext) {
78
+ const dep =
79
+ /** @type {ExternalModuleInitFragmentDependency} */
80
+ (dependency);
81
+ const { chunkInitFragments, runtimeTemplate } = templateContext;
82
+
83
+ chunkInitFragments.push(
84
+ new ExternalModuleInitFragment(
85
+ `${runtimeTemplate.supportNodePrefixForCoreModules() ? "node:" : ""}${
86
+ dep.importedModule
87
+ }`,
88
+ dep.specifiers,
89
+ dep.default
90
+ )
91
+ );
92
+ }
93
+ };
94
+
95
+ module.exports = ExternalModuleInitFragmentDependency;