webpack 5.52.1 → 5.53.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.

@@ -0,0 +1,34 @@
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 WebpackError = require("./WebpackError");
9
+ const makeSerializable = require("./util/makeSerializable");
10
+
11
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
12
+
13
+ class NodeStuffInWebError extends WebpackError {
14
+ /**
15
+ * @param {DependencyLocation} loc loc
16
+ * @param {string} expression expression
17
+ * @param {string} description description
18
+ */
19
+ constructor(loc, expression, description) {
20
+ super(
21
+ `${JSON.stringify(
22
+ expression
23
+ )} has been used, it will be undefined in next major version.
24
+ ${description}`
25
+ );
26
+
27
+ this.name = "NodeStuffInWebError";
28
+ this.loc = loc;
29
+ }
30
+ }
31
+
32
+ makeSerializable(NodeStuffInWebError, "webpack/lib/NodeStuffInWebError");
33
+
34
+ module.exports = NodeStuffInWebError;
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const NodeStuffInWebError = require("./NodeStuffInWebError");
8
9
  const RuntimeGlobals = require("./RuntimeGlobals");
9
10
  const CachedConstDependency = require("./dependencies/CachedConstDependency");
10
11
  const ConstDependency = require("./dependencies/ConstDependency");
@@ -44,7 +45,8 @@ class NodeStuffPlugin {
44
45
  localOptions = { ...localOptions, ...parserOptions.node };
45
46
  }
46
47
 
47
- if (localOptions.global) {
48
+ if (localOptions.global !== false) {
49
+ const withWarning = localOptions.global === "warn";
48
50
  parser.hooks.expression
49
51
  .for("global")
50
52
  .tap("NodeStuffPlugin", expr => {
@@ -55,10 +57,21 @@ class NodeStuffPlugin {
55
57
  );
56
58
  dep.loc = expr.loc;
57
59
  parser.state.module.addPresentationalDependency(dep);
60
+
61
+ // TODO webpack 6 remove
62
+ if (withWarning) {
63
+ parser.state.module.addWarning(
64
+ new NodeStuffInWebError(
65
+ dep.loc,
66
+ "global",
67
+ "The global namespace object is Node.js feature and doesn't present in browser."
68
+ )
69
+ );
70
+ }
58
71
  });
59
72
  }
60
73
 
61
- const setModuleConstant = (expressionName, fn) => {
74
+ const setModuleConstant = (expressionName, fn, warning) => {
62
75
  parser.hooks.expression
63
76
  .for(expressionName)
64
77
  .tap("NodeStuffPlugin", expr => {
@@ -69,22 +82,41 @@ class NodeStuffPlugin {
69
82
  );
70
83
  dep.loc = expr.loc;
71
84
  parser.state.module.addPresentationalDependency(dep);
85
+
86
+ // TODO webpack 6 remove
87
+ if (warning) {
88
+ parser.state.module.addWarning(
89
+ new NodeStuffInWebError(dep.loc, expressionName, warning)
90
+ );
91
+ }
92
+
72
93
  return true;
73
94
  });
74
95
  };
75
96
 
76
- const setConstant = (expressionName, value) =>
77
- setModuleConstant(expressionName, () => value);
97
+ const setConstant = (expressionName, value, warning) =>
98
+ setModuleConstant(expressionName, () => value, warning);
78
99
 
79
100
  const context = compiler.context;
80
101
  if (localOptions.__filename) {
81
- if (localOptions.__filename === "mock") {
82
- setConstant("__filename", "/index.js");
83
- } else if (localOptions.__filename === true) {
84
- setModuleConstant("__filename", module =>
85
- relative(compiler.inputFileSystem, context, module.resource)
86
- );
102
+ switch (localOptions.__filename) {
103
+ case "mock":
104
+ setConstant("__filename", "/index.js");
105
+ break;
106
+ case "warn-mock":
107
+ setConstant(
108
+ "__filename",
109
+ "/index.js",
110
+ "The __filename is Node.js feature and doesn't present in browser."
111
+ );
112
+ break;
113
+ case true:
114
+ setModuleConstant("__filename", module =>
115
+ relative(compiler.inputFileSystem, context, module.resource)
116
+ );
117
+ break;
87
118
  }
119
+
88
120
  parser.hooks.evaluateIdentifier
89
121
  .for("__filename")
90
122
  .tap("NodeStuffPlugin", expr => {
@@ -94,13 +126,24 @@ class NodeStuffPlugin {
94
126
  });
95
127
  }
96
128
  if (localOptions.__dirname) {
97
- if (localOptions.__dirname === "mock") {
98
- setConstant("__dirname", "/");
99
- } else if (localOptions.__dirname === true) {
100
- setModuleConstant("__dirname", module =>
101
- relative(compiler.inputFileSystem, context, module.context)
102
- );
129
+ switch (localOptions.__dirname) {
130
+ case "mock":
131
+ setConstant("__dirname", "/");
132
+ break;
133
+ case "warn-mock":
134
+ setConstant(
135
+ "__dirname",
136
+ "/",
137
+ "The __dirname is Node.js feature and doesn't present in browser."
138
+ );
139
+ break;
140
+ case true:
141
+ setModuleConstant("__dirname", module =>
142
+ relative(compiler.inputFileSystem, context, module.context)
143
+ );
144
+ break;
103
145
  }
146
+
104
147
  parser.hooks.evaluateIdentifier
105
148
  .for("__dirname")
106
149
  .tap("NodeStuffPlugin", expr => {
@@ -118,6 +118,14 @@ class Pack {
118
118
  this.requests.push(undefined);
119
119
  this.requestsTimeout = undefined;
120
120
  }, MAX_TIME_IN_FRESH_PACK);
121
+ if (this.requestsTimeout.unref) this.requestsTimeout.unref();
122
+ }
123
+ }
124
+
125
+ stopCapturingRequests() {
126
+ if (this.requestsTimeout !== undefined) {
127
+ clearTimeout(this.requestsTimeout);
128
+ this.requestsTimeout = undefined;
121
129
  }
122
130
  }
123
131
 
@@ -1232,6 +1240,7 @@ class PackFileCacheStrategy {
1232
1240
  const reportProgress = ProgressPlugin.getReporter(this.compiler);
1233
1241
  return (this.storePromise = packPromise
1234
1242
  .then(pack => {
1243
+ pack.stopCapturingRequests();
1235
1244
  if (!pack.invalid) return;
1236
1245
  this.packPromise = undefined;
1237
1246
  this.logger.log(`Storing pack...`);
@@ -211,7 +211,10 @@ const applyWebpackOptionsDefaults = options => {
211
211
  : "var";
212
212
  });
213
213
 
214
- applyNodeDefaults(options.node, { targetProperties });
214
+ applyNodeDefaults(options.node, {
215
+ futureDefaults: options.experiments.futureDefaults,
216
+ targetProperties
217
+ });
215
218
 
216
219
  F(options, "performance", () =>
217
220
  production &&
@@ -262,6 +265,7 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
262
265
  D(experiments, "layers", false);
263
266
  D(experiments, "lazyCompilation", false);
264
267
  D(experiments, "buildHttp", false);
268
+ D(experiments, "futureDefaults", false);
265
269
 
266
270
  if (typeof experiments.buildHttp === "object") {
267
271
  D(experiments.buildHttp, "frozen", production);
@@ -943,21 +947,26 @@ const applyLoaderDefaults = (loader, { targetProperties }) => {
943
947
  * @param {WebpackNode} node options
944
948
  * @param {Object} options options
945
949
  * @param {TargetProperties | false} options.targetProperties target properties
950
+ * @param {boolean} options.futureDefaults is future defaults enabled
946
951
  * @returns {void}
947
952
  */
948
- const applyNodeDefaults = (node, { targetProperties }) => {
953
+ const applyNodeDefaults = (node, { futureDefaults, targetProperties }) => {
949
954
  if (node === false) return;
955
+
950
956
  F(node, "global", () => {
951
957
  if (targetProperties && targetProperties.global) return false;
952
- return true;
958
+ // TODO webpack 6 should always default to false
959
+ return futureDefaults ? "warn" : true;
953
960
  });
954
961
  F(node, "__filename", () => {
955
962
  if (targetProperties && targetProperties.node) return "eval-only";
956
- return "mock";
963
+ // TODO webpack 6 should always default to false
964
+ return futureDefaults ? "warn-mock" : "mock";
957
965
  });
958
966
  F(node, "__dirname", () => {
959
967
  if (targetProperties && targetProperties.node) return "eval-only";
960
- return "mock";
968
+ // TODO webpack 6 should always default to false
969
+ return futureDefaults ? "warn-mock" : "mock";
961
970
  });
962
971
  };
963
972
 
@@ -41,6 +41,7 @@ const builtins = [
41
41
  "repl",
42
42
  "stream",
43
43
  "stream/promises",
44
+ "stream/web",
44
45
  "string_decoder",
45
46
  "sys",
46
47
  "timers",
@@ -189,6 +189,7 @@ module.exports = {
189
189
  UnsupportedFeatureWarning: () => require("../UnsupportedFeatureWarning"),
190
190
  "util/LazySet": () => require("../util/LazySet"),
191
191
  UnhandledSchemeError: () => require("../UnhandledSchemeError"),
192
+ NodeStuffInWebError: () => require("../NodeStuffInWebError"),
192
193
  WebpackError: () => require("../WebpackError"),
193
194
 
194
195
  "util/registerExternalSerializer": () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.52.1",
3
+ "version": "5.53.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "@babel/core": "^7.11.1",
40
40
  "@babel/preset-react": "^7.10.4",
41
41
  "@types/es-module-lexer": "^0.4.1",
42
- "@types/jest": "^26.0.24",
42
+ "@types/jest": "^27.0.1",
43
43
  "@types/node": "^15.0.1",
44
44
  "babel-loader": "^8.1.0",
45
45
  "benchmark": "^2.1.4",