diff --git a/.env.example b/.env.example index bdd47dedb82d5..ed1f5cecbbba3 100644 --- a/.env.example +++ b/.env.example @@ -83,8 +83,3 @@ LOCAL_SCRIPT_DEBUG=true LOCAL_WP_ENVIRONMENT_TYPE=local LOCAL_WP_DEVELOPMENT_MODE=core LOCAL_WP_TESTS_DOMAIN=example.org - -## -# 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/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 }, } ); } 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..656a0bd8e2417 100644 --- a/tools/local-env/scripts/utils.js +++ b/tools/local-env/scripts/utils.js @@ -27,6 +27,26 @@ 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 ) { + /* + * 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 }` ); + } + } + }, + /** * Runs a Docker Compose command, re-attempting it when it fails. *