Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wp-env After Setup Command #50196

Merged
merged 9 commits into from
May 2, 2023
Merged

Add wp-env After Setup Command #50196

merged 9 commits into from
May 2, 2023

Conversation

ObliviousHarmony
Copy link
Contributor

What?

This pull request will execute a new lifecycle script, afterSetup, whenever WordPress is configured. It will run on:

  • wp-env start: Runs when the cache is invalidated and WordPress is configured.
  • wp-env clean: Runs after the environment is cleaned.

Why?

By allowing users to run their own command after installation, they will be able to define setup scripts and the like that perform additional processing on the environment post-setup.

How?

We've added an afterSetup option that can be set at the root of a .wp-env.json file. This option can also be overridden using the WP_ENV_AFTER_SETUP environment variable.

Testing Instructions

  1. Create (or edit) a .wp-env.override.json to include:
{
  "afterSetup": "echo \"Test\""
}
  1. Run npm run env -- start --update and verify that Test is printed once.
  2. Run npm run env -- start --update --no-execute-scripts and verify that Test is not printed.
  3. Run WP_ENV_AFTER_SETUP="ls -la" npm run env -- start --update and verify that the Gutenberg directory is printed once.
  4. Run npm run env -- clean and verify that Test is printed once.
  5. Run npm run env -- clean --no-execute-scripts and verify that Test is not printed.
@noahtallen noahtallen added [Package] Env /packages/env [Type] Feature New feature to highlight in changelogs. labels Apr 29, 2023
Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one or two minor comments, but this is looking pretty good! It also tests well.

packages/env/lib/config/parse-config.js Outdated Show resolved Hide resolved
packages/env/lib/config/parse-config.js Show resolved Hide resolved
packages/env/lib/config/validate-config.js Outdated Show resolved Hide resolved
@noahtallen
Copy link
Member

noahtallen commented Apr 29, 2023

Another tip is that instead of npm run env -- start --update, you can use npx wp-env start --update. npx finds the local code as well

packages/env/README.md Outdated Show resolved Hide resolved
Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, this looks good to me! I have one non-blocking concern, which is that the sometimes-executed sometimes-not behavior might be confusing to end users. But I agree that the behavior in the PR makes the most sense given how wp-env start works.

@noahtallen noahtallen merged commit 628a1f6 into WordPress:trunk May 2, 2023
@github-actions github-actions bot added this to the Gutenberg 15.8 milestone May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Env /packages/env [Type] Feature New feature to highlight in changelogs.
3 participants