(packageSpecifier, parentURL)
| 731 | return resolved; |
| 732 | } |
| 733 | PACKAGE_RESOLVE(packageSpecifier, parentURL) { |
| 734 | let packageName; |
| 735 | if (packageSpecifier === "") |
| 736 | this.throwInvalidModuleSpecifierError(); |
| 737 | // If packageSpecifier is a Node.js builtin module name, then |
| 738 | // Return the string "node:" concatenated with packageSpecifier. |
| 739 | if (packageSpecifier.startsWith("embedded:")) |
| 740 | return packageSpecifier; |
| 741 | if (packageSpecifier.startsWith("moddable:")) |
| 742 | return packageSpecifier; |
| 743 | if (this.builtins.get("moddable:" + packageSpecifier)) |
| 744 | return "moddable:" + packageSpecifier; |
| 745 | if (!packageSpecifier.startsWith("@")) { |
| 746 | let slash = packageSpecifier.indexOf('/'); |
| 747 | packageName = (slash >= 0) ? packageSpecifier.slice(0, slash) : packageSpecifier; |
| 748 | } |
| 749 | else { |
| 750 | let slash = packageSpecifier.indexOf('/'); |
| 751 | if (slash < 0) |
| 752 | this.throwInvalidModuleSpecifierError(); |
| 753 | slash = packageSpecifier.indexOf('/', slash + 1); |
| 754 | packageName = (slash >= 0) ? packageSpecifier.slice(0, slash) : packageSpecifier; |
| 755 | } |
| 756 | if (packageName.startsWith(".") || (packageName.indexOf("\\") >= 0) || (packageName.indexOf("%") >= 0)) |
| 757 | this.throwInvalidModuleSpecifierError(); |
| 758 | let packageSubpath = '.' + packageSpecifier.slice(packageName.length); |
| 759 | if (packageSubpath.endsWith("/")) |
| 760 | this.throwInvalidModuleSpecifierError(); |
| 761 | let selfURL = this.PACKAGE_SELF_RESOLVE(packageName, packageSubpath, parentURL); |
| 762 | if (selfURL !== undefined) |
| 763 | return selfURL; |
| 764 | while (parentURL != "file:///") { |
| 765 | //@@ let packageURL = this.mergeURL("./node_modules/" + packageSpecifier, parentURL); |
| 766 | let packageURL = this.mergeURL("./node_modules/" + packageName, parentURL); |
| 767 | parentURL = this.getParentURL(parentURL); |
| 768 | if (this.urlToDirectoryPath(packageURL)) { |
| 769 | let pjson = this.READ_PACKAGE_JSON(packageURL); |
| 770 | if (pjson !== null) { |
| 771 | if ((pjson.exports !== null) & (pjson.exports !== undefined)) |
| 772 | return this.PACKAGE_EXPORTS_RESOLVE(packageURL, packageSubpath, pjson.exports, defaultConditions); |
| 773 | if (packageSubpath == ".") { |
| 774 | if (typeof pjson.main === "string") |
| 775 | return this.mergeURL(pjson.main, packageURL + "/package.json"); |
| 776 | } |
| 777 | else |
| 778 | return this.mergeURL(packageSubpath, packageURL + "/package.json"); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | this.throwModuleNotFoundError(); |
| 783 | } |
| 784 | PACKAGE_SELF_RESOLVE(packageName, packageSubpath, parentURL) { |
| 785 | let packageURL = this.LOOKUP_PACKAGE_SCOPE(parentURL); |
| 786 | if (packageURL === null) |
no test coverage detected