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

Expose private .env variables to import.meta.env during SSR #2612

Merged
merged 7 commits into from
Feb 18, 2022

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Feb 17, 2022

Changes

  • Exposes all .env variables to import.meta.env on the server (during SSR).
  • Exposes only PUBLIC_ variables to import.meta.env on the client.
  • Adds a new example named env-vars

Testing

Tested manually in example

Docs

Updated in PR

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2022

🦋 Changeset detected

Latest commit: b1acfa4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) labels Feb 17, 2022
Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Great idea but no need to rush the implementation! I would love to see a pass to clean up the code a bit

@github-actions github-actions bot added the test label Feb 17, 2022
Copy link
Contributor

@jonathantneal jonathantneal left a comment

Choose a reason for hiding this comment

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

Sweetening the release, @natemoo-re. 💯

if (!/\benv\b/.test(source)) return source;

if (typeof privateEnv === 'undefined') {
privateEnv = getPrivateEnv(config, astroConfig);
Copy link
Member

Choose a reason for hiding this comment

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

a little worried about caching issues here if Vite has automatic-reloading of .env files. Not enough to block, just a callout that could deserve a TODO if someone runs into this issue in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good callout. Just checked and Vite does not hot-reload .env files.

@FredKSchott
Copy link
Member

LGTM with a failing test. Reminder that we don't need to race the train on this one: we can get it out in the next release if needed

@natemoo-re natemoo-re merged commit 39cbe50 into main Feb 18, 2022
@natemoo-re natemoo-re deleted the fix/process-env branch February 18, 2022 22:06
@github-actions github-actions bot mentioned this pull request Feb 18, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
…astro#2612)

* chore(examples): add env-vars example

* feat: improve import.meta.env support

* chore: add changeset

* test: update astro-envs test

* refactor: cleanup code based on feedback

* fix: import.meta guard

* fix: update memory test threshold to 10%
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
…astro#2612)

* chore(examples): add env-vars example

* feat: improve import.meta.env support

* chore: add changeset

* test: update astro-envs test

* refactor: cleanup code based on feedback

* fix: import.meta guard

* fix: update memory test threshold to 10%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants