Skip to content

Commit a299b42

Browse files
committed
fix(plugin-npm): add resolver for converting locators with __archiveUrl
1 parent d63d411 commit a299b42

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

.yarn/versions/34906c89.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-npm": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-nm"
13+
- "@yarnpkg/plugin-npm-cli"
14+
- "@yarnpkg/plugin-pack"
15+
- "@yarnpkg/plugin-patch"
16+
- "@yarnpkg/plugin-pnp"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

packages/plugin-npm/sources/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {NpmRemapResolver} from './NpmRemapR
55
import {NpmSemverFetcher} from './NpmSemverFetcher';
66
import {NpmSemverResolver} from './NpmSemverResolver';
77
import {NpmTagResolver} from './NpmTagResolver';
8+
import {NpmTarballResolver} from './NpmTarballResolver';
89
import * as npmConfigUtils from './npmConfigUtils';
910
import * as npmHttpUtils from './npmHttpUtils';
1011
import * as npmPublishUtils from './npmPublishUtils';
@@ -132,6 +133,7 @@ const plugin: Plugin = {
132133
NpmRemapResolver,
133134
NpmSemverResolver,
134135
NpmTagResolver,
136+
NpmTarballResolver,
135137
],
136138
};
137139

0 commit comments

Comments
 (0)