-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathindex.ts
96 lines (84 loc) · 2.27 KB
/
index.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
import * as pep440 from '@renovatebot/pep440';
import type { RangeStrategy } from '../../../types/versioning';
import type { VersioningApi } from '../types';
import { getNewValue, isLessThanRange } from './range';
export const id = 'pep440';
export const displayName = 'PEP440';
export const urls = ['https://www.python.org/dev/peps/pep-0440/'];
export const supportsRanges = true;
export const supportedRangeStrategies: RangeStrategy[] = [
'bump',
'widen',
'pin',
'replace',
];
const {
compare: sortVersions,
satisfies: matches,
valid,
validRange,
explain,
gt: isGreaterThan,
major: getMajor,
minor: getMinor,
patch: getPatch,
eq,
} = pep440;
function isVersion(input: string | undefined | null): boolean {
// @renovatebot/pep440 isn't strict null save
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return !!valid(input!);
}
const isStable = (input: string): boolean => {
const version = explain(input);
if (!version) {
return false;
}
return !version.is_prerelease;
};
// If this is left as an alias, inputs like "17.04.0" throw errors
export function isValid(input: string): boolean {
return validRange(input) || isVersion(input);
}
function getSatisfyingVersion(
versions: string[],
range: string
): string | null {
const found = pep440.filter(versions, range).sort(sortVersions);
return found.length === 0 ? null : found[found.length - 1];
}
function minSatisfyingVersion(
versions: string[],
range: string
): string | null {
const found = pep440.filter(versions, range).sort(sortVersions);
return found.length === 0 ? null : found[0];
}
export function isSingleVersion(constraint: string): boolean {
return (
isVersion(constraint) ||
(constraint?.startsWith('==') && isVersion(constraint.substring(2).trim()))
);
}
export { isVersion, matches };
const equals = (version1: string, version2: string): boolean =>
isVersion(version1) && isVersion(version2) && eq(version1, version2);
export const api: VersioningApi = {
equals,
getMajor,
getMinor,
getPatch,
isCompatible: isVersion,
isGreaterThan,
isSingleVersion,
isStable,
isValid,
isVersion,
matches,
getSatisfyingVersion,
minSatisfyingVersion,
getNewValue,
sortVersions,
isLessThanRange,
};
export default api;