* Main resolution method. * Returns the package path and subpath for the specifier, or undefined if * the specifier is not in the parent package's dependencies. * Throws ERR_PACKAGE_MAP_EXTERNAL_FILE if parentPath is not within any * mapped package. * @param {string} specifier * @p
(specifier, parentPath)
| 171 | * @returns {{packagePath: string, subpath: string}|undefined} |
| 172 | */ |
| 173 | resolve(specifier, parentPath) { |
| 174 | const parentKey = this.#getKeyForPath(parentPath); |
| 175 | |
| 176 | if (parentKey === null) { |
| 177 | throw new ERR_PACKAGE_MAP_EXTERNAL_FILE(specifier, parentPath, this.#configPath); |
| 178 | } |
| 179 | |
| 180 | const { packageName, subpath } = parsePackageName(specifier); |
| 181 | const parentEntry = this.#packages.get(parentKey); |
| 182 | |
| 183 | const targetKey = parentEntry.dependencies.get(packageName); |
| 184 | if (targetKey === undefined) { |
| 185 | // Package not in parent's dependencies - let the caller throw the appropriate error |
| 186 | return undefined; |
| 187 | } |
| 188 | |
| 189 | const targetEntry = this.#packages.get(targetKey); |
| 190 | if (!targetEntry) { |
| 191 | throw new ERR_PACKAGE_MAP_KEY_NOT_FOUND(targetKey, this.#configPath); |
| 192 | } |
| 193 | |
| 194 | return { packagePath: targetEntry.path, subpath }; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /** |
no test coverage detected