From c28a6b0685305abe1b4c1b3f2c456af6642fc1bc Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 31 May 2026 20:07:38 +0100 Subject: [PATCH] Try to fix CI --- reconcile-js/scripts/build-rn.mjs | 52 +++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/reconcile-js/scripts/build-rn.mjs b/reconcile-js/scripts/build-rn.mjs index 9b52c79..dadbc82 100644 --- a/reconcile-js/scripts/build-rn.mjs +++ b/reconcile-js/scripts/build-rn.mjs @@ -3,7 +3,7 @@ // wasm2js (pure-JS) translation. import { execFileSync } from 'node:child_process'; -import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { homedir } from 'node:os'; @@ -66,26 +66,38 @@ function findWasmBindgen() { return onPath; } - // 2. In the wasm-pack cache: require the EXACT pinned version. wasm-pack stores each - // installed CLI under `wasm-bindgen-cargo-install-/`. - const cached = [ - resolve( - homedir(), - `Library/Caches/.wasm-pack/wasm-bindgen-cargo-install-${wanted}/wasm-bindgen` - ), - resolve( - homedir(), - `.cache/.wasm-pack/wasm-bindgen-cargo-install-${wanted}/wasm-bindgen` - ), - ].find((p) => existsSync(p)); - if (!cached) { - throw new Error( - `[build-rn] No wasm-bindgen ${wanted} found on PATH or in the wasm-pack cache. ` + - 'Run `wasm-pack build --target web --features wasm` first (it caches the matching ' + - `wasm-bindgen), or \`cargo install wasm-bindgen-cli --version ${wanted}\`.` - ); + const cacheRoots = [ + resolve(homedir(), 'Library/Caches/.wasm-pack'), + resolve(homedir(), '.cache/.wasm-pack'), + ]; + for (const root of cacheRoots) { + if (!existsSync(root)) { + continue; + } + for (const entry of readdirSync(root)) { + const candidate = resolve(root, entry, 'wasm-bindgen'); + if (!existsSync(candidate)) { + continue; + } + let version; + try { + version = execFileSync(candidate, ['--version'], { encoding: 'utf8' }).match( + /\d+\.\d+\.\d+/ + )?.[0]; + } catch { + continue; // not an invokable wasm-bindgen; ignore + } + if (version === wanted) { + return candidate; + } + } } - return cached; + + throw new Error( + `[build-rn] No wasm-bindgen ${wanted} found on PATH or in the wasm-pack cache. ` + + 'Run `wasm-pack build --target web --features wasm` first (it caches the matching ' + + `wasm-bindgen), or \`cargo install wasm-bindgen-cli --version ${wanted}\`.` + ); } if (!existsSync(releaseWasm)) {