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

In deno tasks, automatically add $DENO_DIR/bin to PATH #23078

Open
dz4k opened this issue Mar 26, 2024 · 4 comments
Open

In deno tasks, automatically add $DENO_DIR/bin to PATH #23078

dz4k opened this issue Mar 26, 2024 · 4 comments
Labels
suggestion suggestions for new features (yet to be agreed) task runner related to deno task

Comments

@dz4k
Copy link

dz4k commented Mar 26, 2024

(Should this issue be in the deno_task_shell repo? Apologies if so.)

I am writing a Deno web app intended to be run by people who might not otherwise use Deno. I use Deno tasks for starting the server.

A user had downloaded Deno but hadn't added it to their PATH, and was trying to run the project with the command ~/.deno/bin/deno task run, which failed since the run task calls Deno recursively.

As far as I can tell, my tasks cannot predict where Deno will be downloaded, and (I assume?) calling Deno within tasks is a common use case.

I propose that the Deno installation directory be prepended to the PATH environment variable before running tasks. This will work for tasks, shell scripts and shebangs since they all will inherit the environment from the deno task process.

@dsherret
Copy link
Member

dsherret commented Mar 26, 2024

A user had downloaded Deno but hadn't added it to their PATH, and was trying to run the project with the command ~/.deno/bin/deno task run, which failed since the run task calls Deno recursively.

That's strange. There's special logic to use the current executing version of deno for the deno command:

https://github.com/denoland/deno_task_shell/blob/250c0b7269bfaf2f9afc03abe4e3e0ae1b5fee8e/src/shell/commands/executable.rs#L110-L124

What was the error they saw? Are they using the latest version of Deno?

@dz4k
Copy link
Author

dz4k commented Mar 26, 2024

Looking at the output more carefully, it seems like the failed execution is in a shebang.

$ ~/.deno/bin/deno task run
Task run deno task bundle-assets && bin/denizen.ts
Task bundle-assets deno run -A tool/assets_to_module.ts
/usr/bin/env: ‘deno’: No such file or directory

Modifying the environment instead of special-casing in the shell would make this work. On the other hand, I don't think that shebang will work on Windows anyway, and I should definitely change it.

@dz4k
Copy link
Author

dz4k commented Mar 26, 2024

bin/denizen.ts:

#!/usr/bin/env -S deno run -A --unstable
import { app } from '../lib/denizen.ts'
Deno.serve({
	hostname: '0.0.0.0',
	port: Deno.env.has('PORT') ? Number(Deno.env.get('PORT')) : undefined,
}, app.fetch)

@dsherret dsherret added the suggestion suggestions for new features (yet to be agreed) label Mar 26, 2024
@dsherret
Copy link
Member

It's a good point that it might be better to add the executing directory of deno to the shell path because then it would work when a sub process executes Deno too.

On the other hand, I don't think that shebang will work on Windows anyway, and I should definitely change it.

I can implement denoland/deno_task_shell#23 -- will try to do it tomorrow as I'd like to get that in the minor release on Thursday.

@dsherret dsherret added the task runner related to deno task label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion suggestions for new features (yet to be agreed) task runner related to deno task
Projects
None yet
Development

No branches or pull requests

2 participants