Skip to content

Commit

Permalink
feat!: support multiline values in env files (#10826)
Browse files Browse the repository at this point in the history
Co-authored-by: bluwy <[email protected]>
close #10149
  • Loading branch information
Dunqing authored Nov 30, 2022
1 parent 1a54e58 commit 606e60d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,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
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 606e60d

Please sign in to comment.