Skip to content

Commit 43ea2c7

Browse files
committed
fix(cli): handle missing yoga-layout WASM files gracefully
Add existence checks before reading yoga.wasm and yoga.js files. Generate placeholder yoga-sync.mjs with minimal API when WASM files are not available (e.g., in CI without WASM build). Follows same pattern as extract-minilm-model.mjs which already has graceful degradation for missing AI models.
1 parent cfe2fb8 commit 43ea2c7

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

packages/cli/scripts/extract-yoga-wasm.mjs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Idempotent: Skips regeneration if source hasn't changed (supports CI caching).
77
*/
88

9-
import { readFileSync, writeFileSync } from 'node:fs'
9+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
1010
import path from 'node:path'
1111
import { fileURLToPath } from 'node:url'
1212

@@ -39,6 +39,43 @@ if (
3939
process.exit(0)
4040
}
4141

42+
// Check if yoga-layout WASM files exist.
43+
if (!existsSync(yogaWasmFile) || !existsSync(yogaJsFile)) {
44+
// Graceful fallback: Generate placeholder for CI builds without WASM.
45+
logger.warn('yoga-layout WASM not built yet, generating placeholder')
46+
47+
const placeholderContent = `/**
48+
* Synchronous yoga-layout with embedded WASM binary (Placeholder).
49+
*
50+
* This file is AUTO-GENERATED by scripts/extract-yoga-wasm.mjs
51+
* DO NOT EDIT MANUALLY - changes will be overwritten on next build.
52+
*
53+
* NOTE: This is a placeholder build. Run 'pnpm build' in yoga-layout first.
54+
*/
55+
56+
// Placeholder yoga export with minimal API.
57+
const yoga = {
58+
Config: class Config {},
59+
Node: class Node {
60+
static create() {
61+
return new Node()
62+
}
63+
calculateLayout() {}
64+
getComputedLayout() {
65+
return { left: 0, top: 0, width: 0, height: 0 }
66+
}
67+
},
68+
}
69+
70+
export default yoga
71+
`
72+
73+
ensureOutputDir(outputPath)
74+
writeFileSync(outputPath, placeholderContent, 'utf-8')
75+
logger.log(`✓ Generated placeholder ${outputPath}`)
76+
process.exit(0)
77+
}
78+
4279
// Read WASM binary and convert to base64.
4380
const wasmBinary = readFileSync(yogaWasmFile)
4481
const base64Data = wasmBinary.toString('base64')

0 commit comments

Comments
 (0)