Skip to content

Commit

Permalink
chore: fix dlint version and sanity check version after download (den…
Browse files Browse the repository at this point in the history
…oland#21058)

Follow-up to fix version error introduced in denoland#21014
  • Loading branch information
mmastrac committed Nov 2, 2023
1 parent 1d0856a commit ec0e387
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tools/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export { delay } from "../test_util/std/async/delay.ts";
// [toolName] --version output
const versions = {
"dprint": "dprint 0.40.0",
"dlint": "dlint 0.52.2",
"dlint": "dlint 0.51.0",
};

export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.url)));
Expand Down Expand Up @@ -155,7 +155,7 @@ export async function getPrebuilt(toolName) {
const toolPath = getPrebuiltToolPath(toolName);
try {
await sanityCheckPrebuiltFile(toolPath);
const versionOk = await verifyVersion(toolName);
const versionOk = await verifyVersion(toolName, toolPath);
if (!versionOk) {
throw new Error("Version mismatch");
}
Expand Down Expand Up @@ -185,7 +185,10 @@ export async function downloadPrebuilt(toolName) {
}

const downloadPromise = DOWNLOAD_TASKS[toolName] = deferred();
const spinner = wait("Downloading prebuilt tool: " + toolName).start();
const spinner = wait({
text: "Downloading prebuilt tool: " + toolName,
interval: 1000,
}).start();
const toolPath = getPrebuiltToolPath(toolName);
const tempFile = `${toolPath}.temp`;

Expand All @@ -208,6 +211,11 @@ export async function downloadPrebuilt(toolName) {
await resp.body.pipeTo(file.writable);
spinner.text = `Checking prebuilt tool: ${toolName}`;
await sanityCheckPrebuiltFile(tempFile);
if (!await verifyVersion(toolName, tempFile)) {
throw new Error(
"Didn't get the correct version of the tool after downloading.",
);
}
spinner.text = `Successfully downloaded: ${toolName}`;
await Deno.rename(tempFile, toolPath);
} catch (e) {
Expand All @@ -220,14 +228,13 @@ export async function downloadPrebuilt(toolName) {
downloadPromise.resolve(null);
}

export async function verifyVersion(toolName) {
export async function verifyVersion(toolName, toolPath) {
const requiredVersion = versions[toolName];
if (!requiredVersion) {
return true;
}

try {
const toolPath = getPrebuiltToolPath(toolName);
const cmd = new Deno.Command(toolPath, {
args: ["--version"],
stdout: "piped",
Expand Down

0 comments on commit ec0e387

Please sign in to comment.