Skip to content

Build/Test Tools: Replace dotenv and dotenv-expand with native Node.js - #15756

Draft
desrosj wants to merge 4 commits into
WordPress:trunkfrom
desrosj:remove/dotenv-native-loadenvfile
Draft

desrosj wants to merge 4 commits into
WordPress:trunkfrom
desrosj:remove/dotenv-native-loadenvfile

Conversation

@desrosj

@desrosj desrosj commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

The local Docker environment scripts (env:start, env:install, env:cli, and the rest that go through docker.js) used dotenv and dotenv-expand to read .env into process.env. Node.js can do this itself with process.loadEnvFile(), and the minimum Node.js version (24.18) supports it, so both packages are removed.

This also avoids dotenv-expand 1000.0.0, which adds command substitution during expansion.

This adds a load_env() helper that the local environment scripts now use, and removes the leftover DOTENV_CONFIG_QUIET settings.

Behavior

  • Precedence is the same: a variable already set in the shell still wins over .env.
  • Values are no longer expanded. No value in .env.example uses a ${VAR} reference, and Docker Compose still expands values itself when it reads .env.
  • A missing .env is silent, because ensure_env_file() already reports it. Any other read error prints a warning and the command keeps running, as ensure_env_file() does.
  • Existing .env files are fine. A leftover DOTENV_CONFIG_QUIET=true line does nothing.

Testing

  • Loading .env gives the expected values (LOCAL_PORT=8889, LOCAL_DIR=src, …). LOCAL_PORT=9999 in the shell overrides the value in .env.
  • A missing .env produces no output. An unreadable .env prints the warning and the script keeps running.
  • jshint passes on tools/local-env/scripts/.
  • npm ls dotenv dotenv-expand is empty.

AI Usage

This patch was written with Claude Code and reviewed by me.

🤖 Generated with Claude Code

claude and others added 2 commits November 6, 2026 13:37
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Y86gwpKRNgXhhtQMbSgQW
…I 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 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

desrosj and others added 2 commits November 6, 2026 14:02
…`load_env()`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desrosj desrosj self-assigned this Nov 6, 2026
@desrosj
desrosj marked this pull request as ready for review November 6, 2026 19:13
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props desrosj.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@desrosj desrosj moved this from Backlog to Ready in WordPress Project Build Tooling Nov 6, 2026
@desrosj desrosj moved this from Ready to In progress in WordPress Project Build Tooling Nov 6, 2026
@desrosj
desrosj marked this pull request as draft November 6, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants