From 594ff0761a75ec73a79588e9268066fb812150b3 Mon Sep 17 00:00:00 2001 From: Mahmud Date: Sat, 24 Sep 2022 21:15:57 +0300 Subject: [PATCH 1/2] Create symbol links only target packages --- src/App/Command/Composer/UpdateCommand.php | 7 ++----- src/App/Command/InstallCommand.php | 4 +++- src/App/Command/UpdateCommand.php | 7 ++----- src/App/PackageService.php | 9 +++------ 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/App/Command/Composer/UpdateCommand.php b/src/App/Command/Composer/UpdateCommand.php index 8929a1c2..59a32c85 100644 --- a/src/App/Command/Composer/UpdateCommand.php +++ b/src/App/Command/Composer/UpdateCommand.php @@ -55,11 +55,6 @@ protected function beforeProcessingPackages(InputInterface $input): void } } - protected function afterProcessingPackages(): void - { - $this->packageService->createSymbolicLinks($this->getPackageList(), $this->getIO()); - } - protected function processPackage(Package $package): void { $io = $this->getIO(); @@ -85,6 +80,8 @@ protected function processPackage(Package $package): void $io ); + $this->packageService->createSymbolicLinks($package, $this->getPackageList(), $this->getIO()); + if (!$io->isVerbose()) { $io ->important() diff --git a/src/App/Command/InstallCommand.php b/src/App/Command/InstallCommand.php index 4f5c80f1..ebbeb333 100644 --- a/src/App/Command/InstallCommand.php +++ b/src/App/Command/InstallCommand.php @@ -48,7 +48,9 @@ protected function beforeProcessingPackages(InputInterface $input): void protected function afterProcessingPackages(): void { - $this->packageService->createSymbolicLinks($this->getPackageList(), $this->getIO()); + foreach ($this->getTargetPackages() as $targetPackage) { + $this->packageService->createSymbolicLinks($targetPackage, $this->getPackageList(), $this->getIO()); + } } protected function processPackage(Package $package): void diff --git a/src/App/Command/UpdateCommand.php b/src/App/Command/UpdateCommand.php index 92cb01a8..5b068ee9 100644 --- a/src/App/Command/UpdateCommand.php +++ b/src/App/Command/UpdateCommand.php @@ -57,11 +57,6 @@ protected function beforeProcessingPackages(InputInterface $input): void } } - protected function afterProcessingPackages(): void - { - $this->packageService->createSymbolicLinks($this->getPackageList(), $this->getIO()); - } - protected function processPackage(Package $package): void { $io = $this->getIO(); @@ -89,6 +84,8 @@ protected function processPackage(Package $package): void $io ); + $this->packageService->createSymbolicLinks($package, $this->getPackageList(), $this->getIO()); + if (!$io->isVerbose()) { $io ->important() diff --git a/src/App/PackageService.php b/src/App/PackageService.php index 04ddcce8..98608b6e 100644 --- a/src/App/PackageService.php +++ b/src/App/PackageService.php @@ -104,17 +104,14 @@ public function gitSetUpstream(Package $package, OutputManager $io): void } } - public function createSymbolicLinks(PackageList $packageList, OutputManager $io): void + public function createSymbolicLinks(Package $package, PackageList $packageList, OutputManager $io): void { $io ->important() - ->info('Re-linking vendor directories...'); + ->info('Re-linking vendor directories for package: ' . $package->getName()); $installedPackages = $packageList->getInstalledAndEnabledPackages(); - foreach ($installedPackages as $package) { - $io->info("Package {$package->getId()} linking..."); - $this->linkPackages($package, $installedPackages); - } + $this->linkPackages($package, $installedPackages); $io->done(); } From 24aca0cf64068f7e9360c92808609b29816f2982 Mon Sep 17 00:00:00 2001 From: Mahmud Date: Sat, 24 Sep 2022 21:52:04 +0300 Subject: [PATCH 2/2] Use composer package name --- src/App/PackageService.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/App/PackageService.php b/src/App/PackageService.php index 98608b6e..ddc9bfea 100644 --- a/src/App/PackageService.php +++ b/src/App/PackageService.php @@ -4,6 +4,7 @@ namespace Yiisoft\YiiDevTool\App; +use RuntimeException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Process; use Yiisoft\Files\FileHelper; @@ -11,6 +12,7 @@ use Yiisoft\YiiDevTool\App\Component\Package\Package; use Yiisoft\YiiDevTool\App\Component\Package\PackageErrorList; use Yiisoft\YiiDevTool\App\Component\Package\PackageList; +use Yiisoft\YiiDevTool\Infrastructure\Composer\ComposerPackage; final class PackageService { @@ -111,7 +113,13 @@ public function createSymbolicLinks(Package $package, PackageList $packageList, ->info('Re-linking vendor directories for package: ' . $package->getName()); $installedPackages = $packageList->getInstalledAndEnabledPackages(); - $this->linkPackages($package, $installedPackages); + try { + $this->linkPackages($package, $installedPackages); + } catch (RuntimeException $e) { + $io + ->important() + ->error("Linking error package {$package->getName()}: " . $e->getMessage()); + } $io->done(); } @@ -129,11 +137,21 @@ public function removeSymbolicLinks(Package $package, PackageList $packageList, $installedPackages = $packageList->getInstalledPackages(); foreach ($installedPackages as $installedPackage) { - $packagePath = "{$vendorDirectory}/{$installedPackage->getName()}"; - - if (is_dir($packagePath) && is_link($packagePath)) { - $io->info("Removing symlink {$packagePath}"); - FileHelper::unlink($packagePath); + try { + $composerPackage = new ComposerPackage($installedPackage->getName(), $installedPackage->getPath()); + $upstreamNamePackage = $composerPackage + ->getComposerConfig() + ->getSection('name'); + $packagePath = "{$vendorDirectory}/{$upstreamNamePackage}"; + + if (is_dir($packagePath) && is_link($packagePath)) { + $io->info("Removing symlink {$packagePath}"); + FileHelper::unlink($packagePath); + } + } catch (RuntimeException $e) { + $io + ->important() + ->error("Error while removing package links {$installedPackage->getName()}: " . $e->getMessage()); } } @@ -156,7 +174,11 @@ private function linkPackages(Package $package, array $installedPackages): void continue; } - $installedPackagePath = "{$vendorDirectory}/{$installedPackage->getName()}"; + $composerPackage = new ComposerPackage($installedPackage->getName(), $installedPackage->getPath()); + $upstreamNamePackage = $composerPackage + ->getComposerConfig() + ->getSection('name'); + $installedPackagePath = "{$vendorDirectory}/{$upstreamNamePackage}"; if (is_dir($installedPackagePath)) { $fs->remove($installedPackagePath);