Skip to content

Commit 316741f

Browse files
committed
fix: compatibility checks
1 parent 258968a commit 316741f

1 file changed

Lines changed: 17 additions & 32 deletions

File tree

apps/site/util/download/archive.tsx

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ import { getNodeDownloadUrl } from '#site/util/url';
1313

1414
import { DIST_URL } from '#site/next.constants';
1515

16-
/**
17-
* Checks if a download item is compatible with the given OS, platform, and version.
18-
*/
19-
function isCompatible(
20-
compatibility: DownloadDropdownItem<Platform>['compatibility'],
21-
os: OperatingSystem,
22-
platform: Platform,
23-
version: string
24-
): boolean {
25-
const {
26-
os: osList,
27-
platform: platformList,
28-
semver: versions,
29-
} = compatibility;
30-
31-
return (
32-
(osList?.includes(os) ?? true) &&
33-
(platformList?.includes(platform) ?? true) &&
34-
(versions?.every(r => semVer.satisfies(version, r)) ?? true)
35-
);
36-
}
37-
3816
type CompatibleArtifactOptions = {
3917
platforms?: Record<OperatingSystem, Array<DownloadDropdownItem<Platform>>>;
4018
exclude?: Array<string>;
@@ -82,17 +60,23 @@ const getCompatiblePlatforms = (
8260
versionWithPrefix: string
8361
): CompatiblePlatforms => {
8462
return Object.entries(platforms).flatMap(([os, items]) => {
85-
if (exclude.includes(os)) return [];
63+
if (exclude.includes(os)) {
64+
return [];
65+
}
8666

8767
return items
88-
.filter(({ compatibility, value }) =>
89-
isCompatible(
90-
compatibility,
91-
os as OperatingSystem,
92-
value,
93-
versionWithPrefix
94-
)
95-
)
68+
.filter(({ compatibility }) => {
69+
// In the download constants file (apps/site/util/download/constants.json),
70+
// if no compatibility is defined as a semver, we treat it as supporting all
71+
// versions by default.
72+
if (!compatibility.semver) {
73+
return true;
74+
}
75+
76+
return compatibility.semver.every(version =>
77+
semVer.satisfies(versionWithPrefix, version)
78+
);
79+
})
9680
.map(platform => ({
9781
os: os as OperatingSystem,
9882
platform: platform,
@@ -174,7 +158,8 @@ export const extractVersionFromPath = (pathname: string | undefined) => {
174158
const segments = pathname.split('/').filter(Boolean);
175159
const version = segments.pop();
176160

177-
// Check version format like (v22.0.4 or 'archive')
161+
// Checks the version prefix + digits + optional dot-separated digits
162+
// (v22, v22.0.4) OR literal "archive"
178163
if (!version || !version.match(/^v\d+(\.\d+)*|archive$/)) {
179164
return null;
180165
}

0 commit comments

Comments
 (0)