* Resolves a package specifier to a URL. * @param {string} specifier - The package specifier to resolve. * @param {string | URL | undefined} base - The base URL to use for resolution. * @param {Set } conditions - An object containing the conditions for resolution. * @returns {URL} - The r
(specifier, base, conditions)
| 760 | * @returns {URL} - The resolved URL. |
| 761 | */ |
| 762 | function packageResolve(specifier, base, conditions) { |
| 763 | // TODO(@anonrig): Move this to a C++ function. |
| 764 | if (BuiltinModule.canBeRequiredWithoutScheme(specifier)) { |
| 765 | return new URL('node:' + specifier); |
| 766 | } |
| 767 | |
| 768 | let packageJSONUrl, packageJSONPath, packageSubpath; |
| 769 | |
| 770 | if (hasPackageMap()) { |
| 771 | // Package map is enabled - use it exclusively |
| 772 | const parentPath = fileURLToPath(base); |
| 773 | const mapped = packageMapResolve(specifier, parentPath); |
| 774 | if (mapped === undefined) { |
| 775 | throw new ERR_MODULE_NOT_FOUND(specifier, fileURLToPath(base), null); |
| 776 | } |
| 777 | const { packagePath, subpath } = mapped; |
| 778 | packageJSONPath = join(packagePath, 'package.json'); |
| 779 | packageJSONUrl = pathToFileURL(packageJSONPath); |
| 780 | packageSubpath = subpath; |
| 781 | } else { |
| 782 | // Standard node_modules resolution |
| 783 | ({ packageJSONUrl, packageJSONPath, packageSubpath } = |
| 784 | packageJsonReader.getPackageJSONURL(specifier, base)); |
| 785 | } |
| 786 | |
| 787 | const packageConfig = packageJsonReader.read(packageJSONPath, { |
| 788 | __proto__: null, specifier, base, isESM: true, |
| 789 | }); |
| 790 | |
| 791 | if (packageConfig.exports != null) { |
| 792 | return packageExportsResolve( |
| 793 | packageJSONUrl, packageSubpath, packageConfig, base, conditions); |
| 794 | } |
| 795 | if (packageSubpath === '.') { |
| 796 | return legacyMainResolve(packageJSONUrl, packageConfig, base); |
| 797 | } |
| 798 | |
| 799 | return new URL(packageSubpath, packageJSONUrl); |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Checks if a specifier is a bare specifier. |
no test coverage detected
searching dependent graphs…