Skip to content

Commit 45ebe6e

Browse files
authored
Build the Phar without composer/composer installed (#1215)
1 parent 5f3f1cb commit 45ebe6e

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"wp-cli/wp-cli": "dev-main"
4141
},
4242
"require-dev": {
43+
"symfony/finder": "^5.4",
4344
"wp-cli/package-command": "^3",
4445
"wp-cli/wp-cli-tests": "^5.4.0"
4546
},

‎composer.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎utils/make-phar.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ function get_composer_versions( $current_version ) {
224224
$finder
225225
->in( WP_CLI_VENDOR_DIR . '/wp-cli/mustangostang-spyc' )
226226
->in( WP_CLI_VENDOR_DIR . '/wp-cli/php-cli-tools' )
227-
->in( WP_CLI_VENDOR_DIR . '/seld/cli-prompt' )
228227
->exclude( 'console' )
229228
->exclude( 'filesystem' )
230229
->exclude( 'composer/ca-bundle' )
@@ -235,9 +234,6 @@ function get_composer_versions( $current_version ) {
235234
$finder
236235
->in( WP_CLI_VENDOR_DIR . '/wp-cli' )
237236
->in( WP_CLI_VENDOR_DIR . '/nb/oxymel' )
238-
->in( WP_CLI_VENDOR_DIR . '/psr' )
239-
->in( WP_CLI_VENDOR_DIR . '/seld' )
240-
->in( WP_CLI_VENDOR_DIR . '/justinrainbow/json-schema' )
241237
->in( WP_CLI_VENDOR_DIR . '/gettext' )
242238
->in( WP_CLI_VENDOR_DIR . '/mck89' )
243239
->exclude( 'demo' )
@@ -253,10 +249,16 @@ function get_composer_versions( $current_version ) {
253249
->exclude( 'composer/composer/src/Composer/Question' )
254250
->exclude( 'composer/composer/src/Composer/Repository/Pear' )
255251
->exclude( 'composer/composer/src/Composer/SelfUpdate' );
252+
}
256253

257-
// required by justinrainbow/json-schema v6+.
258-
if ( is_dir( WP_CLI_VENDOR_DIR . '/marc-mabe/php-enum' ) ) {
259-
$finder->in( WP_CLI_VENDOR_DIR . '/marc-mabe/php-enum' );
254+
// These only exist when a bundled package pulls them in, e.g. composer/composer
255+
// for older versions of wp-cli/package-command. Finder errors out on missing directories.
256+
$optional_dirs = 'cli' === BUILD
257+
? [ 'seld/cli-prompt' ]
258+
: [ 'psr', 'seld', 'justinrainbow/json-schema', 'marc-mabe/php-enum' ];
259+
foreach ( $optional_dirs as $optional_dir ) {
260+
if ( is_dir( WP_CLI_VENDOR_DIR . '/' . $optional_dir ) ) {
261+
$finder->in( WP_CLI_VENDOR_DIR . '/' . $optional_dir );
260262
}
261263
}
262264

@@ -304,7 +306,7 @@ function get_composer_versions( $current_version ) {
304306
}
305307

306308
add_file( $phar, WP_CLI_VENDOR_DIR . '/autoload.php' );
307-
if ( 'cli' !== BUILD ) {
309+
if ( 'cli' !== BUILD && is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) ) {
308310
add_file( $phar, WP_CLI_VENDOR_DIR . '/composer/composer/LICENSE' );
309311
add_file( $phar, WP_CLI_VENDOR_DIR . '/composer/composer/res/composer-schema.json' );
310312
}

0 commit comments

Comments
 (0)