Make WordPress Core


Ignore:
Timestamp:
07/28/2026 04:33:51 PM (6 weeks ago)
Author:
lancewillett
Message:

Build/Test Tools: Copy local environment configuration synchronously.

On a fresh checkout, start.js copied .env.example asynchronously and
then immediately loaded .env, so the read could win the race and leave
configuration unset for that process. Copy synchronously, guarded by an
existsSync check, so .env exists before dotenv.config() runs and an
existing file is left untouched. Dropping the swallow-all callback also
lets a real copy error surface instead of being logged as "already
exists".

Developed in: https://github.com/WordPress/wordpress-develop/pull/12697

Props jonsurrell, lucasbustamante, mukesh27, adrianmoldovanwp.
See #65716.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/local-env/scripts/start.js

    r61459 r62871  
    55const { execSync, spawnSync } = require( 'child_process' );
    66const local_env_utils = require( './utils' );
    7 const { constants, copyFile } = require( 'node:fs' );
     7const { copyFileSync, existsSync } = require( 'node:fs' );
    88
    99// Copy the default .env file when one is not present.
    10 copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, () => {
    11         console.log( '.env file already exists. .env.example was not copied.' );
    12 });
     10if ( ! existsSync( '.env' ) ) {
     11        copyFileSync( '.env.example', '.env' );
     12}
    1313
    1414dotenvExpand.expand( dotenv.config() );
Note: See TracChangeset for help on using the changeset viewer.