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
11 changes: 1 addition & 10 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { analyzeCoverage, formatCoverageReport, type CoverageResult } from "../c
import { checkForUpdate, performUpdate, isNpmInstall } from "./updater.js";
import { confirm } from "./prompts.js";
import { removeFromPath } from "./shell.js";
import { getCurrentExecutablePath } from "./executable.js";

/**
* Print version information.
Expand Down Expand Up @@ -122,16 +123,6 @@ export const handleUpdateCommand = async (): Promise<void> => {
console.log("Please restart to use the new version.");
};

/**
* Get the path to the current executable.
*/
const getCurrentExecutablePath = (): string => {
if (process.execPath.includes("node") || process.execPath.includes("bun")) {
return process.argv[1];
}
return process.execPath;
};

/**
* Handle --uninstall command.
* Removes the binary and PATH entries from shell rc files.
Expand Down
18 changes: 18 additions & 0 deletions src/cli/executable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Shared helpers for locating the running CLI executable.
*/

/**
* Get the path to the current executable.
*
* For Bun-compiled binaries, `process.execPath` points to the binary itself.
* For Node.js, `process.argv[1]` is the script path.
*/
export const getCurrentExecutablePath = (): string => {
if (process.execPath.includes("node") || process.execPath.includes("bun")) {
// Running via node/bun interpreter - use argv[1]
return process.argv[1];
}
// Compiled binary - use execPath
return process.execPath;
};
15 changes: 1 addition & 14 deletions src/cli/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { tmpdir } from "node:os";
import { join, dirname, basename } from "node:path";
import { spawn } from "node:child_process";
import { VERSION, GITHUB_REPO, BINARY_NAME } from "../version.js";
import { getCurrentExecutablePath } from "./executable.js";

/** GitHub release information. */
interface GitHubRelease {
Expand Down Expand Up @@ -198,20 +199,6 @@ const downloadFile = async (url: string, destPath: string): Promise<void> => {
});
};

/**
* Get the path to the current executable.
*/
const getCurrentExecutablePath = (): string => {
// For Bun-compiled binaries, process.execPath points to the binary itself
// For Node.js, process.argv[1] is the script path
if (process.execPath.includes("node") || process.execPath.includes("bun")) {
// Running via node/bun interpreter - use argv[1]
return process.argv[1];
}
// Compiled binary - use execPath
return process.execPath;
};

/**
* Generate a unique backup path with timestamp to avoid conflicts with locked files.
* On Windows, previous backup files may still be locked by the old process.
Expand Down
Loading