| Crates.io | hook-transpiler |
| lib.rs | hook-transpiler |
| version | 0.2.5 |
| created_at | 2025-12-17 17:02:07.205949+00 |
| updated_at | 2025-12-18 20:41:00.943963+00 |
| description | Minimal JSX/TSX transpiler for Relay hooks with dynamic import() rewrite to context.helpers.loadModule and friendly errors |
| homepage | https://github.com/clevertree/hook-transpiler |
| repository | https://github.com/clevertree/hook-transpiler |
| max_upload_size | |
| id | 1990730 |
| size | 124,134 |
Last updated: 2025-12-12 10:02 (local)
Minimal, reliable transpiler used by Relay clients (web and React Native) to:
import() → context.helpers.loadModule(spec) for lazy loadingThis crate is the foundation for client‑side (WASM) and server‑side transpilation. Client‑web uses the WASM build first; server /api/transpile acts as a fallback. RN initially uses the server endpoint, with room to evolve to on‑device transpilation.
import() rewrite)POST /api/transpileswc_core v50.x APIs (in progress; usable subset already powering client‑web)Core crate (this directory)
import() → loader)template/hooks/client/get-client.jsx transpilation (integration test)Web/WASM build (client‑first)
scripts/build-hook-wasm.sh)globalThis.__hook_transpile_jsxswc_core v50.x (isolated browser crate) — in progresstranspile_jsx(source, filename) -> { code, map?, diagnostics? }Server fallback (apps/server)
POST /api/transpile endpoint invoking this crateClient‑web integration (apps/client‑web)
get-client.jsx, verify lazy imports route via helpers.loadModuleClient‑React‑Native integration (apps/client‑react‑native)
transpileJsx(source, filename) -> string | { code }Fetch handling utilities
reqwest TLS‑enabled fetch helper (optional feature)fetchDocumentation
docs/RELEASE_VALIDATION.mdServer GET fallback behavior (integration & tests)
Release & Distribution
get-client.jsx, verify lazy import() via helpers.loadModuleThis crate is part of the Cargo workspace. To build and run tests:
cargo build -p hook-transpiler
cargo test -p hook-transpiler
Artifacts are generated into the web app’s source folder so Vite can bundle them. Run the cross-platform helper from the repo root:
# From repo root (cross-platform)
npm run build:wasm
# Dev cycle (build then start web dev server)
npm run web:dev:wasm
Expected outputs (canonical location under the web app source):
apps/client-web/src/wasm/hook_transpiler.jsapps/client-web/src/wasm/hook_transpiler_bg.wasmClient‑web loads these at startup via apps/client-web/src/wasmEntry.ts (shim) and exposes:
globalThis.__hook_transpile_jsx(source: string, filename: string) => string | { code: string }
See also: Release validation steps in docs/RELEASE_VALIDATION.md.
The crate exposes a Rust API consumed by the server and unit tests:
pub struct TranspileOptions {
pub filename: Option<String>,
pub react_dev: bool,
pub to_commonjs: bool,
pub pragma: Option<String>,
pub pragma_frag: Option<String>,
}
pub struct TranspileOutput {
pub code: String,
pub map: Option<String>,
}
pub fn transpile(source: &str, opts: TranspileOptions) -> Result<TranspileOutput, TranspileError>;
Error types are user‑facing and include filename and (when available) locations:
ParseError { filename, line, col, message }TransformError(filename, source_err)CodegenError(filename, source_err)All import(spec) calls are rewritten to context.helpers.loadModule(spec) so hooks lazily load peer modules through the runtime’s loader. This is essential for TSX/JSX modules importing each other asynchronously.
Run unit tests:
cargo test -p hook-transpiler
Planned tests to add:
template/hooks/client/get-client.jsxto_commonjs: true).Cargo.toml and package.json aligned (e.g., 0.2.x) before releasing.cargo publishnpm run build (regenerates WASM/JS from the crate) → npm publish