Check for correct wasm-bindgen-cli version (#92)

Two people pushing to the same branch is fraught. Three people pushing
to the same branch is a circus. 😂 This should fix the build errors
in #88!
This commit is contained in:
Danny McGee
2024-03-19 23:40:42 -04:00
committed by GitHub
parent 4d5173446e
commit b087f78a15
2 changed files with 39 additions and 5 deletions
+33
View File
@@ -1,5 +1,6 @@
import chalk from "chalk";
import cp from "node:child_process";
import which from "which";
/**
* @param {string} command
@@ -25,3 +26,35 @@ export default function run(command, args, options) {
.on("error", reject);
});
}
/**
* @returns {Promise<string|null>}
*/
export async function wasmBindgenCliVersion() {
const exePath = await which("wasm-bindgen", { nothrow: true });
if (!exePath) return null;
return new Promise((resolve, reject) => {
let stdout = "";
let stderr = "";
const finish = code => {
if (code) reject(new Error(stderr));
else resolve(stdout);
}
const proc = cp.spawn(exePath, ["--version"], {
shell: true,
stdio: ["ignore", "pipe", "pipe"],
})
.on("exit", finish)
.on("close", finish)
.on("error", reject);
proc.stdout.setEncoding("utf-8");
proc.stdout.on("data", chunk => stdout += chunk);
proc.stderr.setEncoding("utf-8");
proc.stderr.on("data", chunk => stderr += chunk);
});
}