Skip to content

Commit

Permalink
Fixed lifecycleScripts Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ObliviousHarmony committed May 23, 2023
1 parent 62a2022 commit 97ca1be
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
} = require( './parse-source-string' );
const {
ValidationError,
checkString,
checkPort,
checkStringArray,
checkObjectWithValues,
Expand Down Expand Up @@ -337,26 +336,28 @@ async function parseRootConfig( configFile, rawConfig, options ) {
checkPort( configFile, `testsPort`, rawConfig.testsPort );
parsedConfig.testsPort = rawConfig.testsPort;
}
parsedConfig.lifecycleScripts = {};
if ( rawConfig.lifecycleScripts ) {
parsedConfig.lifecycleScripts = {};

for ( const key in rawConfig.lifecycleScripts ) {
if ( rawConfig.lifecycleScripts[ key ] !== null ) {
checkString(
configFile,
key,
rawConfig.lifecycleScripts[ key ]
);
}
parsedConfig.lifecycleScripts[ key ] =
rawConfig.lifecycleScripts[ key ];
}
checkObjectWithValues(
configFile,
'lifecycleScripts',
rawConfig.lifecycleScripts,
[ 'null', 'string' ],
true
);
parsedConfig.lifecycleScripts = rawConfig.lifecycleScripts;
}

// Parse the environment-specific configs so they're accessible to the root.
parsedConfig.env = {};
if ( rawConfig.env ) {
checkObjectWithValues( configFile, 'env', rawConfig.env, [ 'object' ] );
checkObjectWithValues(
configFile,
'env',
rawConfig.env,
[ 'object' ],
false
);
for ( const env in rawConfig.env ) {
parsedConfig.env[ env ] = await parseEnvironmentConfig(
configFile,
Expand Down Expand Up @@ -477,7 +478,8 @@ async function parseEnvironmentConfig(
configFile,
`${ environmentPrefix }config`,
config.config,
[ 'string', 'number', 'boolean', 'empty' ]
[ 'string', 'number', 'boolean' ],
true
);
parsedConfig.config = config.config;

Expand All @@ -502,7 +504,8 @@ async function parseEnvironmentConfig(
configFile,
`${ environmentPrefix }mappings`,
config.mappings,
[ 'string' ]
[ 'string' ],
false
);
parsedConfig.mappings = Object.entries( config.mappings ).reduce(
( result, [ wpDir, localDir ] ) => {
Expand Down

0 comments on commit 97ca1be

Please sign in to comment.