-
Notifications
You must be signed in to change notification settings - Fork 5.6k
shebang support #929
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
Comments
I would assume that deno would use TypeScript for extensionless file names. But I'm not really sure what about extensions in file names with a shebang line. Relying on the file name in this particular case is tricky because it's often the case that an executable may be symlinked or renamed during installation. It's common in Node today with scripts installed with npm. I don't want file extensions in my /usr/local/bin but if the file happens to be script.js that needs to be parsed as JS and not TS then script.js cannot be installed to /usr/bin as just "script". The solutions I see are all ugly - maybe someone else has some better ideas.
Works well for
or something like that. I don't like it really but being optional for cases when there is no file extension that would at least make it possible to write scripts to be installed as system commands.
and
This is the last one that I thought about and doesn't seem that bad. But it would mean either installing two binaries or one binary and a symlink. All of the above have some issues, meybe someone has a better idea. |
All JS currently passes through the TypeScript compiler currently, which is likely to persist, especially if we end up supporting type checking of JS via JSDocs. I do not think treating the vast majority of extensionless files as TypeScript though would create any userland problems, as the compiler is in a very loose mode, and any JavaScript that would be invalid TypeScript is probably a bad idea anyways. It would be best to treat it as TypeScript and then only deal with it if it actually causes problems we can't solve. |
@kitsonk I don't think it's that simple. Even this trivial example: let x = 1;
x = 'a';
console.log(x); passes as JS but not as TS - both in Deno itself - see: Update: I know that in theory TS is syntactically a superset of JS, but even though all JS code can in principle be parsed as TS, it doesn't necessarily mean that it doesn't violate the type system. To make it work we would need to use As for me, I'd rather go the other way and compile the TS code with --strict by default (with a --loose switch in deno instead of non-strict by default) but that's just me and I know it will probably be non-strict by default (with hopefully a short switch like -s for strict parsing) but I hope Deno will not be even less strict than the default non-strict tsc mode, by switching off the type inference. |
@rsp there are a few issues here that then get all coupled together that should be solved before we try to solve JavaScript support for shebang:
(A couple of them are things that have been talked about but I realised didn't have issues) My opinion is that we could/should implement shebang support for TypeScript only and then deliver the right solution for JavaScript as an incremental change. |
Perhaps "how should deno handle extensionless files" should be a separate issue from "deno should ignore shebangs"? |
The issue as formulated is about Shebang support. Because scripts need |
From
The following works for me #!/usr/bin/env -S deno run --allow-net
fetch("https://api.ipify.org?format=json")
.then(v => v.json())
.then(console.log) |
You still wouldn't be able to provide runtime flags like permissions :) This is a damning problem with the way shebangs work on Linux which individual CLIs shouldn't cripple themselves to solve, and the |
Yes, that does work in the very latest coreutils (8.30+ has it). So Ubuntu 20.04 is fine, but everyone on an older LTS, of most distros won't have that, the -S flag is new. |
All the older languages/platforms that had to work with |
Wrong, they also have runtime flags which aren't always optional depending on the use case. I don't think having runtime flags is "doing things differently". |
Most binaries have all kinds of runtime flags. But having a subcommand like |
The point was that the runtime flags pose the same issue, so we may as well have a modern subcommand-based CLI. The subcommand issue has nothing specifically to do with shebang compatibility. |
But runtime flags can be optional, but leaving out the subcommand is now causing an error. That is not the common case for most other scripting engines. |
In the tiny set of cases where no permissions are required? Again, requiring
You can search for and read through issues related to that if you're curious. In short, the
|
That's why I am of the opinion that subcommands are not a good idea, because they could be taken as an input filename. I prefer commandline options where there are flags with |
Try to describe the myriad of relationships / exclusions / ordering semantics between such flags, and provide good help messages, without subcommands. Keep in mind that Node's CLI doesn't expose such a varied set of functions like |
Uh oh!
There was an error while loading. Please reload this page.
When using deno to write applications or tools, it is desirable to execute those directly as
binary [argv]
, rather thandeno path/to/binary.ts [argv]
.It could be possible to build custom versions of deno with code embedded, but I won't cover that here (see #986).
In this issue I'm looking at using deno as an executable interpreter with a shebang, such as this file
binary
containing:This currently does not work, for two separate reasons:
binary
rather thanbinary.ts
), deno will not load it.Ultimately this means that it doesn't seem like you can do this with deno directly, rather you need something like a wrapper shell script or binary around invoking deno.
Ignoring the shebang line seems entirely reasonable, as that is not valid JavaScript | TypeScript in the first place.
I'm not sure what would be an acceptable solution regarding the extension.
Node just interprets files without an extension as
.js
files.The text was updated successfully, but these errors were encountered: