@@ -14,6 +14,7 @@ trait Show
1414 private function show (): void
1515 {
1616 $ fullStatus = $ this ->check ();
17+ $ isInSync = $ this ->arePackagesInSync ($ fullStatus ['packages ' ]);
1718
1819 $ headers = ['Package ' , 'Type ' , 'Enabled ' , 'Valid ' , 'Active ' , 'Version ' , 'Path ' ];
1920 $ rows = array_map (function ($ row ) {
@@ -47,26 +48,22 @@ private function show(): void
4748 $ badge = '<fg=black;bg=red;options=bold> ' ;
4849 }
4950
50- if ($ fullStatus ['status ' ] === 'unlinked ' ) {
51- $ badge = '<fg=black;bg=gray ;options=bold> ' ;
51+ if ($ fullStatus ['status ' ] === 'deploy ' ) {
52+ $ badge = '<fg=black;bg=blue ;options=bold> ' ;
5253 }
5354
5455 if ($ fullStatus ['status ' ] === 'linked ' ) {
5556 $ badge = '<fg=black;bg=green;options=bold> ' ;
5657 }
5758
58- if ($ fullStatus ['status ' ] === 'deployed ' ) {
59- $ badge = '<fg=black;bg=green;options=bold> ' ;
60- }
61-
62- if ($ fullStatus ['updated ' ]) {
59+ if ($ isInSync ) {
6360 $ updateBadge = '<fg=black;bg=green;options=bold> ' ;
6461 } else {
6562 $ updateBadge = '<fg=black;bg=red;options=bold> ' ;
6663 }
6764
6865 info (' ' .$ badge .strtoupper ($ fullStatus ['status ' ]).' </> ' .$ fullStatus ['message ' ]);
69- info (' ' .$ updateBadge .' UPDATE </> ' .($ fullStatus [ ' updated ' ] ? 'All packages are in sync with composer.json ' : 'You need to run `php artisan devlink:link` to update the packages ' ));
66+ info (' ' .$ updateBadge .' UPDATE </> ' .($ isInSync ? 'All packages are in sync with composer.json ' : 'You need to run `php artisan devlink:link` to update the packages ' ));
7067 info (' ' );
7168 }
7269
@@ -77,6 +74,16 @@ private function getInstalledVersion(string $name, array $package): ?string
7774 return null ;
7875 }
7976
77+ $ path = $ package ['path ' ] ?? '' ;
78+ if ($ path && ! str_contains ($ path , 'disabled/ ' )) {
79+ $ composerJson = realpath (base_path ($ path )).'/composer.json ' ;
80+ if (file_exists ($ composerJson )) {
81+ $ composerData = json_decode (file_get_contents ($ composerJson ), true );
82+
83+ return $ composerData ['version ' ] ?? 'dev-main ' ;
84+ }
85+ }
86+
8087 $ composerLock = base_path ('composer.lock ' );
8188 if (! file_exists ($ composerLock )) {
8289 return null ;
@@ -97,15 +104,6 @@ private function getInstalledVersion(string $name, array $package): ?string
97104 }
98105 }
99106
100- // If not found in lock file but composer.json exists, assume dev-main
101- $ path = $ package ['path ' ] ?? '' ;
102- if ($ path && ! str_contains ($ path , 'disabled/ ' )) {
103- $ composerJson = realpath (base_path ($ path )).'/composer.json ' ;
104- if (file_exists ($ composerJson )) {
105- return 'dev-main ' ;
106- }
107- }
108-
109107 return null ;
110108 }
111109
@@ -159,4 +157,48 @@ private function getPackageName(string $name, array $package): ?string
159157
160158 return $ data ['name ' ] ?? null ;
161159 }
160+
161+ private function arePackagesInSync (array $ packages ): bool
162+ {
163+ $ composerJson = base_path ('composer.json ' );
164+ if (! file_exists ($ composerJson )) {
165+ return false ;
166+ }
167+
168+ $ composerData = json_decode (file_get_contents ($ composerJson ), true );
169+ if (! $ composerData ) {
170+ return false ;
171+ }
172+
173+ $ composerRequire = array_merge (
174+ $ composerData ['require ' ] ?? [],
175+ $ composerData ['require-dev ' ] ?? []
176+ );
177+
178+ foreach ($ packages as $ package ) {
179+ $ packageName = $ this ->getPackageName ($ package ['name ' ], $ package ['config ' ]);
180+ if (! $ packageName ) {
181+ continue ;
182+ }
183+
184+ $ expectedPath = $ package ['config ' ]['path ' ] ?? '' ;
185+ if (empty ($ expectedPath )) {
186+ continue ;
187+ }
188+
189+ if (! isset ($ composerRequire [$ packageName ])) {
190+ return false ;
191+ }
192+
193+ $ composerPath = $ composerRequire [$ packageName ];
194+ if (str_contains ($ composerPath , 'path: ' )) {
195+ $ composerPath = trim (str_replace ('path: ' , '' , $ composerPath ));
196+ if ($ composerPath !== $ expectedPath ) {
197+ return false ;
198+ }
199+ }
200+ }
201+
202+ return true ;
203+ }
162204}
0 commit comments