(specifier, context, nextResolve)
| 39 | |
| 40 | /** @type {import('module').ResolveHook} */ |
| 41 | export const resolve = async (specifier, context, nextResolve) => { |
| 42 | // True when it's a non-module import without explicit extensions. |
| 43 | const isNonModuleExtensionlessImport = |
| 44 | nonModuleImportRe.test(specifier) && !explicitExtensionRe.test(specifier); |
| 45 | const pathMappings = !nonModuleImportRe.test(specifier) ? pathMappingMatcher(specifier) : []; |
| 46 | |
| 47 | // If it's neither path mapped, nor an extension-less import that may be fixed up, exit early. |
| 48 | if (!isNonModuleExtensionlessImport && pathMappings.length === 0) { |
| 49 | return nextResolve(specifier, context); |
| 50 | } |
| 51 | |
| 52 | if (pathMappings.length > 0) { |
| 53 | for (const mapping of pathMappings) { |
| 54 | const res = await resolve(mapping, context, nextResolve).catch(() => null); |
| 55 | if (res !== null) { |
| 56 | return res; |
| 57 | } |
| 58 | } |
| 59 | } else { |
| 60 | const specifiers = [ |
| 61 | `${specifier}.js`, |
| 62 | `${specifier}/index.js`, |
| 63 | // Legacy variants for the `zone.js` variant using still `ts_library`. |
| 64 | // TODO(rules_js migration): Remove this. |
| 65 | `${specifier}.mjs`, |
| 66 | `${specifier}/index.mjs`, |
| 67 | ]; |
| 68 | for (const specifier of specifiers) { |
| 69 | try { |
| 70 | return await nextResolve(specifier, context); |
| 71 | } catch {} |
| 72 | } |
| 73 | } |
| 74 | return nextResolve(specifier, context); |
| 75 | }; |
no outgoing calls
no test coverage detected