From 7fbc1e35d7328657a3c90eba4f345e6f30bc2b3d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 18:26:46 +0000 Subject: [PATCH 1/3] Build/Test Tools: Replace dotenv and dotenv-expand with native Node.js. The local Docker environment scripts only need the values in `.env` that they read themselves. Node.js can load a `.env` file natively with `process.loadEnvFile()`, available since Node.js 20.12, so the `dotenv` and `dotenv-expand` packages are no longer needed. Values are no longer expanded. Docker Compose expands `${VAR}` references itself when it reads `.env`, and the only reference in `.env.example` (`WP_BASE_URL`) is not read by these scripts. This also avoids `dotenv-expand` 1000.0.0, which adds command substitution during expansion. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011Y86gwpKRNgXhhtQMbSgQW --- .env.example | 5 ----- package-lock.json | 31 ------------------------------ package.json | 2 -- tools/local-env/scripts/docker.js | 4 +--- tools/local-env/scripts/install.js | 4 +--- tools/local-env/scripts/start.js | 4 +--- tools/local-env/scripts/utils.js | 18 +++++++++++++++++ 7 files changed, 21 insertions(+), 47 deletions(-) diff --git a/.env.example b/.env.example index a90402036839c..29daa279d26c9 100644 --- a/.env.example +++ b/.env.example @@ -86,8 +86,3 @@ LOCAL_WP_TESTS_DOMAIN=example.org # The URL to use when running e2e tests. WP_BASE_URL=http://localhost:${LOCAL_PORT} - -## -# This silences the tips output by the dotenv package. -## -DOTENV_CONFIG_QUIET=true diff --git a/package-lock.json b/package-lock.json index 5b497251c419d..572aede0b5624 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57,8 +57,6 @@ "@wordpress/prettier-config": "4.51.0", "@wordpress/scripts": "33.0.0", "autoprefixer": "10.5.3", - "dotenv": "17.4.2", - "dotenv-expand": "13.0.0", "grunt": "1.6.2", "grunt-banner": "^0.6.0", "grunt-contrib-clean": "~2.0.1", @@ -12081,35 +12079,6 @@ "node": ">=8" } }, - "node_modules/dotenv": { - "version": "17.4.2", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", - "integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==", - "dev": true, - "license": "BSD-2-Clause", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, - "node_modules/dotenv-expand": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-13.0.0.tgz", - "integrity": "sha512-aBfBS8eYIeXmpHI9ThIlA7/WLq+SLt18iXUZhb52rW89QLKQFoIpPG1bPeewoPZsTyjSSO3T7234FBVUM1V2rA==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "dotenv": "^17.4.2" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/package.json b/package.json index d8e955f0d9809..8b203318b537c 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,6 @@ "@wordpress/prettier-config": "4.51.0", "@wordpress/scripts": "33.0.0", "autoprefixer": "10.5.3", - "dotenv": "17.4.2", - "dotenv-expand": "13.0.0", "grunt": "1.6.2", "grunt-banner": "^0.6.0", "grunt-contrib-clean": "~2.0.1", diff --git a/tools/local-env/scripts/docker.js b/tools/local-env/scripts/docker.js index 0ef6d469d19d6..9c7297c74bb6d 100644 --- a/tools/local-env/scripts/docker.js +++ b/tools/local-env/scripts/docker.js @@ -1,12 +1,10 @@ /* jshint node:true */ -const dotenv = require( 'dotenv' ); -const dotenvExpand = require( 'dotenv-expand' ); const local_env_utils = require( './utils' ); local_env_utils.ensure_env_file(); -dotenvExpand.expand( dotenv.config() ); +local_env_utils.load_env(); // Use Xdebug to generate HTML code coverage reports, unless PCOV is enabled and Xdebug is not. if ( diff --git a/tools/local-env/scripts/install.js b/tools/local-env/scripts/install.js index 4ee1711faa144..a1bc9fe49ca9c 100644 --- a/tools/local-env/scripts/install.js +++ b/tools/local-env/scripts/install.js @@ -1,7 +1,5 @@ /* jshint node:true */ -const dotenv = require( 'dotenv' ); -const dotenvExpand = require( 'dotenv-expand' ); const wait_on = require( 'wait-on' ); const { execSync } = require( 'child_process' ); const { readFileSync, writeFileSync } = require( 'fs' ); @@ -9,7 +7,7 @@ const local_env_utils = require( './utils' ); local_env_utils.ensure_env_file(); -dotenvExpand.expand( dotenv.config() ); +local_env_utils.load_env(); // Create wp-config.php. This verifies the database connection, so retrying it keeps // `env:install` working on its own, without `env:start` having waited for the mysql diff --git a/tools/local-env/scripts/start.js b/tools/local-env/scripts/start.js index 970fc4b944ed6..2fd43814998c5 100644 --- a/tools/local-env/scripts/start.js +++ b/tools/local-env/scripts/start.js @@ -1,13 +1,11 @@ /* jshint node:true */ -const dotenv = require( 'dotenv' ); -const dotenvExpand = require( 'dotenv-expand' ); const { execSync, spawnSync } = require( 'child_process' ); const local_env_utils = require( './utils' ); local_env_utils.ensure_env_file(); -dotenvExpand.expand( dotenv.config() ); +local_env_utils.load_env(); // Check if the Docker service is running. try { diff --git a/tools/local-env/scripts/utils.js b/tools/local-env/scripts/utils.js index 58c02716241d5..6b7afdb8e726a 100644 --- a/tools/local-env/scripts/utils.js +++ b/tools/local-env/scripts/utils.js @@ -27,6 +27,24 @@ const local_env_utils = { } }, + /** + * Loads the settings in .env into `process.env`. + * + * Variables that are already set in the environment take precedence over the values in .env. + * Values are not expanded: Docker Compose expands `${VAR}` references itself when it reads .env. + */ + load_env: function() { + try { + process.loadEnvFile( join( repo_root, '.env' ) ); + } catch ( e ) { + // A missing .env was already reported by ensure_env_file(), and the scripts can still + // run with their defaults, so this is never a reason to refuse to run a command. + if ( e.code !== 'ENOENT' ) { + console.warn( `Could not load the .env file. ${ e.message }` ); + } + } + }, + /** * Runs a Docker Compose command, re-attempting it when it fails. * From eef8020c90ec942239fe434cee2423ee59bbfbab Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:37:49 -0500 Subject: [PATCH 2/3] Build/Test Tools: Stop setting `DOTENV_CONFIG_QUIET` in the E2E WP-CLI helper. The `wpCli()` helper set this so the tips printed by the `dotenv` package did not end up in the WP-CLI output it captures. The local environment scripts now load `.env` with `process.loadEnvFile()`, which prints nothing, so the variable no longer does anything. Co-Authored-By: Claude Opus 5.5 --- tests/e2e/utils/wp-cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/utils/wp-cli.js b/tests/e2e/utils/wp-cli.js index f336ad375d99e..ada8e354b1461 100644 --- a/tests/e2e/utils/wp-cli.js +++ b/tests/e2e/utils/wp-cli.js @@ -30,7 +30,7 @@ export function wpCli( args, options = {} ) { { encoding: 'utf-8', ...options, - env: { ...process.env, ...options.env, DOTENV_CONFIG_QUIET: 'true' }, + env: { ...process.env, ...options.env }, } ); } From 1446ff3f8069b7b84b79e9e799cb556bd9f9da27 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:06:53 -0500 Subject: [PATCH 3/3] Build/Test Tools: Clarify the comment about a missing `.env` file in `load_env()`. Co-Authored-By: Claude Opus 5.5 --- tools/local-env/scripts/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/local-env/scripts/utils.js b/tools/local-env/scripts/utils.js index 6b7afdb8e726a..656a0bd8e2417 100644 --- a/tools/local-env/scripts/utils.js +++ b/tools/local-env/scripts/utils.js @@ -37,8 +37,10 @@ const local_env_utils = { try { process.loadEnvFile( join( repo_root, '.env' ) ); } catch ( e ) { - // A missing .env was already reported by ensure_env_file(), and the scripts can still - // run with their defaults, so this is never a reason to refuse to run a command. + /* + * The script should still run when the .env file is missing, falling back to the defined + * default values. Missing .env files are already detected and noted by ensure_env_file(). + */ if ( e.code !== 'ENOENT' ) { console.warn( `Could not load the .env file. ${ e.message }` ); }