webpack 5.46.0 → 5.49.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 (39) hide show
  1. package/lib/Compilation.js +5 -2
  2. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  3. package/lib/HotModuleReplacementPlugin.js +4 -4
  4. package/lib/Module.js +1 -0
  5. package/lib/MultiCompiler.js +0 -2
  6. package/lib/NormalModule.js +44 -19
  7. package/lib/NormalModuleFactory.js +145 -76
  8. package/lib/Template.js +1 -4
  9. package/lib/WebpackOptionsApply.js +8 -0
  10. package/lib/asset/AssetGenerator.js +1 -1
  11. package/lib/asset/AssetModulesPlugin.js +0 -1
  12. package/lib/config/defaults.js +44 -17
  13. package/lib/config/normalization.js +6 -1
  14. package/lib/dependencies/AMDRequireDependency.js +2 -8
  15. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +6 -3
  16. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -2
  17. package/lib/dependencies/HarmonyImportDependency.js +5 -1
  18. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -5
  19. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  20. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -2
  21. package/lib/dependencies/ModuleDependency.js +8 -1
  22. package/lib/hmr/HotModuleReplacement.runtime.js +5 -1
  23. package/lib/index.js +0 -3
  24. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -8
  25. package/lib/javascript/JavascriptModulesPlugin.js +48 -29
  26. package/lib/javascript/JavascriptParser.js +14 -9
  27. package/lib/optimize/SplitChunksPlugin.js +4 -4
  28. package/lib/rules/{DescriptionDataMatcherRulePlugin.js → ObjectMatcherRulePlugin.js} +14 -10
  29. package/lib/schemes/HttpUriPlugin.js +942 -25
  30. package/lib/serialization/BinaryMiddleware.js +0 -2
  31. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
  32. package/package.json +3 -2
  33. package/schemas/WebpackOptions.check.js +1 -1
  34. package/schemas/WebpackOptions.json +50 -0
  35. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
  36. package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
  37. package/schemas/plugins/schemes/HttpUriPlugin.json +42 -0
  38. package/types.d.ts +148 -18
  39. package/lib/schemes/HttpsUriPlugin.js +0 -63
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { Parser: AcornParser } = require("acorn");
9
+ const { importAssertions } = require("acorn-import-assertions");
9
10
  const { SyncBailHook, HookMap } = require("tapable");
10
11
  const vm = require("vm");
11
12
  const Parser = require("../Parser");
@@ -42,6 +43,10 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
42
43
  /** @typedef {import("estree").Node} AnyNode */
43
44
  /** @typedef {import("estree").Program} ProgramNode */
44
45
  /** @typedef {import("estree").Statement} StatementNode */
46
+ /** @typedef {import("estree").ImportDeclaration} ImportDeclarationNode */
47
+ /** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclarationNode */
48
+ /** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclarationNode */
49
+ /** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclarationNode */
45
50
  /** @typedef {import("estree").Super} SuperNode */
46
51
  /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpressionNode */
47
52
  /** @typedef {import("estree").TemplateLiteral} TemplateLiteralNode */
@@ -61,7 +66,7 @@ const ALLOWED_MEMBER_TYPES_ALL = 0b11;
61
66
 
62
67
  // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
63
68
 
64
- const parser = AcornParser;
69
+ const parser = AcornParser.extend(importAssertions);
65
70
 
66
71
  class VariableInfo {
67
72
  /**
@@ -190,31 +195,31 @@ class JavascriptParser extends Parser {
190
195
  ]),
191
196
  /** @type {HookMap<SyncBailHook<[LabeledStatementNode], boolean | void>>} */
192
197
  label: new HookMap(() => new SyncBailHook(["statement"])),
193
- /** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
198
+ /** @type {SyncBailHook<[ImportDeclarationNode, ImportSource], boolean | void>} */
194
199
  import: new SyncBailHook(["statement", "source"]),
195
- /** @type {SyncBailHook<[StatementNode, ImportSource, string, string], boolean | void>} */
200
+ /** @type {SyncBailHook<[ImportDeclarationNode, ImportSource, string, string], boolean | void>} */
196
201
  importSpecifier: new SyncBailHook([
197
202
  "statement",
198
203
  "source",
199
204
  "exportName",
200
205
  "identifierName"
201
206
  ]),
202
- /** @type {SyncBailHook<[StatementNode], boolean | void>} */
207
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode], boolean | void>} */
203
208
  export: new SyncBailHook(["statement"]),
204
- /** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
209
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, ImportSource], boolean | void>} */
205
210
  exportImport: new SyncBailHook(["statement", "source"]),
206
- /** @type {SyncBailHook<[StatementNode, DeclarationNode], boolean | void>} */
211
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, DeclarationNode], boolean | void>} */
207
212
  exportDeclaration: new SyncBailHook(["statement", "declaration"]),
208
- /** @type {SyncBailHook<[StatementNode, DeclarationNode], boolean | void>} */
213
+ /** @type {SyncBailHook<[ExportDefaultDeclarationNode, DeclarationNode], boolean | void>} */
209
214
  exportExpression: new SyncBailHook(["statement", "declaration"]),
210
- /** @type {SyncBailHook<[StatementNode, string, string, number | undefined], boolean | void>} */
215
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, string, string, number | undefined], boolean | void>} */
211
216
  exportSpecifier: new SyncBailHook([
212
217
  "statement",
213
218
  "identifierName",
214
219
  "exportName",
215
220
  "index"
216
221
  ]),
217
- /** @type {SyncBailHook<[StatementNode, ImportSource, string, string, number | undefined], boolean | void>} */
222
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, ImportSource, string, string, number | undefined], boolean | void>} */
218
223
  exportImportSpecifier: new SyncBailHook([
219
224
  "statement",
220
225
  "source",
@@ -17,7 +17,7 @@ const {
17
17
  } = require("../util/comparators");
18
18
  const createHash = require("../util/createHash");
19
19
  const deterministicGrouping = require("../util/deterministicGrouping");
20
- const contextify = require("../util/identifier").contextify;
20
+ const { makePathsRelative } = require("../util/identifier");
21
21
  const memoize = require("../util/memoize");
22
22
  const MinMaxSizeWarning = require("./MinMaxSizeWarning");
23
23
 
@@ -748,7 +748,7 @@ module.exports = class SplitChunksPlugin {
748
748
  * @returns {void}
749
749
  */
750
750
  apply(compiler) {
751
- const cachedContextify = contextify.bindContextCache(
751
+ const cachedMakePathsRelative = makePathsRelative.bindContextCache(
752
752
  compiler.context,
753
753
  compiler.root
754
754
  );
@@ -1596,11 +1596,11 @@ module.exports = class SplitChunksPlugin {
1596
1596
  getKey(module) {
1597
1597
  const cache = getKeyCache.get(module);
1598
1598
  if (cache !== undefined) return cache;
1599
- const ident = cachedContextify(module.identifier());
1599
+ const ident = cachedMakePathsRelative(module.identifier());
1600
1600
  const nameForCondition =
1601
1601
  module.nameForCondition && module.nameForCondition();
1602
1602
  const name = nameForCondition
1603
- ? cachedContextify(nameForCondition)
1603
+ ? cachedMakePathsRelative(nameForCondition)
1604
1604
  : ident.replace(/^.*!|\?[^?!]*$/g, "");
1605
1605
  const fullKey =
1606
1606
  name +
@@ -8,28 +8,32 @@
8
8
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
9
9
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
10
10
 
11
- const RULE_PROPERTY = "descriptionData";
11
+ class ObjectMatcherRulePlugin {
12
+ constructor(ruleProperty, dataProperty) {
13
+ this.ruleProperty = ruleProperty;
14
+ this.dataProperty = dataProperty || ruleProperty;
15
+ }
12
16
 
13
- class DescriptionDataMatcherRulePlugin {
14
17
  /**
15
18
  * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
16
19
  * @returns {void}
17
20
  */
18
21
  apply(ruleSetCompiler) {
22
+ const { ruleProperty, dataProperty } = this;
19
23
  ruleSetCompiler.hooks.rule.tap(
20
- "DescriptionDataMatcherRulePlugin",
24
+ "ObjectMatcherRulePlugin",
21
25
  (path, rule, unhandledProperties, result) => {
22
- if (unhandledProperties.has(RULE_PROPERTY)) {
23
- unhandledProperties.delete(RULE_PROPERTY);
24
- const value = rule[RULE_PROPERTY];
26
+ if (unhandledProperties.has(ruleProperty)) {
27
+ unhandledProperties.delete(ruleProperty);
28
+ const value = rule[ruleProperty];
25
29
  for (const property of Object.keys(value)) {
26
- const dataProperty = property.split(".");
30
+ const nestedDataProperties = property.split(".");
27
31
  const condition = ruleSetCompiler.compileCondition(
28
- `${path}.${RULE_PROPERTY}.${property}`,
32
+ `${path}.${ruleProperty}.${property}`,
29
33
  value[property]
30
34
  );
31
35
  result.conditions.push({
32
- property: ["descriptionData", ...dataProperty],
36
+ property: [dataProperty, ...nestedDataProperties],
33
37
  matchWhenEmpty: condition.matchWhenEmpty,
34
38
  fn: condition.fn
35
39
  });
@@ -40,4 +44,4 @@ class DescriptionDataMatcherRulePlugin {
40
44
  }
41
45
  }
42
46
 
43
- module.exports = DescriptionDataMatcherRulePlugin;
47
+ module.exports = ObjectMatcherRulePlugin;