Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-npm): add resolver for converting locators with __archiveUrl #6525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .yarn/versions/34906c89.yml
Original file line number Diff line number Diff line change
@@ -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"
49 changes: 49 additions & 0 deletions packages/plugin-npm/sources/NpmTarballResolver.ts
Original file line number Diff line number Diff line change
@@ -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<string, Package>, opts: ResolveOptions) {
return [structUtils.convertDescriptorToLocator(descriptor)];
}

async getSatisfying(descriptor: Descriptor, dependencies: Record<string, Package>, locators: Array<Locator>, 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`);
}
}
2 changes: 2 additions & 0 deletions packages/plugin-npm/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -132,6 +133,7 @@ const plugin: Plugin = {
NpmRemapResolver,
NpmSemverResolver,
NpmTagResolver,
NpmTarballResolver,
],
};

Expand Down
Loading