Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent loading env outside of root (#6995)
- Loading branch information
Showing
9 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_PARENT_ENV=dont_load_me |
15 changes: 15 additions & 0 deletions
15
packages/playground/env-nested/__tests__/env-nested.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isBuild } from 'testUtils' | ||
|
||
const mode = isBuild ? `production` : `development` | ||
|
||
test('mode', async () => { | ||
expect(await page.textContent('.mode')).toBe(mode) | ||
}) | ||
|
||
test('mode file override', async () => { | ||
expect(await page.textContent('.mode-file')).toBe(`.env.${mode}`) | ||
}) | ||
|
||
test('should not load parent .env file', async () => { | ||
expect(await page.textContent('.parent-env')).not.toBe('dont_load_me') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_EFFECTIVE_MODE_FILE_NAME=.env.development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_EFFECTIVE_MODE_FILE_NAME=.env.production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>Nested Environment Variables</h1> | ||
<p>import.meta.env.MODE: <code class="mode"></code></p> | ||
<p> | ||
import.meta.env.VITE_EFFECTIVE_MODE_FILE_NAME: <code class="mode-file"></code> | ||
</p> | ||
<p>Empty import.meta.env.VITE_PARENT_ENV: <code class="parent-env"></code></p> | ||
|
||
<script type="module"> | ||
text('.mode', import.meta.env.MODE) | ||
text('.mode-file', import.meta.env.VITE_EFFECTIVE_MODE_FILE_NAME) | ||
text('.parent-env', import.meta.env.VITE_PARENT_ENV) | ||
|
||
function text(el, text) { | ||
document.querySelector(el).textContent = text | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "test-env-nested", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"preview": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { defineConfig } = require('vite') | ||
|
||
module.exports = defineConfig({ | ||
envDir: './envs' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters