From bde36863a2ede845a457b37c1191b2ea907e4568 Mon Sep 17 00:00:00 2001 From: Sidharth Sudhir Date: Mon, 5 Jan 2026 23:34:35 -0800 Subject: [PATCH 1/3] add support for 1password .env file mounts (FIFOs) --- packages/vite/src/node/__tests__/env.spec.ts | 49 ++++++++++++++++++++ packages/vite/src/node/env.ts | 4 +- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/__tests__/env.spec.ts b/packages/vite/src/node/__tests__/env.spec.ts index 36fbaa2d8172d0..371439a68669c2 100644 --- a/packages/vite/src/node/__tests__/env.spec.ts +++ b/packages/vite/src/node/__tests__/env.spec.ts @@ -1,7 +1,10 @@ +import { execSync, spawn } from 'node:child_process' +import { mkdtemp, rm } from 'node:fs/promises' import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { describe, expect, test } from 'vitest' import { loadEnv } from '../env' +import { isWindows } from '../../shared/utils' const __dirname = fileURLToPath(new URL('.', import.meta.url)) @@ -81,4 +84,50 @@ describe('loadEnv', () => { } `) }) + + test.skipIf(isWindows)('loads env from FIFO (named pipe)', async () => { + // Create a temporary directory for the test + const tempDir = await mkdtemp(join(__dirname, './env-fifo-test-')) + const fifoPath = join(tempDir, '.env') + + try { + // Create a FIFO (named pipe) + execSync(`mkfifo "${fifoPath}"`) + + // Write content to the FIFO + const envContent = + 'VITE_FIFO_TEST=hello_from_fifo\nVITE_ANOTHER_VAR=test_value' + const writePromise = new Promise((resolve, reject) => { + const echo = spawn('sh', [ + '-c', + `echo "${envContent.replace(/"/g, '\\"')}" > "${fifoPath}"`, + ]) + echo.on('close', (code) => { + if (code === 0) resolve() + else reject(new Error(`Write process exited with code ${code}`)) + }) + echo.on('error', reject) + }) + + // Read from FIFO (this will block until data is available) + // The write process will provide the data + const readPromise = loadEnv('development', tempDir) + + // Wait for both operations to complete + const [env] = await Promise.all([readPromise, writePromise]) + + // Verify the FIFO content was read correctly + expect(env).toMatchObject({ + VITE_FIFO_TEST: 'hello_from_fifo', + VITE_ANOTHER_VAR: 'test_value', + }) + } finally { + // Clean up: remove FIFO and temp directory + try { + await rm(tempDir, { recursive: true, force: true }) + } catch { + // Ignore cleanup errors + } + } + }) }) diff --git a/packages/vite/src/node/env.ts b/packages/vite/src/node/env.ts index 31ffc60be05b4b..70bac27ef977ea 100644 --- a/packages/vite/src/node/env.ts +++ b/packages/vite/src/node/env.ts @@ -45,7 +45,9 @@ export function loadEnv( const parsed = Object.fromEntries( envFiles.flatMap((filePath) => { - if (!tryStatSync(filePath)?.isFile()) return [] + const stat = tryStatSync(filePath) + // Support both regular files and FIFOs (named pipes) + if (!stat || (!stat.isFile() && !stat.isFIFO())) return [] return Object.entries(parse(fs.readFileSync(filePath))) }), From eda36a5473cd3c7bfb5ed7f3af0dd63a1c8f5636 Mon Sep 17 00:00:00 2001 From: Sidharth Sudhir Date: Mon, 12 Jan 2026 10:13:10 -0500 Subject: [PATCH 2/3] remove incorrect test case --- packages/vite/src/node/__tests__/env.spec.ts | 49 -------------------- 1 file changed, 49 deletions(-) diff --git a/packages/vite/src/node/__tests__/env.spec.ts b/packages/vite/src/node/__tests__/env.spec.ts index 371439a68669c2..36fbaa2d8172d0 100644 --- a/packages/vite/src/node/__tests__/env.spec.ts +++ b/packages/vite/src/node/__tests__/env.spec.ts @@ -1,10 +1,7 @@ -import { execSync, spawn } from 'node:child_process' -import { mkdtemp, rm } from 'node:fs/promises' import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { describe, expect, test } from 'vitest' import { loadEnv } from '../env' -import { isWindows } from '../../shared/utils' const __dirname = fileURLToPath(new URL('.', import.meta.url)) @@ -84,50 +81,4 @@ describe('loadEnv', () => { } `) }) - - test.skipIf(isWindows)('loads env from FIFO (named pipe)', async () => { - // Create a temporary directory for the test - const tempDir = await mkdtemp(join(__dirname, './env-fifo-test-')) - const fifoPath = join(tempDir, '.env') - - try { - // Create a FIFO (named pipe) - execSync(`mkfifo "${fifoPath}"`) - - // Write content to the FIFO - const envContent = - 'VITE_FIFO_TEST=hello_from_fifo\nVITE_ANOTHER_VAR=test_value' - const writePromise = new Promise((resolve, reject) => { - const echo = spawn('sh', [ - '-c', - `echo "${envContent.replace(/"/g, '\\"')}" > "${fifoPath}"`, - ]) - echo.on('close', (code) => { - if (code === 0) resolve() - else reject(new Error(`Write process exited with code ${code}`)) - }) - echo.on('error', reject) - }) - - // Read from FIFO (this will block until data is available) - // The write process will provide the data - const readPromise = loadEnv('development', tempDir) - - // Wait for both operations to complete - const [env] = await Promise.all([readPromise, writePromise]) - - // Verify the FIFO content was read correctly - expect(env).toMatchObject({ - VITE_FIFO_TEST: 'hello_from_fifo', - VITE_ANOTHER_VAR: 'test_value', - }) - } finally { - // Clean up: remove FIFO and temp directory - try { - await rm(tempDir, { recursive: true, force: true }) - } catch { - // Ignore cleanup errors - } - } - }) }) From d00c6a90ad990453a9bb551f8b92af5e371f7ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0?= Date: Wed, 14 Jan 2026 14:31:49 +0900 Subject: [PATCH 3/3] chore: update comment --- packages/vite/src/node/env.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/env.ts b/packages/vite/src/node/env.ts index 70bac27ef977ea..0f8847bf2d21ad 100644 --- a/packages/vite/src/node/env.ts +++ b/packages/vite/src/node/env.ts @@ -46,7 +46,7 @@ export function loadEnv( const parsed = Object.fromEntries( envFiles.flatMap((filePath) => { const stat = tryStatSync(filePath) - // Support both regular files and FIFOs (named pipes) + // Support FIFOs (named pipes) for apps like 1Password if (!stat || (!stat.isFile() && !stat.isFIFO())) return [] return Object.entries(parse(fs.readFileSync(filePath)))