Skip to content
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

Ability to execute files with shebang on Windows and older versions of Ubuntu? #23

Closed
dsherret opened this issue Mar 19, 2022 · 1 comment · Fixed by #113
Closed

Ability to execute files with shebang on Windows and older versions of Ubuntu? #23

dsherret opened this issue Mar 19, 2022 · 1 comment · Fixed by #113

Comments

@dsherret
Copy link
Member

dsherret commented Mar 19, 2022

For example, say you had:

{
  "tasks": {
    "my_task": "./my_script.js"
  }
}

And the script had:

#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
// ...etc...

Perhaps if the script has a shebang starting with #!/usr/bin/env -S then deno task should just figure this out. This apparently already works on Mac so making this work on all platforms would reduce some issues.

From @jespertheend in denoland/deno#14036

I like this method because it keeps the required permissions close to the actual file, and running the script is extremely simple because all you have to do is run ./tools/format.js.

But the downside is... it doesn't work very well on Windows. Maybe I'm missing a simple solution for this, but as far as I can tell /usr/bin/env is not really a thing on Windows, and shebang support isn't great either. So Windows users are stuck with having to run scripts using deno run while trying to figure out what the required permissions are (or running with -A).
This wasn't a huge problem for me though. I'm mostly developing on macOS, so I was using shebangs for now, though I did want to have better cross platform support eventually.

To implement this, I think we should attempt to parse the shebang. If we can, execute it the same way on all platforms. If we can't, we should try to run it as a command, but print a warning saying it won't work cross platform and to recommend fixing the shebang.

@dsherret dsherret changed the title Ability to execute files with shebang? Ability to execute files with shebang on Windows and older versions of Ubuntu? Mar 19, 2022
@dsherret
Copy link
Member Author

dsherret commented Mar 7, 2024

This was implemented in Dax here:

https://github.com/dsherret/dax/blob/ed9fbd1f0b7aef914f78efc384dba55b719880b9/src/shell.ts#L1116

...since the two codebases are similar, maybe what's done there could give some guidance for how a first pass of this feature might be implemented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant