Skip to content

Commit 9e00fbc

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

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.yarn/versions/34906c89.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-npm": patch
Lines changed: 49 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {NpmTagResolver} from './NpmTagRes
88
import * as npmConfigUtils from './npmConfigUtils';
99
import * as npmHttpUtils from './npmHttpUtils';
1010
import * as npmPublishUtils from './npmPublishUtils';
11+
import { NpmTarballResolver } from './NpmTarballResolver';
1112

1213
export {npmConfigUtils};
1314
export {npmHttpUtils};
@@ -132,6 +133,7 @@ const plugin: Plugin = {
132133
NpmRemapResolver,
133134
NpmSemverResolver,
134135
NpmTagResolver,
136+
NpmTarballResolver,
135137
],
136138
};
137139

0 commit comments

Comments
 (0)