Skip to content

Commit

Permalink
fix: allow Astro to pass process.env variables to import.meta.env (
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored May 11, 2022
1 parent ce6d798 commit ca4e3aa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/astro/src/vite-plugin-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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> {
Expand Down

0 comments on commit ca4e3aa

Please sign in to comment.