Skip to content

Commit 0e9c869

Browse files
committed
Use Runner::get_packages_dir_path()
1 parent 9057bde commit 0e9c869

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

src/Package_Command.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ public function list_( $args, $assoc_args ) {
526526
public function path( $args ) {
527527
$packages_dir = WP_CLI::get_runner()->get_packages_dir_path();
528528
if ( ! empty( $args ) ) {
529-
$packages_dir .= 'vendor/' . $args[0];
529+
$packages_dir .= 'vendor' . DIRECTORY_SEPARATOR . $args[0];
530530
if ( ! is_dir( $packages_dir ) ) {
531531
WP_CLI::error( 'Invalid package name.' );
532532
}
@@ -1192,21 +1192,12 @@ private function get_composer_json_path() {
11921192

11931193
if ( null === $composer_path || getenv( 'WP_CLI_TEST_PACKAGE_GET_COMPOSER_JSON_PATH' ) ) {
11941194

1195-
if ( getenv( 'WP_CLI_PACKAGES_DIR' ) ) {
1196-
$composer_path = Path::trailingslashit( getenv( 'WP_CLI_PACKAGES_DIR' ) ) . 'composer.json';
1197-
} else {
1198-
$composer_path = Path::trailingslashit( Path::get_home_dir() ) . '.wp-cli/packages/composer.json';
1199-
}
1195+
$packages_dir = WP_CLI::get_runner()->get_packages_dir_path();
1196+
$composer_path = rtrim( $packages_dir, '/\\' ) . DIRECTORY_SEPARATOR . 'composer.json';
12001197

12011198
// `composer.json` and its directory might need to be created
12021199
if ( ! file_exists( $composer_path ) ) {
12031200
$composer_path = $this->create_default_composer_json( $composer_path );
1204-
} else {
1205-
$composer_path = realpath( $composer_path );
1206-
if ( false === $composer_path ) {
1207-
$error = error_get_last();
1208-
WP_CLI::error( sprintf( "Composer path '%s' for packages/composer.json not found: %s", $composer_path, $error['message'] ) );
1209-
}
12101201
}
12111202
}
12121203

@@ -1238,11 +1229,7 @@ private function create_default_composer_json( $composer_path ) {
12381229
}
12391230
}
12401231

1241-
$composer_dir = realpath( $composer_dir );
1242-
if ( false === $composer_dir ) {
1243-
$error = error_get_last();
1244-
WP_CLI::error( sprintf( "Composer directory '%s' for packages not found: %s", $composer_dir, $error['message'] ) );
1245-
}
1232+
// No realpath() here to preserve short names on Windows if applicable.
12461233

12471234
$composer_path = Path::trailingslashit( $composer_dir ) . Path::basename( $composer_path );
12481235

0 commit comments

Comments
 (0)