Make WordPress Core

Changeset 60431


Ignore:
Timestamp:
07/07/2025 11:30:25 PM (8 days ago)
Author:
westonruter
Message:

Build/Test Tools: Improve env:install command with better configurability and error handling.

  • Force WP-CLI to use the wp-config.php in the directory above the src directory via the WP_CONFIG_PATH environment variable [read by WP-CLI](https://github.com/wp-cli/wp-cli/blob/2800ad0a66747a826ae4221b2f022f1df6779cb6/php/utils.php#L328-L329) in the wp_locate_config() function.
  • Update the env:install command to write out the config at the repo root instead of writing it inside of the ABSPATH only then to move it one directory up.
  • Fix JSHint issues.
  • Add error handling to when npm run env:install is executed without having first done npm run env:start, in which case the script will end with an exit code of 1 and emit:

Error: It appears the development environment has not been started. Message: Timed out waiting for: tcp:localhost:8000
Did you forget to do 'npm run env:start'?

Reviewed by audrasjb.
Merges [60305] to the 6.8 branch.

Fixes #63543.
Props westonruter, jorbin, SirLouen.

Location:
branches/6.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/6.8

  • branches/6.8/docker-compose.yml

    r60092 r60431  
    107107      PHP_FPM_GID: ${PHP_FPM_GID-1000}
    108108      HOST_PATH: ${PWD-}/${LOCAL_DIR-src}
     109      WP_CONFIG_PATH: /var/www/wp-config.php
    109110
    110111    volumes:
  • branches/6.8/tools/local-env/scripts/install.js

    r59769 r60431  
     1/* jshint node:true */
     2
    13const dotenv       = require( 'dotenv' );
    24const dotenvExpand = require( 'dotenv-expand' );
    35const wait_on = require( 'wait-on' );
    46const { execSync } = require( 'child_process' );
    5 const { renameSync, readFileSync, writeFileSync } = require( 'fs' );
     7const { readFileSync, writeFileSync } = require( 'fs' );
    68const { utils } = require( './utils.js' );
    79const local_env_utils = require( './utils' );
     
    1315
    1416// Create wp-config.php.
    15 wp_cli( 'config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force' );
     17wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file=${process.env.LOCAL_DIR}/../wp-config.php` );
    1618
    1719// Add the debug settings to wp-config.php.
     
    2426wp_cli( `config set WP_DEVELOPMENT_MODE ${process.env.LOCAL_WP_DEVELOPMENT_MODE} --type=constant` );
    2527
    26 // Move wp-config.php to the base directory, so it doesn't get mixed up in the src or build directories.
    27 renameSync( `${process.env.LOCAL_DIR}/wp-config.php`, 'wp-config.php' );
    28 
    2928// Read in wp-tests-config-sample.php, edit it to work with our config, then write it to wp-tests-config.php.
    3029const testConfig = readFileSync( 'wp-tests-config-sample.php', 'utf8' )
     
    3332    .replace( 'yourpasswordhere', 'password' )
    3433    .replace( 'localhost', 'mysql' )
    35     .replace( "'WP_TESTS_DOMAIN', 'example.org'", `'WP_TESTS_DOMAIN', '${process.env.LOCAL_WP_TESTS_DOMAIN}'` )
    36     .concat( "\ndefine( 'FS_METHOD', 'direct' );\n" );
     34    .replace( `'WP_TESTS_DOMAIN', 'example.org'`, `'WP_TESTS_DOMAIN', '${process.env.LOCAL_WP_TESTS_DOMAIN}'` )
     35    .concat( `\ndefine( 'FS_METHOD', 'direct' );\n` );
    3736
    3837writeFileSync( 'wp-tests-config.php', testConfig );
    3938
    4039// Once the site is available, install WordPress!
    41 wait_on( { resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`] } )
     40wait_on( {
     41    resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`],
     42    timeout: 3000,
     43} )
     44    .catch( err => {
     45        console.error( `Error: It appears the development environment has not been started. Message: ${ err.message }` );
     46        console.error( `Did you forget to do 'npm run env:start'?` );
     47        process.exit( 1 );
     48    } )
    4249    .then( () => {
    4350        wp_cli( 'db reset --yes' );
    4451        const installCommand = process.env.LOCAL_MULTISITE === 'true'  ? 'multisite-install' : 'install';
    4552        wp_cli( `core ${ installCommand } --title="WordPress Develop" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:${process.env.LOCAL_PORT}` );
     53    } )
     54    .catch( err => {
     55        console.error( `Error: Unable to reset DB and install WordPress. Message: ${ err.message }` );
     56        process.exit( 1 );
    4657    } );
    4758
Note: See TracChangeset for help on using the changeset viewer.