This commit is contained in:
parent
c963db6cf2
commit
c28a6b0685
1 changed files with 32 additions and 20 deletions
|
|
@ -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-<version>/`.
|
||||
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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue