Skip to content

Commit a156a15

Browse files
committed
Devlink multi-vendor and version fix
1 parent f670710 commit a156a15

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

packages/devlink/src/Console/Traits/Link.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ private function updateComposerJson(): void
229229
continue;
230230
}
231231

232-
$packageName = "moox/{$name}";
232+
$packageName = $this->getPackageName($name, $package);
233+
if (! $packageName) {
234+
info("Skipping $name: no composer.json found or invalid");
235+
236+
continue;
237+
}
238+
233239
$isLocal = ($package['type'] ?? '') === 'local';
234240
$isPrivate = ($package['type'] ?? '') === 'private';
235241
$isDev = ($package['dev'] ?? false);
@@ -311,6 +317,28 @@ private function updateComposerJson(): void
311317
}
312318
}
313319

320+
private function getPackageName(string $name, array $package): ?string
321+
{
322+
$isLocal = ($package['type'] ?? '') === 'local';
323+
$path = $isLocal ? "packages/$name" : ($package['path'] ?? '');
324+
325+
if (! $path || ! is_dir($path)) {
326+
return null;
327+
}
328+
329+
$composerJson = "$path/composer.json";
330+
if (! file_exists($composerJson)) {
331+
return null;
332+
}
333+
334+
$data = json_decode(file_get_contents($composerJson), true);
335+
if (! isset($data['name'])) {
336+
return null;
337+
}
338+
339+
return $data['name'];
340+
}
341+
314342
private function createLinkedComposerJson(): void
315343
{
316344
if (! file_exists($this->composerJsonPath)) {

packages/devlink/src/Console/Traits/Show.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)