* Resolves a module specifier to a URL. * @param {string} specifier - The module specifier to resolve. * @param {string | URL | undefined} base - The base URL to resolve against. * @param {Set } conditions - An object containing environment conditions. * @param {boolean} preserveSymlinks
(specifier, base, conditions, preserveSymlinks)
| 843 | * @returns {URL} |
| 844 | */ |
| 845 | function moduleResolve(specifier, base, conditions, preserveSymlinks) { |
| 846 | const protocol = typeof base === 'string' ? |
| 847 | StringPrototypeSlice(base, 0, StringPrototypeIndexOf(base, ':') + 1) : |
| 848 | base.protocol; |
| 849 | const isData = protocol === 'data:'; |
| 850 | // Order swapped from spec for minor perf gain. |
| 851 | // Ok since relative URLs cannot parse as URLs. |
| 852 | let resolved; |
| 853 | if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) { |
| 854 | try { |
| 855 | resolved = new URL(specifier, base); |
| 856 | } catch (cause) { |
| 857 | const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base); |
| 858 | setOwnProperty(error, 'cause', cause); |
| 859 | throw error; |
| 860 | } |
| 861 | } else if (protocol === 'file:' && specifier[0] === '#') { |
| 862 | resolved = packageImportsResolve(specifier, base, conditions); |
| 863 | } else { |
| 864 | const url = URLParse(specifier); |
| 865 | if (url !== null) { |
| 866 | resolved = url; |
| 867 | } else { |
| 868 | if (isData && !BuiltinModule.canBeRequiredWithoutScheme(specifier)) { |
| 869 | const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base); |
| 870 | setOwnProperty(error, 'cause', new ERR_INVALID_URL(specifier)); |
| 871 | throw error; |
| 872 | } |
| 873 | resolved = packageResolve(specifier, base, conditions); |
| 874 | } |
| 875 | } |
| 876 | if (resolved.protocol !== 'file:') { |
| 877 | return resolved; |
| 878 | } |
| 879 | return finalizeResolution(resolved, base, preserveSymlinks); |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Try to resolve an import as a CommonJS module. |
no test coverage detected
searching dependent graphs…