1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ProtocolResolver = exports.TAG_REGEXP = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const semver_1 = tslib_1.__importDefault(require("semver"));
|
6 | const semverUtils = tslib_1.__importStar(require("./semverUtils"));
|
7 | const structUtils = tslib_1.__importStar(require("./structUtils"));
|
8 | exports.TAG_REGEXP = /^(?!v)[a-z0-9-.]+$/i;
|
9 | class ProtocolResolver {
|
10 | supportsDescriptor(descriptor, opts) {
|
11 | if (semverUtils.validRange(descriptor.range))
|
12 | return true;
|
13 | if (exports.TAG_REGEXP.test(descriptor.range))
|
14 | return true;
|
15 | return false;
|
16 | }
|
17 | supportsLocator(locator, opts) {
|
18 | if (semver_1.default.valid(locator.reference))
|
19 | return true;
|
20 | if (exports.TAG_REGEXP.test(locator.reference))
|
21 | return true;
|
22 | return false;
|
23 | }
|
24 | shouldPersistResolution(locator, opts) {
|
25 | return opts.resolver.shouldPersistResolution(this.forwardLocator(locator, opts), opts);
|
26 | }
|
27 | bindDescriptor(descriptor, fromLocator, opts) {
|
28 | return opts.resolver.bindDescriptor(this.forwardDescriptor(descriptor, opts), fromLocator, opts);
|
29 | }
|
30 | getResolutionDependencies(descriptor, opts) {
|
31 | return opts.resolver.getResolutionDependencies(this.forwardDescriptor(descriptor, opts), opts);
|
32 | }
|
33 | async getCandidates(descriptor, dependencies, opts) {
|
34 | return await opts.resolver.getCandidates(this.forwardDescriptor(descriptor, opts), dependencies, opts);
|
35 | }
|
36 | async getSatisfying(descriptor, references, opts) {
|
37 | return await opts.resolver.getSatisfying(this.forwardDescriptor(descriptor, opts), references, opts);
|
38 | }
|
39 | async resolve(locator, opts) {
|
40 | const pkg = await opts.resolver.resolve(this.forwardLocator(locator, opts), opts);
|
41 | return structUtils.renamePackage(pkg, locator);
|
42 | }
|
43 | forwardDescriptor(descriptor, opts) {
|
44 | return structUtils.makeDescriptor(descriptor, `${opts.project.configuration.get(`defaultProtocol`)}${descriptor.range}`);
|
45 | }
|
46 | forwardLocator(locator, opts) {
|
47 | return structUtils.makeLocator(locator, `${opts.project.configuration.get(`defaultProtocol`)}${locator.reference}`);
|
48 | }
|
49 | }
|
50 | exports.ProtocolResolver = ProtocolResolver;
|