-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Consistent handling of environment variables (#5663)
* feat: Add env config object * feat: Added types * feat: Add .d.ts import to tsconfig * feat: Generate env var dump code * fix: imports * fix: Remove old error mechanism * feat: Rough edges of server-side module protection * fix: Performance and add Vite overlay * feat: First full draft of static environment vars * fix unit tests * fix: Rich is smarter than I am * feat: Let know about Vite mode * feat: Added to sync CLI * feat: Added runtime variable support * feat: Make server.init multicalls a noop * feat: Set runtime env in preview * this doesn't work?!: Set runtime env in dev * feat: Added runtime env handler to cloudflare for testing * Update packages/kit/src/cli.js * Update packages/kit/src/core/sync/write_env.js * Update packages/kit/src/core/sync/write_env.js * Update packages/kit/src/vite/build/build_server.js * Update packages/kit/src/core/sync/write_env.js * make mode required * move env/runtime to a file * simplify write_env * Update packages/kit/src/vite/preview/index.js * remove unnecessary index.js suffix * simplify * tabs * make init sync, make options required * format * cast process.env * remove the overlay stuff, just throw an error * just throw * simplify traversal * make build-time traversal more efficient * move dev code into dev module * always set env * simplify * remove hard-coded .svelte-kit * rename env/runtime to env/platform and get it working in dev * remove outdated comment * docs * App.RuntimeEnv -> App.Env * add Env interface where necessary * update more adapters * changesets * tweak changesets * add a test * replace doc links * fix: Invalid js identifiers skipped * rename modules * fix some stuff, break some stuff * update tests * ok i think thats almost everything * oops * hide functions * separate PrivateEnv from PublicEnv * expose entry points * fix turbo config * fix * Update .changeset/beige-gorillas-tell.md * Update packages/kit/src/runtime/env-public.js * Update packages/kit/src/runtime/env-private.js * Update packages/kit/src/runtime/env-public.js * Update packages/kit/src/runtime/env-private.js * Update packages/kit/src/core/sync/sync.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/src/vite/utils.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/src/vite/utils.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/test/apps/basics/.env Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/test/apps/basics/.gitignore Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * write_env in init, not update * lint * simplify valid identifier check, allow exports of reserved words * move types/ambient.d.ts to ambient.d.ts so it doesnt get nuked on update * Update documentation/docs/15-configuration.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * remove env vars FAQ * feat: Testing for import analysis * Update packages/kit/types/ambient.d.ts * warn if env vars are invalid * oops * argh * Update packages/kit/scripts/extract-types.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * explain why we strip the origin * Update packages/kit/types/ambient.d.ts Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * temporarily disable * Revert "temporarily disable" This reverts commit c1a5d52. * tidy up * remove another unused import * Update packages/kit/src/vite/utils.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/src/vite/utils.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/src/vite/utils.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/src/vite/utils.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * Update packages/kit/src/core/sync/write_env.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Rich Harris <hello@rich-harris.dev> Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
- Loading branch information
1 parent
a6b0f00
commit b1a4055
Showing
47 changed files
with
851 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@sveltejs/adapter-cloudflare': patch | ||
'@sveltejs/adapter-cloudflare-workers': patch | ||
'@sveltejs/adapter-netlify': patch | ||
'@sveltejs/adapter-node': patch | ||
'@sveltejs/adapter-vercel': patch | ||
--- | ||
|
||
Initialise `env` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Add `$env/static/private`, `$env/static/public`, `$env/dynamic/private` and `$env/dynamic/public` modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Environment variables [loaded by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files) from `.env` files and `process.env`. Like [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-platform), this module cannot be imported into client-side code. | ||
|
||
_Unlike_ [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-platform), the values exported from this module are statically injected into your bundle at build time, enabling optimisations like dead code elimination. | ||
|
||
```ts | ||
import { API_KEY } from '$env/static/private'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Similar to [`$env/static/private`](https://kit.svelte.dev/docs/modules#$env-static-private), except that it only includes environment variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code. | ||
|
||
Values are replaced statically at build time. | ||
|
||
```ts | ||
import { PUBLIC_BASE_URL } from '$env/static/public'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a simple alias to `src/lib`, or whatever directory is specified as [`config.kit.files.lib`](https://kit.svelte.dev/docs/configuration#files). It allows you to access common components and utility modules without `../../../../` nonsense. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.