Skip to content

Commit 2bca7ce

Browse files
authored
feat: add "latest" as possible version (#65)
1 parent f99b7ed commit 2bca7ce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/version.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function parseVersionRange(version) {
3030
return { range: "latest", isCanary: true };
3131
}
3232

33+
if (version == "latest") {
34+
return { range: "latest", isCanary: false };
35+
}
36+
3337
if (GIT_HASH_RE.test(version)) {
3438
return { range: version, isCanary: true };
3539
}
@@ -92,6 +96,23 @@ async function resolveVersion({ range, isCanary }) {
9296
return { version: range, isCanary: true };
9397
}
9498

99+
if (range === "latest") {
100+
const res = await fetchWithRetries(
101+
"https://dl.deno.land/release-latest.txt",
102+
);
103+
if (res.status !== 200) {
104+
throw new Error(
105+
"Failed to fetch release version info from dl.deno.land. Please try again later.",
106+
);
107+
}
108+
let version = (await res.text()).trim();
109+
version = semver.clean(version);
110+
if (version === null) {
111+
return null;
112+
}
113+
return { version, isCanary: false };
114+
}
115+
95116
const res = await fetchWithRetries("https://deno.com/versions.json");
96117
if (res.status !== 200) {
97118
throw new Error(

0 commit comments

Comments
 (0)