Skip to content

Commit

Permalink
Merge pull request #2 from benjamin-wilkins/main
Browse files Browse the repository at this point in the history
Fix bug in execpath.ts
  • Loading branch information
Hexagon authored Sep 9, 2024
2 parents e92c3c6 + 1a424fe commit df31065
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
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

0 comments on commit df31065

Please sign in to comment.