-
Notifications
You must be signed in to change notification settings - Fork 640
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
to-do(dotenv): document key restrictions #5619
Comments
I think this restriction comes from the restriction of env var names in shell script (because .env file is modeled after them). However maybe it's good idea to align it to other dotenv tools. BTW Deno CLI also supports Can anybody check how other tools handles |
|
Oh, sorry, I see. These restrictions are in place so that environment variables are portable between |
Thank you for your responses. I have a few more questions.
I'm not entirely sure what is meant by "portability" and "sanity" here. Are they suggesting that by restricting environment variable names for shell scripts, deno-std makes it easier to use across different environments? From my perspective, these restrictions in deno-std actually reduce portability because I’m unable to use the keys in permissive environment. The mention of "sanity" is also confusing. I spent a significant amount of time debugging because I wasn’t aware that deno-std would ignore certain keys. My intention in raising this issue was to help improve the developer experience for other's sanity. The point about following the same policy as Rust, as mentioned by kt3k, does seem more convincing. However, to my knowledge, the current implementations in deno-std and Rust aren't identical, so I don’t think that was the intended alignment. If the restrictions on keys are to be maintained, I suggest providing a warning when environment variables are ignored. Also, I’m curious about what alternatives you would recommend for using .env files for esbuild’s define functionality under the current policy. That said, I still support my original proposal as a way to avoid these issues altogether. |
This sounds good to me. Let's do this
I don't see well what this mean. |
In my custom bundler, the I could have used JSON or TOML for this, but I felt the .env format was the most natural choice. |
As you can see from this discussion, I think JSON/TOML/YAML are more appropriate for your use case. |
I think the only relavant ground on this discussion is timreichen's link, but I can't think of concrete problematic case for this. I described about this on my previous comment. So I'll appreciate if anyone give me concrete problem by loosing key constraint. I've searched dotenvx's issues but couldn't find such case. It might also be helpful to clarify what is meant by "general purpose data". For example, if an external application requires the use of |
Why would an app need that? If a key value with special chars is relevant, I think one can use the variable to store the key |
I admit I don't know such app, but I think such need exists from an issue.
This approach seems more like a workaround than a proper solution. Given this restriction I see at least two issues:
And from now on I suggest considering the following too.
|
I agree. Deno even throws if on invalid keys: Dot in key:
Uncaught (in promise) ReferenceError: FOO is not defined Number at beginning of the key:
Warning Parsing failed within the specified environment file: .env at index: 0 of the value: 1FOO="bar"
error: The module's source code could not be parsed: Identifier cannot follow number at file:///path/to/.env:1:2 So I guess std dotenv should also throw on an invalid key. |
Is your feature request related to a problem? Please describe.
It seems that the current dotenv implementation restricts certain strings from being used as keys. For example, keys like
'1a'
and'process.env.xxx'
are not allowed.Describe the solution you'd like
I'd like to see these restrictions removed so that these keys can be used.
Describe alternatives you've considered
I'd appreciate an explanation of the rationale behind these restrictions. Or is it possible that I just haven't found the right way to do this?
I found npm dotenv package allowing this.
The text was updated successfully, but these errors were encountered: