Skip to content

Commit 0b17512

Browse files
committed
Used a Composer class to check for package existence in projects with varying structures
1 parent 95ef1d4 commit 0b17512

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/StimulusBundle/src/Ux/UxPackageReader.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\UX\StimulusBundle\Ux;
1313

14+
use Composer\InstalledVersions;
15+
1416
/**
1517
* @internal
1618
*
@@ -28,7 +30,12 @@ public function readPackageMetadata(string $packageName): UxPackageMetadata
2830
{
2931
// remove the '@' from the name to get back to the PHP package name
3032
$phpPackageName = substr($packageName, 1);
31-
$phpPackagePath = $this->projectDir.'/vendor/'.$phpPackageName;
33+
if (class_exists(InstalledVersions::class) && InstalledVersions::isInstalled($phpPackageName)) {
34+
$phpPackagePath = InstalledVersions::getInstallPath($phpPackageName);
35+
} else {
36+
$phpPackagePath = $this->projectDir.'/vendor/'.$phpPackageName;
37+
}
38+
3239
if (!is_dir($phpPackagePath)) {
3340
throw new \RuntimeException(sprintf('Could not find package "%s" referred to from controllers.json.', $phpPackageName));
3441
}

0 commit comments

Comments
 (0)