Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create symbol links only target packages #230

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/App/Command/Composer/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -83,6 +78,8 @@ protected function processPackage(Package $package): void
$io
);

$this->packageService->createSymbolicLinks($package, $this->getPackageList(), $this->getIO());

if (!$io->isVerbose()) {
$io
->important()
Expand Down
4 changes: 3 additions & 1 deletion src/App/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/App/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -87,6 +82,8 @@ protected function processPackage(Package $package): void
$io
);

$this->packageService->createSymbolicLinks($package, $this->getPackageList(), $this->getIO());

if (!$io->isVerbose()) {
$io
->important()
Expand Down
39 changes: 29 additions & 10 deletions src/App/PackageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Yiisoft\YiiDevTool\App;

use RuntimeException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
use Yiisoft\Files\FileHelper;
use Yiisoft\YiiDevTool\App\Component\Console\OutputManager;
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
{
Expand Down Expand Up @@ -89,16 +91,19 @@ public function gitClone(
$errorList->set($package, $output, 'cloning package repository');
}

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>{$package->getId()}</package> linking...");
try {
$this->linkPackages($package, $installedPackages);
} catch (RuntimeException $e) {
$io
->important()
->error("Linking error package {$package->getName()}: " . $e->getMessage());
}

$io->done();
Expand All @@ -117,11 +122,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 <file>{$packagePath}</file>");
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 <file>{$packagePath}</file>");
FileHelper::unlink($packagePath);
}
} catch (RuntimeException $e) {
$io
->important()
->error("Error while removing package links {$installedPackage->getName()}: " . $e->getMessage());
}
}

Expand All @@ -144,7 +159,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);

Expand Down