refactor and add test case

This commit is contained in:
Tobias Koppers 2021-10-25 12:12:52 +02:00
parent 537da95879
commit ba154bc741
14 changed files with 431 additions and 187 deletions

View File

@ -1117,43 +1117,7 @@ export interface Experiments {
/**
* Compile entrypoints and import()s only when they are accessed.
*/
lazyCompilation?:
| boolean
| {
/**
* A custom backend.
*/
backend?:
| ((
compiler: import("../lib/Compiler"),
client: string,
callback: (err?: Error, api?: any) => void
) => void)
| ((
compiler: import("../lib/Compiler"),
client: string
) => Promise<any>);
/**
* Additional configuration to pass to the backend server.
*/
backendConfiguration?: import("../lib/hmr/lazyCompilationBackend").BackendConfiguration;
/**
* A custom client.
*/
client?: string;
/**
* Enable/disable lazy compilation for entries.
*/
entries?: boolean;
/**
* Enable/disable lazy compilation for import() modules.
*/
imports?: boolean;
/**
* Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.
*/
test?: RegExp | string | ((module: import("../lib/Module")) => boolean);
};
lazyCompilation?: boolean | LazyCompilationOptions;
/**
* Allow output javascript files as module source type.
*/
@ -1188,6 +1152,65 @@ export interface HttpUriOptions {
*/
upgrade?: boolean;
}
/**
* This interface was referenced by `WebpackOptions`'s JSON-Schema
* via the `definition` "LazyCompilationOptions".
*/
export interface LazyCompilationOptions {
backend?:
| (
| ((
compiler: import("../lib/Compiler"),
callback: (
err?: Error,
api?: import("../lib/hmr/LazyCompilationPlugin").BackendApi
) => void
) => void)
| ((
compiler: import("../lib/Compiler")
) => Promise<import("../lib/hmr/LazyCompilationPlugin").BackendApi>)
)
| LazyCompilationDefaultBackendOptions;
/**
* Enable/disable lazy compilation for entries.
*/
entries?: boolean;
/**
* Enable/disable lazy compilation for import() modules.
*/
imports?: boolean;
/**
* Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.
*/
test?: RegExp | string | ((module: import("../lib/Module")) => boolean);
}
/**
* Options for the default backend.
*/
export interface LazyCompilationDefaultBackendOptions {
/**
* A custom client.
*/
client?: string;
/**
* Specifies where to listen to from the server.
*/
listen?:
| number
| import("net").ListenOptions
| ((server: import("net").Server) => void);
/**
* Specifies the protocol the client should use to connect to the server.
*/
protocol?: "http" | "https";
/**
* Specifies how to create the server handling the EventSource requests.
*/
server?:
| (import("https").ServerOptions | import("http").ServerOptions)
| (() => import("net").Server);
[k: string]: any;
}
/**
* Enable presets of externals for specific targets.
*/

View File

@ -9,7 +9,9 @@ exports.keepAlive = function (options) {
var active = options.active;
var module = options.module;
var response;
var request = require("http").request(
var request = (
urlBase.startsWith("https") ? require("https") : require("http")
).request(
urlBase + data,
{
agent: false,

View File

@ -261,20 +261,21 @@ class WebpackOptionsApply extends OptionsApply {
: null;
new LazyCompilationPlugin({
backend:
(lazyOptions && lazyOptions.backend) ||
require("./hmr/lazyCompilationBackend"),
client:
(lazyOptions && lazyOptions.client) ||
require.resolve(
`../hot/lazy-compilation-${
options.externalsPresets.node ? "node" : "web"
}.js`
),
typeof lazyOptions.backend === "function"
? lazyOptions.backend
: require("./hmr/lazyCompilationBackend")({
...lazyOptions.backend,
client:
lazyOptions.backend.client ||
require.resolve(
`../hot/lazy-compilation-${
options.externalsPresets.node ? "node" : "web"
}.js`
)
}),
entries: !lazyOptions || lazyOptions.entries !== false,
imports: !lazyOptions || lazyOptions.imports !== false,
test: (lazyOptions && lazyOptions.test) || undefined,
backendConfiguration:
(lazyOptions && lazyOptions.backendConfiguration) || undefined
test: (lazyOptions && lazyOptions.test) || undefined
}).apply(compiler);
}

View File

@ -32,6 +32,12 @@ const { registerNotSerializable } = require("../util/serialization");
/** @typedef {import("../util/Hash")} Hash */
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
/**
* @typedef {Object} BackendApi
* @property {function(Error=): void} dispose
* @property {function(Module): { client: string, data: string, active: boolean }} module
*/
const IGNORED_DEPENDENCY_TYPES = new Set([
"import.meta.webpackHot.accept",
"import.meta.webpackHot.decline",
@ -303,27 +309,16 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
class LazyCompilationPlugin {
/**
* @param {Object} options options
* @param {(function(Compiler, string, function(Error?, any?): void, Object): void) | function(Compiler, string): Promise<any>} options.backend the backend
* @param {Object} options.backendConfiguration additional configuration passed to backend
* @param {string} options.client the client reference
* @param {(function(Compiler, function(Error?, BackendApi?): void): void) | function(Compiler): Promise<BackendApi>} options.backend the backend
* @param {boolean} options.entries true, when entries are lazy compiled
* @param {boolean} options.imports true, when import() modules are lazy compiled
* @param {RegExp | string | (function(Module): boolean)} options.test additional filter for lazy compiled entrypoint modules
*/
constructor({
backend,
client,
entries,
imports,
test,
backendConfiguration
}) {
constructor({ backend, entries, imports, test }) {
this.backend = backend;
this.client = client;
this.entries = entries;
this.imports = imports;
this.test = test;
this.backendConfiguration = backendConfiguration;
}
/**
* Apply the plugin
@ -336,16 +331,11 @@ class LazyCompilationPlugin {
"LazyCompilationPlugin",
(params, callback) => {
if (backend !== undefined) return callback();
const promise = this.backend(
compiler,
this.client,
(err, result) => {
if (err) return callback(err);
backend = result;
callback();
},
this.backendConfiguration
);
const promise = this.backend(compiler, (err, result) => {
if (err) return callback(err);
backend = result;
callback();
});
if (promise && promise.then) {
promise.then(b => {
backend = b;

View File

@ -7,32 +7,43 @@
/** @typedef {import("http").ServerOptions} HttpServerOptions */
/** @typedef {import("https").ServerOptions} HttpsServerOptions */
/** @typedef {import("../../declarations/WebpackOptions").LazyCompilationDefaultBackendOptions} LazyCompilationDefaultBackendOptions */
/** @typedef {import("../Compiler")} Compiler */
/**
* @typedef {Object} BackendConfiguration
* @property {HttpServerOptions} httpServerOptions Options to be passed to the Node.js HTTP module.
* @property {HttpsServerOptions} httpsServerOptions Options to be passed to the Node.js HTTPS module.
* @property {number?} port Custom port for lazy compilation backend. If not defined, a random port will be used.
* @callback BackendHandler
* @param {Compiler} compiler compiler
* @param {function(Error?, any?): void} callback callback
* @returns {void}
*/
/**
* @param {Compiler} compiler compiler
* @param {string} client client reference
* @param {function(Error?, any?): void} callback callback
* @param {?BackendConfiguration} backendConfiguration additional options for the backend
* @returns {void}
* @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
* @returns {BackendHandler} backend
*/
module.exports = (compiler, client, callback, backendConfiguration) => {
module.exports = options => (compiler, callback) => {
const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
const activeModules = new Map();
const prefix = "/lazy-compilation-using-";
const isHTTPS =
!!backendConfiguration && !!backendConfiguration.httpsServerOptions;
const isHttps =
options.protocol === "https" ||
(typeof options.server === "object" &&
("key" in options.server || "pfx" in options.server));
const protocol = isHTTPS ? "https" : "http";
const httpModule = isHTTPS ? require("https") : require("http");
const createServer =
typeof options.server === "function"
? options.server
: (() => {
const http = isHttps ? require("https") : require("http");
return http.createServer.bind(http, options.server);
})();
const listen =
typeof options.listen === "function"
? options.listen
: server => server.listen(options.listen);
const protocol = options.protocol || (isHttps ? "https" : "http");
const requestListener = (req, res) => {
const keys = req.url.slice(prefix.length).split("@");
@ -67,12 +78,8 @@ module.exports = (compiler, client, callback, backendConfiguration) => {
if (moduleActivated && compiler.watching) compiler.watching.invalidate();
};
const server = httpModule.createServer(
backendConfiguration &&
(backendConfiguration.httpServerOptions ||
backendConfiguration.httpsServerOptions),
requestListener
);
const server = /** @type {import("net").Server} */ (createServer());
server.on("request", requestListener);
let isClosing = false;
/** @type {Set<import("net").Socket>} */
@ -84,7 +91,8 @@ module.exports = (compiler, client, callback, backendConfiguration) => {
});
if (isClosing) socket.destroy();
});
server.listen(backendConfiguration && backendConfiguration.port, err => {
server.on("clientError", e => logger.warn(e));
server.on("listening", err => {
if (err) return callback(err);
const addr = server.address();
if (typeof addr === "string") throw new Error("addr must not be a string");
@ -115,11 +123,12 @@ module.exports = (compiler, client, callback, backendConfiguration) => {
).replace(/%(2F|3A|24|26|2B|2C|3B|3D|3A)/g, decodeURIComponent)}`;
const active = activeModules.get(key) > 0;
return {
client: `${client}?${encodeURIComponent(urlBase + prefix)}`,
client: `${options.client}?${encodeURIComponent(urlBase + prefix)}`,
data: key,
active
};
}
});
});
listen(server);
};

File diff suppressed because one or more lines are too long

View File

@ -714,47 +714,7 @@
"type": "boolean"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"backend": {
"description": "A custom backend.",
"instanceof": "Function",
"tsType": "(((compiler: import('../lib/Compiler'), client: string, callback: (err?: Error, api?: any) => void) => void) | ((compiler: import('../lib/Compiler'), client: string) => Promise<any>))"
},
"backendConfiguration": {
"description": "Additional configuration to pass to the backend server.",
"tsType": "import('../lib/hmr/lazyCompilationBackend').BackendConfiguration"
},
"client": {
"description": "A custom client.",
"type": "string"
},
"entries": {
"description": "Enable/disable lazy compilation for entries.",
"type": "boolean"
},
"imports": {
"description": "Enable/disable lazy compilation for import() modules.",
"type": "boolean"
},
"test": {
"description": "Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.",
"anyOf": [
{
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string"
},
{
"instanceof": "Function",
"tsType": "((module: import('../lib/Module')) => boolean)"
}
]
}
}
"$ref": "#/definitions/LazyCompilationOptions"
}
]
},
@ -1492,6 +1452,109 @@
}
]
},
"LazyCompilationDefaultBackendOptions": {
"description": "Options for the default backend.",
"type": "object",
"properties": {
"client": {
"description": "A custom client.",
"type": "string"
},
"listen": {
"description": "Specifies where to listen to from the server.",
"anyOf": [
{
"description": "A port.",
"type": "number"
},
{
"description": "Listen options.",
"type": "object",
"additionalProperties": true,
"properties": {
"host": {
"description": "A host.",
"type": "number"
},
"port": {
"description": "A port.",
"type": "number"
}
},
"tsType": "import(\"net\").ListenOptions"
},
{
"description": "A custom listen function.",
"instanceof": "Function",
"tsType": "((server: import(\"net\").Server) => void)"
}
]
},
"protocol": {
"description": "Specifies the protocol the client should use to connect to the server.",
"enum": ["http", "https"]
},
"server": {
"description": "Specifies how to create the server handling the EventSource requests.",
"anyOf": [
{
"description": "ServerOptions for the http or https createServer call.",
"type": "object",
"additionalProperties": true,
"properties": {},
"tsType": "(import(\"https\").ServerOptions | import(\"http\").ServerOptions)"
},
{
"description": "A custom create server function.",
"instanceof": "Function",
"tsType": "(() => import(\"net\").Server)"
}
]
}
}
},
"LazyCompilationOptions": {
"type": "object",
"additionalProperties": false,
"properties": {
"backend": {
"anyOf": [
{
"description": "A custom backend.",
"instanceof": "Function",
"tsType": "(((compiler: import('../lib/Compiler'), callback: (err?: Error, api?: import(\"../lib/hmr/LazyCompilationPlugin\").BackendApi) => void) => void) | ((compiler: import('../lib/Compiler')) => Promise<import(\"../lib/hmr/LazyCompilationPlugin\").BackendApi>))"
},
{
"$ref": "#/definitions/LazyCompilationDefaultBackendOptions"
}
]
},
"entries": {
"description": "Enable/disable lazy compilation for entries.",
"type": "boolean"
},
"imports": {
"description": "Enable/disable lazy compilation for import() modules.",
"type": "boolean"
},
"test": {
"description": "Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.",
"anyOf": [
{
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string"
},
{
"instanceof": "Function",
"tsType": "((module: import('../lib/Module')) => boolean)"
}
]
}
}
},
"Library": {
"description": "Make the output files a library, exporting the exports of the entry point.",
"anyOf": [

View File

@ -8,7 +8,9 @@
module.exports = class EventSource {
constructor(url) {
this.response = undefined;
const request = require("http").request(
const request = (
url.startsWith("https:") ? require("https") : require("http")
).request(
url,
{
agent: false,

View File

@ -0,0 +1,30 @@
-----BEGIN CERTIFICATE-----
MIIFLzCCAxegAwIBAgIUMiqUWfKzylbMlsLgBHwuNRlTIw0wDQYJKoZIhvcNAQEL
BQAwJjEQMA4GA1UECgwHd2VicGFjazESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTIx
MTAyNTEwMDkzMVoYDzIyOTUwODA5MTAwOTMxWjAmMRAwDgYDVQQKDAd3ZWJwYWNr
MRIwEAYDVQQDDAlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK
AoICAQDcb/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7/wK8R6K4riVb
OLsgd/Edx6AEJEUHs5iHcqnn6PSWDsAbqCSSYUxTv8gPERAofMg/Gy1W20T3+Xsf
fLJm4nGhjy3IIIf8L+A95onSkArdyrejHIzNvpmxrWVGVXoc5GEqFd9jPhnAIy6o
mm9clKFbRSTI/NdqpSnVvWzDucqukACU8Tjl+cnWNEhEx/qTMITMJ0Pdih+/2I3S
3z4WmUlPoBb2Xj9TFZ63SFTk/W7o2vtR7k7YkROAiYudnsyyofmJNNqx7m6fbEEi
gzbOSvMrwT1F66HitmO6vm1WwH9ig0sMpGXRq+S2/5tf2OPEuvJiChJ126Ocqr5X
BbeSicG0avgXcIMYv6YaG1MIkV2XJ8vIIaLX1ZrevFaVW0/Jq9/HDeNxuVZaKAFm
s/OsWVidX2wVDFzxBflyCG2ITbx87IsBpE/7juG+PSARjqg=
-----END CERTIFICATE-----

View File

@ -0,0 +1,36 @@
// Avoid errors because of self-signed certificate
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
it("should compile to lazy imported module", done => {
let resolved;
const promise = import("./module").then(r => (resolved = r));
let generation = 0;
import.meta.webpackHot.accept("./module", () => {
generation++;
});
expect(resolved).toBe(undefined);
setTimeout(() => {
expect(resolved).toBe(undefined);
expect(generation).toBe(0);
NEXT(
require("../../update")(done, true, () => {
promise.then(result => {
expect(result).toHaveProperty("default", 42);
expect(generation).toBe(0);
NEXT(
require("../../update")(done, true, () => {
expect(result).toHaveProperty("default", 42);
expect(generation).toBe(1);
import("./module").then(result => {
expect(result).toHaveProperty("default", 43);
setTimeout(() => {
done();
}, 1000);
}, done);
})
);
}, done);
})
);
}, 1000);
});

View File

@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQDcb/zeGyPgXWUQ
nxpaawe9VfgxCgYDPrJ6hk3t6pALZk5P28szQfBYTIv4MC7eicagYwNFEAJOHx7M
1j7ZGdlE+E+qW03nt+wxAG38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XtWs9Y2AWS7suL
ePI8OWIWKzR/XNFLQKOMNfsnppStPsmH5jMuwZOjDbEiWH38ysRXV9IRZhQKG/2f
eJ3eUsRHMNNzzwXz2qoReOL3KI+RukNLBIHNq5kH2X7vt1hlFcpcWUxtV/OR423Y
v2mp/uRWiL3fY09adyae453Z3SFo1u5cCrRXcUECggEANyHtTwHK22ghDiTjoYCk
iSxJxUz8x6246W6tEtTDGGg8vXEeEK8XzU2oQ2/6O3vcGQKW8n8vWR6BVskh5Jz9
iP5/oZucpdK6hf5+VEr+gPKADLtCuN36QPZ0gdQZuhKOvJVsEmMXodONdI4iARWt
ZYcnub7i/BGlwAj0/nh6n8Tp4M1ETURIgORQNbwkMAZbNN4posI6LMj96HoKrHZI
sebuxJv+adVRxVjEaV3SzXTFB00y2dBEuBpn/pSHVRkt8jsnUAfkpyEmzUu5k2vY
+VHYLR1s1cAisybOTVTuzZtRzeBCu2vpPuaMTA0BIzHGQsE3IGsAMEvo02XHgOj4
SwKCAQBE8paK0mGRf6X9u/B9xmJPfVLpT0MYIjuT+sc09IECECSNk4eWEjFUuqcb
4FKPdlsYP+NUnHHTwaLyPkCI3YYEX/tQpymnjoM75IwDa/zycNJu7/49SYS9kTQS
pSOwzmM64pTxlBEbaKbsLzTk6Kh7Rx029cMe2wKYMKSpZ4psm+q287qBP4TcTYWR
Ol7T8PYSoHaHUNvzYtXhyiwx/wMWjTweLl56ItCS3QQ6KHEAcHRFJF1qiWMmOJBA
00mSIlsCHoG0u3dn3UU4CuibO8z/y8tX8/WlgwcWTvnc+eR+mtkDTxAV6o8LvKxR
j23uAFMMHV6/+WMYg9tmoSEnn0Mp
-----END PRIVATE KEY-----

View File

@ -0,0 +1,5 @@
export default 42;
---
export default 42;
---
export default 43;

View File

@ -0,0 +1,19 @@
"use strict";
const fs = require("fs");
const path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
experiments: {
lazyCompilation: {
entries: false,
backend: {
server: {
key: fs.readFileSync(path.join(__dirname, "key.pem")),
cert: fs.readFileSync(path.join(__dirname, "cert.pem"))
}
}
}
}
};

110
types.d.ts vendored
View File

@ -81,6 +81,7 @@ import {
YieldExpression
} from "estree";
import { ServerOptions as ServerOptionsImport } from "http";
import { ListenOptions, Server } from "net";
import { validate as validateFunction } from "schema-utils";
import { default as ValidationError } from "schema-utils/declarations/ValidationError";
import { ValidationErrorConfiguration } from "schema-utils/declarations/validate";
@ -386,21 +387,9 @@ declare class AutomaticPrefetchPlugin {
apply(compiler: Compiler): void;
}
type AuxiliaryComment = string | LibraryCustomUmdCommentObject;
declare interface BackendConfiguration {
/**
* Options to be passed to the Node.js HTTP module.
*/
httpServerOptions: ServerOptionsImport;
/**
* Options to be passed to the Node.js HTTPS module.
*/
httpsServerOptions: ServerOptionsHttps;
/**
* Custom port for lazy compilation backend. If not defined, a random port will be used.
*/
port: null | number;
declare interface BackendApi {
dispose: (arg0?: Error) => void;
module: (arg0: Module) => { client: string; data: string; active: boolean };
}
declare class BannerPlugin {
constructor(options: BannerPluginArgument);
@ -3313,40 +3302,7 @@ declare interface Experiments {
/**
* Compile entrypoints and import()s only when they are accessed.
*/
lazyCompilation?:
| boolean
| {
/**
* A custom backend.
*/
backend?:
| ((
compiler: Compiler,
client: string,
callback: (err?: Error, api?: any) => void
) => void)
| ((compiler: Compiler, client: string) => Promise<any>);
/**
* Additional configuration to pass to the backend server.
*/
backendConfiguration?: BackendConfiguration;
/**
* A custom client.
*/
client?: string;
/**
* Enable/disable lazy compilation for entries.
*/
entries?: boolean;
/**
* Enable/disable lazy compilation for import() modules.
*/
imports?: boolean;
/**
* Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.
*/
test?: string | RegExp | ((module: Module) => boolean);
};
lazyCompilation?: boolean | LazyCompilationOptions;
/**
* Allow output javascript files as module source type.
@ -5788,6 +5744,62 @@ declare interface KnownStatsProfile {
factory: number;
dependencies: number;
}
/**
* Options for the default backend.
*/
declare interface LazyCompilationDefaultBackendOptions {
[index: string]: any;
/**
* A custom client.
*/
client?: string;
/**
* Specifies where to listen to from the server.
*/
listen?: number | ListenOptions | ((server: typeof Server) => void);
/**
* Specifies the protocol the client should use to connect to the server.
*/
protocol?: "http" | "https";
/**
* Specifies how to create the server handling the EventSource requests.
*/
server?: ServerOptionsImport | ServerOptionsHttps | (() => typeof Server);
}
/**
* This interface was referenced by `WebpackOptions`'s JSON-Schema
* via the `definition` "LazyCompilationOptions".
*/
declare interface LazyCompilationOptions {
backend?:
| ((
compiler: Compiler,
callback: (err?: Error, api?: BackendApi) => void
) => void)
| ((compiler: Compiler) => Promise<BackendApi>)
| LazyCompilationDefaultBackendOptions;
/**
* Enable/disable lazy compilation for entries.
*/
entries?: boolean;
/**
* Enable/disable lazy compilation for import() modules.
*/
imports?: boolean;
/**
* Specify which entrypoints or import()ed modules should be lazily compiled. This is matched with the imported module and not the entrypoint name.
*/
test?: string | RegExp | ((module: Module) => boolean);
}
declare class LazySet<T> {
constructor(iterable?: Iterable<T>);
readonly size: number;