Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,15 @@ Options:

You can customize the WordPress installation, plugins and themes that the development environment will use by specifying a `.wp-env.json` file in the directory that you run `wp-env` from.

To enable editor autocomplete and validation, add a `$schema` key:

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

Comment on lines +589 to +597

Copy link
Copy Markdown
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 👍🏻

`.wp-env.json` supports the following fields:

| Field | Type | Default | Description |
Expand Down
74 changes: 74 additions & 0 deletions packages/env/lib/config/test/wp-env-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

const Ajv = require( 'ajv' );
const schema = require( '../wp-env.schema.json' );

describe( 'wp-env schema', () => {
const ajv = new Ajv( { allErrors: true } );
const validate = ajv.compile( schema );

it( 'accepts a valid root and env configuration', () => {
const config = {
$schema: 'https://schemas.wordpress.org/wp-env.schema.json',
core: 'WordPress/WordPress#6.8',
phpVersion: '8.2',
plugins: [ '.' ],
port: 8888,
autoPort: true,
phpmyadmin: true,
phpmyadminPort: 3307,
config: {
WP_HOME: 'http://localhost:8888',
WP_SITEURL: 'http://localhost:8888',
WP_DEBUG: true,
},
env: {
tests: {
port: 8889,
config: {
WP_DEBUG: false,
},
},
},
};

expect( validate( config ) ).toBe( true );
} );

it( 'rejects unknown root and environment keys', () => {
const config = {
port: 8888,
unknownRootOption: true,
env: {
development: {
testsPort: 9999,
autoPort: true,
},
},
};

expect( validate( config ) ).toBe( false );
expect( validate.errors ).toEqual(
expect.arrayContaining( [
expect.objectContaining( {
keyword: 'additionalProperties',
params: expect.objectContaining( {
additionalProperty: 'unknownRootOption',
} ),
} ),
expect.objectContaining( {
keyword: 'additionalProperties',
params: expect.objectContaining( {
additionalProperty: 'testsPort',
} ),
} ),
expect.objectContaining( {
keyword: 'additionalProperties',
params: expect.objectContaining( {
additionalProperty: 'autoPort',
} ),
} ),
] )
);
} );
} );
165 changes: 165 additions & 0 deletions packages/env/lib/config/wp-env.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
Comment thread
kraftbj marked this conversation as resolved.
Resolved
"$id": "https://schemas.wordpress.org/wp-env.schema.json",
"title": "wp-env config",
"type": "object",
"additionalProperties": false,
"properties": {
"$schema": {
"type": "string"
},
"core": {
"type": [ "string", "null" ]
},
"phpVersion": {
"type": [ "string", "null" ],
"pattern": "^[0-9]+\\.[0-9]+$"
},
"plugins": {
"type": "array",
"items": {
"type": "string"
}
},
"themes": {
"type": "array",
"items": {
"type": "string"
}
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
},
"testsPort": {
"type": "integer",
"minimum": 1,
"maximum": 65535
},
"mysqlPort": {
"type": [ "integer", "null" ],
"minimum": 1,
"maximum": 65535
},
"phpmyadmin": {
"type": "boolean"
},
"phpmyadminPort": {
"type": [ "integer", "null" ],
"minimum": 1,
"maximum": 65535
},
"multisite": {
"type": "boolean"
},
"testsEnvironment": {
"type": "boolean"
},
"autoPort": {
"type": "boolean"
},
"config": {
"type": "object",
"additionalProperties": {
"type": [ "string", "number", "boolean" ]
}
},
"mappings": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"lifecycleScripts": {
"type": "object",
"additionalProperties": false,
"properties": {
"afterStart": {
"type": [ "string", "null" ]
},
"afterClean": {
"type": [ "string", "null" ]
},
"afterReset": {
"type": [ "string", "null" ]
},
"afterCleanup": {
"type": [ "string", "null" ]
},
"afterDestroy": {
"type": [ "string", "null" ]
}
}
},
"env": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/environmentConfig"
}
}
},
"definitions": {
"environmentConfig": {
"type": "object",
"additionalProperties": false,
"properties": {
"$schema": {
"type": "string"
},
"core": {
"type": [ "string", "null" ]
},
"phpVersion": {
"type": [ "string", "null" ],
"pattern": "^[0-9]+\\.[0-9]+$"
},
"plugins": {
"type": "array",
"items": {
"type": "string"
}
},
"themes": {
"type": "array",
"items": {
"type": "string"
}
},
"port": {
"type": "integer",
"minimum": 1,
"maximum": 65535
},
"mysqlPort": {
"type": [ "integer", "null" ],
"minimum": 1,
"maximum": 65535
},
"phpmyadmin": {
"type": "boolean"
},
"phpmyadminPort": {
"type": [ "integer", "null" ],
"minimum": 1,
"maximum": 65535
},
"multisite": {
"type": "boolean"
},
"config": {
"type": "object",
"additionalProperties": {
"type": [ "string", "number", "boolean" ]
}
},
"mappings": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
Loading