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

feat(env): client/public variables #10848

Merged
merged 46 commits into from
Apr 26, 2024

Conversation

florian-lefebvre
Copy link
Member

@florian-lefebvre florian-lefebvre commented Apr 22, 2024

Depends on #10829

Changes

  • Implements client/public variables handling
  • Refactors how src/env.d.ts references are generated
  • Moves envField to the right place

Testing

  • Updates the astro sync test
  • Adds an integration test
  • Updates the validators test to also include getType

Docs

N/A

Copy link

changeset-bot bot commented Apr 22, 2024

⚠️ No Changeset found

Latest commit: e519f82

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Apr 22, 2024
@github-actions github-actions bot added the pkg: example Related to an example package (scope) label Apr 22, 2024
@florian-lefebvre florian-lefebvre requested review from ematipico and removed request for ematipico April 24, 2024 13:55
@florian-lefebvre florian-lefebvre marked this pull request as ready for review April 24, 2024 14:40
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Left some comments

packages/astro/src/env/vite-plugin-env-virtual-mod.ts Outdated Show resolved Hide resolved
packages/astro/src/env/vite-plugin-env-virtual-mod.ts Outdated Show resolved Hide resolved
Comment on lines 41 to 42
const { clientContent, clientDts } = handleClientModule({ schema, loadedEnv });
handleDts({ settings, fs, content: clientDts });
Copy link
Member

Choose a reason for hiding this comment

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

We are generating code before the load function; is that correct? Shouldn't we generate code inside load? Types and client code will be emitted only if the user attempts to use the virtual module.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I also think we should be lazy loading the virtual module code. One thing to also check though is if new env vars get picked up across server restarts. As a Vite plugin, it's best to cache or reset the cache with the buildStart/buildEnd/config/configResolved hooks etc so that we re-compute the env when needed.

packages/astro/src/env/vite-plugin-env-virtual-mod.ts Outdated Show resolved Hide resolved
packages/astro/src/env/vite-plugin-env-virtual-mod.ts Outdated Show resolved Hide resolved
packages/astro/src/vite-plugin-inject-env-ts/index.ts Outdated Show resolved Hide resolved
packages/astro/src/vite-plugin-inject-env-ts/index.ts Outdated Show resolved Hide resolved
packages/astro/src/core/errors/errors-data.ts Outdated Show resolved Hide resolved
packages/astro/src/core/errors/errors-data.ts Outdated Show resolved Hide resolved
packages/astro/src/env/constants.ts Outdated Show resolved Hide resolved
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Great work here @florian-lefebvre!

Let's sheep it

@florian-lefebvre florian-lefebvre merged commit eec5403 into feat/astro-env Apr 26, 2024
14 checks passed
@florian-lefebvre florian-lefebvre deleted the feat/astro-env-client-public branch April 26, 2024 09:12
ematipico added a commit that referenced this pull request Jun 5, 2024
* feat(env): add schema, types and envField (#10805)

* feat(env): add validators (#10827)

* feat(env): add vite plugin (#10829)

* feat(env): client/public variables (#10848)

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* feat(env): server/public variables (#10881)

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* feat(env): server/secret variables (#10954)

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* fix: import

* fix: test

* feat: work on jsdoc

* feat: more jsdoc

* chore: remove todo

* feat: fix test error and write changeset

* feat: update config reference

* feat: apply recommendations from review

* feat: rework getEnv/setGetEnv

* chore: move tests

* fix: rename

* fix: dev mode

* chore: improve error

* feat: add overrideProcessEnv helper

* fix: make eslint happy

* Update .changeset/poor-berries-occur.md

Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>

* Update .changeset/poor-berries-occur.md

Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>

* Update .changeset/poor-berries-occur.md

Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>

* Update .changeset/poor-berries-occur.md

Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>

* feat: fix build and address reviews

* fix: container api

* fix: tests

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/astro/src/@types/astro.ts

* chore: update changeset

* feat: address reviews

* feat: address Ema's reviews

* Update .changeset/poor-berries-occur.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
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) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants