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

Feature: Automatically add .exe when running on Windows. #281

Open
NfNitLoop opened this issue Jul 19, 2024 · 4 comments
Open

Feature: Automatically add .exe when running on Windows. #281

NfNitLoop opened this issue Jul 19, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@NfNitLoop
Copy link
Contributor

I love that Dax lets me write cross-platforms scripts. One shortcoming, though, is in binary names.

As an example, if I run a deno compile foo.ts, I'd expect to then be able to run ./foo on the result.

But, of course, on Windows, that file is foo.exe. I end up having to special case every time I want my Dax script to work in multiple places.

It would be nice if this were automatic, or opt-in.

@bpollack
Copy link

bpollack commented Aug 28, 2024

Thing is, this is really hard to do generically. If there's interest, I could put together a PR that would key off %PATHEXT%, which contains a semicolon-delimited list of what cmd.exe considers to be executable extensions (including the prefix period). The annoying way to do that would be something like

const executableName(prefix: string): string => {
  try {
    Deno.statSync(prefix);
    // hey it existed
    return prefix;
  } catch { /* don't care */ }
  const pathext = Deno.env.get("PATHEXT").split(";");
  for (const extension of pathext) {
    try {
      const name = `${prefix}${extension}`;
      Deno.statSync(name);
      return name;
    } catch { /* continue */ }
  }
}
      

An alternative would be to check just the exact path, the exact path with .exe (and maybe .com?) slapped on, and otherwise give up and try invoking cmd /c ${path} to let cmd.exe deal with it.

If any of that is a direction you want to go @dsherret, I'd be happy to put together a PR, but I think there's unfortunately a viable case to be made that dax should just require the exact executable name.

@dsherret
Copy link
Owner

Yes, using PATHEXT is the correct way to do this.

@dsherret dsherret added the enhancement New feature or request label Aug 28, 2024
@bpollack
Copy link

Would you like me to put together a PR making this change? If so, would you want me to use raw Deno, @std/fs, or your new path lib?

@dsherret
Copy link
Owner

It can just use raw Deno doing what you described. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants