Skip to content

Commit

Permalink
env: Ignore \$schema key in environment config parsing (#62626)
Browse files Browse the repository at this point in the history
* env: Ignore `\$schema` key in environment config parsing

* Add changelog

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
  • Loading branch information
3 people authored and ellatrix committed Jun 25, 2024
1 parent ad97722 commit f3ef36c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancement

- Ignore `$schema` key in environment config parsing ([#62626](https://github.com/WordPress/gutenberg/pull/62626)).

## 10.0.0 (2024-05-31)

### Breaking Changes
Expand Down
5 changes: 5 additions & 0 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ async function parseEnvironmentConfig(
continue;
}

// The $schema key is a special key that is used to validate the configuration.
if ( key === '$schema' ) {
continue;
}

// We should also check root-only options for the root config
// because these aren't part of the above defaults but are
// configuration options that we will parse.
Expand Down
20 changes: 20 additions & 0 deletions packages/env/lib/config/test/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,26 @@ describe( 'parseConfig', () => {
} );
} );

it( 'should ignore `$schema` key', async () => {
readRawConfigFile.mockImplementation( async ( configFile ) => {
if ( configFile === '/test/gutenberg/.wp-env.json' ) {
return {
$schema: 'test',
};
}

if ( configFile === '/test/gutenberg/.wp-env.override.json' ) {
return {};
}

throw new Error( 'Invalid File: ' + configFile );
} );

const parsed = await parseConfig( '/test/gutenberg', '/cache' );

expect( parsed ).toEqual( DEFAULT_CONFIG );
} );

it( 'should override with environment variables', async () => {
process.env.WP_ENV_PORT = 123;
process.env.WP_ENV_TESTS_PORT = 456;
Expand Down

0 comments on commit f3ef36c

Please sign in to comment.