-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
privatePrefix
for private environment variables (#9996)
Closes #9776. Adds a new config option, config.kit.env.privatePrefix, for setting a private prefix on environment variables. This defaults to ''. To prevent super-weird and unexpected behaviors, the logic is: - private: does not begin with public prefix, does begin with private prefix - public: does begin with public prefix, does not begin with private prefix This has the side benefit of not allowing the two prefixes to be the same. Note: Had to create env.js utils file so that the utils could be imported into server/index -- putting them pretty much anywhere else ended up causing a transitive dependency on some node package somewhere that wasn't compatible with Node 16. --------- Co-authored-by: Simon H <[email protected]>
- Loading branch information
1 parent
316a4af
commit 47d8048
Showing
20 changed files
with
124 additions
and
35 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,5 @@ | ||
--- | ||
'@sveltejs/kit': minor | ||
--- | ||
|
||
feat: add `privatePrefix` to `config.kit.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
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
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,33 @@ | ||
/** | ||
* @param {Record<string, string>} env | ||
* @param {{ | ||
* public_prefix: string; | ||
* private_prefix: string; | ||
* }} prefixes | ||
* @returns {Record<string, string>} | ||
*/ | ||
export function filter_private_env(env, { public_prefix, private_prefix }) { | ||
return Object.fromEntries( | ||
Object.entries(env).filter( | ||
([k]) => | ||
k.startsWith(private_prefix) && (public_prefix === '' || !k.startsWith(public_prefix)) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @param {Record<string, string>} env | ||
* @param {{ | ||
* public_prefix: string; | ||
* private_prefix: string; | ||
* }} prefixes | ||
* @returns {Record<string, string>} | ||
*/ | ||
export function filter_public_env(env, { public_prefix, private_prefix }) { | ||
return Object.fromEntries( | ||
Object.entries(env).filter( | ||
([k]) => | ||
k.startsWith(public_prefix) && (private_prefix === '' || !k.startsWith(private_prefix)) | ||
) | ||
); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "test-options", | ||
"name": "test-embed", | ||
"private": true, | ||
"version": "0.0.1", | ||
"scripts": { | ||
|
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
GO_AWAY_PLEASE=and thank you | ||
GO_AWAY_PLEASE=and thank you | ||
TOP_SECRET_SHH_PLS=shhhh | ||
MATCHES_NEITHER=should be discarded |
10 changes: 10 additions & 0 deletions
10
packages/kit/test/apps/options/source/pages/env/+page.server.js
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,10 @@ | ||
import { TOP_SECRET_SHH_PLS } from '$env/static/private'; | ||
import { env } from '$env/dynamic/private'; | ||
|
||
export function load() { | ||
return { | ||
TOP_SECRET_SHH_PLS, | ||
// @ts-expect-error | ||
MATCHES_NEITHER: env.MATCHES_NEITHER || '' | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<script> | ||
import { GO_AWAY_PLEASE } from '$env/static/public'; | ||
export let data; | ||
</script> | ||
|
||
<p>{GO_AWAY_PLEASE}</p> | ||
<p id="public">{GO_AWAY_PLEASE}</p> | ||
<p id="private">{data.TOP_SECRET_SHH_PLS}</p> | ||
<p id="neither">{data.MATCHES_NEITHER}</p> |
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