* Try to resolve using package map (if enabled via --experimental-package-map). * @param {string} request - The bare specifier * @param {Module} parent - The parent module * @param {Set } conditions - Export conditions * @returns {string|undefined}
(request, parent, conditions)
| 688 | * @returns {string|undefined} |
| 689 | */ |
| 690 | function tryPackageMapResolveCJS(request, parent, conditions) { |
| 691 | if (!hasPackageMap()) { return undefined; } |
| 692 | |
| 693 | const parentPath = trySelfParentPath(parent); |
| 694 | if (!parentPath) { return undefined; } |
| 695 | |
| 696 | const mapped = packageMapResolve(request, parentPath); |
| 697 | if (mapped === undefined) { |
| 698 | const requireStack = getRequireStack(parent); |
| 699 | const message = getRequireStackMessage(request, requireStack); |
| 700 | // eslint-disable-next-line no-restricted-syntax |
| 701 | const err = new Error(message); |
| 702 | setOwnProperty(err, 'code', 'MODULE_NOT_FOUND'); |
| 703 | setOwnProperty(err, 'requireStack', requireStack); |
| 704 | throw err; |
| 705 | } |
| 706 | |
| 707 | const { packagePath, subpath } = mapped; |
| 708 | |
| 709 | const packageJSONPath = path.resolve(packagePath, 'package.json'); |
| 710 | const pkg = packageJsonReader.read(packageJSONPath); |
| 711 | if (pkg.exports !== undefined) { |
| 712 | return resolveExpansion(subpath, packageJSONPath, pkg, parentPath, conditions); |
| 713 | } |
| 714 | |
| 715 | // No exports - try standard path resolution within the package |
| 716 | return Module._findPath(subpath, [packagePath], false, conditions); |
| 717 | } |
| 718 | |
| 719 | function resolveExpansion(expansion, pkgJsonPath, pkgData, parentPath, conditions) { |
| 720 | const pkgPath = path.dirname(pkgJsonPath); |
no test coverage detected
searching dependent graphs…