MCPcopy Index your code
hub / github.com/nodejs/node / resolveExports

Function resolveExports

lib/internal/modules/cjs/loader.js:748–768  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

746 * @returns {undefined|string}
747 */
748function 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.

Callers 1

loader.jsFile · 0.85

Calls 7

_readPackageFunction · 0.85
finalizeEsmResolutionFunction · 0.85
packageExportsResolveFunction · 0.85
createEsmNotFoundErrFunction · 0.85
requireFunction · 0.50
pathToFileURLFunction · 0.50
resolveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…