({packageManager, binaryName, binaryVersion}: PackageManagerRequest, {cwd, args}: {cwd: string, args: Array<string>})
| 314 | } |
| 315 | |
| 316 | async executePackageManagerRequest({packageManager, binaryName, binaryVersion}: PackageManagerRequest, {cwd, args}: {cwd: string, args: Array<string>}): Promise<void> { |
| 317 | let fallbackLocator: Locator | LazyLocator = { |
| 318 | name: binaryName as SupportedPackageManagers, |
| 319 | reference: undefined as any, |
| 320 | }; |
| 321 | |
| 322 | let isTransparentCommand = false; |
| 323 | if (packageManager != null) { |
| 324 | const defaultVersion = binaryVersion || (() => this.getDefaultVersion(packageManager)); |
| 325 | const definition = this.config.definitions[packageManager]!; |
| 326 | |
| 327 | // If all leading segments match one of the patterns defined in the `transparent` |
| 328 | // key, we tolerate calling this binary even if the local project isn't explicitly |
| 329 | // configured for it, and we use the special default version if requested. |
| 330 | for (const transparentPath of definition.transparent.commands) { |
| 331 | if (transparentPath[0] === binaryName && transparentPath.slice(1).every((segment, index) => segment === args[index])) { |
| 332 | isTransparentCommand = true; |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | const fallbackReference = isTransparentCommand |
| 338 | ? definition.transparent.default ?? defaultVersion |
| 339 | : defaultVersion; |
| 340 | |
| 341 | fallbackLocator = { |
| 342 | name: packageManager, |
| 343 | reference: fallbackReference as string, |
| 344 | }; |
| 345 | } |
| 346 | |
| 347 | const descriptor = await this.findProjectSpec(cwd, fallbackLocator, {transparent: isTransparentCommand, binaryVersion}); |
| 348 | |
| 349 | if (binaryVersion) |
| 350 | descriptor.range = binaryVersion; |
| 351 | |
| 352 | const resolved = await this.resolveDescriptor(descriptor, {allowTags: true}); |
| 353 | if (resolved === null) |
| 354 | throw new UsageError(`Failed to successfully resolve '${descriptor.range}' to a valid ${descriptor.name} release`); |
| 355 | |
| 356 | const installSpec = await this.ensurePackageManager(resolved); |
| 357 | |
| 358 | return await corepackUtils.runVersion(resolved, installSpec, binaryName, args); |
| 359 | } |
| 360 | |
| 361 | async resolveDescriptor(descriptor: Descriptor, {allowTags = false, useCache = true}: {allowTags?: boolean, useCache?: boolean} = {}): Promise<Locator | null> { |
| 362 | if (!corepackUtils.isSupportedPackageManagerDescriptor(descriptor)) { |
no test coverage detected