* Resolves the exports for a given module path and request. * @param {string} nmPath The path to the module. * @param {string} request The request for the module. * @param {Set } conditions The conditions to use for resolution. * @returns {undefined|string}
(nmPath, request, conditions)
| 746 | * @returns {undefined|string} |
| 747 | */ |
| 748 | function resolveExports(nmPath, request, conditions) { |
| 749 | // The implementation's behavior is meant to mirror resolution in ESM. |
| 750 | const { 1: name, 2: expansion = '' } = |
| 751 | RegExpPrototypeExec(EXPORTS_PATTERN, request) || kEmptyObject; |
| 752 | if (!name) { return; } |
| 753 | const pkgPath = path.resolve(nmPath, name); |
| 754 | const pkg = _readPackage(pkgPath); |
| 755 | if (pkg.exists && pkg.exports != null) { |
| 756 | try { |
| 757 | const { packageExportsResolve } = require('internal/modules/esm/resolve'); |
| 758 | return finalizeEsmResolution(packageExportsResolve( |
| 759 | pathToFileURL(pkgPath + '/package.json'), '.' + expansion, pkg, null, |
| 760 | conditions), null, pkgPath); |
| 761 | } catch (e) { |
| 762 | if (e.code === 'ERR_MODULE_NOT_FOUND') { |
| 763 | throw createEsmNotFoundErr(request, pkgPath + '/package.json'); |
| 764 | } |
| 765 | throw e; |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * Get the absolute path to a module. |
no test coverage detected
searching dependent graphs…