@@ -42,7 +42,7 @@ public function resolve(): array
4242 return $ this ->resolvedInstalledPackages ;
4343 }
4444
45- $ installedPackagesFilePath = self :: resolveVendorDir () . '/composer/installed.json ' ;
45+ $ installedPackagesFilePath = $ this -> resolveVendorDir () . '/composer/installed.json ' ;
4646 if (! file_exists ($ installedPackagesFilePath )) {
4747 throw new ShouldNotHappenException (
4848 'The installed package json not found. Make sure you run `composer update` and the "vendor/composer/installed.json" file exists '
@@ -59,6 +59,20 @@ public function resolve(): array
5959 return $ installedPackages ;
6060 }
6161
62+ public function resolvePackageVersion (string $ packageName ): ?string
63+ {
64+ $ installedPackages = $ this ->resolve ();
65+ foreach ($ installedPackages as $ installedPackage ) {
66+ if ($ installedPackage ->getName () !== $ packageName ) {
67+ continue ;
68+ }
69+
70+ return $ installedPackage ->getVersion ();
71+ }
72+
73+ return null ;
74+ }
75+
6276 /**
6377 * @param mixed[] $packages
6478 * @return InstalledPackage[]
@@ -77,6 +91,7 @@ private function createInstalledPackages(array $packages): array
7791 private function resolveVendorDir (): string
7892 {
7993 $ projectComposerJsonFilePath = $ this ->projectDirectory . '/composer.json ' ;
94+
8095 if (\file_exists ($ projectComposerJsonFilePath )) {
8196 $ projectComposerContents = FileSystem::read ($ projectComposerJsonFilePath );
8297 $ projectComposerJson = Json::decode ($ projectComposerContents , true );
0 commit comments