0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix: allow Astro to pass process.env variables to import.meta.env (#3327)

This commit is contained in:
Nate Moore 2022-05-11 10:23:55 -05:00 committed by GitHub
parent ce6d798282
commit ca4e3aa048
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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> {