Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,37 @@ describe("DesktopPreReadyPlatform", () => {
assert.isNull(value);
});

it("detects --version and -V as whole-token version requests", () => {
assert.isTrue(DesktopPreReadyPlatform.isVersionRequest(["--version"]));
assert.isTrue(DesktopPreReadyPlatform.isVersionRequest(["-V"]));
assert.isFalse(DesktopPreReadyPlatform.isVersionRequest(["--no-sandbox"]));
assert.isFalse(DesktopPreReadyPlatform.isVersionRequest(["--version=1"]));
assert.isFalse(DesktopPreReadyPlatform.isVersionRequest(["--version-foo"]));
assert.isFalse(DesktopPreReadyPlatform.isVersionRequest(["-v"]));
assert.isFalse(DesktopPreReadyPlatform.isVersionRequest([]));
});

it("writes a version line to stdout synchronously and swallows EPIPE", () => {
const writes: Array<{ fd: number; data: string }> = [];
DesktopPreReadyPlatform.writeStdoutLineSync("1.2.3", (fd, data) => {
writes.push({ fd, data });
});
assert.deepEqual(writes, [{ fd: 1, data: "1.2.3\n" }]);

DesktopPreReadyPlatform.writeStdoutLineSync("1.2.3", () => {
throw Object.assign(new Error("broken pipe"), { code: "EPIPE" });
});

try {
DesktopPreReadyPlatform.writeStdoutLineSync("1.2.3", () => {
throw Object.assign(new Error("bad fd"), { code: "EBADF" });
});
assert.fail("expected EBADF to propagate");
} catch (error) {
assert.equal((error as NodeJS.ErrnoException).code, "EBADF");
}
});

it.effect(
"acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer",
() =>
Expand Down
18 changes: 18 additions & 0 deletions apps/desktop/src/app/DesktopPreReadyPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ export function readCommandLineSwitchValue(
return value.length > 0 ? value : null;
}

export function isVersionRequest(argv: ReadonlyArray<string>): boolean {
return argv.includes("--version") || argv.includes("-V");
}

export function writeStdoutLineSync(
line: string,
writeSync: (fd: number, data: string) => void = (fd, data) => {
NodeFS.writeSync(fd, data);
},
): void {
try {
writeSync(1, `${line}\n`);
} catch (error) {
const err = error as NodeJS.ErrnoException;
if (err.code !== "EPIPE") throw error;
}
}

export const resolveEarlyLinuxElectronOptionsFromProcess =
(): DesktopEarlyElectronStartup.EarlyLinuxElectronOptions =>
DesktopEarlyElectronStartup.resolveEarlyLinuxElectronOptions({
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,9 @@ const desktopRuntimeLayer = desktopClerkLayer.pipe(
Layer.provideMerge(DesktopPreReadyPlatform.layer),
);

if (DesktopPreReadyPlatform.isVersionRequest(process.argv)) {
DesktopPreReadyPlatform.writeStdoutLineSync(Electron.app.getVersion());
process.exit(0);
Comment thread
cursor[bot] marked this conversation as resolved.
}

DesktopApp.program.pipe(Effect.provide(desktopRuntimeLayer), NodeRuntime.runMain);
Loading