Overview
Concrete tool for resolving the platform-specific jcode binary from optional NPM dependencies, provided by the TypeScript SDK.
Description
The binary module maps the current platform and architecture to an optional NPM package name (e.g. @1jehuang/jcode-linux-x64) and resolves the bundled executable path. platformBinaryPackage() returns the package name for the current platform-arch pair, returning undefined on unsupported platforms. bundledJcodeBinary() uses require.resolve to locate the package's package.json and derives the binary path, returning undefined when the optional dependency was deliberately omitted so that launch() can fall back to a PATH lookup.
Usage
- SDK launch: Call
bundledJcodeBinary() before spawning the server to find the bundled binary.
- PATH fallback: When
bundledJcodeBinary() returns undefined, fall back to jcode on PATH.
- Platform detection: Call
platformBinaryPackage() to check if the current platform has a dedicated package.
Code Reference
Source Location
Signature
export function platformBinaryPackage(
platform = process.platform,
arch = process.arch,
): string | undefined
export function bundledJcodeBinary(): string | undefined
Import
import { platformBinaryPackage, bundledJcodeBinary } from "@1jehuang/jcode/binary";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| platform |
string |
No (defaults to process.platform) |
OS platform identifier
|
| arch |
string |
No (defaults to process.arch) |
CPU architecture identifier
|
Outputs
| Name |
Type |
Description
|
| platformBinaryPackage |
undefined |
NPM package name for the platform, or undefined if unsupported
|
| bundledJcodeBinary |
undefined |
Absolute path to the bundled binary, or undefined if not installed
|
Usage Examples
Resolve Binary with PATH Fallback
import { bundledJcodeBinary } from "@1jehuang/jcode/binary";
const binary = bundledJcodeBinary() ?? "jcode";
// If bundled binary exists, use it; otherwise fall back to PATH
const child = spawn(binary, ["run", "--socket", socketPath, prompt]);
Check Platform Support
import { platformBinaryPackage } from "@1jehuang/jcode/binary";
const pkg = platformBinaryPackage();
if (!pkg) {
console.error(`No bundled binary for ${process.platform}-${process.arch}`);
console.error("Install jcode globally or ensure it is on PATH.");
}
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.