-
Notifications
You must be signed in to change notification settings - Fork 16
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
Env file cross-platform #24
Comments
I think the way to do this would be something like: {
"tasks": {
"some_task": "deno task --quiet with_vars deno eval 'console.log(5);'",
"with_vars": "deno run -A scripts/with_vars.ts"
}
} Then in import "https://deno.land/[email protected]/dotenv/load.ts";
const p = Deno.run({
cmd: [...Deno.args],
});
Deno.exit(await p.status()); So essentially, it launches a script that loads the environment variables from |
@dsherret Will you consider opening this again? I think that recommending privilege escalation isn't a great solution… and that proper support for safely supplying environment variables from a file is a great feature for the task shell to provide. Recently I wanted to use
HOSTNAME=localhost
PORT=3000
{
"tasks": {
"serve": "deno serve --allow-net=localhost:3000 --host=$HOSTNAME --port=$PORT server.ts",
}
} I wanted to:
…so I ended up running the serve task like this in my *nix shell: eval $(< .env) deno task serve This met the criteria above, but
I'd like for the task shell to offer a way to support this case natively: safely parsing and loading environment variables from a |
The shell in deno task already has full permissions and can execute executables.
Maybe |
Doesn't this work on Windows? export $(cat .env | xargs) && mycommand |
Right, I meant "recommending privilege escalation to the deno process…"
It's definitely an abstract operation, and I haven't yet thought about how to solve it, but I still think it's a useful feature to offer: so that the same environment variables can be used by the task itself and by the code that is run by the task (without duplication). |
@Leokuma No — one of the requirements I listed is to not export the variables to the shell… so that they don't remain available to subsequent processes. |
@dsherret Since you didn't reopen this issue when you replied… it wasn't clear to me from what you wrote: Are you declining this feature request completely, or should I create a new issue instead? |
You can use a subshell for this (just ensure you're using a newish version of Deno that has denoland/deno#24279): (export $(cat .env | xargs) && mycommand)
I don't see anything actionable at the moment because there's no proposals. If someone has a proposal for how this could work then please open a new issue outlining that. |
How can I load environment variables from an
.env
file in a way that works cross-platform?I have too many variables to add to the command line. I could load them manually from inside my app using dotenv, but I wouldn't like to add the
--allow-read
permission just for that, and also I'd like to keep my script as clean as possible, with as few deps as possible.The text was updated successfully, but these errors were encountered: