Skip to content

Commit

Permalink
Used a Composer class to check for package existence in projects with…
Browse files Browse the repository at this point in the history
… varying structures
  • Loading branch information
yobrx committed Feb 7, 2024
1 parent 95ef1d4 commit 0b17512
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/StimulusBundle/src/Ux/UxPackageReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\UX\StimulusBundle\Ux;

use Composer\InstalledVersions;

/**
* @internal
*
Expand All @@ -28,7 +30,12 @@ public function readPackageMetadata(string $packageName): UxPackageMetadata
{
// remove the '@' from the name to get back to the PHP package name
$phpPackageName = substr($packageName, 1);
$phpPackagePath = $this->projectDir.'/vendor/'.$phpPackageName;
if (class_exists(InstalledVersions::class) && InstalledVersions::isInstalled($phpPackageName)) {
$phpPackagePath = InstalledVersions::getInstallPath($phpPackageName);
} else {
$phpPackagePath = $this->projectDir.'/vendor/'.$phpPackageName;
}

if (!is_dir($phpPackagePath)) {
throw new \RuntimeException(sprintf('Could not find package "%s" referred to from controllers.json.', $phpPackageName));
}
Expand Down

0 comments on commit 0b17512

Please sign in to comment.