Make WordPress Core

Changeset 60305


Ignore:
Timestamp:
06/12/2025 09:00:24 PM (7 months 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'?

Fixes #63543.
Props westonruter, jorbin, SirLouen.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/docker-compose.yml

    r59679 r60305  
    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:
  • trunk/tools/local-env/scripts/install.js

    r60287 r60305  
     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 local_env_utils = require( './utils' );
    79
     
    1214
    1315// Create wp-config.php.
    14 wp_cli( 'config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force' );
     16wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file=${process.env.LOCAL_DIR}/../wp-config.php` );
    1517
    1618// Add the debug settings to wp-config.php.
     
    2325wp_cli( `config set WP_DEVELOPMENT_MODE ${process.env.LOCAL_WP_DEVELOPMENT_MODE} --type=constant` );
    2426
    25 // Move wp-config.php to the base directory, so it doesn't get mixed up in the src or build directories.
    26 renameSync( `${process.env.LOCAL_DIR}/wp-config.php`, 'wp-config.php' );
    27 
    2827// Read in wp-tests-config-sample.php, edit it to work with our config, then write it to wp-tests-config.php.
    2928const testConfig = readFileSync( 'wp-tests-config-sample.php', 'utf8' )
     
    3231    .replace( 'yourpasswordhere', 'password' )
    3332    .replace( 'localhost', 'mysql' )
    34     .replace( "'WP_TESTS_DOMAIN', 'example.org'", `'WP_TESTS_DOMAIN', '${process.env.LOCAL_WP_TESTS_DOMAIN}'` )
    35     .concat( "\ndefine( 'FS_METHOD', 'direct' );\n" );
     33    .replace( `'WP_TESTS_DOMAIN', 'example.org'`, `'WP_TESTS_DOMAIN', '${process.env.LOCAL_WP_TESTS_DOMAIN}'` )
     34    .concat( `\ndefine( 'FS_METHOD', 'direct' );\n` );
    3635
    3736writeFileSync( 'wp-tests-config.php', testConfig );
    3837
    3938// Once the site is available, install WordPress!
    40 wait_on( { resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`] } )
     39wait_on( {
     40    resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`],
     41    timeout: 3000,
     42} )
     43    .catch( err => {
     44        console.error( `Error: It appears the development environment has not been started. Message: ${ err.message }` );
     45        console.error( `Did you forget to do 'npm run env:start'?` );
     46        process.exit( 1 );
     47    } )
    4148    .then( () => {
    4249        wp_cli( 'db reset --yes' );
    4350        const installCommand = process.env.LOCAL_MULTISITE === 'true'  ? 'multisite-install' : 'install';
    4451        wp_cli( `core ${ installCommand } --title="WordPress Develop" --admin_user=admin --admin_password=password --admin_email=test@example.com --skip-email --url=http://localhost:${process.env.LOCAL_PORT}` );
     52    } )
     53    .catch( err => {
     54        console.error( `Error: Unable to reset DB and install WordPress. Message: ${ err.message }` );
     55        process.exit( 1 );
    4556    } );
    4657
Note: See TracChangeset for help on using the changeset viewer.