Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in execpath.ts #2

Merged
merged 1 commit into from
Sep 9, 2024
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
Loading