summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2022-05-11 10:23:55 -0500
committerGravatar GitHub <noreply@github.com> 2022-05-11 09:23:55 -0600
commitca4e3aa048288ba9d28bfdfb3aaeab080765cac5 (patch)
tree793797fe4ba8e64750cd4501f1ac19fd24e1a4d1
parentce6d79828250e9a3631778a37d43068cae04bb4f (diff)
downloadastro-ca4e3aa048288ba9d28bfdfb3aaeab080765cac5.tar.gz
astro-ca4e3aa048288ba9d28bfdfb3aaeab080765cac5.tar.zst
astro-ca4e3aa048288ba9d28bfdfb3aaeab080765cac5.zip
fix: allow Astro to pass `process.env` variables to `import.meta.env` (#3327)
-rw-r--r--packages/astro/src/vite-plugin-env/index.ts8
1 files changed, 4 insertions, 4 deletions
diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts
index 7a716019e..bc3447214 100644
--- a/packages/astro/src/vite-plugin-env/index.ts
+++ b/packages/astro/src/vite-plugin-env/index.ts
@@ -22,9 +22,6 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig
''
);
const privateKeys = Object.keys(fullEnv).filter((key) => {
- // don't expose any variables also on `process.env`
- // note: this filters out `CLI_ARGS=1` passed to node!
- if (typeof process.env[key] !== 'undefined') return false;
// don't inject `PUBLIC_` variables, Vite handles that for us
for (const envPrefix of envPrefixes) {
@@ -37,7 +34,10 @@ function getPrivateEnv(viteConfig: vite.ResolvedConfig, astroConfig: AstroConfig
if (privateKeys.length === 0) {
return null;
}
- return Object.fromEntries(privateKeys.map((key) => [key, JSON.stringify(fullEnv[key])]));
+ return Object.fromEntries(privateKeys.map((key) => {
+ if (typeof process.env[key] !== 'undefined') return [key, `process.env.${key}`];
+ return [key, JSON.stringify(fullEnv[key])]
+ }));
}
function getReferencedPrivateKeys(source: string, privateEnv: Record<string, any>): Set<string> {