Shared Bun binary infrastructure: asset embedding, manifest generation, and cross-compilation
Internal use only. This package is published publicly for convenience but is intended for use by Stripe-internal projects. It is not supported for general community use and carries no stability guarantees for external consumers.
Shared Bun binary infrastructure: asset embedding, manifest generation, and cross-compilation.
@stripe/bun-toolkit/runtime) — getAssetDir() / resolveAsset() for transparent asset access in both dev and compiled binary modesbun-generate-manifest) — reads bun.assets globs from package.json, generates a Bun compile entrypoint that embeds all assetsbun-build-binaries) — full cross-compilation pipeline with version validation and target mapping{
"bun": {
"assets": ["openapi/*.yaml", "assets/**"],
"entry": "./dist/main.js",
"buildScript": "prebuild-binary"
}
}
assets — glob patterns for files to embed in the binaryentry — the JS entrypoint to re-export from the generated manifestbuildScript — (optional) package.json script to run before compilation. Defaults to "prebuild-binary". Skipped if the script doesn’t exist.import { resolveAsset } from "@stripe/bun-toolkit/runtime";
const specPath = resolveAsset("openapi/spec.yaml");
npx bun-build-binaries ./bin "macos-arm64,linux-x64"
Build time: bun-generate-manifest expands the asset globs and writes dist/bun-compile-entrypoint.js with import ... with { type: "file" } statements. This tells Bun to embed each file directly in the binary.
Binary mode: When the binary runs, globalThis.__EMBEDDED_ASSET_MANIFEST__ maps logical paths to Bun’s virtual filesystem paths. getAssetDir() extracts all embedded files to a temp directory on first call. The temp directory is cleaned up on process exit.
Dev mode: When running via Node/tsx/bun without compilation, getAssetDir() returns the repo root where assets exist on disk. No extraction needed.
pnpm build — compile TypeScriptpnpm test — run unit tests./scripts/smoke-test.sh — end-to-end test: builds a fixture into a binary and verifies embedded assets work from a foreign cwd