-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(cli): Add Deno.mainModule
#6180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All for this addition but it should be unstable first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably put this behind a blind read permission check like CWD and exec path. This will in a lot of cases leak the user's username, for example.
Okay, done. Hopefully I did that correctly. |
@ry FYI, the tests pass when I run them locally. The CI failure seems to have been caused by a connection timeout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
@Alhadis would you mind explaining what the difference is to Put in a script file, these two outputs are equivalent:
Or is it meant to have a more concise wording? |
It isn't when that module imports another module. They are only equivalent in the main module. |
Right, thanks! I just had the usual case in mind, that the script entry point triggers all main-file related code actions, so |
This PR exposes the path/URL of the original script that was executed on the command-line (previously available as
location.pathname
; removed in #5034). It's the moral equivalent of Node'sprocess.argv[1]
value, except that it's a URL string instead of an ordinary path. This is becausedeno run
can execute remote files directly, making it necessary to distinguish between/foo/bar
andhttps://deno.land/foo/bar
.Be aware that for
deno eval
,Deno.mainModule
will contain some fabricated location ending in__$deno$eval.ts
. I would have set this property tonull
in such cases, but this is literally the first time I've ever touched Rust, and my attempts were met with confusing and frustrating errors (I guess 15 minutes isn't enough to wrap one's head around the basics of Rust…)