* The `resolve` method that gets attached to module-scope `require`. * @param {string} request * @param {Parameters [3]} options * @returns {string}
(request, options)
| 198 | * @returns {string} |
| 199 | */ |
| 200 | function resolve(request, options) { |
| 201 | validateString(request, 'request'); |
| 202 | const { resolveForCJSWithHooks } = lazyCJSLoader(); |
| 203 | // require.resolve() has different behaviors from the internal resolution used by |
| 204 | // Module._load: |
| 205 | // 1. When the request resolves to a non-existent built-in, it throws MODULE_NOT_FOUND |
| 206 | // instead of UNKNOWN_BUILTIN_MODULE. This is handled by resolveForCJSWithHooks. |
| 207 | // 2. If the request is a prefixed built-in, the returned value is also prefixed. This |
| 208 | // is handled below. |
| 209 | const { filename, url } = resolveForCJSWithHooks( |
| 210 | request, mod, /* isMain */ false, { |
| 211 | __proto__: null, |
| 212 | shouldSkipModuleHooks: false, |
| 213 | requireResolveOptions: options ?? {}, |
| 214 | }); |
| 215 | if (url === request && StringPrototypeStartsWith(request, 'node:')) { |
| 216 | return url; |
| 217 | } |
| 218 | return filename; |
| 219 | } |
| 220 | |
| 221 | require.resolve = resolve; |
| 222 |
no test coverage detected
searching dependent graphs…