| | |
| | | |
| | | /** @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 = { |
| | |
| | | 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( |
| | |
| | | } |
| | | ); |
| | | }); |
| | | } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) { |
| | | } else if (/^(?:\/|[a-z]:\\|\\\\)/i.test(request)) { |
| | | // absolute path |
| | | resolved.set(request, config); |
| | | } else if (request.endsWith("/")) { |
| | |
| | | }) |
| | | ).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 }; |