dax
dax copied to clipboard
Feature: Automatically add .exe when running on Windows.
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.
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.
Yes, using PATHEXT is the correct way to do this.
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?
It can just use raw Deno doing what you described. Thanks!