diff --git a/apps/desktop/src/fixPath.ts b/apps/desktop/src/fixPath.ts index 150848c14c6..10d4e3fd32e 100644 --- a/apps/desktop/src/fixPath.ts +++ b/apps/desktop/src/fixPath.ts @@ -1,18 +1,28 @@ import * as ChildProcess from "node:child_process"; export function fixPath(): void { - if (process.platform !== "darwin") return; + if (process.platform === "win32") return; - try { - const shell = process.env.SHELL ?? "/bin/zsh"; - const result = ChildProcess.execFileSync(shell, ["-ilc", "echo -n $PATH"], { - encoding: "utf8", - timeout: 5000, - }); - if (result) { - process.env.PATH = result; + const shell = process.env.SHELL ?? (process.platform === "darwin" ? "/bin/zsh" : "/bin/sh"); + const commandArgSets = [ + ["-ilc", "echo -n $PATH"], + ["-lc", "echo -n $PATH"], + ] as const; + + for (const args of commandArgSets) { + try { + const result = ChildProcess.execFileSync(shell, args, { + encoding: "utf8", + timeout: 5000, + }); + if (result) { + process.env.PATH = result; + return; + } + } catch { + // Try the next shell invocation mode. } - } catch { - // Keep inherited PATH if shell lookup fails. } + + // Keep inherited PATH if shell lookup fails. } diff --git a/apps/server/src/os-jank.ts b/apps/server/src/os-jank.ts index 3f5e2129da0..79084f9c956 100644 --- a/apps/server/src/os-jank.ts +++ b/apps/server/src/os-jank.ts @@ -3,20 +3,30 @@ import { Effect, Path } from "effect"; import { execFileSync } from "node:child_process"; export function fixPath(): void { - if (process.platform !== "darwin") return; + if (process.platform === "win32") return; - try { - const shell = process.env.SHELL ?? "/bin/zsh"; - const result = execFileSync(shell, ["-ilc", "echo -n $PATH"], { - encoding: "utf8", - timeout: 5000, - }); - if (result) { - process.env.PATH = result; + const shell = process.env.SHELL ?? (process.platform === "darwin" ? "/bin/zsh" : "/bin/sh"); + const commandArgSets = [ + ["-ilc", "echo -n $PATH"], + ["-lc", "echo -n $PATH"], + ] as const; + + for (const args of commandArgSets) { + try { + const result = execFileSync(shell, args, { + encoding: "utf8", + timeout: 5000, + }); + if (result) { + process.env.PATH = result; + return; + } + } catch { + // Try the next shell invocation mode. } - } catch { - // Silently ignore — keep default PATH } + + // Silently ignore and keep default PATH. } export const expandHomePath = Effect.fn(function* (input: string) { diff --git a/scripts/build-desktop-artifact.ts b/scripts/build-desktop-artifact.ts index 8823b885134..4e8b0647240 100644 --- a/scripts/build-desktop-artifact.ts +++ b/scripts/build-desktop-artifact.ts @@ -117,6 +117,30 @@ function resolveGitCommitHash(repoRoot: string): string { return hash.toLowerCase(); } +function resolveGitTaggedVersion(repoRoot: string): string | undefined { + const result = spawnSync("git", ["tag", "--points-at", "HEAD"], { + cwd: repoRoot, + encoding: "utf8", + }); + if (result.status !== 0) { + return undefined; + } + + const tags = result.stdout + .split("\n") + .map((value) => value.trim()) + .filter((value) => value.length > 0); + + for (const tag of tags) { + const match = tag.match(/^v(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/); + if (match?.[1]) { + return match[1]; + } + } + + return undefined; +} + function resolvePythonForNodeGyp(): string | undefined { const configured = process.env.npm_config_python ?? process.env.PYTHON; if (configured && existsSync(configured)) { @@ -558,7 +582,8 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( }), }); - const appVersion = options.version ?? serverPackageJson.version; + const tagVersion = resolveGitTaggedVersion(repoRoot); + const appVersion = options.version ?? tagVersion ?? serverPackageJson.version; const commitHash = resolveGitCommitHash(repoRoot); const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped; const stageRoot = yield* mkdir({