dax icon indicating copy to clipboard operation
dax copied to clipboard

Feature: Automatically add .exe when running on Windows.

Open NfNitLoop opened this issue 1 year ago • 4 comments

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.

NfNitLoop avatar Jul 19 '24 19:07 NfNitLoop

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.

bpollack avatar Aug 28 '24 14:08 bpollack

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

dsherret avatar Aug 28 '24 14:08 dsherret

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?

bpollack avatar Aug 28 '24 14:08 bpollack

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

dsherret avatar Aug 28 '24 15:08 dsherret