forked from yarnpkg/yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-resolver.js
43 lines (33 loc) 路 1.26 KB
/
github-resolver.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
/* @flow */
import type {ExplodedFragment} from './hosted-git-resolver.js';
import HostedGitResolver from './hosted-git-resolver.js';
export default class GitHubResolver extends HostedGitResolver {
static protocol = 'github';
static hostname = 'github.com';
static isVersion(pattern: string): boolean {
// github proto
if (pattern.startsWith('github:')) {
return true;
}
// github shorthand
if (/^[^:@%/\s.-][^:@%/\s]*[/][^:@\s/%]+(?:#.*)?$/.test(pattern)) {
return true;
}
return false;
}
static getTarballUrl(parts: ExplodedFragment, hash: string): string {
return `https://codeload.github.com/${parts.user}/${parts.repo}/tar.gz/${hash}`;
}
static getGitSSHUrl(parts: ExplodedFragment): string {
return `git+ssh://git@github.com/${ parts.user }/${ parts.repo }.git`;
}
static getGitSSH(parts: ExplodedFragment): string {
return `git@github.com:${parts.user}/${parts.repo}.git`;
}
static getGitHTTPUrl(parts: ExplodedFragment): string {
return `https://github.com/${parts.user}/${parts.repo}.git`;
}
static getHTTPFileUrl(parts: ExplodedFragment, filename: string, commit: string): string {
return `https://raw.githubusercontent.com/${parts.user}/${parts.repo}/${commit}/${filename}`;
}
}