Fix desktop CLI environment boundary
This commit is contained in:
@@ -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";
|
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);
|
const [argvMode, entryPath, ...args] = process.argv.slice(2);
|
||||||
if (argvMode !== "bare" && argvMode !== "node-script") {
|
if (argvMode !== "bare" && argvMode !== "node-script") {
|
||||||
throw new Error(`Unsupported node entrypoint argv mode: ${argvMode ?? "<missing>"}`);
|
throw new Error(`Unsupported node entrypoint argv mode: ${argvMode ?? "<missing>"}`);
|
||||||
@@ -13,11 +18,14 @@ async function main(): Promise<void> {
|
|||||||
argvMode === "bare"
|
argvMode === "bare"
|
||||||
? [process.argv[0] ?? "node", ...args]
|
? [process.argv[0] ?? "node", ...args]
|
||||||
: [process.argv[0] ?? "node", entryPath, ...args];
|
: [process.argv[0] ?? "node", entryPath, ...args];
|
||||||
|
sanitizeNodeEntrypointEnv();
|
||||||
await import(pathToFileURL(entryPath).href);
|
await import(pathToFileURL(entryPath).href);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main().catch((error) => {
|
if (require.main === module) {
|
||||||
const message = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
void main().catch((error) => {
|
||||||
process.stderr.write(`${message}\n`);
|
const message = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
||||||
process.exit(1);
|
process.stderr.write(`${message}\n`);
|
||||||
});
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
|||||||
import { resolveCliInstallSourcePath } from "./cli-install-path";
|
import { resolveCliInstallSourcePath } from "./cli-install-path";
|
||||||
|
|
||||||
describe("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(
|
expect(
|
||||||
resolveCliInstallSourcePath({
|
resolveCliInstallSourcePath({
|
||||||
platform: "darwin",
|
platform: "darwin",
|
||||||
@@ -10,7 +10,7 @@ describe("cli-install-path", () => {
|
|||||||
executablePath: "/Applications/Paseo.app/Contents/MacOS/Paseo",
|
executablePath: "/Applications/Paseo.app/Contents/MacOS/Paseo",
|
||||||
shimPath: "/Applications/Paseo.app/Contents/Resources/bin/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", () => {
|
it("prefers the original AppImage path on linux", () => {
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ export function resolveCliInstallSourcePath(input: {
|
|||||||
return input.shimPath;
|
return input.shimPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.platform === "darwin") {
|
||||||
|
return input.shimPath;
|
||||||
|
}
|
||||||
|
|
||||||
if (input.platform === "linux") {
|
if (input.platform === "linux") {
|
||||||
const appImagePath = input.appImagePath?.trim();
|
const appImagePath = input.appImagePath?.trim();
|
||||||
if (appImagePath) {
|
if (appImagePath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user