From f954bf14604fa1e31264be25477846f0c38027a5 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Sun, 26 Jul 2026 10:52:01 -0700 Subject: [PATCH] Build/Test Tools: Copy the local environment configuration synchronously. On a fresh checkout, the asynchronous copy of .env.example can race with dotenv loading .env. This leaves configuration values unset for the process. Use copyFileSync() to ensure .env exists before dotenv loads it. Fixes #65716. Props lance.willett@automattic.com --- tools/local-env/scripts/start.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/local-env/scripts/start.js b/tools/local-env/scripts/start.js index 66559d4c10b85..b45f8199738b0 100644 --- a/tools/local-env/scripts/start.js +++ b/tools/local-env/scripts/start.js @@ -4,12 +4,14 @@ const dotenv = require( 'dotenv' ); const dotenvExpand = require( 'dotenv-expand' ); const { execSync, spawnSync } = require( 'child_process' ); const local_env_utils = require( './utils' ); -const { constants, copyFile } = require( 'node:fs' ); +const { constants, copyFileSync } = require( 'node:fs' ); // Copy the default .env file when one is not present. -copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, () => { +try { + copyFileSync( '.env.example', '.env', constants.COPYFILE_EXCL ); +} catch ( e ) { console.log( '.env file already exists. .env.example was not copied.' ); -}); +} dotenvExpand.expand( dotenv.config() );