webpack 5.47.0 → 5.50.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 (35) hide show
  1. package/lib/CompatibilityPlugin.js +21 -4
  2. package/lib/Compilation.js +5 -2
  3. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  4. package/lib/HotModuleReplacementPlugin.js +4 -4
  5. package/lib/Module.js +1 -0
  6. package/lib/MultiCompiler.js +0 -2
  7. package/lib/NormalModule.js +47 -20
  8. package/lib/NormalModuleFactory.js +145 -76
  9. package/lib/Parser.js +1 -0
  10. package/lib/WebpackOptionsApply.js +8 -0
  11. package/lib/asset/AssetModulesPlugin.js +0 -1
  12. package/lib/config/defaults.js +45 -18
  13. package/lib/config/normalization.js +6 -1
  14. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +6 -3
  15. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -2
  16. package/lib/dependencies/HarmonyImportDependency.js +5 -1
  17. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -5
  18. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  19. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -2
  20. package/lib/dependencies/ModuleDependency.js +8 -1
  21. package/lib/hmr/HotModuleReplacement.runtime.js +5 -1
  22. package/lib/index.js +0 -3
  23. package/lib/javascript/JavascriptParser.js +16 -9
  24. package/lib/optimize/SplitChunksPlugin.js +4 -4
  25. package/lib/rules/{DescriptionDataMatcherRulePlugin.js → ObjectMatcherRulePlugin.js} +14 -10
  26. package/lib/schemes/HttpUriPlugin.js +942 -25
  27. package/lib/serialization/BinaryMiddleware.js +293 -267
  28. package/package.json +3 -2
  29. package/schemas/WebpackOptions.check.js +1 -1
  30. package/schemas/WebpackOptions.json +50 -0
  31. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
  32. package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
  33. package/schemas/plugins/schemes/HttpUriPlugin.json +42 -0
  34. package/types.d.ts +99 -15
  35. package/lib/schemes/HttpsUriPlugin.js +0 -63
@@ -14,7 +14,11 @@ const HarmonyExports = require("./HarmonyExports");
14
14
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
15
15
  const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
16
16
 
17
+ /** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */
18
+ /** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */
17
19
  /** @typedef {import("estree").Identifier} Identifier */
20
+ /** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
21
+ /** @typedef {import("estree").ImportExpression} ImportExpression */
18
22
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
19
23
  /** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
20
24
  /** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
@@ -29,8 +33,32 @@ const harmonySpecifierTag = Symbol("harmony import");
29
33
  * @property {number} sourceOrder
30
34
  * @property {string} name
31
35
  * @property {boolean} await
36
+ * @property {Record<string, any> | undefined} assertions
32
37
  */
33
38
 
39
+ /**
40
+ * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
41
+ * @returns {Record<string, any> | undefined} assertions
42
+ */
43
+ function getAssertions(node) {
44
+ // TODO remove cast when @types/estree has been updated to import assertions
45
+ const assertions = /** @type {{ assertions?: ImportAttributeNode[] }} */ (
46
+ node
47
+ ).assertions;
48
+ if (assertions === undefined) {
49
+ return undefined;
50
+ }
51
+ const result = {};
52
+ for (const assertion of assertions) {
53
+ const key =
54
+ assertion.key.type === "Identifier"
55
+ ? assertion.key.name
56
+ : assertion.key.value;
57
+ result[key] = assertion.value.value;
58
+ }
59
+ return result;
60
+ }
61
+
34
62
  module.exports = class HarmonyImportDependencyParserPlugin {
35
63
  constructor(options) {
36
64
  this.strictExportPresence = options.strictExportPresence;
@@ -65,9 +93,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
65
93
  clearDep.loc = statement.loc;
66
94
  parser.state.module.addPresentationalDependency(clearDep);
67
95
  parser.unsetAsiPosition(statement.range[1]);
96
+ const assertions = getAssertions(statement);
68
97
  const sideEffectDep = new HarmonyImportSideEffectDependency(
69
98
  source,
70
- parser.state.lastHarmonyImportOrder
99
+ parser.state.lastHarmonyImportOrder,
100
+ assertions
71
101
  );
72
102
  sideEffectDep.loc = statement.loc;
73
103
  parser.state.module.addDependency(sideEffectDep);
@@ -82,7 +112,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
82
112
  name,
83
113
  source,
84
114
  ids,
85
- sourceOrder: parser.state.lastHarmonyImportOrder
115
+ sourceOrder: parser.state.lastHarmonyImportOrder,
116
+ assertions: getAssertions(statement)
86
117
  });
87
118
  return true;
88
119
  }
@@ -97,7 +128,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
97
128
  settings.ids,
98
129
  settings.name,
99
130
  expr.range,
100
- this.strictExportPresence
131
+ this.strictExportPresence,
132
+ settings.assertions
101
133
  );
102
134
  dep.shorthand = parser.scope.inShorthand;
103
135
  dep.directImport = true;
@@ -118,7 +150,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
118
150
  ids,
119
151
  settings.name,
120
152
  expr.range,
121
- this.strictExportPresence
153
+ this.strictExportPresence,
154
+ settings.assertions
122
155
  );
123
156
  dep.asiSafe = !parser.isAsiPosition(expr.range[0]);
124
157
  dep.loc = expr.loc;
@@ -138,7 +171,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
138
171
  ids,
139
172
  settings.name,
140
173
  callee.range,
141
- this.strictExportPresence
174
+ this.strictExportPresence,
175
+ settings.assertions
142
176
  );
143
177
  dep.directImport = members.length === 0;
144
178
  dep.call = true;
@@ -206,3 +240,4 @@ module.exports = class HarmonyImportDependencyParserPlugin {
206
240
  };
207
241
 
208
242
  module.exports.harmonySpecifierTag = harmonySpecifierTag;
243
+ module.exports.getAssertions = getAssertions;
@@ -20,8 +20,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
20
20
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
21
21
 
22
22
  class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
23
- constructor(request, sourceOrder) {
24
- super(request, sourceOrder);
23
+ constructor(request, sourceOrder, assertions) {
24
+ super(request, sourceOrder, assertions);
25
25
  }
26
26
 
27
27
  get type() {
@@ -29,8 +29,16 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
29
29
  const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
30
30
 
31
31
  class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
32
- constructor(request, sourceOrder, ids, name, range, strictExportPresence) {
33
- super(request, sourceOrder);
32
+ constructor(
33
+ request,
34
+ sourceOrder,
35
+ ids,
36
+ name,
37
+ range,
38
+ strictExportPresence,
39
+ assertions
40
+ ) {
41
+ super(request, sourceOrder, assertions);
34
42
  this.ids = ids;
35
43
  this.name = name;
36
44
  this.range = range;
@@ -22,13 +22,20 @@ class ModuleDependency extends Dependency {
22
22
  this.request = request;
23
23
  this.userRequest = request;
24
24
  this.range = undefined;
25
+ // assertions must be serialized by subclasses that use it
26
+ /** @type {Record<string, any> | undefined} */
27
+ this.assertions = undefined;
25
28
  }
26
29
 
27
30
  /**
28
31
  * @returns {string | null} an identifier to merge equal requests
29
32
  */
30
33
  getResourceIdentifier() {
31
- return `module${this.request}`;
34
+ let str = `module${this.request}`;
35
+ if (this.assertions !== undefined) {
36
+ str += JSON.stringify(this.assertions);
37
+ }
38
+ return str;
32
39
  }
33
40
 
34
41
  /**
@@ -252,7 +252,11 @@ module.exports = function () {
252
252
  .then($hmrDownloadManifest$)
253
253
  .then(function (update) {
254
254
  if (!update) {
255
- return setStatus(applyInvalidatedModules() ? "ready" : "idle");
255
+ return setStatus(applyInvalidatedModules() ? "ready" : "idle").then(
256
+ function () {
257
+ return null;
258
+ }
259
+ );
256
260
  }
257
261
 
258
262
  return setStatus("prepare").then(function () {
package/lib/index.js CHANGED
@@ -554,9 +554,6 @@ module.exports = mergeExports(fn, {
554
554
  schemes: {
555
555
  get HttpUriPlugin() {
556
556
  return require("./schemes/HttpUriPlugin");
557
- },
558
- get HttpsUriPlugin() {
559
- return require("./schemes/HttpsUriPlugin");
560
557
  }
561
558
  }
562
559
  }
@@ -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
  /**
@@ -130,6 +135,8 @@ const defaultParserOptions = {
130
135
  locations: true,
131
136
  ecmaVersion: "latest",
132
137
  sourceType: "module",
138
+ // https://github.com/tc39/proposal-hashbang
139
+ allowHashBang: true,
133
140
  onComment: null
134
141
  };
135
142
 
@@ -190,31 +197,31 @@ class JavascriptParser extends Parser {
190
197
  ]),
191
198
  /** @type {HookMap<SyncBailHook<[LabeledStatementNode], boolean | void>>} */
192
199
  label: new HookMap(() => new SyncBailHook(["statement"])),
193
- /** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
200
+ /** @type {SyncBailHook<[ImportDeclarationNode, ImportSource], boolean | void>} */
194
201
  import: new SyncBailHook(["statement", "source"]),
195
- /** @type {SyncBailHook<[StatementNode, ImportSource, string, string], boolean | void>} */
202
+ /** @type {SyncBailHook<[ImportDeclarationNode, ImportSource, string, string], boolean | void>} */
196
203
  importSpecifier: new SyncBailHook([
197
204
  "statement",
198
205
  "source",
199
206
  "exportName",
200
207
  "identifierName"
201
208
  ]),
202
- /** @type {SyncBailHook<[StatementNode], boolean | void>} */
209
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode], boolean | void>} */
203
210
  export: new SyncBailHook(["statement"]),
204
- /** @type {SyncBailHook<[StatementNode, ImportSource], boolean | void>} */
211
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, ImportSource], boolean | void>} */
205
212
  exportImport: new SyncBailHook(["statement", "source"]),
206
- /** @type {SyncBailHook<[StatementNode, DeclarationNode], boolean | void>} */
213
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, DeclarationNode], boolean | void>} */
207
214
  exportDeclaration: new SyncBailHook(["statement", "declaration"]),
208
- /** @type {SyncBailHook<[StatementNode, DeclarationNode], boolean | void>} */
215
+ /** @type {SyncBailHook<[ExportDefaultDeclarationNode, DeclarationNode], boolean | void>} */
209
216
  exportExpression: new SyncBailHook(["statement", "declaration"]),
210
- /** @type {SyncBailHook<[StatementNode, string, string, number | undefined], boolean | void>} */
217
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, string, string, number | undefined], boolean | void>} */
211
218
  exportSpecifier: new SyncBailHook([
212
219
  "statement",
213
220
  "identifierName",
214
221
  "exportName",
215
222
  "index"
216
223
  ]),
217
- /** @type {SyncBailHook<[StatementNode, ImportSource, string, string, number | undefined], boolean | void>} */
224
+ /** @type {SyncBailHook<[ExportNamedDeclarationNode | ExportAllDeclarationNode, ImportSource, string, string, number | undefined], boolean | void>} */
218
225
  exportImportSpecifier: new SyncBailHook([
219
226
  "statement",
220
227
  "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;