@@ -24,7 +24,7 @@ private function show(): void
2424 default => $ row ['type ' ],
2525 };
2626
27- $ version = $ this ->getInstalledVersion (' moox/ ' . $ row ['name ' ]);
27+ $ version = $ this ->getInstalledVersion ($ row ['name ' ], $ row );
2828 $ path = $ this ->getShortPath ($ row );
2929
3030 return [
@@ -70,8 +70,13 @@ private function show(): void
7070 info (' ' );
7171 }
7272
73- private function getInstalledVersion (string $ package ): ?string
73+ private function getInstalledVersion (string $ name , array $ package ): ?string
7474 {
75+ $ packageName = $ this ->getPackageName ($ name , $ package );
76+ if (! $ packageName ) {
77+ return null ;
78+ }
79+
7580 $ composerLock = base_path ('composer.lock ' );
7681 if (! file_exists ($ composerLock )) {
7782 return null ;
@@ -80,7 +85,7 @@ private function getInstalledVersion(string $package): ?string
8085 $ lockData = json_decode (file_get_contents ($ composerLock ), true );
8186 foreach ([$ lockData ['packages ' ] ?? [], $ lockData ['packages-dev ' ] ?? []] as $ packages ) {
8287 foreach ($ packages as $ pkg ) {
83- if ($ pkg ['name ' ] === $ package ) {
88+ if ($ pkg ['name ' ] === $ packageName ) {
8489 return $ pkg ['version ' ];
8590 }
8691 }
@@ -116,4 +121,26 @@ private function getShortPath(array $row): string
116121
117122 return $ path ;
118123 }
124+
125+ private function getPackageName (string $ name , array $ package ): ?string
126+ {
127+ $ isLocal = ($ package ['type ' ] ?? '' ) === 'local ' ;
128+ $ path = $ isLocal ? "packages/ $ name " : ($ package ['path ' ] ?? '' );
129+
130+ if (! $ path || ! is_dir ($ path )) {
131+ return null ;
132+ }
133+
134+ $ composerJson = "$ path/composer.json " ;
135+ if (! file_exists ($ composerJson )) {
136+ return null ;
137+ }
138+
139+ $ data = json_decode (file_get_contents ($ composerJson ), true );
140+ if (! isset ($ data ['name ' ])) {
141+ return null ;
142+ }
143+
144+ return $ data ['name ' ];
145+ }
119146}
0 commit comments