WXL
3 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
node_modules/webpack/lib/ExternalModuleFactoryPlugin.js
@@ -17,20 +17,23 @@
/** @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
@@ -48,6 +51,7 @@
// 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
@@ -61,9 +65,11 @@
   "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
 */
@@ -72,6 +78,7 @@
const cache = new WeakMap();
/**
 * Returns result.
 * @param {ExternalItemObject} obj obj
 * @param {IssuerLayer} layer layer
 * @returns {Omit<ExternalItemObject, "byLayer">} result
@@ -96,7 +103,8 @@
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) {
@@ -105,6 +113,7 @@
   }
   /**
    * Applies the plugin by registering its hooks on the compiler.
    * @param {NormalModuleFactory} normalModuleFactory the normal module factory
    * @returns {void}
    */
@@ -121,6 +130,7 @@
            /** @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
@@ -159,7 +169,11 @@
                  }
               }
               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} */
@@ -208,6 +222,7 @@
            };
            /**
             * Processes the provided external.
             * @param {Externals} externals externals config
             * @param {HandleExternalCallback} callback callback
             * @returns {void}
@@ -223,6 +238,7 @@
                     /** @type {boolean | undefined} */
                     let asyncFlag;
                     /**
                      * Handle externals and callback.
                      * @param {(Error | null)=} err err
                      * @param {ExternalModule=} module module
                      * @returns {void}
@@ -255,6 +271,7 @@
                  }
               } else if (typeof externals === "function") {
                  /**
                   * Processes the provided err.
                   * @param {Error | null | undefined} err err
                   * @param {ExternalValue=} value value
                   * @param {ExternalsType=} type type