fix(daemon): skip Bun virtual entry path in detached child spawn

In Bun compiled binaries, process.argv[1] is a virtual /$bunfs/...
path that Bun auto-injects into every spawned child process. The
daemon launcher was including this path explicitly in the spawn args,
causing it to appear twice in the child's argv. The child then parsed
the duplicate path as the CLI command instead of "daemon", silently
failing to start.

Detect the /$bunfs/ prefix and omit the entry from spawn args, letting
Bun handle it automatically.
This commit is contained in:
Peter Dedene 2026-03-16 13:38:21 +01:00 committed by Peter Steinberger
parent 41e049ddc0
commit 586c57d11b

View File

@ -15,7 +15,7 @@ export function launchDaemonDetached(options: DaemonLaunchOptions): void {
const configArgs = options.configExplicit ? ['--config', options.configPath] : [];
const args = [
...process.execArgv,
cliEntry,
...(cliEntry ? [cliEntry] : []),
...configArgs,
...(options.rootDir ? ['--root', options.rootDir] : []),
'daemon',
@ -36,10 +36,16 @@ export function launchDaemonDetached(options: DaemonLaunchOptions): void {
child.unref();
}
function resolveCliEntry(): string {
function resolveCliEntry(): string | undefined {
const entry = process.argv[1];
if (!entry) {
throw new Error('Unable to resolve mcporter entry script.');
}
// In Bun compiled binaries, argv[1] is a virtual /$bunfs/... path that Bun
// auto-injects into every spawned child. Including it explicitly would
// duplicate it and break CLI argument parsing in the child process.
if (entry.startsWith('/$bunfs/')) {
return undefined;
}
return path.resolve(entry);
}