Files
routstrd/src/runtime.ts
T
hzrd149GitHubhzrd149, redshift <213178690+1ftredsh@users.noreply.github.com>
d3749d4638 feat: add standalone binary releases (#89)
* feat: add standalone binary releases

* fix: propagate async CLI failures

* fix: detect older Bun standalone builds

* fix: constrain npm package contents

* fix: preserve npm daemon entrypoint

* fix: compare prerelease versions correctly

* fix: verify daemon ownership before update restart

* docs: add release and PM2 migration guidance

* ci: validate standalone builds before release

* chore: prepare v0.4.9 release

---------

Co-authored-by: hzrd149, redshift <213178690+1ftredsh@users.noreply.github.com>
2026-09-08 15:23:36 +00:00

56 lines
1.2 KiB
TypeScript

export const DAEMON_COMMAND = "daemon";
type BunRuntime = {
isStandaloneExecutable?: boolean;
main: string;
};
export function isStandaloneExecutable(
runtime: BunRuntime = Bun as unknown as BunRuntime,
): boolean {
return (
runtime.isStandaloneExecutable === true ||
runtime.main.startsWith("/$bunfs/")
);
}
type RuntimeExecutable = {
standalone: boolean;
execPath: string;
main: string;
};
export function daemonSpawnCommand(
args: string[],
runtime: RuntimeExecutable = {
standalone: isStandaloneExecutable(),
execPath: process.execPath,
main: Bun.main,
},
): string[] {
return runtime.standalone
? [runtime.execPath, DAEMON_COMMAND, ...args]
: [runtime.execPath, runtime.main, DAEMON_COMMAND, ...args];
}
export function pm2DaemonArgs(
runtime: RuntimeExecutable = {
standalone: isStandaloneExecutable(),
execPath: process.execPath,
main: Bun.main,
},
): string[] {
const entrypoint = runtime.standalone ? runtime.execPath : runtime.main;
const interpreter = runtime.standalone ? "none" : runtime.execPath;
return [
"start",
entrypoint,
"--name",
"routstrd",
"--interpreter",
interpreter,
"--",
DAEMON_COMMAND,
];
}