webpack 5.59.1 → 5.60.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.

@@ -9,7 +9,9 @@ exports.keepAlive = function (options) {
9
9
  var active = options.active;
10
10
  var module = options.module;
11
11
  var response;
12
- var request = require("http").request(
12
+ var request = (
13
+ urlBase.startsWith("https") ? require("https") : require("http")
14
+ ).request(
13
15
  urlBase + data,
14
16
  {
15
17
  agent: false,
@@ -793,16 +793,19 @@ class NormalModule extends Module {
793
793
  this.buildInfo.fileDependencies = new LazySet();
794
794
  this.buildInfo.contextDependencies = new LazySet();
795
795
  this.buildInfo.missingDependencies = new LazySet();
796
- if (this.loaders.length > 0) {
797
- this.buildInfo.buildDependencies = new LazySet();
798
- }
799
796
  this.buildInfo.cacheable = true;
797
+
800
798
  try {
801
799
  hooks.beforeLoaders.call(this.loaders, this, loaderContext);
802
800
  } catch (err) {
803
801
  processResult(err);
804
802
  return;
805
803
  }
804
+
805
+ if (this.loaders.length > 0) {
806
+ this.buildInfo.buildDependencies = new LazySet();
807
+ }
808
+
806
809
  runLoaders(
807
810
  {
808
811
  resource: this.resource,
@@ -261,15 +261,18 @@ class WebpackOptionsApply extends OptionsApply {
261
261
  : null;
262
262
  new LazyCompilationPlugin({
263
263
  backend:
264
- (lazyOptions && lazyOptions.backend) ||
265
- require("./hmr/lazyCompilationBackend"),
266
- client:
267
- (lazyOptions && lazyOptions.client) ||
268
- require.resolve(
269
- `../hot/lazy-compilation-${
270
- options.externalsPresets.node ? "node" : "web"
271
- }.js`
272
- ),
264
+ typeof lazyOptions.backend === "function"
265
+ ? lazyOptions.backend
266
+ : require("./hmr/lazyCompilationBackend")({
267
+ ...lazyOptions.backend,
268
+ client:
269
+ (lazyOptions.backend && lazyOptions.backend.client) ||
270
+ require.resolve(
271
+ `../hot/lazy-compilation-${
272
+ options.externalsPresets.node ? "node" : "web"
273
+ }.js`
274
+ )
275
+ }),
273
276
  entries: !lazyOptions || lazyOptions.entries !== false,
274
277
  imports: !lazyOptions || lazyOptions.imports !== false,
275
278
  test: (lazyOptions && lazyOptions.test) || undefined
@@ -991,7 +991,10 @@ class PackFileCacheStrategy {
991
991
  allowCollectingMemory,
992
992
  compression
993
993
  }) {
994
- this.fileSerializer = createFileSerializer(fs);
994
+ this.fileSerializer = createFileSerializer(
995
+ fs,
996
+ compiler.options.output.hashFunction
997
+ );
995
998
  this.fileSystemInfo = new FileSystemInfo(fs, {
996
999
  managedPaths: snapshot.managedPaths,
997
1000
  immutablePaths: snapshot.immutablePaths,
@@ -32,6 +32,12 @@ const { registerNotSerializable } = require("../util/serialization");
32
32
  /** @typedef {import("../util/Hash")} Hash */
33
33
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
34
34
 
35
+ /**
36
+ * @typedef {Object} BackendApi
37
+ * @property {function(Error=): void} dispose
38
+ * @property {function(Module): { client: string, data: string, active: boolean }} module
39
+ */
40
+
35
41
  const IGNORED_DEPENDENCY_TYPES = new Set([
36
42
  "import.meta.webpackHot.accept",
37
43
  "import.meta.webpackHot.decline",
@@ -303,15 +309,13 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
303
309
  class LazyCompilationPlugin {
304
310
  /**
305
311
  * @param {Object} options options
306
- * @param {(function(Compiler, string, function(Error?, any?): void): void) | function(Compiler, string): Promise<any>} options.backend the backend
307
- * @param {string} options.client the client reference
312
+ * @param {(function(Compiler, function(Error?, BackendApi?): void): void) | function(Compiler): Promise<BackendApi>} options.backend the backend
308
313
  * @param {boolean} options.entries true, when entries are lazy compiled
309
314
  * @param {boolean} options.imports true, when import() modules are lazy compiled
310
315
  * @param {RegExp | string | (function(Module): boolean)} options.test additional filter for lazy compiled entrypoint modules
311
316
  */
312
- constructor({ backend, client, entries, imports, test }) {
317
+ constructor({ backend, entries, imports, test }) {
313
318
  this.backend = backend;
314
- this.client = client;
315
319
  this.entries = entries;
316
320
  this.imports = imports;
317
321
  this.test = test;
@@ -327,7 +331,7 @@ class LazyCompilationPlugin {
327
331
  "LazyCompilationPlugin",
328
332
  (params, callback) => {
329
333
  if (backend !== undefined) return callback();
330
- const promise = this.backend(compiler, this.client, (err, result) => {
334
+ const promise = this.backend(compiler, (err, result) => {
331
335
  if (err) return callback(err);
332
336
  backend = result;
333
337
  callback();
@@ -5,21 +5,46 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const http = require("http");
9
-
8
+ /** @typedef {import("http").ServerOptions} HttpServerOptions */
9
+ /** @typedef {import("https").ServerOptions} HttpsServerOptions */
10
+ /** @typedef {import("../../declarations/WebpackOptions").LazyCompilationDefaultBackendOptions} LazyCompilationDefaultBackendOptions */
10
11
  /** @typedef {import("../Compiler")} Compiler */
11
12
 
12
13
  /**
14
+ * @callback BackendHandler
13
15
  * @param {Compiler} compiler compiler
14
- * @param {string} client client reference
15
16
  * @param {function(Error?, any?): void} callback callback
16
17
  * @returns {void}
17
18
  */
18
- module.exports = (compiler, client, callback) => {
19
+
20
+ /**
21
+ * @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
22
+ * @returns {BackendHandler} backend
23
+ */
24
+ module.exports = options => (compiler, callback) => {
19
25
  const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
20
26
  const activeModules = new Map();
21
27
  const prefix = "/lazy-compilation-using-";
22
28
 
29
+ const isHttps =
30
+ options.protocol === "https" ||
31
+ (typeof options.server === "object" &&
32
+ ("key" in options.server || "pfx" in options.server));
33
+
34
+ const createServer =
35
+ typeof options.server === "function"
36
+ ? options.server
37
+ : (() => {
38
+ const http = isHttps ? require("https") : require("http");
39
+ return http.createServer.bind(http, options.server);
40
+ })();
41
+ const listen =
42
+ typeof options.listen === "function"
43
+ ? options.listen
44
+ : server => server.listen(options.listen);
45
+
46
+ const protocol = options.protocol || (isHttps ? "https" : "http");
47
+
23
48
  const requestListener = (req, res) => {
24
49
  const keys = req.url.slice(prefix.length).split("@");
25
50
  req.socket.on("close", () => {
@@ -52,7 +77,10 @@ module.exports = (compiler, client, callback) => {
52
77
  }
53
78
  if (moduleActivated && compiler.watching) compiler.watching.invalidate();
54
79
  };
55
- const server = http.createServer(requestListener);
80
+
81
+ const server = /** @type {import("net").Server} */ (createServer());
82
+ server.on("request", requestListener);
83
+
56
84
  let isClosing = false;
57
85
  /** @type {Set<import("net").Socket>} */
58
86
  const sockets = new Set();
@@ -63,16 +91,19 @@ module.exports = (compiler, client, callback) => {
63
91
  });
64
92
  if (isClosing) socket.destroy();
65
93
  });
66
- server.listen(err => {
94
+ server.on("clientError", e => {
95
+ if (e.message !== "Server is disposing") logger.warn(e);
96
+ });
97
+ server.on("listening", err => {
67
98
  if (err) return callback(err);
68
99
  const addr = server.address();
69
100
  if (typeof addr === "string") throw new Error("addr must not be a string");
70
101
  const urlBase =
71
102
  addr.address === "::" || addr.address === "0.0.0.0"
72
- ? `http://localhost:${addr.port}`
103
+ ? `${protocol}://localhost:${addr.port}`
73
104
  : addr.family === "IPv6"
74
- ? `http://[${addr.address}]:${addr.port}`
75
- : `http://${addr.address}:${addr.port}`;
105
+ ? `${protocol}://[${addr.address}]:${addr.port}`
106
+ : `${protocol}://${addr.address}:${addr.port}`;
76
107
  logger.log(
77
108
  `Server-Sent-Events server for lazy compilation open at ${urlBase}.`
78
109
  );
@@ -94,11 +125,12 @@ module.exports = (compiler, client, callback) => {
94
125
  ).replace(/%(2F|3A|24|26|2B|2C|3B|3D|3A)/g, decodeURIComponent)}`;
95
126
  const active = activeModules.get(key) > 0;
96
127
  return {
97
- client: `${client}?${encodeURIComponent(urlBase + prefix)}`,
128
+ client: `${options.client}?${encodeURIComponent(urlBase + prefix)}`,
98
129
  data: key,
99
130
  active
100
131
  };
101
132
  }
102
133
  });
103
134
  });
135
+ listen(server);
104
136
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.59.1",
3
+ "version": "5.60.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",