(exports: unknown, subpath: string)
| 656 | } |
| 657 | |
| 658 | function getPackageExportMatch(exports: unknown, subpath: string): PackageExportMatch | undefined { |
| 659 | if (!isRecord(exports)) { |
| 660 | return subpath === "." ? { key: ".", value: exports, star: null, specificity: 1, prefixLength: 1 } : undefined |
| 661 | } |
| 662 | if (Object.hasOwn(exports, subpath)) { |
| 663 | return { |
| 664 | key: subpath, |
| 665 | value: exports[subpath], |
| 666 | star: null, |
| 667 | specificity: Number.MAX_SAFE_INTEGER, |
| 668 | prefixLength: subpath.length |
| 669 | } |
| 670 | } |
| 671 | const matches: Array<PackageExportMatch> = [] |
| 672 | for (const [key, value] of Object.entries(exports)) { |
| 673 | const starIndex = key.indexOf("*") |
| 674 | if (!key.startsWith(".") || starIndex === -1) { |
| 675 | continue |
| 676 | } |
| 677 | const prefix = key.slice(0, starIndex) |
| 678 | const suffix = key.slice(starIndex + 1) |
| 679 | if (!subpath.startsWith(prefix) || !subpath.endsWith(suffix)) { |
| 680 | continue |
| 681 | } |
| 682 | matches.push({ |
| 683 | key, |
| 684 | value, |
| 685 | star: subpath.slice(prefix.length, subpath.length - suffix.length), |
| 686 | specificity: prefix.length + suffix.length, |
| 687 | prefixLength: prefix.length |
| 688 | }) |
| 689 | } |
| 690 | return matches.sort((a, b) => |
| 691 | b.specificity - a.specificity || b.prefixLength - a.prefixLength || b.key.length - a.key.length |
| 692 | )[0] |
| 693 | } |
| 694 | |
| 695 | function packageExportTargetMatches(value: unknown, star: string | null, expectedTarget: string): boolean { |
| 696 | if (typeof value === "string") { |
no test coverage detected