Skip to content

wp-env: Add JSON Schema for .wp-env.json configuration#76115

Open
kraftbj wants to merge 1 commit intoWordPress:trunkfrom
kraftbj:env-client-json-schema
Open

wp-env: Add JSON Schema for .wp-env.json configuration#76115
kraftbj wants to merge 1 commit intoWordPress:trunkfrom
kraftbj:env-client-json-schema

Conversation

@kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Mar 4, 2026

What?

Add a JSON Schema file for .wp-env.json configuration files, enabling editor autocomplete and validation.

Why?

The .wp-env.json config supports many options across root-level and per-environment overrides. A JSON Schema lets editors (VS Code, JetBrains, etc.) provide inline autocomplete, type checking, and unknown-key warnings — reducing config errors and improving discoverability.

How?

  • Add packages/env/lib/config/wp-env.schema.json with all root-level and per-environment properties, including the recently added autoPort option.
  • Root-only options (testsPort, autoPort, testsEnvironment, lifecycleScripts, env) are excluded from the environmentConfig definition so the schema rejects them inside env overrides.
  • Add a brief note in packages/env/README.md showing how to opt in via the $schema key.
  • Add packages/env/lib/config/test/wp-env-schema.js with tests verifying valid configs are accepted and unknown/misplaced keys are rejected.

Testing Instructions

  1. Create or edit a .wp-env.json file in any project.
  2. Add "$schema": "https://schemas.wordpress.org/wp-env.schema.json" (or use a relative path to packages/env/lib/config/wp-env.schema.json).
  3. Verify your editor provides autocomplete for known keys (core, plugins, port, autoPort, etc.).
  4. Verify unknown keys show a validation warning.
  5. Verify that root-only keys like autoPort and testsPort show warnings when placed inside an env override.

Testing Instructions for Keyboard

N/A — no UI changes.

Add a JSON Schema file that enables editor autocomplete and validation
for .wp-env.json configuration files. Users can opt in by adding a
$schema key pointing to the published schema URL.

The schema covers all root-level and per-environment options, including
the recently added autoPort option, and rejects unknown keys to catch
typos early.
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kraftbj <kraftbj@git.wordpress.org>

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

@ramonjd ramonjd added the [Type] Enhancement A suggestion for improvement. label Mar 4, 2026
@@ -0,0 +1,165 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
Copy link
Member

Choose a reason for hiding this comment

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

Might be a naive question, but what the relationship between this schema and https://schemas.wp.org/trunk/wp-env.json (https://github.com/WordPress/gutenberg/blob/trunk/schemas/json/wp-env.json)?

I think autoPort is missing from the existing one. Would updating the existing schema have the same effect?

Comment on lines +589 to +597
To enable editor autocomplete and validation, add a `$schema` key:

```json
{
"$schema": "https://schemas.wordpress.org/wp-env.schema.json",
"plugins": [ "." ]
}
```

Copy link
Member

Choose a reason for hiding this comment

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

I think this is a good to have regardless of whether we have a new schema doc or keep on using https://schemas.wp.org/trunk/wp-env.json 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants