|
6 | 6 | * Idempotent: Skips regeneration if source hasn't changed (supports CI caching). |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { readFileSync, writeFileSync } from 'node:fs' |
| 9 | +import { existsSync, readFileSync, writeFileSync } from 'node:fs' |
10 | 10 | import path from 'node:path' |
11 | 11 | import { fileURLToPath } from 'node:url' |
12 | 12 |
|
|
39 | 39 | process.exit(0) |
40 | 40 | } |
41 | 41 |
|
| 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 | + |
42 | 79 | // Read WASM binary and convert to base64. |
43 | 80 | const wasmBinary = readFileSync(yogaWasmFile) |
44 | 81 | const base64Data = wasmBinary.toString('base64') |
|
0 commit comments