Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: support multiline values in env files #10826

Merged
merged 7 commits into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vite/package.json
Expand Up @@ -88,8 +88,8 @@
"cross-spawn": "^7.0.3",
"debug": "^4.3.4",
"dep-types": "link:./src/types",
"dotenv": "^14.3.2",
"dotenv-expand": "^5.1.0",
"dotenv": "^16.0.3",
"dotenv-expand": "^9.0.0",
"es-module-lexer": "^1.1.0",
"estree-walker": "^3.0.1",
"etag": "^1.8.1",
Expand Down
14 changes: 5 additions & 9 deletions packages/vite/src/node/env.ts
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'
import { parse } from 'dotenv'
import { expand } from 'dotenv-expand'
import { arraify, lookupFile } from './utils'
import type { UserConfig } from './config'

Expand Down Expand Up @@ -31,23 +31,19 @@ export function loadEnv(
rootDir: envDir
})
if (!path) return []
return Object.entries(
dotenv.parse(fs.readFileSync(path), {
debug: process.env.DEBUG?.includes('vite:dotenv')
})
)
return Object.entries(parse(fs.readFileSync(path)))
})
)

// let environment variables use each other
const expandParsed = dotenvExpand({
const expandParsed = expand({
parsed: {
...(process.env as any),
...parsed
},
// prevent process.env mutation
ignoreProcessEnv: true
} as any).parsed!
}).parsed!

Object.keys(parsed).forEach((key) => {
parsed[key] = expandParsed[key]
Expand Down
17 changes: 9 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.