Skip to content

Commit

Permalink
fix: inline process.env boolean values (0, 1, false, true) (#6910)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed May 1, 2023
1 parent e5bd084 commit 895fa07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shaggy-berries-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Inline `process.env` boolean values (`0`, `1`, `true`, `false`) during the build. This helps with DCE and allows for better `export const prerender` detection.
9 changes: 8 additions & 1 deletion packages/astro/src/vite-plugin-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ function getPrivateEnv(
// Ignore public env var
if (envPrefixes.every((prefix) => !key.startsWith(prefix))) {
if (typeof process.env[key] !== 'undefined') {
privateEnv[key] = `process.env.${key}`;
const value = process.env[key];
// Boolean values should be inlined to support `export const prerender`
// We already know that these are NOT sensitive values, so inlining is safe
if (value === '0' || value === '1' || value === 'true' || value === 'false') {
privateEnv[key] = value;
} else {
privateEnv[key] = `process.env.${key}`;
}
} else {
privateEnv[key] = JSON.stringify(fullEnv[key]);
}
Expand Down

0 comments on commit 895fa07

Please sign in to comment.