refactor and add test case
This commit is contained in:
parent
537da95879
commit
ba154bc741
|
@ -1117,43 +1117,7 @@ export interface Experiments {
|
||||||
/**
|
/**
|
||||||
* Compile entrypoints and import()s only when they are accessed.
|
* Compile entrypoints and import()s only when they are accessed.
|
||||||
*/
|
*/
|
||||||
lazyCompilation?:
|
lazyCompilation?: boolean | LazyCompilationOptions;
|
||||||
| 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);
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* Allow output javascript files as module source type.
|
* Allow output javascript files as module source type.
|
||||||
*/
|
*/
|
||||||
|
@ -1188,6 +1152,65 @@ export interface HttpUriOptions {
|
||||||
*/
|
*/
|
||||||
upgrade?: boolean;
|
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.
|
* Enable presets of externals for specific targets.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,7 +9,9 @@ exports.keepAlive = function (options) {
|
||||||
var active = options.active;
|
var active = options.active;
|
||||||
var module = options.module;
|
var module = options.module;
|
||||||
var response;
|
var response;
|
||||||
var request = require("http").request(
|
var request = (
|
||||||
|
urlBase.startsWith("https") ? require("https") : require("http")
|
||||||
|
).request(
|
||||||
urlBase + data,
|
urlBase + data,
|
||||||
{
|
{
|
||||||
agent: false,
|
agent: false,
|
||||||
|
|
|
@ -261,20 +261,21 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
: null;
|
: null;
|
||||||
new LazyCompilationPlugin({
|
new LazyCompilationPlugin({
|
||||||
backend:
|
backend:
|
||||||
(lazyOptions && lazyOptions.backend) ||
|
typeof lazyOptions.backend === "function"
|
||||||
require("./hmr/lazyCompilationBackend"),
|
? lazyOptions.backend
|
||||||
client:
|
: require("./hmr/lazyCompilationBackend")({
|
||||||
(lazyOptions && lazyOptions.client) ||
|
...lazyOptions.backend,
|
||||||
require.resolve(
|
client:
|
||||||
`../hot/lazy-compilation-${
|
lazyOptions.backend.client ||
|
||||||
options.externalsPresets.node ? "node" : "web"
|
require.resolve(
|
||||||
}.js`
|
`../hot/lazy-compilation-${
|
||||||
),
|
options.externalsPresets.node ? "node" : "web"
|
||||||
|
}.js`
|
||||||
|
)
|
||||||
|
}),
|
||||||
entries: !lazyOptions || lazyOptions.entries !== false,
|
entries: !lazyOptions || lazyOptions.entries !== false,
|
||||||
imports: !lazyOptions || lazyOptions.imports !== false,
|
imports: !lazyOptions || lazyOptions.imports !== false,
|
||||||
test: (lazyOptions && lazyOptions.test) || undefined,
|
test: (lazyOptions && lazyOptions.test) || undefined
|
||||||
backendConfiguration:
|
|
||||||
(lazyOptions && lazyOptions.backendConfiguration) || undefined
|
|
||||||
}).apply(compiler);
|
}).apply(compiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,12 @@ const { registerNotSerializable } = require("../util/serialization");
|
||||||
/** @typedef {import("../util/Hash")} Hash */
|
/** @typedef {import("../util/Hash")} Hash */
|
||||||
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
/** @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([
|
const IGNORED_DEPENDENCY_TYPES = new Set([
|
||||||
"import.meta.webpackHot.accept",
|
"import.meta.webpackHot.accept",
|
||||||
"import.meta.webpackHot.decline",
|
"import.meta.webpackHot.decline",
|
||||||
|
@ -303,27 +309,16 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
||||||
class LazyCompilationPlugin {
|
class LazyCompilationPlugin {
|
||||||
/**
|
/**
|
||||||
* @param {Object} options options
|
* @param {Object} options options
|
||||||
* @param {(function(Compiler, string, function(Error?, any?): void, Object): void) | function(Compiler, string): Promise<any>} options.backend the backend
|
* @param {(function(Compiler, function(Error?, BackendApi?): void): void) | function(Compiler): Promise<BackendApi>} options.backend the backend
|
||||||
* @param {Object} options.backendConfiguration additional configuration passed to backend
|
|
||||||
* @param {string} options.client the client reference
|
|
||||||
* @param {boolean} options.entries true, when entries are lazy compiled
|
* @param {boolean} options.entries true, when entries are lazy compiled
|
||||||
* @param {boolean} options.imports true, when import() modules 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
|
* @param {RegExp | string | (function(Module): boolean)} options.test additional filter for lazy compiled entrypoint modules
|
||||||
*/
|
*/
|
||||||
constructor({
|
constructor({ backend, entries, imports, test }) {
|
||||||
backend,
|
|
||||||
client,
|
|
||||||
entries,
|
|
||||||
imports,
|
|
||||||
test,
|
|
||||||
backendConfiguration
|
|
||||||
}) {
|
|
||||||
this.backend = backend;
|
this.backend = backend;
|
||||||
this.client = client;
|
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
this.imports = imports;
|
this.imports = imports;
|
||||||
this.test = test;
|
this.test = test;
|
||||||
this.backendConfiguration = backendConfiguration;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Apply the plugin
|
* Apply the plugin
|
||||||
|
@ -336,16 +331,11 @@ class LazyCompilationPlugin {
|
||||||
"LazyCompilationPlugin",
|
"LazyCompilationPlugin",
|
||||||
(params, callback) => {
|
(params, callback) => {
|
||||||
if (backend !== undefined) return callback();
|
if (backend !== undefined) return callback();
|
||||||
const promise = this.backend(
|
const promise = this.backend(compiler, (err, result) => {
|
||||||
compiler,
|
if (err) return callback(err);
|
||||||
this.client,
|
backend = result;
|
||||||
(err, result) => {
|
callback();
|
||||||
if (err) return callback(err);
|
});
|
||||||
backend = result;
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
this.backendConfiguration
|
|
||||||
);
|
|
||||||
if (promise && promise.then) {
|
if (promise && promise.then) {
|
||||||
promise.then(b => {
|
promise.then(b => {
|
||||||
backend = b;
|
backend = b;
|
||||||
|
|
|
@ -7,32 +7,43 @@
|
||||||
|
|
||||||
/** @typedef {import("http").ServerOptions} HttpServerOptions */
|
/** @typedef {import("http").ServerOptions} HttpServerOptions */
|
||||||
/** @typedef {import("https").ServerOptions} HttpsServerOptions */
|
/** @typedef {import("https").ServerOptions} HttpsServerOptions */
|
||||||
|
/** @typedef {import("../../declarations/WebpackOptions").LazyCompilationDefaultBackendOptions} LazyCompilationDefaultBackendOptions */
|
||||||
/** @typedef {import("../Compiler")} Compiler */
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} BackendConfiguration
|
* @callback BackendHandler
|
||||||
* @property {HttpServerOptions} httpServerOptions Options to be passed to the Node.js HTTP module.
|
* @param {Compiler} compiler compiler
|
||||||
* @property {HttpsServerOptions} httpsServerOptions Options to be passed to the Node.js HTTPS module.
|
* @param {function(Error?, any?): void} callback callback
|
||||||
* @property {number?} port Custom port for lazy compilation backend. If not defined, a random port will be used.
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Compiler} compiler compiler
|
* @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
|
||||||
* @param {string} client client reference
|
* @returns {BackendHandler} backend
|
||||||
* @param {function(Error?, any?): void} callback callback
|
|
||||||
* @param {?BackendConfiguration} backendConfiguration additional options for the backend
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
*/
|
||||||
module.exports = (compiler, client, callback, backendConfiguration) => {
|
module.exports = options => (compiler, callback) => {
|
||||||
const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
|
const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
|
||||||
const activeModules = new Map();
|
const activeModules = new Map();
|
||||||
const prefix = "/lazy-compilation-using-";
|
const prefix = "/lazy-compilation-using-";
|
||||||
|
|
||||||
const isHTTPS =
|
const isHttps =
|
||||||
!!backendConfiguration && !!backendConfiguration.httpsServerOptions;
|
options.protocol === "https" ||
|
||||||
|
(typeof options.server === "object" &&
|
||||||
|
("key" in options.server || "pfx" in options.server));
|
||||||
|
|
||||||
const protocol = isHTTPS ? "https" : "http";
|
const createServer =
|
||||||
const httpModule = isHTTPS ? require("https") : require("http");
|
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 requestListener = (req, res) => {
|
||||||
const keys = req.url.slice(prefix.length).split("@");
|
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();
|
if (moduleActivated && compiler.watching) compiler.watching.invalidate();
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = httpModule.createServer(
|
const server = /** @type {import("net").Server} */ (createServer());
|
||||||
backendConfiguration &&
|
server.on("request", requestListener);
|
||||||
(backendConfiguration.httpServerOptions ||
|
|
||||||
backendConfiguration.httpsServerOptions),
|
|
||||||
requestListener
|
|
||||||
);
|
|
||||||
|
|
||||||
let isClosing = false;
|
let isClosing = false;
|
||||||
/** @type {Set<import("net").Socket>} */
|
/** @type {Set<import("net").Socket>} */
|
||||||
|
@ -84,7 +91,8 @@ module.exports = (compiler, client, callback, backendConfiguration) => {
|
||||||
});
|
});
|
||||||
if (isClosing) socket.destroy();
|
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);
|
if (err) return callback(err);
|
||||||
const addr = server.address();
|
const addr = server.address();
|
||||||
if (typeof addr === "string") throw new Error("addr must not be a string");
|
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)}`;
|
).replace(/%(2F|3A|24|26|2B|2C|3B|3D|3A)/g, decodeURIComponent)}`;
|
||||||
const active = activeModules.get(key) > 0;
|
const active = activeModules.get(key) > 0;
|
||||||
return {
|
return {
|
||||||
client: `${client}?${encodeURIComponent(urlBase + prefix)}`,
|
client: `${options.client}?${encodeURIComponent(urlBase + prefix)}`,
|
||||||
data: key,
|
data: key,
|
||||||
active
|
active
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
listen(server);
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -714,47 +714,7 @@
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "object",
|
"$ref": "#/definitions/LazyCompilationOptions"
|
||||||
"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)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -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": {
|
"Library": {
|
||||||
"description": "Make the output files a library, exporting the exports of the entry point.",
|
"description": "Make the output files a library, exporting the exports of the entry point.",
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
module.exports = class EventSource {
|
module.exports = class EventSource {
|
||||||
constructor(url) {
|
constructor(url) {
|
||||||
this.response = undefined;
|
this.response = undefined;
|
||||||
const request = require("http").request(
|
const request = (
|
||||||
|
url.startsWith("https:") ? require("https") : require("http")
|
||||||
|
).request(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
agent: false,
|
agent: false,
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFLzCCAxegAwIBAgIUMiqUWfKzylbMlsLgBHwuNRlTIw0wDQYJKoZIhvcNAQEL
|
||||||
|
BQAwJjEQMA4GA1UECgwHd2VicGFjazESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTIx
|
||||||
|
MTAyNTEwMDkzMVoYDzIyOTUwODA5MTAwOTMxWjAmMRAwDgYDVQQKDAd3ZWJwYWNr
|
||||||
|
MRIwEAYDVQQDDAlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK
|
||||||
|
AoICAQDcb/zeGyPgXWUQnxpaawe9VfgxCgYDPrJ6hk3t6pALZk5P28szQfBYTIv4
|
||||||
|
MC7eicagYwNFEAJOHx7M1j7ZGdlE+E+qW03nt+wxAG38Nyp5nVjssqEKifSFekIJ
|
||||||
|
RHpUS1CKhVkZdjHuJWu2NhZEpstMNhJFsqixSXNA1h0Qrg2eFmeQU/Cxzi+SPBU6
|
||||||
|
ByTf/83mcGcTEXQOCEmIdH6UzUVfY4MuRSab+X3eL5DHByZ0/sMqV7SZdTy3DRoO
|
||||||
|
Cnk/swHKINSFMdSO7OdpoyRLPuOiGRuuyekg7ygTRHwhtgwusVyGl1FY0zqY5hkX
|
||||||
|
TOjVRrLEKYypY+6soWc+gwfREfXLeLoUBIkS8PbfXPTtslYLl93KSFrVuZfVhqSM
|
||||||
|
8GNPpKcA0ZMleMhL8Yy8SknY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SvMrwT1F66HitmO6vm1WwH9ig0sMpGXRq+S2/5tf2OPEuvJiChJ126Ocqr5X
|
||||||
|
BbeSicG0avgXcIMYv6YaG1MIkV2XJ8vIIaLX1ZrevFaVW0/Jq9/HDeNxuVZaKAFm
|
||||||
|
s/OsWVidX2wVDFzxBflyCG2ITbx87IsBpE/7juG+PSARjqg=
|
||||||
|
-----END CERTIFICATE-----
|
|
@ -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);
|
||||||
|
});
|
|
@ -0,0 +1,52 @@
|
||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQDcb/zeGyPgXWUQ
|
||||||
|
nxpaawe9VfgxCg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iyPz97s+7kJpLNDW
|
||||||
|
eDsx5e9On80WZw+dVwHDqq0V0pXO9vrYEi2hjblltSLslI6Q54at3V0kj9NjrRHj
|
||||||
|
uXlmcurUSNBe/pGxbnI76AzvxrouXlu0yTaD2wrs8rP3zYKI6QQVoApUNwKzFOKr
|
||||||
|
OyyCROGYlOMPAoIBAGbjMxfyYqU67Ayt75Y6F15zP/gBFo3EhuM5t8dhFKE+RbBH
|
||||||
|
qNOEtsY+mer1iM95btxgyfWx83nj+fomAAnVkMo42uaAx7RNPFh6BmtiJZFQWaCS
|
||||||
|
J9KS7VUND2utF80BeBQGL6JtoJVl+acm7syTcZ0leOxcUTsz2gXtWs9Y2AWS7suL
|
||||||
|
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-----
|
|
@ -0,0 +1,5 @@
|
||||||
|
export default 42;
|
||||||
|
---
|
||||||
|
export default 42;
|
||||||
|
---
|
||||||
|
export default 43;
|
|
@ -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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -81,6 +81,7 @@ import {
|
||||||
YieldExpression
|
YieldExpression
|
||||||
} from "estree";
|
} from "estree";
|
||||||
import { ServerOptions as ServerOptionsImport } from "http";
|
import { ServerOptions as ServerOptionsImport } from "http";
|
||||||
|
import { ListenOptions, Server } from "net";
|
||||||
import { validate as validateFunction } from "schema-utils";
|
import { validate as validateFunction } from "schema-utils";
|
||||||
import { default as ValidationError } from "schema-utils/declarations/ValidationError";
|
import { default as ValidationError } from "schema-utils/declarations/ValidationError";
|
||||||
import { ValidationErrorConfiguration } from "schema-utils/declarations/validate";
|
import { ValidationErrorConfiguration } from "schema-utils/declarations/validate";
|
||||||
|
@ -386,21 +387,9 @@ declare class AutomaticPrefetchPlugin {
|
||||||
apply(compiler: Compiler): void;
|
apply(compiler: Compiler): void;
|
||||||
}
|
}
|
||||||
type AuxiliaryComment = string | LibraryCustomUmdCommentObject;
|
type AuxiliaryComment = string | LibraryCustomUmdCommentObject;
|
||||||
declare interface BackendConfiguration {
|
declare interface BackendApi {
|
||||||
/**
|
dispose: (arg0?: Error) => void;
|
||||||
* Options to be passed to the Node.js HTTP module.
|
module: (arg0: Module) => { client: string; data: string; active: boolean };
|
||||||
*/
|
|
||||||
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 class BannerPlugin {
|
declare class BannerPlugin {
|
||||||
constructor(options: BannerPluginArgument);
|
constructor(options: BannerPluginArgument);
|
||||||
|
@ -3313,40 +3302,7 @@ declare interface Experiments {
|
||||||
/**
|
/**
|
||||||
* Compile entrypoints and import()s only when they are accessed.
|
* Compile entrypoints and import()s only when they are accessed.
|
||||||
*/
|
*/
|
||||||
lazyCompilation?:
|
lazyCompilation?: boolean | LazyCompilationOptions;
|
||||||
| 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);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow output javascript files as module source type.
|
* Allow output javascript files as module source type.
|
||||||
|
@ -5788,6 +5744,62 @@ declare interface KnownStatsProfile {
|
||||||
factory: number;
|
factory: number;
|
||||||
dependencies: 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> {
|
declare class LazySet<T> {
|
||||||
constructor(iterable?: Iterable<T>);
|
constructor(iterable?: Iterable<T>);
|
||||||
readonly size: number;
|
readonly size: number;
|
||||||
|
|
Loading…
Reference in New Issue