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

fix: don't override dot envs with site envs #1490

Merged
merged 8 commits into from
Nov 2, 2020

Conversation

erezrokah
Copy link
Contributor

- Summary

Fixes #1386
Related to #1331

Also fixed some stuff related to addons since during my manual testing I noticed it was broken.

- Test plan

Fixed some tests.
I still need to think about adding new tests, as testing #1386 will require creating a live site and then running netlify dev or netlify dev:exec.

- Description for the changelog

Refactor environment variables handling.

- A picture of a cute animal (not mandatory but encouraged)
image

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Oct 29, 2020

execa(this.argv[0], this.argv.slice(1), {
stdio: 'inherit',
env: fromEntries(envSettings.vars),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are applied globally now (which is not nice, but would require more refactoring as we log each env that is applied in a different way)

Copy link
Contributor

@ehmicky ehmicky Oct 30, 2020

Choose a reason for hiding this comment

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

Would it be possible to keep those envSettings as a variable, instead of modifying process.env?

Copy link
Contributor Author

@erezrokah erezrokah Nov 2, 2020

Choose a reason for hiding this comment

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

addEnvVariables modifies process.env but also prints log messages while doing so:
https://github.com/netlify/cli/pull/1490/files#diff-fc861c54030ca23b6d43638aa92f3f446bca1b187ce3b3fea5b8e6d7d1c0a19cR98

We can clone process.env in addEnvVariables, use the clone instead of process.env and return it to dev:exec.
That would work for dev:exec but we would still need to modify process.env in other places due to the way netlify dev and netlify functions:create commands work at the moment.

I would rather be consistent in how we're applying env variables and handle mutating process.env (in all locations we're doing it) in another PR. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense 👍
Should we create an issue for it?

Copy link
Contributor Author

@erezrokah erezrokah Nov 2, 2020

Choose a reason for hiding this comment

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

see #1517

src/utils/dev.js Outdated Show resolved Hide resolved
src/utils/proxy.js Outdated Show resolved Hide resolved
src/utils/proxy.js Outdated Show resolved Hide resolved
@erezrokah erezrokah force-pushed the refactor/cleanup_add_envs branch from c93d29b to 1c41dc4 Compare November 2, 2020 17:12
@erezrokah erezrokah requested a review from ehmicky November 2, 2020 17:52
@erezrokah erezrokah merged commit 5804724 into master Nov 2, 2020
@erezrokah erezrokah deleted the refactor/cleanup_add_envs branch November 2, 2020 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Next.js dev environment variables overwritten with production values by netlify dev
2 participants