diff --git a/.yarn/versions/34906c89.yml b/.yarn/versions/34906c89.yml new file mode 100644 index 000000000000..f198b962fb44 --- /dev/null +++ b/.yarn/versions/34906c89.yml @@ -0,0 +1,24 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/plugin-npm": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-pack" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/plugin-workspace-tools" + - "@yarnpkg/builder" + - "@yarnpkg/core" + - "@yarnpkg/doctor" diff --git a/packages/plugin-npm/sources/NpmTarballResolver.ts b/packages/plugin-npm/sources/NpmTarballResolver.ts new file mode 100644 index 000000000000..14063a3b8654 --- /dev/null +++ b/packages/plugin-npm/sources/NpmTarballResolver.ts @@ -0,0 +1,49 @@ +import {Descriptor, Locator, MinimalResolveOptions, ResolveOptions, Resolver, Package} from '@yarnpkg/core'; +import {structUtils} from '@yarnpkg/core'; + +import {PROTOCOL} from './constants'; + +export class NpmTarballResolver implements Resolver { + supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) { + if (!descriptor.range.startsWith(PROTOCOL)) + return false; + + const {params} = structUtils.parseRange(descriptor.range); + if (params === null || typeof params.__archiveUrl !== `string`) + return false; + + return true; + } + + supportsLocator(locator: Locator, opts: MinimalResolveOptions) { + // Once transformed into locators, the descriptors are resolved by the NpmSemverResolver + return false; + } + + shouldPersistResolution(locator: Locator, opts: MinimalResolveOptions): never { + // Once transformed into locators, the descriptors are resolved by the NpmSemverResolver + throw new Error(`Unreachable`); + } + + bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) { + return descriptor; + } + + getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) { + return {}; + } + + async getCandidates(descriptor: Descriptor, dependencies: Record, opts: ResolveOptions) { + return [structUtils.convertDescriptorToLocator(descriptor)]; + } + + async getSatisfying(descriptor: Descriptor, dependencies: Record, locators: Array, opts: ResolveOptions) { + const baseLocator = structUtils.convertDescriptorToLocator(descriptor); + return {locators: locators.filter(locator => structUtils.areLocatorsEqual(locator, baseLocator)), sorted: false}; + } + + resolve(locator: Locator, opts: ResolveOptions): never { + // Once transformed into locators, the descriptors are resolved by the NpmSemverResolver + throw new Error(`Unreachable`); + } +} diff --git a/packages/plugin-npm/sources/index.ts b/packages/plugin-npm/sources/index.ts index 64a60d2885a0..e94724bcca4f 100644 --- a/packages/plugin-npm/sources/index.ts +++ b/packages/plugin-npm/sources/index.ts @@ -5,6 +5,7 @@ import {NpmRemapResolver} from './NpmRemapR import {NpmSemverFetcher} from './NpmSemverFetcher'; import {NpmSemverResolver} from './NpmSemverResolver'; import {NpmTagResolver} from './NpmTagResolver'; +import {NpmTarballResolver} from './NpmTarballResolver'; import * as npmConfigUtils from './npmConfigUtils'; import * as npmHttpUtils from './npmHttpUtils'; import * as npmPublishUtils from './npmPublishUtils'; @@ -132,6 +133,7 @@ const plugin: Plugin = { NpmRemapResolver, NpmSemverResolver, NpmTagResolver, + NpmTarballResolver, ], };