fix(infra): deterministic env var ordering (#4893)
This change sorts environment variables alphabetically before they're processed with import-meta-env that injects them into the index.html. This makes sure consistent hashes across pod restarts when there aren't any functional changes made to the `.env` file. The issue was affecting desktop app reconnections after k8s pod restarts. The cause was non-deterministic env var ordering (a sideeffect of `Map`) during the import-meta-env injection process. Even when the env vars themselves didn't change, their order in the injected JSON could change, ultimately resulting in different file hashes. This fix ensures that regardless of the order in which env vars are provided by the runtime, they will be sorted alphabetically before being written to the build.env file.
This commit is contained in:
parent
18c233b9f9
commit
86c0bb619d
3 changed files with 3 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ function runChildProcessWithPrefix(command, args, prefix) {
|
|||
|
||||
const envFileContent = Object.entries(process.env)
|
||||
.filter(([env]) => env.startsWith("VITE_"))
|
||||
.sort(([envA], [envB]) => envA.localeCompare(envB))
|
||||
.map(([env, val]) => `${env}=${
|
||||
(val.startsWith("\"") && val.endsWith("\""))
|
||||
? val
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import fs from "fs"
|
|||
|
||||
const envFileContent = Object.entries(process.env)
|
||||
.filter(([env]) => env.startsWith("VITE_"))
|
||||
.sort(([envA], [envB]) => envA.localeCompare(envB))
|
||||
.map(
|
||||
([env, val]) =>
|
||||
`${env}=${val.startsWith('"') && val.endsWith('"') ? val : `"${val}"`}`
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ function runChildProcessWithPrefix(command, args, prefix) {
|
|||
|
||||
const envFileContent = Object.entries(process.env)
|
||||
.filter(([env]) => env.startsWith('VITE_'))
|
||||
.sort(([envA], [envB]) => envA.localeCompare(envB))
|
||||
.map(
|
||||
([env, val]) =>
|
||||
`${env}=${val.startsWith('"') && val.endsWith('"') ? val : `"${val}"`}`
|
||||
|
|
|
|||
Loading…
Reference in a new issue