diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 3334ccfe8676d5..7471b1cea78397 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -1,5 +1,9 @@ ## Master +### Bug Fixes + +- Ensure `packages-update` work when `dependencies` or `devDependencies` are missing in the `package.json` file ([#20408](https://github.com/WordPress/gutenberg/pull/20408)). + ## 7.1.0 (2020-02-10) ### Bug Fixes diff --git a/packages/scripts/scripts/packages-update.js b/packages/scripts/scripts/packages-update.js index 6ebde42cc7b618..5bf8ce531d5822 100644 --- a/packages/scripts/scripts/packages-update.js +++ b/packages/scripts/scripts/packages-update.js @@ -15,9 +15,9 @@ function readJSONFile( fileName ) { return JSON.parse( data ); } -function getWordPressPackages( packageJSON ) { - return Object.keys( packageJSON.dependencies ) - .concat( Object.keys( packageJSON.devDependencies ) ) +function getWordPressPackages( { dependencies = {}, devDependencies = {} } ) { + return Object.keys( dependencies ) + .concat( Object.keys( devDependencies ) ) .filter( ( packageName ) => packageName.startsWith( WORDPRESS_PACKAGES_PREFIX ) ); @@ -26,19 +26,17 @@ function getWordPressPackages( packageJSON ) { function getPackageVersionDiff( initialPackageJSON, finalPackageJSON ) { const diff = [ 'dependencies', 'devDependencies' ].reduce( ( result, keyPackageJSON ) => { - return Object.keys( finalPackageJSON[ keyPackageJSON ] ).reduce( - ( _result, dependency ) => { - const initial = - initialPackageJSON[ keyPackageJSON ][ dependency ]; - const final = - finalPackageJSON[ keyPackageJSON ][ dependency ]; - if ( initial !== final ) { - _result.push( { dependency, initial, final } ); - } - return _result; - }, - result - ); + return Object.keys( + finalPackageJSON[ keyPackageJSON ] || {} + ).reduce( ( _result, dependency ) => { + const initial = + initialPackageJSON[ keyPackageJSON ][ dependency ]; + const final = finalPackageJSON[ keyPackageJSON ][ dependency ]; + if ( initial !== final ) { + _result.push( { dependency, initial, final } ); + } + return _result; + }, result ); }, [] );