diff --git a/studio/scripts/build-web.mjs b/studio/scripts/build-web.mjs index 21e4b6f..dda5eec 100644 --- a/studio/scripts/build-web.mjs +++ b/studio/scripts/build-web.mjs @@ -2,11 +2,12 @@ import fs from "node:fs"; import url from "node:url"; import path from "node:path"; import { rimraf } from "rimraf"; -import which from "which"; import copyAssets from "./copy-assets.mjs"; import handleError from "./handle-error.mjs"; -import run from "./run.mjs"; +import run, { wasmBindgenCliVersion } from "./run.mjs"; + +const WASM_BINDGEN_CLI_VERSION = "0.2.92"; async function main() { try { @@ -39,11 +40,11 @@ async function main() { stdio, }); - const wasmBindgenInstalled = Boolean(await which("wasm-bindgen", { nothrow: true })); - if (!wasmBindgenInstalled) { + const wbVersion = await wasmBindgenCliVersion(); + if (!wbVersion || !wbVersion.includes(WASM_BINDGEN_CLI_VERSION)) { await run("cargo", [ "install", "-f", "wasm-bindgen-cli", - "--version", "0.2.92", + "--version", WASM_BINDGEN_CLI_VERSION, ], { shell: true, cwd: workspaceRoot, diff --git a/studio/scripts/run.mjs b/studio/scripts/run.mjs index 91ffe08..5f9d021 100644 --- a/studio/scripts/run.mjs +++ b/studio/scripts/run.mjs @@ -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} + */ +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); + }); +}