Skip to content

Commit 4db452c

Browse files
Drive Composer as a child process instead of embedding it (#248)
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
1 parent 17f799f commit 4db452c

15 files changed

Lines changed: 1084 additions & 407 deletions

‎README.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ wp package
2222
WP-CLI packages are community-maintained projects built on WP-CLI. They can
2323
contain WP-CLI commands, but they can also just extend WP-CLI in some way.
2424

25+
Composer is downloaded on first use to the WP-CLI cache (`WP_CLI_CACHE_DIR`).
26+
Set `WP_CLI_COMPOSER_BINARY` to a readable Composer Phar or executable to use
27+
an existing installation instead.
28+
2529
Learn how to create your own command from the
2630
[Commands Cookbook](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/)
2731

@@ -391,12 +395,15 @@ If you want to contribute to a package, this is a great way to jump to it.
391395
Updates installed WP-CLI packages to their latest version.
392396

393397
~~~
394-
wp package update [<package-name>...] [--interaction]
398+
wp package update [<package-name>...] [--insecure] [--interaction]
395399
~~~
396400

397401
[<package-name>...]
398402
One or more package names to update. If not specified, all packages will be updated.
399403

404+
[--insecure]
405+
Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
406+
400407
[--interaction]
401408
Control interactive mode. Use `--no-interaction` to disable prompts (interactive by default). Useful for scripting.
402409

‎composer.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
],
1414
"require": {
1515
"ext-json": "*",
16-
"composer/composer": "^2.10.2",
1716
"wp-cli/wp-cli": "^3.0"
1817
},
1918
"require-dev": {

‎features/package-install.feature‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,4 +1563,4 @@ Feature: Install WP-CLI packages
15631563
Package installation failed
15641564
"""
15651565
# Git should report it couldn't authenticate, not prompt
1566-
And STDERR should match /fatal:|Could not read from remote repository|Repository not found/
1566+
And STDOUT should match /fatal:|Could not read from remote repository|Repository not found/

‎features/package-update.feature‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ Feature: Update WP-CLI packages
179179
Success: Package already at latest version.
180180
"""
181181

182+
When I run `wp package update danielbachhuber/wp-cli-reset-post-date-command --insecure`
183+
Then STDOUT should contain:
184+
"""
185+
Success: Package already at latest version.
186+
"""
187+
182188
Scenario: Error when trying to update a non-existent package
183189
Given an empty directory
184190

‎features/package.feature‎

Lines changed: 98 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,55 @@ Feature: Manage WP-CLI packages
6161
When I run `wp --require=bad-command.php package list`
6262
Then STDERR should be empty
6363

64-
@require-php-7.2 @broken
65-
Scenario: Revert the WP-CLI packages composer.json when fail to install/uninstall a package due to memory limit
64+
Scenario: Revert composer.json when Composer cannot resolve an install or uninstall
6665
Given an empty directory
67-
When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=10M -ddisable_functions=ini_set} package install runcommand/hook`
66+
67+
When I run `wp package list --skip-update-check`
68+
And I run `wp package path`
69+
Then save STDOUT as {PACKAGE_PATH}
70+
71+
When I run `wp eval "echo md5_file( '{PACKAGE_PATH}/composer.json' );" --skip-wordpress`
72+
Then save STDOUT as {COMPOSER_JSON_MD5}
73+
74+
When I try `wp package install runcommand/hook:999999.0.0`
6875
Then the return code should not be 0
6976
And STDERR should contain:
7077
"""
7178
Reverted composer.json.
7279
"""
7380

74-
When I run `wp package install runcommand/hook`
75-
Then STDOUT should contain:
81+
When I run `wp eval "echo md5_file( '{PACKAGE_PATH}/composer.json' );" --skip-wordpress`
82+
Then STDOUT should be:
7683
"""
77-
Success: Package installed.
84+
{COMPOSER_JSON_MD5}
7885
"""
7986

80-
When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=10M -ddisable_functions=ini_set} package uninstall runcommand/hook`
81-
Then the return code should not be 0
82-
And STDERR should contain:
87+
Given a kept/composer.json file:
8388
"""
84-
Reverted composer.json.
89+
{"name":"local/kept","version":"1.0.0"}
90+
"""
91+
When I run `wp package install ./kept`
92+
And I run `wp package install runcommand/hook`
93+
Then STDOUT should contain:
94+
"""
95+
Success: Package installed.
8596
"""
8697

87-
# Create a default composer.json first to compare.
88-
When I run `WP_CLI_PACKAGES_DIR={RUN_DIR}/mypackages wp package list`
89-
Then the {RUN_DIR}/mypackages/composer.json file should exist
90-
And save the {RUN_DIR}/mypackages/composer.json file as {MYPACKAGES_COMPOSER_JSON}
98+
When I run `wp eval "file_put_contents( '{PACKAGE_PATH}/composer.json', str_replace( '1.0.0', '999999.0.0', file_get_contents( '{PACKAGE_PATH}/composer.json' ) ) );" --skip-wordpress`
99+
And I run `wp eval "echo md5_file( '{PACKAGE_PATH}/composer.json' );" --skip-wordpress`
100+
Then save STDOUT as {COMPOSER_JSON_MD5}
91101

92-
When I try `WP_CLI_PACKAGES_DIR={RUN_DIR}/mypackages {INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=10M -ddisable_functions=ini_set} package install runcommand/hook`
102+
When I try `wp package uninstall runcommand/hook`
93103
Then the return code should not be 0
94104
And STDERR should contain:
95105
"""
96106
Reverted composer.json.
97107
"""
98-
And the mypackages/composer.json file should be:
108+
109+
When I run `wp eval "echo md5_file( '{PACKAGE_PATH}/composer.json' );" --skip-wordpress`
110+
Then STDOUT should be:
99111
"""
100-
{MYPACKAGES_COMPOSER_JSON}
112+
{COMPOSER_JSON_MD5}
101113
"""
102114

103115
@github-api
@@ -170,12 +182,9 @@ Feature: Manage WP-CLI packages
170182
Then the return code should be 1
171183
And STDERR should contain:
172184
"""
173-
Error: Package installation failed.
174-
"""
175-
And STDERR should contain:
176-
"""
177-
Repository not found
185+
Error: Package installation failed (Composer return code 1).
178186
"""
187+
And STDOUT should match /Repository not found|Could not read from remote repository/
179188
And STDERR should contain:
180189
"""
181190
Reverted composer.json.
@@ -193,12 +202,9 @@ Feature: Manage WP-CLI packages
193202
Then the return code should be 1
194203
And STDERR should contain:
195204
"""
196-
Error: Failed to update packages.
197-
"""
198-
And STDERR should contain:
199-
"""
200-
Repository not found
205+
Error: Failed to update packages (Composer return code 1).
201206
"""
207+
And STDOUT should match /Repository not found|Could not read from remote repository/
202208
And STDERR should not contain:
203209
"""
204210
Reverted composer.json.
@@ -316,3 +322,68 @@ Feature: Manage WP-CLI packages
316322

317323
When I run `wp package uninstall runcommand/hook`
318324
Then STDERR should be empty
325+
326+
Scenario: Download Composer once into the WP-CLI cache
327+
When I run `wp package path`
328+
Then save STDOUT as {PACKAGE_PATH}
329+
330+
Given an empty directory
331+
And an empty cache
332+
And a local-package/composer.json file:
333+
"""
334+
{"name":"local/cache-test","version":"1.0.0"}
335+
"""
336+
337+
When I run `wp package install ./local-package`
338+
Then STDERR should be empty
339+
And STDOUT should match /Downloading Composer 2\.[0-9.]+ to .*composer\/composer-2\.[0-9.]+\.phar/
340+
And STDOUT should contain:
341+
"""
342+
{SUITE_CACHE_DIR}/composer/composer-
343+
"""
344+
345+
When I run `wp eval "echo current( glob( '{SUITE_CACHE_DIR}/composer/composer-*.phar' ) );" --skip-wordpress`
346+
Then save STDOUT as {COMPOSER_PHAR}
347+
And the {COMPOSER_PHAR} file should exist
348+
And the {SUITE_CACHE_DIR}/composer/versions.json file should exist
349+
350+
When I run `wp package update`
351+
Then STDERR should be empty
352+
And STDOUT should not contain:
353+
"""
354+
Downloading Composer
355+
"""
356+
357+
Scenario: Install using an explicitly configured Composer Phar
358+
When I run `wp package path`
359+
Then save STDOUT as {PACKAGE_PATH}
360+
361+
Given an empty directory
362+
And an empty cache
363+
And a local-package/composer.json file:
364+
"""
365+
{"name":"local/binary-test","version":"1.0.0"}
366+
"""
367+
368+
When I run `wp package install ./local-package`
369+
And I run `wp eval "echo current( glob( '{SUITE_CACHE_DIR}/composer/composer-*.phar' ) );" --skip-wordpress`
370+
Then save STDOUT as {COMPOSER_PHAR}
371+
372+
When I run `wp package uninstall local/binary-test`
373+
And I run `WP_CLI_COMPOSER_BINARY={COMPOSER_PHAR} wp package install ./local-package`
374+
Then STDERR should be empty
375+
And STDOUT should contain:
376+
"""
377+
Success: Package installed.
378+
"""
379+
And STDOUT should not contain:
380+
"""
381+
Downloading Composer
382+
"""
383+
384+
When I run `WP_CLI_COMPOSER_BINARY={RUN_DIR}/missing wp package list --skip-update-check`
385+
Then STDERR should be empty
386+
And STDOUT should contain:
387+
"""
388+
local/binary-test
389+
"""

0 commit comments

Comments
 (0)