@avmc/bun-extractor
v0.5.1
Published
Extract embedded JS modules from Bun standalone (--compile) binaries
Readme
bun-extractor
Extract embedded JS modules from Bun standalone (bun build --compile) binaries.
Parses the binary's embedded payload, recovers all bundled modules, and rewrites internal /$bunfs/ imports to relative paths so the extracted source is immediately runnable.
Install
npm install @avmc/bun-extractorCLI
# List embedded modules
npx @avmc/bun-extractor ./my-app --list
# Extract all modules to a directory
npx @avmc/bun-extractor ./my-app -o ./extractedOptions
| Flag | Description |
|---|---|
| -l, --list | List embedded modules without extracting |
| -o, --out <dir> | Extract to a specific directory (default: cwd) |
| -h, --help | Show help |
API
import { openBinary } from "@avmc/bun-extractor";
import { readFileSync } from "fs";
const bin = openBinary(readFileSync("./my-app"));
console.log(bin.entryPoint.path); // e.g. "src/index.js"
console.log(bin.entryPoint.source); // JS with /$bunfs/ imports rewritten
for (const mod of bin.modules) {
console.log(mod.path, mod.size, mod.loader);
}openBinary(buffer: Buffer): BunBinary
Parse a Bun standalone binary and return a BunBinary instance.
BunBinary
modules: Module[]— all embedded modulesentryPoint: Module— the binary's entry point module
Module
name: string— full virtual path (e.g./$bunfs/root/src/foo.js)path: string— cleaned path with virtual prefix stripped (e.g.src/foo.js)loader: string—js,ts,jsx,tsx,json,css,file, etc.format: string—esm,cjs, ornoneisEntry: booleanhasSourcemap: booleanhasBytecode: booleancontents: Buffer— raw bytes (zero-copy view into the binary buffer)source: string— decoded JS/TS source with/$bunfs/imports rewritten to relative pathssize: number
Supported platforms
Works on Linux, macOS, and Windows binaries. Handles both /$bunfs/ (Linux/macOS) and B:\~BUN\ (Windows) virtual path formats.
Requires Node.js >= 18.
License
MIT
