diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index 82662093a..d3b690eca 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -24,10 +24,12 @@ use Composer\Repository\PlatformRepository; use Composer\Repository\RepositoryFactory; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Composer\Package\Version\VersionParser; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Composer\Util\PackageInfo; /** * Base implementation for commands mapping dependency relationships. @@ -180,7 +182,9 @@ abstract class BaseDependencyCommand extends BaseCommand } $doubles[$unique] = true; $version = $package->getPrettyVersion() === RootPackage::DEFAULT_PRETTY_VERSION ? '-' : $package->getPrettyVersion(); - $rows[] = [$package->getPrettyName(), $version, $link->getDescription(), sprintf('%s (%s)', $link->getTarget(), $link->getPrettyConstraint())]; + $packageUrl = PackageInfo::getViewSourceOrHomepageUrl($package); + $nameWithLink = $packageUrl !== null ? '' . $package->getPrettyName() . '' : $package->getPrettyName(); + $rows[] = [$nameWithLink, $version, $link->getDescription(), sprintf('%s (%s)', $link->getTarget(), $link->getPrettyConstraint())]; if ($children) { $queue = array_merge($queue, $children); } @@ -229,7 +233,9 @@ abstract class BaseDependencyCommand extends BaseCommand $prevColor = $this->colors[($level - 1) % count($this->colors)]; $isLast = (++$idx === $count); $versionText = $package->getPrettyVersion() === RootPackage::DEFAULT_PRETTY_VERSION ? '' : $package->getPrettyVersion(); - $packageText = rtrim(sprintf('<%s>%s %s', $color, $package->getPrettyName(), $versionText)); + $packageUrl = PackageInfo::getViewSourceOrHomepageUrl($package); + $nameWithLink = $packageUrl !== null ? '' . $package->getPrettyName() . '' : $package->getPrettyName(); + $packageText = rtrim(sprintf('<%s>%s %s', $color, $nameWithLink, $versionText)); $linkText = sprintf('%s <%s>%s %s', $link->getDescription(), $prevColor, $link->getTarget(), $link->getPrettyConstraint()); $circularWarn = $children === false ? '(circular dependency aborted here)' : ''; $this->writeTreeLine(rtrim(sprintf("%s%s%s (%s) %s", $prefix, $isLast ? '└──' : '├──', $packageText, $linkText, $circularWarn))); diff --git a/src/Composer/Util/PackageInfo.php b/src/Composer/Util/PackageInfo.php index 0b2607ac9..e93c58447 100644 --- a/src/Composer/Util/PackageInfo.php +++ b/src/Composer/Util/PackageInfo.php @@ -19,7 +19,7 @@ class PackageInfo { public static function getViewSourceUrl(PackageInterface $package): ?string { - if ($package instanceof CompletePackageInterface && isset($package->getSupport()['source'])) { + if ($package instanceof CompletePackageInterface && isset($package->getSupport()['source']) && '' !== $package->getSupport()['source']) { return $package->getSupport()['source']; } @@ -28,6 +28,12 @@ class PackageInfo public static function getViewSourceOrHomepageUrl(PackageInterface $package): ?string { - return self::getViewSourceUrl($package) ?? ($package instanceof CompletePackageInterface ? $package->getHomepage() : null); + $url = self::getViewSourceUrl($package) ?? ($package instanceof CompletePackageInterface ? $package->getHomepage() : null); + + if ($url === '') { + return null; + } + + return $url; } }