WXL
3 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/enhanced-resolve/lib/ResolverFactory.js
@@ -34,6 +34,7 @@
const SymlinkPlugin = require("./SymlinkPlugin");
const SyncAsyncFileSystemDecorator = require("./SyncAsyncFileSystemDecorator");
const TryNextPlugin = require("./TryNextPlugin");
const TsconfigPathsPlugin = require("./TsconfigPathsPlugin");
const UnsafeCachePlugin = require("./UnsafeCachePlugin");
const UseFilePlugin = require("./UseFilePlugin");
const { PathType, getType } = require("./util/path");
@@ -50,9 +51,16 @@
/** @typedef {string | string[] | false} AliasOptionNewRequest */
/** @typedef {{ [k: string]: AliasOptionNewRequest }} AliasOptions */
/** @typedef {{ [k: string]: string|string[] }} ExtensionAliasOptions */
/** @typedef {{ [k: string]: string | string[] }} ExtensionAliasOptions */
/** @typedef {false | 0 | "" | null | undefined} Falsy */
/** @typedef {{apply: (resolver: Resolver) => void} | ((this: Resolver, resolver: Resolver) => void) | Falsy} Plugin */
/** @typedef {{ apply: (resolver: Resolver) => void } | ((this: Resolver, resolver: Resolver) => void) | Falsy} Plugin */
/**
 * @typedef {object} TsconfigOptions
 * @property {string=} configFile A relative path to the tsconfig file based on cwd, or an absolute path of tsconfig file
 * @property {string[] | "auto"=} references References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths
 * @property {string=} baseUrl Override baseUrl from tsconfig.json. If provided, this value will be used instead of the baseUrl in the tsconfig file
 */
/**
 * @typedef {object} UserResolveOptions
@@ -73,17 +81,18 @@
 * @property {boolean=} symlinks Resolve symlinks to their symlinked location
 * @property {Resolver=} resolver A prepared Resolver to which the plugins are attached
 * @property {string[] | string=} modules A list of directories to resolve modules from, can be absolute path or folder name
 * @property {(string | string[] | {name: string | string[], forceRelative: boolean})[]=} mainFields A list of main fields in description files
 * @property {(string | string[] | { name: string | string[], forceRelative: boolean })[]=} mainFields A list of main fields in description files
 * @property {string[]=} mainFiles A list of main files in directories
 * @property {Plugin[]=} plugins A list of additional resolve plugins which should be applied
 * @property {PnpApi | null=} pnpApi A PnP API that should be used - null is "never", undefined is "auto"
 * @property {string[]=} roots A list of root paths
 * @property {boolean=} fullySpecified The request is already fully specified and no extensions or directories are resolved for it
 * @property {boolean=} resolveToContext Resolve to a context instead of a file
 * @property {(string|RegExp)[]=} restrictions A list of resolve restrictions
 * @property {(string | RegExp)[]=} restrictions A list of resolve restrictions
 * @property {boolean=} useSyncFileSystemCalls Use only the sync constraints of the file system calls
 * @property {boolean=} preferRelative Prefer to resolve module requests as relative requests before falling back to modules
 * @property {boolean=} preferAbsolute Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots
 * @property {string | boolean | TsconfigOptions=} tsconfig TypeScript config file path or config object with configFile and references
 */
/**
@@ -104,7 +113,7 @@
 * @property {Cache | false} unsafeCache unsafe cache
 * @property {boolean} symlinks symlinks
 * @property {Resolver=} resolver resolver
 * @property {Array<string | string[]>} modules modules
 * @property {(string | string[])[]} modules modules
 * @property {{ name: string[], forceRelative: boolean }[]} mainFields main fields
 * @property {Set<string>} mainFiles main files
 * @property {Plugin[]} plugins plugins
@@ -115,6 +124,7 @@
 * @property {Set<string | RegExp>} restrictions restrictions
 * @property {boolean} preferRelative prefer relative
 * @property {boolean} preferAbsolute prefer absolute
 * @property {string | boolean | TsconfigOptions} tsconfig tsconfig file path or config object
 */
/**
@@ -124,7 +134,7 @@
function processPnpApiOption(option) {
   if (
      option === undefined &&
      /** @type {NodeJS.ProcessVersions & {pnp: string}} */ versions.pnp
      /** @type {NodeJS.ProcessVersions & { pnp: string }} */ versions.pnp
   ) {
      const _findPnpApi =
         /** @type {(issuer: string) => PnpApi | null}} */
@@ -169,17 +179,17 @@
            return obj;
         })
      : /** @type {Array<AliasOptionEntry>} */ (alias) || [];
      : /** @type {AliasOptionEntry[]} */ (alias) || [];
}
/**
 * Merging filtered elements
 * @param {string[]} array source array
 * @param {(item: string) => boolean} filter predicate
 * @returns {Array<string | string[]>} merge result
 * @returns {(string | string[])[]} merge result
 */
function mergeFilteredToArray(array, filter) {
   /** @type {Array<string | string[]>} */
   /** @type {(string | string[])[]} */
   const result = [];
   const set = new Set(array);
@@ -294,6 +304,8 @@
      preferRelative: options.preferRelative || false,
      preferAbsolute: options.preferAbsolute || false,
      restrictions: new Set(options.restrictions),
      tsconfig:
         typeof options.tsconfig === "undefined" ? false : options.tsconfig,
   };
}
@@ -332,6 +344,7 @@
      resolver: customResolver,
      restrictions,
      roots,
      tsconfig,
   } = normalizedOptions;
   const plugins = [...userPlugins];
@@ -379,22 +392,7 @@
      { source: "resolve", resolveOptions: { fullySpecified } },
      { source: "internal-resolve", resolveOptions: { fullySpecified: false } },
   ]) {
      if (unsafeCache) {
         plugins.push(
            new UnsafeCachePlugin(
               source,
               cachePredicate,
               /** @type {import("./UnsafeCachePlugin").Cache} */ (unsafeCache),
               cacheWithContext,
               `new-${source}`,
            ),
         );
         plugins.push(
            new ParsePlugin(`new-${source}`, resolveOptions, "parsed-resolve"),
         );
      } else {
         plugins.push(new ParsePlugin(source, resolveOptions, "parsed-resolve"));
      }
      plugins.push(new ParsePlugin(source, resolveOptions, "parsed-resolve"));
   }
   // parsed-resolve
@@ -409,17 +407,31 @@
   plugins.push(new NextPlugin("after-parsed-resolve", "described-resolve"));
   // described-resolve
   plugins.push(new NextPlugin("described-resolve", "raw-resolve"));
   if (unsafeCache) {
      plugins.push(
         new UnsafeCachePlugin(
            "described-resolve",
            cachePredicate,
            /** @type {import("./UnsafeCachePlugin").Cache} */ (unsafeCache),
            cacheWithContext,
            "raw-resolve",
         ),
      );
   } else {
      plugins.push(new NextPlugin("described-resolve", "raw-resolve"));
   }
   if (fallback.length > 0) {
      plugins.push(
         new AliasPlugin("described-resolve", fallback, "internal-resolve"),
      );
   }
   // raw-resolve
   if (alias.length > 0) {
      plugins.push(new AliasPlugin("raw-resolve", alias, "internal-resolve"));
   }
   if (tsconfig) {
      plugins.push(new TsconfigPathsPlugin(tsconfig));
   }
   for (const item of aliasFields) {
      plugins.push(new AliasFieldPlugin("raw-resolve", item, "internal-resolve"));
   }