* Fix desktop CLI passthrough tty handling * Fix desktop daemon manager test drift * Update daemon stop test after main merge * test(cli): isolate npx cache per CLI test
66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
const PASEO_NODE_ENV = "PASEO_NODE_ENV";
|
|
|
|
export interface NodeEntrypointSpec {
|
|
entryPath: string;
|
|
execArgv: string[];
|
|
}
|
|
|
|
export interface NodeEntrypointInvocation {
|
|
command: string;
|
|
args: string[];
|
|
env: NodeJS.ProcessEnv;
|
|
}
|
|
|
|
export type NodeEntrypointArgvMode = "bare" | "node-script";
|
|
|
|
interface CreateNodeEntrypointInvocationInput {
|
|
execPath: string;
|
|
isPackaged: boolean;
|
|
packagedRunnerPath: string | null;
|
|
entrypoint: NodeEntrypointSpec;
|
|
argvMode: NodeEntrypointArgvMode;
|
|
args: string[];
|
|
baseEnv: NodeJS.ProcessEnv;
|
|
}
|
|
|
|
export function createElectronNodeEnv(
|
|
baseEnv: NodeJS.ProcessEnv,
|
|
options?: { isPackaged?: boolean },
|
|
): NodeJS.ProcessEnv {
|
|
return {
|
|
...baseEnv,
|
|
ELECTRON_RUN_AS_NODE: "1",
|
|
...(options?.isPackaged === true ? { [PASEO_NODE_ENV]: "production" } : {}),
|
|
};
|
|
}
|
|
|
|
export function createNodeEntrypointInvocation(
|
|
input: CreateNodeEntrypointInvocationInput,
|
|
): NodeEntrypointInvocation {
|
|
const env = createElectronNodeEnv(input.baseEnv, { isPackaged: input.isPackaged });
|
|
|
|
if (input.isPackaged) {
|
|
if (!input.packagedRunnerPath) {
|
|
throw new Error("Packaged node entrypoint runner is required for desktop launches.");
|
|
}
|
|
|
|
return {
|
|
command: input.execPath,
|
|
args: [
|
|
"--disable-warning=DEP0040",
|
|
input.packagedRunnerPath,
|
|
input.argvMode,
|
|
input.entrypoint.entryPath,
|
|
...input.args,
|
|
],
|
|
env,
|
|
};
|
|
}
|
|
|
|
return {
|
|
command: input.execPath,
|
|
args: [...input.entrypoint.execArgv, input.entrypoint.entryPath, ...input.args],
|
|
env,
|
|
};
|
|
}
|