Skip to content

Commit

Permalink
fix: correct conditions for new nightlies
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Mar 28, 2024
1 parent a48be9e commit 498bb81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
isWindows,
makeStates,
openLink,
parseNightly,
tryStatSync,
which,
} from "./utils";
Expand Down Expand Up @@ -145,10 +146,13 @@ async function downloadLspBinary(context: vscode.ExtensionContext) {
const shaLink = `${link}.sha256`;
const shaOutput = `${latest}.sha256`;

let stat: Stats | null;
const hasNewerNightly =
// biome-ignore lint/suspicious/noAssignInExpressions:
release.startsWith("nightly") && (!(stat = tryStatSync(vsixOutput)) || compareDate(stat.ctime, new Date()) < 0);
const hasNewerNightly = (() => {
if (!release.startsWith("nightly-")) return false;
const releaseDate = parseNightly(release);
const vsixStat = tryStatSync(vsixOutput);
if (!vsixStat) return false;
return compareDate(vsixStat.birthtime, releaseDate) < 0;
})();

const powershell = { shell: "powershell.exe" };
const sh = { shell: "sh" };
Expand Down
12 changes: 12 additions & 0 deletions client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ export async function openLink(url: string) {
}
return await $(`${opener} ${url}`);
}

export function parseNightly(releaseName: string) {
if (!releaseName.startsWith('nightly-')) {
throw new Error(`bug: releaseName=${releaseName} is not a nightly release`);
}
// nightly-YYYYMMDD
const dateString = releaseName.slice('nightly-'.length);
const yearString = dateString.slice(0, 4);
const monthString = dateString.slice(4, 6);
const dayString = dateString.slice(6, 8);
return new Date(Date.UTC(+yearString, +monthString, +dayString))
}

0 comments on commit 498bb81

Please sign in to comment.