@adecore/shell 0.49.0 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/versions.js +29 -4
- package/package.json +1 -1
- package/src/bridge/versions.ts +37 -4
package/dist/bridge/versions.js
CHANGED
|
@@ -2,10 +2,30 @@
|
|
|
2
2
|
* The order the shell sorts the release list in has to be the order the page reads it in, or the
|
|
3
3
|
* notes of a version land under the wrong heading. One comparison, so the two cannot disagree.
|
|
4
4
|
*/
|
|
5
|
-
const SEMVER = /^(\d+)\.(\d+)\.(\d+)
|
|
6
|
-
|
|
5
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
6
|
+
const NUMERIC = /^\d+$/;
|
|
7
|
+
/* A `1.2.3` or `1.2.3-beta.1`. A git tag carries a `v` in front of it, which is the tag's and not the version's. */
|
|
7
8
|
export const isVersion = (version) => SEMVER.test(version);
|
|
8
|
-
/*
|
|
9
|
+
/* Semver's order: part by part, numbers by value and below words, and a shorter list below a longer one it starts. */
|
|
10
|
+
const comparePrereleases = (a, b) => {
|
|
11
|
+
const left = a.split('.');
|
|
12
|
+
const right = b.split('.');
|
|
13
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
14
|
+
const leftPart = left[i];
|
|
15
|
+
const rightPart = right[i];
|
|
16
|
+
const leftNumeric = NUMERIC.test(leftPart);
|
|
17
|
+
const rightNumeric = NUMERIC.test(rightPart);
|
|
18
|
+
if (leftNumeric !== rightNumeric) {
|
|
19
|
+
return leftNumeric ? -1 : 1;
|
|
20
|
+
}
|
|
21
|
+
const difference = leftNumeric ? Number(leftPart) - Number(rightPart) : leftPart < rightPart ? -1 : leftPart > rightPart ? 1 : 0;
|
|
22
|
+
if (difference !== 0) {
|
|
23
|
+
return difference;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return left.length - right.length;
|
|
27
|
+
};
|
|
28
|
+
/* Negative when `a` is older than `b`, a prerelease coming before its own release. A version that is not semver sorts below every one that is. */
|
|
9
29
|
export const compareVersions = (a, b) => {
|
|
10
30
|
const left = SEMVER.exec(a);
|
|
11
31
|
const right = SEMVER.exec(b);
|
|
@@ -18,5 +38,10 @@ export const compareVersions = (a, b) => {
|
|
|
18
38
|
return difference;
|
|
19
39
|
}
|
|
20
40
|
}
|
|
21
|
-
|
|
41
|
+
const leftPrerelease = left[4];
|
|
42
|
+
const rightPrerelease = right[4];
|
|
43
|
+
if (leftPrerelease === undefined || rightPrerelease === undefined) {
|
|
44
|
+
return (leftPrerelease === undefined ? 1 : 0) - (rightPrerelease === undefined ? 1 : 0);
|
|
45
|
+
}
|
|
46
|
+
return comparePrereleases(leftPrerelease, rightPrerelease);
|
|
22
47
|
};
|
package/package.json
CHANGED
package/src/bridge/versions.ts
CHANGED
|
@@ -3,12 +3,38 @@
|
|
|
3
3
|
* notes of a version land under the wrong heading. One comparison, so the two cannot disagree.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const SEMVER = /^(\d+)\.(\d+)\.(\d+)
|
|
6
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
7
|
+
const NUMERIC = /^\d+$/;
|
|
7
8
|
|
|
8
|
-
/* A
|
|
9
|
+
/* A `1.2.3` or `1.2.3-beta.1`. A git tag carries a `v` in front of it, which is the tag's and not the version's. */
|
|
9
10
|
export const isVersion = (version: string): boolean => SEMVER.test(version);
|
|
10
11
|
|
|
11
|
-
/*
|
|
12
|
+
/* Semver's order: part by part, numbers by value and below words, and a shorter list below a longer one it starts. */
|
|
13
|
+
const comparePrereleases = (a: string, b: string): number => {
|
|
14
|
+
const left = a.split('.');
|
|
15
|
+
const right = b.split('.');
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
18
|
+
const leftPart = left[i]!;
|
|
19
|
+
const rightPart = right[i]!;
|
|
20
|
+
const leftNumeric = NUMERIC.test(leftPart);
|
|
21
|
+
const rightNumeric = NUMERIC.test(rightPart);
|
|
22
|
+
|
|
23
|
+
if (leftNumeric !== rightNumeric) {
|
|
24
|
+
return leftNumeric ? -1 : 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const difference = leftNumeric ? Number(leftPart) - Number(rightPart) : leftPart < rightPart ? -1 : leftPart > rightPart ? 1 : 0;
|
|
28
|
+
|
|
29
|
+
if (difference !== 0) {
|
|
30
|
+
return difference;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return left.length - right.length;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/* Negative when `a` is older than `b`, a prerelease coming before its own release. A version that is not semver sorts below every one that is. */
|
|
12
38
|
export const compareVersions = (a: string, b: string): number => {
|
|
13
39
|
const left = SEMVER.exec(a);
|
|
14
40
|
const right = SEMVER.exec(b);
|
|
@@ -25,5 +51,12 @@ export const compareVersions = (a: string, b: string): number => {
|
|
|
25
51
|
}
|
|
26
52
|
}
|
|
27
53
|
|
|
28
|
-
|
|
54
|
+
const leftPrerelease = left[4];
|
|
55
|
+
const rightPrerelease = right[4];
|
|
56
|
+
|
|
57
|
+
if (leftPrerelease === undefined || rightPrerelease === undefined) {
|
|
58
|
+
return (leftPrerelease === undefined ? 1 : 0) - (rightPrerelease === undefined ? 1 : 0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return comparePrereleases(leftPrerelease, rightPrerelease);
|
|
29
62
|
};
|