fix(vite): inline import.meta.env.* (#3306)

This commit is contained in:
Marvin Hagemeister
2025-09-02 09:55:21 +02:00
committed by GitHub
parent ae2a27e174
commit 0d94bb0405
2 changed files with 20 additions and 0 deletions
@@ -41,6 +41,18 @@ export function inlineEnvVarsPlugin(mode: string) {
const name = path.node.property.name;
replace(path, name);
}
// Check: import.meta.env.*
if (
t.isIdentifier(path.node.property) &&
t.isMemberExpression(path.node.object) &&
t.isIdentifier(path.node.object.property) &&
path.node.object.property.name === "env" &&
t.isMetaProperty(path.node.object.object)
) {
const name = path.node.property.name;
replace(path, name);
}
},
CallExpression(path) {
// Check: Deno.env.get("<string>")
@@ -69,3 +69,11 @@ Deno.test("env vars - inline const _ = Deno.env.get()", () => {
expected: `const deno = "test";`,
});
});
Deno.test("env vars - inline import.meta.env.FRESH_PUBLIC_FOO", () => {
using _ = usingEnv("FRESH_PUBLIC_FOO", "test");
runTest({
input: `() => import.meta.env.FRESH_PUBLIC_FOO;`,
expected: `() => "test";`,
});
});