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

Allow Astro to pass process.env variables to import.meta.env #3327

Merged
merged 1 commit into from
May 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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