-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Runtime API to check whether in self-contained exe #15996
Comments
Would you be able to provide some use cases for this suggestion? There might be alternatives. |
I want to have a data directory at a relative path to the executable (or the main module when not compiled). I can't use Also the relative path differs a bit between compiled and not compiled. For compiled it is This is my specific use case, but I bet there are more use cases, which would benefit from such an API. |
@DerZade Not a solution, but here's a potential workaround if you're in control of compiling the binary: You can switch on the presence of a specific CLI argument to make the determination, and embed that argument into the compiled binary:
import * as path from "https://deno.land/[email protected]/path/mod.ts";
const isCompiled = Deno.args.includes("--is_compiled_binary");
const programPath = isCompiled
? Deno.execPath()
: path.fromFileUrl(Deno.mainModule);
const programDir = path.dirname(programPath);
console.log({
isCompiled,
programDir,
programPath,
});
Of course, you'll have to account for this potential extra argument if your program already accepts other arguments — and if you're concerned about the target argument being inadvertently used with the not-compiled script (a false positive), just use something unguessable like a UUID in place of the one I used in the example above. |
@jsejcksn I also thought about that workaround and we will probably use something similar in our product, but I still think a actual Deno-API would be nice. |
What I don’t like about the suggestion is the user could supply this argument themselves to Also I would feel better if the code I'm trying to change is actively not included in the final binaries, which I would expect to happen due to dead code removal if there was a static API for the “you're being compiled” condition. |
Hei, is there any update on this (the PR seems to be stale, last update a year ago) I would really like this feature as a workaround (if the behaviour is intended) for my issue: #24318 |
I couldn't find a runtime API to check whether the current code is running inside a self-contained exe.
This would make it easy to distinguish between the "production" (compiled) version and testing via
deno run
.I was thinking about something like
Deno.standalone
or maybe something more descriptive likeDeno.selfContainedExe
.The text was updated successfully, but these errors were encountered: