WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/sharing/resolveMatchedConfigs.js
@@ -10,31 +10,40 @@
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Compilation").FileSystemDependencies} FileSystemDependencies */
/** @typedef {import("../ResolverFactory").ResolveOptionsWithDependencyType} ResolveOptionsWithDependencyType */
/**
 * Defines the matched configs item type used by this module.
 * @template T
 * @typedef {Map<string, T>} MatchedConfigsItem
 */
/**
 * Defines the matched configs type used by this module.
 * @template T
 * @typedef {object} MatchedConfigs
 * @property {Map<string, T>} resolved
 * @property {Map<string, T>} unresolved
 * @property {Map<string, T>} prefixed
 * @property {MatchedConfigsItem<T>} resolved
 * @property {MatchedConfigsItem<T>} unresolved
 * @property {MatchedConfigsItem<T>} prefixed
 */
/** @type {ResolveOptionsWithDependencyType} */
const RESOLVE_OPTIONS = { dependencyType: "esm" };
/**
 * Returns resolved matchers.
 * @template T
 * @param {Compilation} compilation the compilation
 * @param {[string, T][]} configs to be processed configs
 * @returns {Promise<MatchedConfigs<T>>} resolved matchers
 */
module.exports.resolveMatchedConfigs = (compilation, configs) => {
   /** @type {Map<string, T>} */
   /** @type {MatchedConfigsItem<T>} */
   const resolved = new Map();
   /** @type {Map<string, T>} */
   /** @type {MatchedConfigsItem<T>} */
   const unresolved = new Map();
   /** @type {Map<string, T>} */
   /** @type {MatchedConfigsItem<T>} */
   const prefixed = new Map();
   /** @type {ResolveContext} */
   const resolveContext = {
@@ -48,7 +57,7 @@
   return Promise.all(
      // eslint-disable-next-line array-callback-return
      configs.map(([request, config]) => {
         if (/^\.\.?(\/|$)/.test(request)) {
         if (/^\.\.?(?:\/|$)/.test(request)) {
            // relative request
            return new Promise((resolve) => {
               resolver.resolve(
@@ -71,7 +80,7 @@
                  }
               );
            });
         } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) {
         } else if (/^(?:\/|[a-z]:\\|\\\\)/i.test(request)) {
            // absolute path
            resolved.set(request, config);
         } else if (request.endsWith("/")) {
@@ -84,15 +93,15 @@
      })
   ).then(() => {
      compilation.contextDependencies.addAll(
         /** @type {LazySet<string>} */
         /** @type {FileSystemDependencies} */
         (resolveContext.contextDependencies)
      );
      compilation.fileDependencies.addAll(
         /** @type {LazySet<string>} */
         /** @type {FileSystemDependencies} */
         (resolveContext.fileDependencies)
      );
      compilation.missingDependencies.addAll(
         /** @type {LazySet<string>} */
         /** @type {FileSystemDependencies} */
         (resolveContext.missingDependencies)
      );
      return { resolved, unresolved, prefixed };