@@ -370,7 +370,7 @@ public function install( $args, $assoc_args ) {
370370 $ this ->register_revert_shutdown_function ( $ json_path , $ composer_backup , $ revert );
371371
372372 // Add the 'require' to composer.json
373- WP_CLI ::log ( sprintf ( 'Updating %s to require the package... ' , $ json_path ) );
373+ WP_CLI ::log ( sprintf ( 'Updating %s to require the package... ' , Path:: normalize ( $ json_path ) ) );
374374 $ json_manipulator = new JsonManipulator ( $ composer_backup );
375375 $ json_manipulator ->addMainKey ( 'name ' , 'wp-cli/wp-cli ' );
376376 $ json_manipulator ->addMainKey ( 'version ' , self ::get_wp_cli_version_composer () );
@@ -538,12 +538,12 @@ public function list_( $args, $assoc_args ) {
538538 public function path ( $ args ) {
539539 $ packages_dir = WP_CLI ::get_runner ()->get_packages_dir_path ();
540540 if ( ! empty ( $ args ) ) {
541- $ packages_dir .= 'vendor/ ' . $ args [0 ];
541+ $ packages_dir .= 'vendor ' . DIRECTORY_SEPARATOR . $ args [0 ];
542542 if ( ! is_dir ( $ packages_dir ) ) {
543543 WP_CLI ::error ( 'Invalid package name. ' );
544544 }
545545 }
546- WP_CLI ::line ( $ packages_dir );
546+ WP_CLI ::line ( Path:: normalize ( $ packages_dir ) );
547547 }
548548
549549 /**
@@ -847,12 +847,12 @@ public function uninstall( $args, $assoc_args ) {
847847 $ this ->register_revert_shutdown_function ( $ json_path , $ composer_backup , $ revert );
848848
849849 // Remove the 'require' from composer.json.
850- WP_CLI ::log ( sprintf ( 'Removing require statement for package \'%s \' from %s ' , $ package_name , $ json_path ) );
850+ WP_CLI ::log ( sprintf ( 'Removing require statement for package \'%s \' from %s ' , $ package_name , Path:: normalize ( $ json_path ) ) );
851851 $ manipulator = new JsonManipulator ( $ composer_backup );
852852 $ manipulator ->removeSubNode ( 'require ' , $ package_name , true /*caseInsensitive*/ );
853853
854854 // Remove the 'repository' details from composer.json.
855- WP_CLI ::log ( sprintf ( 'Removing repository details from %s ' , $ json_path ) );
855+ WP_CLI ::log ( sprintf ( 'Removing repository details from %s ' , Path:: normalize ( $ json_path ) ) );
856856 $ manipulator ->removeSubNode ( 'repositories ' , $ package_name , true /*caseInsensitive*/ );
857857
858858 file_put_contents ( $ json_path , $ manipulator ->getContents () );
@@ -1170,7 +1170,7 @@ private function get_installed_package_by_name( $package_name ) {
11701170 * @return array Two-element array containing package name and version.
11711171 */
11721172 private static function get_package_name_and_version_from_dir_package ( $ dir_package ) {
1173- $ composer_file = $ dir_package . '/composer.json ' ;
1173+ $ composer_file = Path:: normalize ( $ dir_package . '/composer.json ' ) ;
11741174 if ( ! file_exists ( $ composer_file ) ) {
11751175 WP_CLI ::error ( sprintf ( "Invalid package: composer.json file '%s' not found. " , $ composer_file ) );
11761176 }
@@ -1204,21 +1204,12 @@ private function get_composer_json_path() {
12041204
12051205 if ( null === $ composer_path || getenv ( 'WP_CLI_TEST_PACKAGE_GET_COMPOSER_JSON_PATH ' ) ) {
12061206
1207- if ( getenv ( 'WP_CLI_PACKAGES_DIR ' ) ) {
1208- $ composer_path = Path::trailingslashit ( getenv ( 'WP_CLI_PACKAGES_DIR ' ) ) . 'composer.json ' ;
1209- } else {
1210- $ composer_path = Path::trailingslashit ( Path::get_home_dir () ) . '.wp-cli/packages/composer.json ' ;
1211- }
1207+ $ packages_dir = WP_CLI ::get_runner ()->get_packages_dir_path ();
1208+ $ composer_path = rtrim ( $ packages_dir , '/ \\' ) . DIRECTORY_SEPARATOR . 'composer.json ' ;
12121209
12131210 // `composer.json` and its directory might need to be created
12141211 if ( ! file_exists ( $ composer_path ) ) {
12151212 $ composer_path = $ this ->create_default_composer_json ( $ composer_path );
1216- } else {
1217- $ composer_path = realpath ( $ composer_path );
1218- if ( false === $ composer_path ) {
1219- $ error = error_get_last ();
1220- WP_CLI ::error ( sprintf ( "Composer path '%s' for packages/composer.json not found: %s " , $ composer_path , $ error ['message ' ] ) );
1221- }
12221213 }
12231214 }
12241215
@@ -1250,11 +1241,7 @@ private function create_default_composer_json( $composer_path ) {
12501241 }
12511242 }
12521243
1253- $ composer_dir = realpath ( $ composer_dir );
1254- if ( false === $ composer_dir ) {
1255- $ error = error_get_last ();
1256- WP_CLI ::error ( sprintf ( "Composer directory '%s' for packages not found: %s " , $ composer_dir , $ error ['message ' ] ) );
1257- }
1244+ // No realpath() here to preserve short names on Windows if applicable.
12581245
12591246 $ composer_path = Path::trailingslashit ( $ composer_dir ) . Path::basename ( $ composer_path );
12601247
@@ -1358,6 +1345,10 @@ private function maybe_add_git_suffix( $package_name ) {
13581345 if ( preg_match ( '#\.git(?::[^:]+)?$#i ' , $ package_name ) ) {
13591346 return $ package_name ;
13601347 }
1348+ // Skip if it looks like a zip file.
1349+ if ( preg_match ( '#\.zip$#i ' , $ package_name ) ) {
1350+ return $ package_name ;
1351+ }
13611352 // Append .git for GitHub/GitLab HTTPS or SSH URLs, preserving any :version suffix.
13621353 // Pattern: (https?://github.com/<user>/<repo>[...subgroups...] or git@github.com:<user>/<repo>[...subgroups...])(:version)?
13631354 if ( preg_match ( '#^((?:https?://(?:github|gitlab)\.com/|git@(?:github|gitlab)\.com:)[^/:]+(?:/[^/:]+)*)(:.*)?$#i ' , $ package_name , $ matches ) ) {
0 commit comments