* Resolves a bare specifier from the `node_modules` directory of the current working directory. * @param {string} specifier module specifier * @param {Error & { code?: string }} err error thrown by the next resolve hook * @returns {{ url: string, shortCircuit: boolean }} resolution result
(specifier, err)
| 8 | * @returns {{ url: string, shortCircuit: boolean }} resolution result |
| 9 | */ |
| 10 | function resolveFromCwd(specifier, err) { |
| 11 | if (err.code === "ERR_MODULE_NOT_FOUND" && !specifier.startsWith(".")) { |
| 12 | const baseDir = join(process.cwd(), "node_modules/"); |
| 13 | const resolved = join(baseDir, specifier, "index.js"); |
| 14 | |
| 15 | return { |
| 16 | url: pathToFileURL(resolved).href, |
| 17 | shortCircuit: true, |
| 18 | }; |
| 19 | } |
| 20 | |
| 21 | throw err; |
| 22 | } |
| 23 | |
| 24 | // Asynchronous hook, used with `module.register()` |
| 25 | export async function resolve(specifier, context, nextResolve) { |
no outgoing calls
no test coverage detected