mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
Fix desktop CLI environment boundary
This commit is contained in:
18
packages/desktop/src/daemon/node-entrypoint-runner.test.ts
Normal file
18
packages/desktop/src/daemon/node-entrypoint-runner.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sanitizeNodeEntrypointEnv } from "./node-entrypoint-runner";
|
||||
|
||||
describe("node-entrypoint-runner", () => {
|
||||
it("removes Electron node-mode env before loading the target entrypoint", () => {
|
||||
const env = {
|
||||
ELECTRON_RUN_AS_NODE: "1",
|
||||
ELECTRON_NO_ATTACH_CONSOLE: "1",
|
||||
PATH: "/usr/bin",
|
||||
};
|
||||
|
||||
sanitizeNodeEntrypointEnv(env);
|
||||
|
||||
expect(env).toEqual({
|
||||
PATH: "/usr/bin",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,11 @@
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
async function main(): Promise<void> {
|
||||
export function sanitizeNodeEntrypointEnv(env: NodeJS.ProcessEnv = process.env): void {
|
||||
delete env.ELECTRON_RUN_AS_NODE;
|
||||
delete env.ELECTRON_NO_ATTACH_CONSOLE;
|
||||
}
|
||||
|
||||
export async function main(): Promise<void> {
|
||||
const [argvMode, entryPath, ...args] = process.argv.slice(2);
|
||||
if (argvMode !== "bare" && argvMode !== "node-script") {
|
||||
throw new Error(`Unsupported node entrypoint argv mode: ${argvMode ?? "<missing>"}`);
|
||||
@@ -13,11 +18,14 @@ async function main(): Promise<void> {
|
||||
argvMode === "bare"
|
||||
? [process.argv[0] ?? "node", ...args]
|
||||
: [process.argv[0] ?? "node", entryPath, ...args];
|
||||
sanitizeNodeEntrypointEnv();
|
||||
await import(pathToFileURL(entryPath).href);
|
||||
}
|
||||
|
||||
void main().catch((error) => {
|
||||
const message = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
||||
process.stderr.write(`${message}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
if (require.main === module) {
|
||||
void main().catch((error) => {
|
||||
const message = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
||||
process.stderr.write(`${message}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import { resolveCliInstallSourcePath } from "./cli-install-path";
|
||||
|
||||
describe("cli-install-path", () => {
|
||||
it("uses the packaged executable on supported unix platforms", () => {
|
||||
it("uses the bundled shim for packaged macOS installs", () => {
|
||||
expect(
|
||||
resolveCliInstallSourcePath({
|
||||
platform: "darwin",
|
||||
@@ -10,7 +10,7 @@ describe("cli-install-path", () => {
|
||||
executablePath: "/Applications/Paseo.app/Contents/MacOS/Paseo",
|
||||
shimPath: "/Applications/Paseo.app/Contents/Resources/bin/paseo",
|
||||
}),
|
||||
).toBe("/Applications/Paseo.app/Contents/MacOS/Paseo");
|
||||
).toBe("/Applications/Paseo.app/Contents/Resources/bin/paseo");
|
||||
});
|
||||
|
||||
it("prefers the original AppImage path on linux", () => {
|
||||
|
||||
@@ -13,6 +13,10 @@ export function resolveCliInstallSourcePath(input: {
|
||||
return input.shimPath;
|
||||
}
|
||||
|
||||
if (input.platform === "darwin") {
|
||||
return input.shimPath;
|
||||
}
|
||||
|
||||
if (input.platform === "linux") {
|
||||
const appImagePath = input.appImagePath?.trim();
|
||||
if (appImagePath) {
|
||||
|
||||
Reference in New Issue
Block a user