Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ functionality:
table(myData);
```

- **execPath(): Promise<string>**
- **execPath(): string**
- Returns the actual path to the current runtime executable.
- **Examples:**
```javascript
Expand Down
15 changes: 5 additions & 10 deletions utils/execpath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import process from "node:process";
* Cross-runtime compatible way to return the current executable path in a manner, regardless of Node, Deno or Bun.
*
* @returns {string} The current working directory path.
* @throws
* @throws {Error} If the runtime executable cannot be found from the runtime.
* @example
* // import { execPath } from "@cross/utils";
*
* const currentExecPath = execPath();
* console.log("The path to the current runtime executable is :", currentExecPath);
*/
export function execPath(): Promise<string> {
export function execPath(): string {
if (CurrentRuntime === Runtime.Deno) {
//@ts-ignore cross-runtime
return Deno.execPath();
} else if (
CurrentRuntime === Runtime.Node || CurrentRuntime === Runtime.Bun
) {
//@ts-ignore cross-runtime
return process.execPath();
return process.execPath;
} else {
throw new Error(
`Cannot determine execPath using current runtime ('${CurrentRuntime}').`,
Expand Down Expand Up @@ -49,24 +47,21 @@ export async function resolvedExecPath(): Promise<string> {
if (foundDeno !== null) {
return foundDeno;
} else {
//@ts-ignore cross-runtime
return Deno.execPath();
}
} else if (CurrentRuntime === Runtime.Node) {
const foundNode = await which("node");
if (foundNode !== null) {
return foundNode;
} else {
//@ts-ignore cross-runtime
return process.execPath();
return process.execPath;
}
} else if (CurrentRuntime === Runtime.Bun) {
const foundBun = await which("bun");
if (foundBun !== null) {
return foundBun;
} else {
//@ts-ignore cross-runtime
return process.execPath();
return process.execPath;
}
} else {
throw new Error(
Expand Down