Update changelogger validation to work with turborepo (#33388)

* Update changelogger validation to work with turborepo

* Update file_get_contents call to include base_path
This commit is contained in:
jonathansadowski 2022-06-10 15:23:14 -05:00 committed by GitHub
parent 9d98f1b1da
commit 1fe5137152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 18 deletions

View File

@ -86,26 +86,20 @@ if ( $verbose ) {
$base_path = dirname( dirname( __DIR__ ) );
// Read workspace.json file to find potential composer files.
try {
$workspace = json_decode( file_get_contents( $base_path . '/workspace.json' ), true, 10, JSON_THROW_ON_ERROR );
} catch ( Exception $e ) {
$workspace = false;
}
if ( ! $workspace || ! is_array( $workspace['projects'] ) ) {
debug( 'Unable to parse workspace file' );
exit( 1 );
$workspace_paths = array();
$workspace_yaml = file_get_contents( $base_path . '/pnpm-workspace.yaml' );
if ( preg_match( '/^packages:((\n\s+.+)+)/', $workspace_yaml, $matches ) ) {
$packages_config = $matches[1];
if ( preg_match_all( "/^\s+-\s?'([^']+)'/m", $packages_config, $matches ) ) {
$workspace_paths = $matches[1];
}
}
$composer_projects = array();
foreach( $workspace['projects'] as $project => $directory ) {
if ( $path && $directory !== $path ) {
continue;
}
if ( file_exists( $base_path . '/' . $directory . '/composer.json' ) ) {
$composer_projects[] = $directory;
}
}
$composer_files = array_map( function( $path ) {
return glob( $path . '/composer.json' );
}, $workspace_paths );
$composer_files = array_merge( ...$composer_files );
$composer_projects = array_map( 'dirname', $composer_files );
if ( $path && ! count( $composer_projects ) ) {
debug( sprintf( 'The provided project path, %s, did not contain a composer file.', $path ) );