fix: inline process.env boolean values (0, 1, false, true) (#6910)
This commit is contained in:
parent
e5bd084c01
commit
895fa07d8b
2 changed files with 13 additions and 1 deletions
5
.changeset/shaggy-berries-accept.md
Normal file
5
.changeset/shaggy-berries-accept.md
Normal file
|
@ -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.
|
|
@ -31,7 +31,14 @@ function getPrivateEnv(
|
||||||
// Ignore public env var
|
// Ignore public env var
|
||||||
if (envPrefixes.every((prefix) => !key.startsWith(prefix))) {
|
if (envPrefixes.every((prefix) => !key.startsWith(prefix))) {
|
||||||
if (typeof process.env[key] !== 'undefined') {
|
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 {
|
} else {
|
||||||
privateEnv[key] = JSON.stringify(fullEnv[key]);
|
privateEnv[key] = JSON.stringify(fullEnv[key]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue