diff --git a/features/make-phar.feature b/features/make-phar.feature index d93b1566d..c6eec1c81 100644 --- a/features/make-phar.feature +++ b/features/make-phar.feature @@ -66,3 +66,23 @@ Feature: Check `utils/make-phar.php` output """ SHA-512 """ + + Scenario: Bundled command assets are included in the Phar + Given an empty directory + And a new Phar with the same version + + When I run `php -r '$phar = new Phar( "{PHAR_PATH}" ); echo isset( $phar["vendor/wp-cli/i18n-command/assets/block-i18n.json"] ) && isset( $phar["vendor/wp-cli/i18n-command/assets/theme-i18n.json"] ) ? "present" : "missing";'` + Then STDOUT should be: + """ + present + """ + + Scenario: Dev-only Symfony packages are excluded from the Phar + Given an empty directory + And a new Phar with the same version + + When I run `php -r '$phar = new Phar( "{PHAR_PATH}" ); $found = 0; foreach ( new RecursiveIteratorIterator( $phar ) as $file ) { if ( false !== strpos( $file->getPathname(), "/vendor/symfony/" ) ) { ++$found; } } echo $found;'` + Then STDOUT should be: + """ + 0 + """ diff --git a/utils/make-phar.php b/utils/make-phar.php index 2db663f2e..3b14de5ed 100644 --- a/utils/make-phar.php +++ b/utils/make-phar.php @@ -78,7 +78,7 @@ function add_file( $phar, $path ) { '\/nb\/oxymel\/', '-command\/src\/', '\/wp-cli\/[^\n]+?-command\/', - '\/symfony\/(?:config|console|debug|dependency-injection|event-dispatcher|filesystem|translation|yaml)', + is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) ? '\/symfony\/(?:config|console|debug|dependency-injection|event-dispatcher|filesystem|translation|yaml)' : '\/symfony\/', '\/(?:dealerdirect|myclabs|squizlabs|wimg)\/', '\/yoast\/', ]; @@ -91,7 +91,7 @@ function add_file( $phar, $path ) { '\/phpspec\/', '\/sebastian\/', '\/php-parallel-lint\/', - '\/symfony\/(?:config|debug|dependency-injection|event-dispatcher|translation|yaml)', + is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) ? '\/symfony\/(?:config|debug|dependency-injection|event-dispatcher|translation|yaml)' : '\/symfony\/', '\/composer\/spdx-licenses\/', '\/Composer\/(?:Command\/|Compiler\.php|Console\/|Downloader\/Pear|Installer\/Pear|Question\/|Repository\/Pear|SelfUpdate\/)', '\/(?:dealerdirect|myclabs|squizlabs|wimg)\/', @@ -201,7 +201,6 @@ function get_composer_versions( $current_version ) { ->in( WP_CLI_VENDOR_DIR . '/eftec/bladeone' ) ->in( WP_CLI_ROOT . '/bundle/rmccue/requests' ) ->in( WP_CLI_VENDOR_DIR . '/composer' ) - ->in( WP_CLI_VENDOR_DIR . '/symfony' ) ->notName( 'behat-tags.php' ) ->notPath( '#(?:[^/]+-command|php-cli-tools)/vendor/#' ) // For running locally, in case have composer installed or symlinked them. ->exclude( 'config' ) @@ -216,6 +215,10 @@ function get_composer_versions( $current_version ) { ->exclude( 'tests' ) ->exclude( 'Test' ) ->exclude( 'Tests' ); +if ( is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) && is_dir( WP_CLI_VENDOR_DIR . '/symfony' ) ) { + $finder + ->in( WP_CLI_VENDOR_DIR . '/symfony' ); +} if ( is_dir( WP_CLI_VENDOR_DIR . '/react' ) ) { $finder ->in( WP_CLI_VENDOR_DIR . '/react' ); @@ -275,6 +278,13 @@ function get_composer_versions( $current_version ) { ->in( WP_CLI_ROOT . '/templates' ) ->in( WP_CLI_VENDOR_DIR . '/wp-cli/*-command/templates' ); +if ( 'cli' !== BUILD ) { + $asset_dirs = glob( WP_CLI_VENDOR_DIR . '/wp-cli/*-command/assets', GLOB_ONLYDIR ); + if ( ! empty( $asset_dirs ) ) { + $finder->in( $asset_dirs ); + } +} + foreach ( $finder as $file ) { add_file( $phar, $file ); }