Skip to content

Commit f7bd113

Browse files
authored
Include command assets and exclude dev-only Symfony packages in Phar builds (#1219)
* Include bundled command assets directories in the Phar * Exclude dev-only Symfony packages from the Phar when composer/composer is absent
1 parent 4bc3ca0 commit f7bd113

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎features/make-phar.feature‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,23 @@ Feature: Check `utils/make-phar.php` output
6666
"""
6767
SHA-512
6868
"""
69+
70+
Scenario: Bundled command assets are included in the Phar
71+
Given an empty directory
72+
And a new Phar with the same version
73+
74+
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";'`
75+
Then STDOUT should be:
76+
"""
77+
present
78+
"""
79+
80+
Scenario: Dev-only Symfony packages are excluded from the Phar
81+
Given an empty directory
82+
And a new Phar with the same version
83+
84+
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;'`
85+
Then STDOUT should be:
86+
"""
87+
0
88+
"""

‎utils/make-phar.php‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function add_file( $phar, $path ) {
7878
'\/nb\/oxymel\/',
7979
'-command\/src\/',
8080
'\/wp-cli\/[^\n]+?-command\/',
81-
'\/symfony\/(?:config|console|debug|dependency-injection|event-dispatcher|filesystem|translation|yaml)',
81+
is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) ? '\/symfony\/(?:config|console|debug|dependency-injection|event-dispatcher|filesystem|translation|yaml)' : '\/symfony\/',
8282
'\/(?:dealerdirect|myclabs|squizlabs|wimg)\/',
8383
'\/yoast\/',
8484
];
@@ -91,7 +91,7 @@ function add_file( $phar, $path ) {
9191
'\/phpspec\/',
9292
'\/sebastian\/',
9393
'\/php-parallel-lint\/',
94-
'\/symfony\/(?:config|debug|dependency-injection|event-dispatcher|translation|yaml)',
94+
is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) ? '\/symfony\/(?:config|debug|dependency-injection|event-dispatcher|translation|yaml)' : '\/symfony\/',
9595
'\/composer\/spdx-licenses\/',
9696
'\/Composer\/(?:Command\/|Compiler\.php|Console\/|Downloader\/Pear|Installer\/Pear|Question\/|Repository\/Pear|SelfUpdate\/)',
9797
'\/(?:dealerdirect|myclabs|squizlabs|wimg)\/',
@@ -201,7 +201,6 @@ function get_composer_versions( $current_version ) {
201201
->in( WP_CLI_VENDOR_DIR . '/eftec/bladeone' )
202202
->in( WP_CLI_ROOT . '/bundle/rmccue/requests' )
203203
->in( WP_CLI_VENDOR_DIR . '/composer' )
204-
->in( WP_CLI_VENDOR_DIR . '/symfony' )
205204
->notName( 'behat-tags.php' )
206205
->notPath( '#(?:[^/]+-command|php-cli-tools)/vendor/#' ) // For running locally, in case have composer installed or symlinked them.
207206
->exclude( 'config' )
@@ -216,6 +215,10 @@ function get_composer_versions( $current_version ) {
216215
->exclude( 'tests' )
217216
->exclude( 'Test' )
218217
->exclude( 'Tests' );
218+
if ( is_dir( WP_CLI_VENDOR_DIR . '/composer/composer' ) && is_dir( WP_CLI_VENDOR_DIR . '/symfony' ) ) {
219+
$finder
220+
->in( WP_CLI_VENDOR_DIR . '/symfony' );
221+
}
219222
if ( is_dir( WP_CLI_VENDOR_DIR . '/react' ) ) {
220223
$finder
221224
->in( WP_CLI_VENDOR_DIR . '/react' );
@@ -275,6 +278,13 @@ function get_composer_versions( $current_version ) {
275278
->in( WP_CLI_ROOT . '/templates' )
276279
->in( WP_CLI_VENDOR_DIR . '/wp-cli/*-command/templates' );
277280

281+
if ( 'cli' !== BUILD ) {
282+
$asset_dirs = glob( WP_CLI_VENDOR_DIR . '/wp-cli/*-command/assets', GLOB_ONLYDIR );
283+
if ( ! empty( $asset_dirs ) ) {
284+
$finder->in( $asset_dirs );
285+
}
286+
}
287+
278288
foreach ( $finder as $file ) {
279289
add_file( $phar, $file );
280290
}

0 commit comments

Comments
 (0)