Add react-native support #63

Merged
andras merged 6 commits from asch/wasm2js into main 2026-05-31 20:28:20 +01:00
Showing only changes of commit c28a6b0685 - Show all commits

Try to fix CI
All checks were successful
Check / build (pull_request) Successful in 9m24s

Andras Schmelczer 2026-05-31 20:07:38 +01:00

View file

@ -3,7 +3,7 @@
// wasm2js (pure-JS) translation. // wasm2js (pure-JS) translation.
import { execFileSync } from 'node:child_process'; 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 { dirname, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url'; import { fileURLToPath, pathToFileURL } from 'node:url';
import { homedir } from 'node:os'; import { homedir } from 'node:os';
@ -66,26 +66,38 @@ function findWasmBindgen() {
return onPath; return onPath;
} }
// 2. In the wasm-pack cache: require the EXACT pinned version. wasm-pack stores each const cacheRoots = [
// installed CLI under `wasm-bindgen-cargo-install-<version>/`. resolve(homedir(), 'Library/Caches/.wasm-pack'),
const cached = [ resolve(homedir(), '.cache/.wasm-pack'),
resolve( ];
homedir(), for (const root of cacheRoots) {
`Library/Caches/.wasm-pack/wasm-bindgen-cargo-install-${wanted}/wasm-bindgen` if (!existsSync(root)) {
), continue;
resolve( }
homedir(), for (const entry of readdirSync(root)) {
`.cache/.wasm-pack/wasm-bindgen-cargo-install-${wanted}/wasm-bindgen` const candidate = resolve(root, entry, 'wasm-bindgen');
), if (!existsSync(candidate)) {
].find((p) => existsSync(p)); continue;
if (!cached) { }
throw new Error( let version;
`[build-rn] No wasm-bindgen ${wanted} found on PATH or in the wasm-pack cache. ` + try {
'Run `wasm-pack build --target web --features wasm` first (it caches the matching ' + version = execFileSync(candidate, ['--version'], { encoding: 'utf8' }).match(
`wasm-bindgen), or \`cargo install wasm-bindgen-cli --version ${wanted}\`.` /\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)) { if (!existsSync(releaseWasm)) {