mirror of https://github.com/webpack/webpack.git
fix: external function types (#19920)
This commit is contained in:
parent
898c48042d
commit
cf17a41259
|
|
@ -191,16 +191,13 @@ export type ExternalItemFunction =
|
|||
/**
|
||||
* The function is called on each dependency (`function(context, request, callback(err, result))`).
|
||||
*/
|
||||
export type ExternalItemFunctionCallback = (
|
||||
data: ExternalItemFunctionData,
|
||||
callback: (err?: Error | null, result?: ExternalItemValue) => void
|
||||
) => void;
|
||||
export type ExternalItemFunctionCallback =
|
||||
import("../lib/ExternalModuleFactoryPlugin").ExternalItemFunctionCallback;
|
||||
/**
|
||||
* The function is called on each dependency (`function(context, request)`).
|
||||
*/
|
||||
export type ExternalItemFunctionPromise = (
|
||||
data: ExternalItemFunctionData
|
||||
) => Promise<ExternalItemValue>;
|
||||
export type ExternalItemFunctionPromise =
|
||||
import("../lib/ExternalModuleFactoryPlugin").ExternalItemFunctionPromise;
|
||||
/**
|
||||
* Specifies the default type of externals ('amd*', 'umd*', 'system' and 'jsonp' depend on output.libraryTarget set to the same value).
|
||||
*/
|
||||
|
|
@ -807,33 +804,6 @@ export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
|
|||
*/
|
||||
export type ExperimentsNormalized = ExperimentsCommon &
|
||||
ExperimentsNormalizedExtra;
|
||||
/**
|
||||
* Get a resolve function with the current resolver options.
|
||||
*/
|
||||
export type ExternalItemFunctionDataGetResolve = (
|
||||
options?: ResolveOptions
|
||||
) =>
|
||||
| ExternalItemFunctionDataGetResolveCallbackResult
|
||||
| ExternalItemFunctionDataGetResolveResult;
|
||||
/**
|
||||
* Result of get a resolve function with the current resolver options.
|
||||
*/
|
||||
export type ExternalItemFunctionDataGetResolveCallbackResult = (
|
||||
context: string,
|
||||
request: string,
|
||||
callback: (
|
||||
err?: Error | null,
|
||||
result?: string | false,
|
||||
resolveRequest?: import("enhanced-resolve").ResolveRequest
|
||||
) => void
|
||||
) => void;
|
||||
/**
|
||||
* Callback result of get a resolve function with the current resolver options.
|
||||
*/
|
||||
export type ExternalItemFunctionDataGetResolveResult = (
|
||||
context: string,
|
||||
request: string
|
||||
) => Promise<string>;
|
||||
/**
|
||||
* The dependency used for the external.
|
||||
*/
|
||||
|
|
@ -3186,31 +3156,6 @@ export interface ExperimentsCommon {
|
|||
*/
|
||||
syncWebAssembly?: boolean;
|
||||
}
|
||||
/**
|
||||
* Data object passed as argument when a function is set for 'externals'.
|
||||
*/
|
||||
export interface ExternalItemFunctionData {
|
||||
/**
|
||||
* The directory in which the request is placed.
|
||||
*/
|
||||
context?: string;
|
||||
/**
|
||||
* Contextual information.
|
||||
*/
|
||||
contextInfo?: import("../lib/ModuleFactory").ModuleFactoryCreateDataContextInfo;
|
||||
/**
|
||||
* The category of the referencing dependencies.
|
||||
*/
|
||||
dependencyType?: string;
|
||||
/**
|
||||
* Get a resolve function with the current resolver options.
|
||||
*/
|
||||
getResolve?: ExternalItemFunctionDataGetResolve;
|
||||
/**
|
||||
* The request as written by the user in the require/import expression/statement.
|
||||
*/
|
||||
request?: string;
|
||||
}
|
||||
/**
|
||||
* Options for building http resources.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -15,13 +15,32 @@ const ImportDependency = require("./dependencies/ImportDependency");
|
|||
const { cachedSetProperty, resolveByProperty } = require("./util/cleverMerge");
|
||||
|
||||
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
|
||||
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
||||
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
||||
/** @typedef {import("./ModuleFactory").IssuerLayer} IssuerLayer */
|
||||
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */
|
||||
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
||||
|
||||
/** @typedef {((context: string, request: string, callback: (err?: Error | null, result?: string | false, resolveRequest?: import('enhanced-resolve').ResolveRequest) => void) => void)} ExternalItemFunctionDataGetResolveCallbackResult */
|
||||
/** @typedef {((context: string, request: string) => Promise<string>)} ExternalItemFunctionDataGetResolveResult */
|
||||
/** @typedef {(options?: ResolveOptions) => ExternalItemFunctionDataGetResolveCallbackResult | ExternalItemFunctionDataGetResolveResult} ExternalItemFunctionDataGetResolve */
|
||||
|
||||
/**
|
||||
* @typedef {object} ExternalItemFunctionData
|
||||
* @property {string} context the directory in which the request is placed
|
||||
* @property {ModuleFactoryCreateDataContextInfo} contextInfo contextual information
|
||||
* @property {string} dependencyType the category of the referencing dependency
|
||||
* @property {ExternalItemFunctionDataGetResolve} getResolve get a resolve function with the current resolver options
|
||||
* @property {string} request the request as written by the user in the require/import expression/statement
|
||||
*/
|
||||
|
||||
/** @typedef {((data: ExternalItemFunctionData, callback: (err?: (Error | null), result?: ExternalItemValue) => void) => void)} ExternalItemFunctionCallback */
|
||||
/** @typedef {((data: import("../lib/ExternalModuleFactoryPlugin").ExternalItemFunctionData) => Promise<ExternalItemValue>)} ExternalItemFunctionPromise */
|
||||
|
||||
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
||||
|
|
@ -306,7 +325,9 @@ class ExternalModuleFactoryPlugin {
|
|||
},
|
||||
cb
|
||||
);
|
||||
if (promise && promise.then) promise.then((r) => cb(null, r), cb);
|
||||
if (promise && promise.then) {
|
||||
promise.then((r) => cb(null, r), cb);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (typeof externals === "object") {
|
||||
|
|
|
|||
|
|
@ -120,9 +120,8 @@ class WebpackOptionsApply extends OptionsApply {
|
|||
"module",
|
||||
({ request, dependencyType, contextInfo }, callback) => {
|
||||
if (
|
||||
contextInfo &&
|
||||
/\.css(\?|$)/.test(contextInfo.issuer) &&
|
||||
/^(\/\/|https?:\/\/|#)/.test(/** @type {string} */ (request))
|
||||
/^(\/\/|https?:\/\/|#)/.test(request)
|
||||
) {
|
||||
if (dependencyType === "url") {
|
||||
return callback(null, `asset ${request}`);
|
||||
|
|
@ -146,11 +145,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|||
const ExternalsPlugin = require("./ExternalsPlugin");
|
||||
|
||||
new ExternalsPlugin(type, ({ request, dependencyType }, callback) => {
|
||||
if (
|
||||
/^(\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(
|
||||
/** @type {string} */ (request)
|
||||
)
|
||||
) {
|
||||
if (/^(\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) {
|
||||
if (dependencyType === "url") {
|
||||
return callback(null, `asset ${request}`);
|
||||
} else if (
|
||||
|
|
@ -158,12 +153,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|||
options.experiments.css
|
||||
) {
|
||||
return callback(null, `css-import ${request}`);
|
||||
} else if (
|
||||
/^(\/\/|https?:\/\/|std:|jsr:|npm:)/.test(
|
||||
/** @type {string} */
|
||||
(request)
|
||||
)
|
||||
) {
|
||||
} else if (/^(\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) {
|
||||
return callback(null, `${type} ${request}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
lib/index.js
12
lib/index.js
|
|
@ -13,12 +13,6 @@ const memoize = require("./util/memoize");
|
|||
/** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItem} ExternalItem */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunction} ExternalItemFunction */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionCallback} ExternalItemFunctionCallback */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionData} ExternalItemFunctionData */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionDataGetResolve} ExternalItemFunctionDataGetResolve */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionDataGetResolveCallbackResult} ExternalItemFunctionDataGetResolveCallbackResult */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionDataGetResolveResult} ExternalItemFunctionDataGetResolveResult */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionPromise} ExternalItemFunctionPromise */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
|
||||
/** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
|
||||
|
|
@ -49,6 +43,12 @@ const memoize = require("./util/memoize");
|
|||
/** @typedef {import("./Compilation").PathData} PathData */
|
||||
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
||||
/** @typedef {import("./Entrypoint")} Entrypoint */
|
||||
/** @typedef {import("./ExternalModuleFactoryPlugin").ExternalItemFunctionCallback} ExternalItemFunctionCallback */
|
||||
/** @typedef {import("./ExternalModuleFactoryPlugin").ExternalItemFunctionData} ExternalItemFunctionData */
|
||||
/** @typedef {import("./ExternalModuleFactoryPlugin").ExternalItemFunctionDataGetResolve} ExternalItemFunctionDataGetResolve */
|
||||
/** @typedef {import("./ExternalModuleFactoryPlugin").ExternalItemFunctionDataGetResolveCallbackResult} ExternalItemFunctionDataGetResolveCallbackResult */
|
||||
/** @typedef {import("./ExternalModuleFactoryPlugin").ExternalItemFunctionDataGetResolveResult} ExternalItemFunctionDataGetResolveResult */
|
||||
/** @typedef {import("./ExternalModuleFactoryPlugin").ExternalItemFunctionPromise} ExternalItemFunctionPromise */
|
||||
/** @typedef {import("./MultiCompiler").MultiCompilerOptions} MultiCompilerOptions */
|
||||
/** @typedef {import("./MultiCompiler").MultiWebpackOptions} MultiConfiguration */
|
||||
/** @typedef {import("./MultiStats")} MultiStats */
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1186,54 +1186,12 @@
|
|||
"ExternalItemFunctionCallback": {
|
||||
"description": "The function is called on each dependency (`function(context, request, callback(err, result))`).",
|
||||
"instanceof": "Function",
|
||||
"tsType": "((data: ExternalItemFunctionData, callback: (err?: (Error | null), result?: ExternalItemValue) => void) => void)"
|
||||
},
|
||||
"ExternalItemFunctionData": {
|
||||
"description": "Data object passed as argument when a function is set for 'externals'.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"context": {
|
||||
"description": "The directory in which the request is placed.",
|
||||
"type": "string"
|
||||
},
|
||||
"contextInfo": {
|
||||
"description": "Contextual information.",
|
||||
"type": "object",
|
||||
"tsType": "import('../lib/ModuleFactory').ModuleFactoryCreateDataContextInfo"
|
||||
},
|
||||
"dependencyType": {
|
||||
"description": "The category of the referencing dependencies.",
|
||||
"type": "string"
|
||||
},
|
||||
"getResolve": {
|
||||
"$ref": "#/definitions/ExternalItemFunctionDataGetResolve"
|
||||
},
|
||||
"request": {
|
||||
"description": "The request as written by the user in the require/import expression/statement.",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ExternalItemFunctionDataGetResolve": {
|
||||
"description": "Get a resolve function with the current resolver options.",
|
||||
"instanceof": "Function",
|
||||
"tsType": "((options?: ResolveOptions) => ExternalItemFunctionDataGetResolveCallbackResult | ExternalItemFunctionDataGetResolveResult)"
|
||||
},
|
||||
"ExternalItemFunctionDataGetResolveCallbackResult": {
|
||||
"description": "Result of get a resolve function with the current resolver options.",
|
||||
"instanceof": "Function",
|
||||
"tsType": "((context: string, request: string, callback: (err?: Error | null, result?: string | false, resolveRequest?: import('enhanced-resolve').ResolveRequest) => void) => void)"
|
||||
},
|
||||
"ExternalItemFunctionDataGetResolveResult": {
|
||||
"description": "Callback result of get a resolve function with the current resolver options.",
|
||||
"instanceof": "Function",
|
||||
"tsType": "((context: string, request: string) => Promise<string>)"
|
||||
"tsType": "(import(\"../lib/ExternalModuleFactoryPlugin\").ExternalItemFunctionCallback)"
|
||||
},
|
||||
"ExternalItemFunctionPromise": {
|
||||
"description": "The function is called on each dependency (`function(context, request)`).",
|
||||
"instanceof": "Function",
|
||||
"tsType": "((data: ExternalItemFunctionData) => Promise<ExternalItemValue>)"
|
||||
"tsType": "(import(\"../lib/ExternalModuleFactoryPlugin\").ExternalItemFunctionPromise)"
|
||||
},
|
||||
"ExternalItemValue": {
|
||||
"description": "The dependency used for the external.",
|
||||
|
|
|
|||
|
|
@ -5274,30 +5274,26 @@ type ExternalItemFunction =
|
|||
) => void
|
||||
) => void)
|
||||
| ((data: ExternalItemFunctionData) => Promise<ExternalItemValue>);
|
||||
|
||||
/**
|
||||
* Data object passed as argument when a function is set for 'externals'.
|
||||
*/
|
||||
declare interface ExternalItemFunctionData {
|
||||
/**
|
||||
* The directory in which the request is placed.
|
||||
* the directory in which the request is placed
|
||||
*/
|
||||
context?: string;
|
||||
context: string;
|
||||
|
||||
/**
|
||||
* Contextual information.
|
||||
* contextual information
|
||||
*/
|
||||
contextInfo?: ModuleFactoryCreateDataContextInfo;
|
||||
contextInfo: ModuleFactoryCreateDataContextInfo;
|
||||
|
||||
/**
|
||||
* The category of the referencing dependencies.
|
||||
* the category of the referencing dependency
|
||||
*/
|
||||
dependencyType?: string;
|
||||
dependencyType: string;
|
||||
|
||||
/**
|
||||
* Get a resolve function with the current resolver options.
|
||||
* get a resolve function with the current resolver options
|
||||
*/
|
||||
getResolve?: (
|
||||
getResolve: (
|
||||
options?: ResolveOptions
|
||||
) =>
|
||||
| ((
|
||||
|
|
@ -5312,9 +5308,9 @@ declare interface ExternalItemFunctionData {
|
|||
| ((context: string, request: string) => Promise<string>);
|
||||
|
||||
/**
|
||||
* The request as written by the user in the require/import expression/statement.
|
||||
* the request as written by the user in the require/import expression/statement
|
||||
*/
|
||||
request?: string;
|
||||
request: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -18789,42 +18785,6 @@ declare namespace exports {
|
|||
export { SyncModuleIdsPlugin };
|
||||
}
|
||||
}
|
||||
export type ExternalItemFunctionCallback = (
|
||||
data: ExternalItemFunctionData,
|
||||
callback: (
|
||||
err?: null | Error,
|
||||
result?: string | boolean | string[] | { [index: string]: any }
|
||||
) => void
|
||||
) => void;
|
||||
export type ExternalItemFunctionDataGetResolve = (
|
||||
options?: ResolveOptions
|
||||
) =>
|
||||
| ((
|
||||
context: string,
|
||||
request: string,
|
||||
callback: (
|
||||
err?: null | Error,
|
||||
result?: string | false,
|
||||
resolveRequest?: ResolveRequest
|
||||
) => void
|
||||
) => void)
|
||||
| ((context: string, request: string) => Promise<string>);
|
||||
export type ExternalItemFunctionDataGetResolveCallbackResult = (
|
||||
context: string,
|
||||
request: string,
|
||||
callback: (
|
||||
err?: null | Error,
|
||||
result?: string | false,
|
||||
resolveRequest?: ResolveRequest
|
||||
) => void
|
||||
) => void;
|
||||
export type ExternalItemFunctionDataGetResolveResult = (
|
||||
context: string,
|
||||
request: string
|
||||
) => Promise<string>;
|
||||
export type ExternalItemFunctionPromise = (
|
||||
data: ExternalItemFunctionData
|
||||
) => Promise<ExternalItemValue>;
|
||||
export type RuleSetUseFunction = (data: EffectData) =>
|
||||
| string
|
||||
| RuleSetUseFunction
|
||||
|
|
@ -18868,6 +18828,42 @@ declare namespace exports {
|
|||
this: Compiler,
|
||||
compiler: Compiler
|
||||
) => void;
|
||||
export type ExternalItemFunctionCallback = (
|
||||
data: ExternalItemFunctionData,
|
||||
callback: (
|
||||
err?: null | Error,
|
||||
result?: string | boolean | string[] | { [index: string]: any }
|
||||
) => void
|
||||
) => void;
|
||||
export type ExternalItemFunctionDataGetResolve = (
|
||||
options?: ResolveOptions
|
||||
) =>
|
||||
| ((
|
||||
context: string,
|
||||
request: string,
|
||||
callback: (
|
||||
err?: null | Error,
|
||||
result?: string | false,
|
||||
resolveRequest?: ResolveRequest
|
||||
) => void
|
||||
) => void)
|
||||
| ((context: string, request: string) => Promise<string>);
|
||||
export type ExternalItemFunctionDataGetResolveCallbackResult = (
|
||||
context: string,
|
||||
request: string,
|
||||
callback: (
|
||||
err?: null | Error,
|
||||
result?: string | false,
|
||||
resolveRequest?: ResolveRequest
|
||||
) => void
|
||||
) => void;
|
||||
export type ExternalItemFunctionDataGetResolveResult = (
|
||||
context: string,
|
||||
request: string
|
||||
) => Promise<string>;
|
||||
export type ExternalItemFunctionPromise = (
|
||||
data: ExternalItemFunctionData
|
||||
) => Promise<ExternalItemValue>;
|
||||
export {
|
||||
AutomaticPrefetchPlugin,
|
||||
AsyncDependenciesBlock,
|
||||
|
|
@ -18933,7 +18929,6 @@ declare namespace exports {
|
|||
EntryObject,
|
||||
ExternalItem,
|
||||
ExternalItemFunction,
|
||||
ExternalItemFunctionData,
|
||||
ExternalItemObjectKnown,
|
||||
ExternalItemObjectUnknown,
|
||||
ExternalItemValue,
|
||||
|
|
@ -18962,6 +18957,7 @@ declare namespace exports {
|
|||
PathData,
|
||||
CodeGenerationResults,
|
||||
Entrypoint,
|
||||
ExternalItemFunctionData,
|
||||
MultiCompilerOptions,
|
||||
MultiConfiguration,
|
||||
MultiStats,
|
||||
|
|
|
|||
Loading…
Reference in New Issue