-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathindex.js
79 lines (63 loc) · 1.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* @flow */
import BaseResolver from './base-resolver.js';
import RegistryNpm from './registries/npm-resolver.js';
import RegistryYarn from './registries/yarn-resolver.js';
export const registries = {
npm: RegistryNpm,
yarn: RegistryYarn,
};
//
import ExoticGit from './exotics/git-resolver.js';
import ExoticTarball from './exotics/tarball-resolver.js';
import ExoticGitHub from './exotics/github-resolver.js';
import ExoticFile from './exotics/file-resolver.js';
import ExoticLink from './exotics/link-resolver.js';
import ExoticGitLab from './exotics/gitlab-resolver.js';
import ExoticGist from './exotics/gist-resolver.js';
import ExoticBitbucket from './exotics/bitbucket-resolver.js';
const exotics: Set<Class<$Subtype<BaseResolver>>> = new Set([
ExoticGit,
ExoticTarball,
ExoticGitHub,
ExoticFile,
ExoticLink,
ExoticGitLab,
ExoticGist,
ExoticBitbucket,
]);
export function getExoticResolver(pattern: string): ?Class<$Subtype<BaseResolver>> {
for (const Resolver of exotics) {
if (Resolver.isVersion(pattern)) {
return Resolver;
}
}
return null;
}
//
import type {Reporter} from '../reporters/index.js';
import {explodeHostedGitFragment} from './exotics/hosted-git-resolver.js';
export const hostedGit = {
github: ExoticGitHub,
gitlab: ExoticGitLab,
bitbucket: ExoticBitbucket,
};
export function hostedGitFragmentToGitUrl(fragment: string, reporter: Reporter): string {
for (const key in hostedGit) {
const Resolver = hostedGit[key];
if (Resolver.isVersion(fragment)) {
return Resolver.getGitHTTPUrl(explodeHostedGitFragment(fragment, reporter));
}
}
return fragment;
}
//
import ExoticRegistryResolver from './exotics/registry-resolver.js';
for (const key in registries) {
const RegistryResolver = registries[key];
exotics.add(
class extends ExoticRegistryResolver {
static protocol = key;
static factory = RegistryResolver;
},
);
}