first commit
This commit is contained in:
47
docs/devtools/tooling/javy-cli-linux-x64/src/index.md
Normal file
47
docs/devtools/tooling/javy-cli-linux-x64/src/index.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# `getJavyBinary` — @suaveplan/javy-cli-linux-x64
|
||||
|
||||
## Purpose
|
||||
|
||||
This module exposes the absolute filesystem path to the platform-specific Javy v8.1.1 binary bundled with this wrapper package. The Javy CLI is a Bytecode-Alliance project that compiles JavaScript source files into self-contained WebAssembly modules; `@suaveplan/wasm-compiler-javy` consumes `getJavyBinary()` to locate the binary it spawns via `child_process.spawnSync`, eliminating the need for consumers to ship their own download or PATH lookup.
|
||||
|
||||
The wrapper carries matching `os` + `cpu` constraints in `package.json` so npm/bun skip installation on mismatched platforms — this means a single monorepo install stays cross-platform-safe, and the compiler can iterate its `optionalDependencies` to find whichever wrapper actually installed.
|
||||
|
||||
## Features
|
||||
|
||||
- `getJavyBinary()` — returns the absolute path to the platform binary, throwing a structured `Error` if the postinstall download failed or was bypassed.
|
||||
- `JAVY_PLATFORM` — the platform triple this wrapper serves (`linux-x64`).
|
||||
- `JAVY_VERSION` — the pinned Javy upstream version (`v8.1.1`).
|
||||
|
||||
## Usage: Basic
|
||||
|
||||
```ts
|
||||
import { getJavyBinary } from "@suaveplan/javy-cli-linux-x64";
|
||||
|
||||
const javy = getJavyBinary();
|
||||
// javy === "/abs/path/to/bin/javy"
|
||||
```
|
||||
|
||||
## Usage: Advanced
|
||||
|
||||
```ts
|
||||
import { getJavyBinary, JAVY_PLATFORM, JAVY_VERSION } from "@suaveplan/javy-cli-linux-x64";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
if (JAVY_PLATFORM !== `${process.platform}-${process.arch}`) {
|
||||
throw new Error("wrong wrapper");
|
||||
}
|
||||
const result = spawnSync(getJavyBinary(), ["build", "src.js", "-o", "out.wasm", "-C", "deterministic=y"], {
|
||||
encoding: "utf8",
|
||||
});
|
||||
console.log("javy version:", JAVY_VERSION, "exit:", result.status);
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
- `getJavyBinary(): string` — resolves the bundled binary path. Throws `Error` when the binary is absent.
|
||||
- `JAVY_PLATFORM: "linux-x64"` — readonly string literal.
|
||||
- `JAVY_VERSION: "v8.1.1"` — readonly string literal.
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
The binary is downloaded at install time by `postinstall.mjs` from `github.com/bytecodealliance/javy/releases/download/v8.1.1/javy-x86_64-linux-v8.1.1.gz` with a committed SHA-256 checksum verifying the gzip payload before decompression. The decompressed binary is chmod-ed to `0o755` (no-op on Windows) and placed at `bin/javy` relative to the package root. The committed sha for this wrapper is `4bec224e1d51827808fd063541a2b4d94cf474744636b692be63e7a29bec83a6`. `JAVY_SKIP_DOWNLOAD=1` skips the download for offline CI sandboxes — callers MUST seed `bin/javy` themselves in that mode. The wrapper is intentionally tiny: a path string and two constants, no logic beyond fs.existsSync.
|
||||
Reference in New Issue
Block a user