From e5e8736383b0d85b0f646fc3931d8d8379ebe6a0 Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 20:22:06 +1300 Subject: [PATCH 01/11] Fix: Fail fast when the project directory is not empty Avoid waiting until after `getBestCandidate()` has finished, as it can add notably delay on slow connections due to downloading megabytes of data. Only to fail if the install location is invalid. --- src/Composer/Command/CreateProjectCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 2985aa57a..e84234467 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -279,6 +279,11 @@ EOT $packageVersion = $requirements[0]['version']; } + $fs = new Filesystem(); + if (is_dir($directory) && !$fs->isDirEmpty($directory)) { + throw new \InvalidArgumentException("Project directory $directory is not empty."); + } + if (null === $stability) { if (preg_match('{^[^,\s]*?@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $packageVersion, $match)) { $stability = $match[1]; From 11207a9a2ee21821fd19528bf92bf5c649cb2e94 Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 20:26:06 +1300 Subject: [PATCH 02/11] Fix: Check for null install directory earlier Allows for failing fast when no install directory was provided to the command(uses package name instead). --- src/Composer/Command/CreateProjectCommand.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index e84234467..7a43eb990 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -279,6 +279,12 @@ EOT $packageVersion = $requirements[0]['version']; } + // if no directory was specified, use the 2nd part of the package name + if (null === $directory) { + $parts = explode("/", $name, 2); + $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); + } + $fs = new Filesystem(); if (is_dir($directory) && !$fs->isDirEmpty($directory)) { throw new \InvalidArgumentException("Project directory $directory is not empty."); @@ -325,11 +331,6 @@ EOT throw new \InvalidArgumentException($errorMessage .'.'); } - if (null === $directory) { - $parts = explode("/", $name, 2); - $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); - } - // handler Ctrl+C for unix-like systems if (function_exists('pcntl_async_signals')) { @mkdir($directory, 0777, true); From 5987114f6ce0c26e4adb825c7156bf7367464f4e Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 20:29:57 +1300 Subject: [PATCH 03/11] Fix: Fail when install location is a file In the event a file has the same name as the intended install directory, fail fast too. --- src/Composer/Command/CreateProjectCommand.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 7a43eb990..9fc9ea0d7 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -286,8 +286,12 @@ EOT } $fs = new Filesystem(); - if (is_dir($directory) && !$fs->isDirEmpty($directory)) { - throw new \InvalidArgumentException("Project directory $directory is not empty."); + if (file_exists($directory)) { + if (!is_dir($directory)) { + throw new \InvalidArgumentException('Cannot create project directory at "'.$directory.'", it exists as a file.'); + } elseif (!$fs->isDirEmpty($directory)) { + throw new \InvalidArgumentException('Project directory "'.$directory.'" is not empty.'); + } } if (null === $stability) { From 1b2582ff5b46b3eae8f7677268ae85b4d4069be3 Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 20:33:20 +1300 Subject: [PATCH 04/11] Chore: Improve create-project install UX Provides feedback output before a potentially long wait on getBestCandidate() call on slow network connections where unresponsiveness/hang may be assumed. --- src/Composer/Command/CreateProjectCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 9fc9ea0d7..02ec63c9e 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -285,6 +285,8 @@ EOT $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); } + $io->writeError('Creating a "' . $packageName . '" project at "' . $directory . '"'); + $fs = new Filesystem(); if (file_exists($directory)) { if (!is_dir($directory)) { From 43e0321ee74aa5efb9b720f8576145c351d7f3e3 Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 21:14:22 +1300 Subject: [PATCH 05/11] Chore: Use consistent directory path Only when a install directory was not specified, was the CWD prepended to `$directory`. This change provides consistency in paths displayed to the user. --- src/Composer/Command/CreateProjectCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 02ec63c9e..2ebf3f8c0 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -282,9 +282,10 @@ EOT // if no directory was specified, use the 2nd part of the package name if (null === $directory) { $parts = explode("/", $name, 2); - $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); + $directory = array_pop($parts); } + $directory = getcwd() . DIRECTORY_SEPARATOR . $directory; $io->writeError('Creating a "' . $packageName . '" project at "' . $directory . '"'); $fs = new Filesystem(); From e8626505718981bf67fd7262f65a611d4000f6c6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 29 Nov 2019 10:58:30 +0100 Subject: [PATCH 06/11] Create FUNDING.yml --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..d071feff1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +custom: https://packagist.com From 920d690d90409d3b190f2a3f05343953e1144ac4 Mon Sep 17 00:00:00 2001 From: gary houbre Date: Mon, 2 Dec 2019 18:54:54 +0100 Subject: [PATCH 07/11] Added new Alias For Clear cache --- src/Composer/Command/ClearCacheCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/ClearCacheCommand.php b/src/Composer/Command/ClearCacheCommand.php index 08ec04701..80e63d8ec 100644 --- a/src/Composer/Command/ClearCacheCommand.php +++ b/src/Composer/Command/ClearCacheCommand.php @@ -26,7 +26,7 @@ class ClearCacheCommand extends BaseCommand { $this ->setName('clear-cache') - ->setAliases(array('clearcache')) + ->setAliases(array('clearcache', 'cc')) ->setDescription('Clears composer\'s internal package cache.') ->setHelp( << Date: Tue, 3 Dec 2019 15:30:08 +0400 Subject: [PATCH 08/11] Resolves #8461: [ZipDownloader] Print `unzip` exit code when the command is failed --- src/Composer/Downloader/ZipDownloader.php | 4 ++-- tests/Composer/Test/Downloader/ZipDownloaderTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index 6534db3d8..8aca21e59 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -105,11 +105,11 @@ class ZipDownloader extends ArchiveDownloader $command = 'unzip -qq '.$overwrite.' '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path); try { - if (0 === $this->process->execute($command, $ignoredOutput)) { + if (0 === $exitCode = $this->process->execute($command, $ignoredOutput)) { return true; } - $processError = new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); + $processError = new \RuntimeException('Failed to execute ('.$exitCode.') '.$command."\n\n".$this->process->getErrorOutput()); } catch (\Exception $e) { $processError = $e; } diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index 239ec9221..4ff3f055c 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -184,7 +184,7 @@ class ZipDownloaderTest extends TestCase /** * @expectedException \Exception - * @expectedExceptionMessage Failed to execute unzip + * @expectedExceptionMessage Failed to execute (1) unzip */ public function testSystemUnzipOnlyFailed() { @@ -310,7 +310,7 @@ class ZipDownloaderTest extends TestCase /** * @expectedException \Exception - * @expectedExceptionMessage Failed to execute unzip + * @expectedExceptionMessage Failed to execute (1) unzip */ public function testWindowsFallbackFailed() { From ff3eda6d40d16810f920336a0188d3842bb404a4 Mon Sep 17 00:00:00 2001 From: gary houbre Date: Wed, 4 Dec 2019 11:41:39 +0100 Subject: [PATCH 09/11] Added Documentation from new alias --- doc/03-cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/03-cli.md b/doc/03-cli.md index d73f5a81e..eccafbcc0 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -706,7 +706,7 @@ performance. * **--apcu:** Use APCu to cache found/not-found classes. * **--no-dev:** Disables autoload-dev rules. -## clear-cache (clearcache) +## clear-cache / clearcache / cc Deletes all content from Composer's cache directories. From 2f69ebc624bfce8ea038aa083850f6632b5cefba Mon Sep 17 00:00:00 2001 From: Abdouni Abdelkarim Date: Fri, 6 Dec 2019 09:56:16 +0100 Subject: [PATCH 10/11] Update 01-basic-usage.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, I add the `php composer.phar dump-autoload` command explicity because i didn't find it on the doc like this. Cheers 😉 --- doc/01-basic-usage.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/01-basic-usage.md b/doc/01-basic-usage.md index 4981542e8..cc5ac5459 100644 --- a/doc/01-basic-usage.md +++ b/doc/01-basic-usage.md @@ -241,8 +241,14 @@ be in your project root, on the same level as `vendor` directory is. An example filename would be `src/Foo.php` containing an `Acme\Foo` class. After adding the [`autoload`](04-schema.md#autoload) field, you have to re-run -[`dump-autoload`](03-cli.md#dump-autoload) to re-generate the -`vendor/autoload.php` file. +this command : + +```sh +php composer.phar dump-autoload +``` + +This command will re-generate the `vendor/autoload.php` file. +See the [`dump-autoload`](03-cli.md#dump-autoload) section for more informations. Including that file will also return the autoloader instance, so you can store the return value of the include call in a variable and add more namespaces. From 8449a113b314c776bbf653f94fcf04131c1bb42f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 7 Dec 2019 21:09:26 +0100 Subject: [PATCH 11/11] Fix build --- .../create-project-shows-full-hash-for-dev-packages.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Composer/Test/Fixtures/functional/create-project-shows-full-hash-for-dev-packages.test b/tests/Composer/Test/Fixtures/functional/create-project-shows-full-hash-for-dev-packages.test index 2de92f067..357f51619 100644 --- a/tests/Composer/Test/Fixtures/functional/create-project-shows-full-hash-for-dev-packages.test +++ b/tests/Composer/Test/Fixtures/functional/create-project-shows-full-hash-for-dev-packages.test @@ -1,4 +1,4 @@ --RUN-- create-project --repository=packages.json -v seld/jsonlint %testDir% dev-master --EXPECT-ERROR-REGEX-- -{^Installing seld/jsonlint \(dev-master [a-f0-9]{40}\)} +{^Installing seld/jsonlint \(dev-master [a-f0-9]{40}\)}m