forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackends.ts
223 lines (210 loc) · 6.68 KB
/
backends.ts
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import is from '@sindresorhus/is';
import { regEx } from '../../../util/regex';
import { CrateDatasource } from '../../datasource/crate';
import { GitRefsDatasource } from '../../datasource/git-refs';
import { GitTagsDatasource } from '../../datasource/git-tags';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { GoDatasource } from '../../datasource/go';
import { NpmDatasource } from '../../datasource/npm';
import { NugetDatasource } from '../../datasource/nuget';
import { PypiDatasource } from '../../datasource/pypi';
import { normalizePythonDepName } from '../../datasource/pypi/common';
import { RubygemsDatasource } from '../../datasource/rubygems';
import type { PackageDependency } from '../types';
import type { MiseToolOptionsSchema } from './schema';
export type BackendToolingConfig = Omit<PackageDependency, 'depName'> &
Required<
| Pick<PackageDependency, 'packageName' | 'datasource'>
| Pick<PackageDependency, 'packageName' | 'skipReason'>
>;
/**
* Create a tooling config for aqua backend
* @link https://mise.jdx.dev/dev-tools/backends/aqua.html
*/
export function createAquaToolConfig(
name: string,
version: string,
): BackendToolingConfig {
// mise supports http aqua package type but we cannot determine it from the tool name
// An error will be thrown afterwards if the package type is http
// ref: https://github.com/jdx/mise/blob/d1b9749d8f3e13ef705c1ea471d96c5935b79136/src/aqua/aqua_registry.rs#L39-L45
return {
packageName: name,
datasource: GithubTagsDatasource.id,
// Trim the leading 'v' from both the current and extracted version
currentValue: version.replace(/^v/, ''),
extractVersion: '^v?(?<version>.+)',
};
}
const cargoGitVersionRegex = regEx(/^(?<type>tag|branch|rev):(?<version>.+)$/);
/**
* Create a tooling config for cargo backend
* @link https://mise.jdx.dev/dev-tools/backends/cargo.html
*/
export function createCargoToolConfig(
name: string,
version: string,
): BackendToolingConfig {
// Avoid narrowing the type of name to never
if (!(is.urlString as (value: unknown) => boolean)(name)) {
return {
packageName: name,
datasource: CrateDatasource.id,
};
}
// tag: branch: or rev: is required for git repository url
// e.g. branch:main, tag:0.1.0, rev:abcdef
const matchGroups = cargoGitVersionRegex.exec(version)?.groups;
if (is.undefined(matchGroups)) {
return {
packageName: name,
skipReason: 'invalid-version',
};
}
const { type, version: gitVersion } = matchGroups;
switch (type as 'tag' | 'branch' | 'rev') {
case 'tag':
return {
packageName: name,
datasource: GitTagsDatasource.id,
currentValue: gitVersion,
};
case 'branch':
return {
packageName: name,
skipReason: 'unsupported-version',
};
case 'rev':
return {
packageName: name,
datasource: GitRefsDatasource.id,
currentValue: gitVersion,
};
}
}
/**
* Create a tooling config for dotnet backend
* @link https://mise.jdx.dev/dev-tools/backends/dotnet.html
*/
export function createDotnetToolConfig(name: string): BackendToolingConfig {
return {
packageName: name,
datasource: NugetDatasource.id,
};
}
/**
* Create a tooling config for gem backend
* @link https://mise.jdx.dev/dev-tools/backends/gem.html
*/
export function createGemToolConfig(name: string): BackendToolingConfig {
return {
packageName: name,
datasource: RubygemsDatasource.id,
};
}
/**
* Create a tooling config for go backend
* @link https://mise.jdx.dev/dev-tools/backends/go.html
*/
export function createGoToolConfig(name: string): BackendToolingConfig {
return {
packageName: name,
datasource: GoDatasource.id,
};
}
/**
* Create a tooling config for npm backend
* @link https://mise.jdx.dev/dev-tools/backends/npm.html
*/
export function createNpmToolConfig(name: string): BackendToolingConfig {
return {
packageName: name,
datasource: NpmDatasource.id,
};
}
const pipxGitHubRegex = regEx(/^git\+https:\/\/github\.com\/(?<repo>.+)\.git$/);
/**
* Create a tooling config for pipx backend
* @link https://mise.jdx.dev/dev-tools/backends/pipx.html
*/
export function createPipxToolConfig(name: string): BackendToolingConfig {
const isGitSyntax = name.startsWith('git+');
// Does not support zip file url
// Avoid type narrowing to prevent type error
if (!isGitSyntax && (is.urlString as (value: unknown) => boolean)(name)) {
return {
packageName: name,
skipReason: 'unsupported-url',
};
}
if (isGitSyntax || name.includes('/')) {
let repoName: string | undefined;
if (isGitSyntax) {
repoName = pipxGitHubRegex.exec(name)?.groups?.repo;
// If the url is not a github repo, treat the version as a git ref
if (is.undefined(repoName)) {
return {
packageName: name.replace(/^git\+/g, '').replaceAll(/\.git$/g, ''),
datasource: GitRefsDatasource.id,
};
}
} else {
repoName = name;
}
return {
packageName: repoName,
datasource: GithubTagsDatasource.id,
};
}
return {
packageName: normalizePythonDepName(name),
datasource: PypiDatasource.id,
};
}
const spmGitHubRegex = regEx(/^https:\/\/github.com\/(?<repo>.+).git$/);
/**
* Create a tooling config for spm backend
* @link https://mise.jdx.dev/dev-tools/backends/spm.html
*/
export function createSpmToolConfig(name: string): BackendToolingConfig {
let repoName: string | undefined;
// Avoid type narrowing to prevent type error
if ((is.urlString as (value: unknown) => boolean)(name)) {
repoName = spmGitHubRegex.exec(name)?.groups?.repo;
// spm backend only supports github repos
if (!repoName) {
return {
packageName: name,
skipReason: 'unsupported-url',
};
}
}
return {
packageName: repoName ?? name,
datasource: GithubReleasesDatasource.id,
};
}
/**
* Create a tooling config for ubi backend
* @link https://mise.jdx.dev/dev-tools/backends/ubi.html
*/
export function createUbiToolConfig(
name: string,
version: string,
toolOptions: MiseToolOptionsSchema,
): BackendToolingConfig {
return {
packageName: name,
datasource: GithubReleasesDatasource.id,
// Trim the leading 'v' from both the current and extracted version
currentValue: version.replace(/^v/, ''),
// Filter versions by tag_regex if it is specified
// ref: https://mise.jdx.dev/dev-tools/backends/ubi.html#ubi-uses-weird-versions
extractVersion: `^v?(?<version>${
is.string(toolOptions.tag_regex)
? toolOptions.tag_regex.replace(/^\^?v?\??/, '')
: '.+'
})`,
};
}