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

Add support for loading env values #23

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

nkahlor
Copy link

@nkahlor nkahlor commented Feb 26, 2021

Pre-Requisites

  • Yes, I updated Authors.md OR this is not my first contribution
  • Yes, I included and/or modified tests to cover relevent code OR my change is non-technical
  • Yes, I wrote this code entirely myself OR I properly attributed these changes in Third Party Notices

Description of Changes

Extends the capabilities of dotenv-flow, so the users of this package don't need to install both packages.

simple-env should play nice with .env files out of the box :^)

Related Issues

Closes Add support for loading env values

@nkahlor nkahlor marked this pull request as ready for review February 26, 2021 18:18
Copy link
Contributor

@johnkahn johnkahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the parsing code to it's own file that is imported into index.ts? It's about doubled the length of the file, so I think it'll help readability.

Great work, I think this will definitely help us going forward as it's one less dependency in our projects. In the future, I would love to see us add support for multiple .env files similar to dotenv-flow since some of our projects will still need to use that for multiple environments.

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/types/Options.ts Outdated Show resolved Hide resolved
src/types/Options.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Author

@nkahlor nkahlor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just about wrap it up for this PR, please let me know if there's anything else I missed and I'll try to get to it quickly!

.vscode/launch.json Outdated Show resolved Hide resolved
@nkahlor nkahlor requested a review from johnkahn March 10, 2021 23:46
src/test/index.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@SpencerKaiser SpencerKaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two big things in addition to a question (and more feedback from @johnkahn):

  • Make sure to update the README with info about how to use it (make sure to make restrictions clear and add a snippet to show an example of it being used)
  • Since this is a rather significant feature addition, make sure to bump the minor version in both of the package files

This is going to be an awesome addition!!! Thanks for doing this 😄

src/types/Options.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@johnkahn johnkahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple README updates.

Also reading through the example I want to make sure that the implementation here matches what dotenv does so it's an easy swap for people. Looks like we have some extra stuff (like // comments) and we're missing some things. @SpencerKaiser what is your thought on changing envPath to experimentalEnvPath and merging as is? Then changing it to envPath once it matches?

https://github.com/motdotla/dotenv#rules

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Co-authored-by: John Kahn <[email protected]>
Co-authored-by: John Kahn <[email protected]>
@nkahlor
Copy link
Author

nkahlor commented Mar 18, 2021

A couple README updates.

Also reading through the example I want to make sure that the implementation here matches what dotenv does so it's an easy swap for people. Looks like we have some extra stuff (like // comments) and we're missing some things. @SpencerKaiser what is your thought on changing envPath to experimentalEnvPath and merging as is? Then changing it to envPath once it matches?

https://github.com/motdotla/dotenv#rules

I don't think adding // comments is a bad thing

But we definitely want our parser to handle the same cases as DotEnv so that it's easy for people to swap to our package painlessly. I'll re-work it a bit to cover all those cases.

Copy link
Contributor

@SpencerKaiser SpencerKaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few quick things and then I think we can merge!


If you set a path to an `.env` file, `simple-env` will parse the file and import the contents into the environment automatically. These will be available in the `process.env` object.

> If you don't specify a path, `simple-env` **will not** automatically load any `.env` files. This is to avoid a breaking change.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> If you don't specify a path, `simple-env` **will not** automatically load any `.env` files. This is to avoid a breaking change.
> :warning: **NOTE**: If you don't specify a path, `simple-env` **will not** automatically load any `.env` files.

someRequiredSecret: 'SOME_REQUIRED_SECRET',
},
options: {
envPath: "./.env"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work as well. Do you think the original is better?

Suggested change
envPath: "./.env"
envPath: ".env"

}
});
```
Each variable needs to be declared on a separate line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add all of this to a new sub-section called Correct .env Syntax (or something like it). To keep the README simple, can we add all of that to a <details> tag?

@@ -1,3 +1,5 @@
.vscode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including that file was intentional; revert this

@SpencerKaiser
Copy link
Contributor

@johnkahn I'm ok with the rules as of now; while I don't want to encourage // as a comment within .env, we can't use that line as a variable anyways, so we should still ignore it. As long as we're inclusive of the use-cases dotenv covers, I think we'll be good to go for people swapping.

And re: experimentalEnvPath, keep in mind that bumping that to envPath would be a breaking change, so we'd need to bump the minor version again.

@johnkahn
Copy link
Contributor

johnkahn commented Mar 23, 2021

@SpencerKaiser I was wondering if having //SOMETHING="something" would create process.env['//SOMETHING'] though 🤔 That was my main thing is that if that works in dotenv we may want to keep it that way for now. Plus editors don't highlight // as a comment like # does

And for experimentalEnvPath we would put in the description and the README that it can change or be removed at any time, so it's more of a use at your own risk. It's how I've seen React handles experimental features, but I'm cool with not doing it.

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

Successfully merging this pull request may close these issues.

Add support for loading env values
3 participants