|
| 1 | +import {Descriptor, Locator, MinimalResolveOptions, ResolveOptions, Resolver, Package} from '@yarnpkg/core'; |
| 2 | +import {structUtils} from '@yarnpkg/core'; |
| 3 | + |
| 4 | +import {PROTOCOL} from './constants'; |
| 5 | + |
| 6 | +export class NpmTarballResolver implements Resolver { |
| 7 | + supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) { |
| 8 | + if (!descriptor.range.startsWith(PROTOCOL)) |
| 9 | + return false; |
| 10 | + |
| 11 | + const {params} = structUtils.parseRange(descriptor.range); |
| 12 | + if (params === null || typeof params.__archiveUrl !== `string`) |
| 13 | + return false; |
| 14 | + |
| 15 | + return true; |
| 16 | + } |
| 17 | + |
| 18 | + supportsLocator(locator: Locator, opts: MinimalResolveOptions) { |
| 19 | + // Once transformed into locators, the descriptors are resolved by the NpmSemverResolver |
| 20 | + return false; |
| 21 | + } |
| 22 | + |
| 23 | + shouldPersistResolution(locator: Locator, opts: MinimalResolveOptions): never { |
| 24 | + // Once transformed into locators, the descriptors are resolved by the NpmSemverResolver |
| 25 | + throw new Error(`Unreachable`); |
| 26 | + } |
| 27 | + |
| 28 | + bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) { |
| 29 | + return descriptor; |
| 30 | + } |
| 31 | + |
| 32 | + getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) { |
| 33 | + return {}; |
| 34 | + } |
| 35 | + |
| 36 | + async getCandidates(descriptor: Descriptor, dependencies: Record<string, Package>, opts: ResolveOptions) { |
| 37 | + return [structUtils.convertDescriptorToLocator(descriptor)]; |
| 38 | + } |
| 39 | + |
| 40 | + async getSatisfying(descriptor: Descriptor, dependencies: Record<string, Package>, locators: Array<Locator>, opts: ResolveOptions) { |
| 41 | + const baseLocator = structUtils.convertDescriptorToLocator(descriptor); |
| 42 | + return {locators: locators.filter(locator => structUtils.areLocatorsEqual(locator, baseLocator)), sorted: false}; |
| 43 | + } |
| 44 | + |
| 45 | + resolve(locator: Locator, opts: ResolveOptions): never { |
| 46 | + // Once transformed into locators, the descriptors are resolved by the NpmSemverResolver |
| 47 | + throw new Error(`Unreachable`); |
| 48 | + } |
| 49 | +} |
0 commit comments