* Legacy CommonJS main resolution: * 1. let M = pkg_url + (json main field) * 2. TRY(M, M.js, M.json, M.node) * 3. TRY(M/index.js, M/index.json, M/index.node) * 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node) * 5. NOT_FOUND * @param {URL} packageJSONUrl * @param {import('typi
(packageJSONUrl, packageConfig, base)
| 194 | * @returns {URL} |
| 195 | */ |
| 196 | function legacyMainResolve(packageJSONUrl, packageConfig, base) { |
| 197 | assert(isURL(packageJSONUrl)); |
| 198 | const pkgPath = fileURLToPath(new URL('.', packageJSONUrl)); |
| 199 | |
| 200 | const baseStringified = isURL(base) ? base.href : base; |
| 201 | |
| 202 | const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified); |
| 203 | |
| 204 | const maybeMain = resolvedOption <= legacyMainResolveExtensionsIndexes.kResolvedByMainIndexNode ? |
| 205 | packageConfig.main || './' : ''; |
| 206 | const resolvedPath = resolve(pkgPath, maybeMain + legacyMainResolveExtensions[resolvedOption]); |
| 207 | const resolvedUrl = pathToFileURL(resolvedPath); |
| 208 | |
| 209 | emitLegacyIndexDeprecation(resolvedUrl, resolvedPath, pkgPath, base, packageConfig.main); |
| 210 | |
| 211 | return resolvedUrl; |
| 212 | } |
| 213 | |
| 214 | const encodedSepRegEx = /%2F|%5C/i; |
| 215 | /** |
no test coverage detected
searching dependent graphs…