(
cb: () => ReturnType<typeof resolve> | Awaited<ReturnType<typeof resolve>>
)
| 162 | // See: https://github.com/nodejs/node/discussions/41711 |
| 163 | // nodejs will likely implement a similar fallback. Till then, we can do our users a favor and fallback today. |
| 164 | async function entrypointFallback( |
| 165 | cb: () => ReturnType<typeof resolve> | Awaited<ReturnType<typeof resolve>> |
| 166 | ): ReturnType<typeof resolve> { |
| 167 | try { |
| 168 | const resolution = await cb(); |
| 169 | if ( |
| 170 | resolution?.url && |
| 171 | isProbablyEntrypoint(specifier, context.parentURL) |
| 172 | ) |
| 173 | rememberIsProbablyEntrypoint.add(resolution.url); |
| 174 | return resolution; |
| 175 | } catch (esmResolverError) { |
| 176 | if (!isProbablyEntrypoint(specifier, context.parentURL)) |
| 177 | throw esmResolverError; |
| 178 | try { |
| 179 | let cjsSpecifier = specifier; |
| 180 | // Attempt to convert from ESM file:// to CommonJS path |
| 181 | try { |
| 182 | if (specifier.startsWith('file://')) |
| 183 | cjsSpecifier = fileURLToPath(specifier); |
| 184 | } catch {} |
| 185 | const resolution = pathToFileURL( |
| 186 | createRequire(process.cwd()).resolve(cjsSpecifier) |
| 187 | ).toString(); |
| 188 | rememberIsProbablyEntrypoint.add(resolution); |
| 189 | rememberResolvedViaCommonjsFallback.add(resolution); |
| 190 | return { url: resolution, format: 'commonjs' }; |
| 191 | } catch (commonjsResolverError) { |
| 192 | throw esmResolverError; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return addShortCircuitFlag(async () => { |
| 198 | const parsed = parseUrl(specifier); |
no test coverage detected
searching dependent graphs…