import { spawn } from "node:child_process";
/** Windows CREATE_NO_WINDOW — subprocess must not allocate a visible console. */
export const WINDOWS_CREATE_NO_WINDOW = 0x08000000;
/**
 * Spawn a background child without flashing an empty cmd.exe on Windows.
 *
 * On Windows, `detached: true` allocates a new console even with windowsHide.
 * Use CREATE_NO_WINDOW and `unref()` instead of detached.
 */
export function spawnHidden(command, args, options = {}) {
    if (process.platform === "win32") {
        const win32Options = {
            ...options,
            detached: false,
            stdio: options.stdio ?? "ignore",
            windowsHide: true,
            creationFlags: WINDOWS_CREATE_NO_WINDOW,
        };
        return spawn(command, args, win32Options);
    }
    return spawn(command, args, {
        ...options,
        detached: options.detached ?? true,
        stdio: options.stdio ?? "ignore",
        windowsHide: true,
    });
}
