| | |
| | | /** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */ |
| | | /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").ExternalsType} ExternalsType */ |
| | | /** @typedef {import("../declarations/WebpackOptions").ExternalItem} ExternalItem */ |
| | | /** @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("./Dependency")} Dependency */ |
| | | /** @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, 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 */ |
| | | |
| | | /** |
| | | * Defines the external item function data type used by this module. |
| | | * @typedef {object} ExternalItemFunctionData |
| | | * @property {string} context the directory in which the request is placed |
| | | * @property {ModuleFactoryCreateDataContextInfo} contextInfo contextual information |
| | |
| | | // TODO webpack 6 remove this |
| | | const callDeprecatedExternals = util.deprecate( |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {EXPECTED_FUNCTION} externalsFunction externals function |
| | | * @param {string} context context |
| | | * @param {string} request request |
| | |
| | | "DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS" |
| | | ); |
| | | |
| | | /** @typedef {(layer: string | null) => ExternalItem} ExternalItemByLayerFn */ |
| | | /** @typedef {ExternalItemObjectKnown & ExternalItemObjectUnknown} ExternalItemObject */ |
| | | |
| | | /** |
| | | * Defines the external weak cache type used by this module. |
| | | * @template {ExternalItemObject} T |
| | | * @typedef {WeakMap<T, Map<IssuerLayer, Omit<T, "byLayer">>>} ExternalWeakCache |
| | | */ |
| | |
| | | const cache = new WeakMap(); |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {ExternalItemObject} obj obj |
| | | * @param {IssuerLayer} layer layer |
| | | * @returns {Omit<ExternalItemObject, "byLayer">} result |
| | |
| | | |
| | | class ExternalModuleFactoryPlugin { |
| | | /** |
| | | * @param {ExternalsType} type default external type |
| | | * Creates an instance of ExternalModuleFactoryPlugin. |
| | | * @param {ExternalsType | ((dependency: Dependency) => ExternalsType)} type default external type |
| | | * @param {Externals} externals externals config |
| | | */ |
| | | constructor(type, externals) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {NormalModuleFactory} normalModuleFactory the normal module factory |
| | | * @returns {void} |
| | | */ |
| | |
| | | /** @typedef {(err?: Error | null, externalModule?: ExternalModule) => void} HandleExternalCallback */ |
| | | |
| | | /** |
| | | * Processes the provided value. |
| | | * @param {ExternalValue} value the external config |
| | | * @param {ExternalsType | undefined} type type of external |
| | | * @param {HandleExternalCallback} callback callback |
| | |
| | | } |
| | | } |
| | | |
| | | const resolvedType = type || globalType; |
| | | const defaultType = |
| | | typeof globalType === "function" |
| | | ? globalType(dependency) |
| | | : globalType; |
| | | const resolvedType = type || defaultType; |
| | | |
| | | // TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals? |
| | | /** @type {DependencyMeta | undefined} */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Processes the provided external. |
| | | * @param {Externals} externals externals config |
| | | * @param {HandleExternalCallback} callback callback |
| | | * @returns {void} |
| | |
| | | /** @type {boolean | undefined} */ |
| | | let asyncFlag; |
| | | /** |
| | | * Handle externals and callback. |
| | | * @param {(Error | null)=} err err |
| | | * @param {ExternalModule=} module module |
| | | * @returns {void} |
| | |
| | | } |
| | | } else if (typeof externals === "function") { |
| | | /** |
| | | * Processes the provided err. |
| | | * @param {Error | null | undefined} err err |
| | | * @param {ExternalValue=} value value |
| | | * @param {ExternalsType=} type type |