Skip to content

Commit a5cdaa6

Browse files
committed
feat: only include MCP guidelines if direct dependency
Every Boost user would get the MCP guidelines because they have an indirect dependency on laravel/mcp. Users should only get the MCP guidelines if they _directly_ require laravel/mcp.
1 parent 1a6b6bf commit a5cdaa6

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/Install/GuidelineComposer.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Collection;
88
use Illuminate\Support\Facades\Blade;
99
use Laravel\Roster\Enums\Packages;
10+
use Laravel\Roster\Package;
1011
use Laravel\Roster\Roster;
1112
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
1213
use Symfony\Component\Finder\Finder;
@@ -30,11 +31,24 @@ class GuidelineComposer
3031
*/
3132
protected array $packagePriorities;
3233

34+
/**
35+
* Only include guidelines for these package names, if they're a direct requirement.
36+
* This fixes every Boost user getting the MCP guidelines due to indirect import.
37+
*
38+
* @var array<int, class-string<Packages>>
39+
* */
40+
protected array $mustBeDirect;
41+
3342
public function __construct(protected Roster $roster, protected Herd $herd)
3443
{
3544
$this->packagePriorities = [
3645
Packages::PEST->value => [Packages::PHPUNIT->value],
3746
];
47+
48+
$this->mustBeDirect = [
49+
Packages::MCP,
50+
];
51+
3852
$this->config = new GuidelineConfig;
3953
$this->guidelineAssist = new GuidelineAssist($roster);
4054
}
@@ -131,7 +145,7 @@ protected function find(): Collection
131145
// We don't add guidelines for packages unsupported by Roster right now
132146
foreach ($this->roster->packages() as $package) {
133147
// Skip packages that should be excluded due to priority rules
134-
if ($this->shouldExcludePackage($package->package()->value)) {
148+
if ($this->shouldExcludePackage($package)) {
135149
continue;
136150
}
137151

@@ -173,17 +187,21 @@ protected function find(): Collection
173187
/**
174188
* Determines if a package should be excluded from guidelines based on priority rules.
175189
*/
176-
protected function shouldExcludePackage(string $packageName): bool
190+
protected function shouldExcludePackage(Package $package): bool
177191
{
178192
foreach ($this->packagePriorities as $priorityPackage => $excludedPackages) {
179-
if (in_array($packageName, $excludedPackages, true)) {
193+
if (in_array($package->package()->value, $excludedPackages, true)) {
180194
$priorityEnum = Packages::from($priorityPackage);
181195
if ($this->roster->uses($priorityEnum)) {
182196
return true;
183197
}
184198
}
185199
}
186200

201+
if ($package->indirect() && in_array($package->package(), $this->mustBeDirect, true)) {
202+
return true;
203+
}
204+
187205
return false;
188206
}
189207

tests/Feature/Install/GuidelineComposerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,32 @@
316316
->not->toContain('=== phpunit/core rules ===');
317317
});
318318

319+
test('excludes laravel/mcp guidelines when indirectly required', function (): void {
320+
$packages = new PackageCollection([
321+
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
322+
(new Package(Packages::MCP, 'laravel/mcp', '0.2.2'))->setDirect(false),
323+
]);
324+
325+
$this->roster->shouldReceive('packages')->andReturn($packages);
326+
$this->roster->shouldReceive('uses')->with(Packages::LARAVEL)->andReturn(true);
327+
$this->roster->shouldReceive('uses')->with(Packages::MCP)->andReturn(true);
328+
329+
expect($this->composer->compose())->not->toContain('Mcp::web');
330+
});
331+
332+
test('includes laravel/mcp guidelines when directly required', function (): void {
333+
$packages = new PackageCollection([
334+
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
335+
(new Package(Packages::MCP, 'laravel/mcp', '0.2.2'))->setDirect(true),
336+
]);
337+
338+
$this->roster->shouldReceive('packages')->andReturn($packages);
339+
$this->roster->shouldReceive('uses')->with(Packages::LARAVEL)->andReturn(true);
340+
$this->roster->shouldReceive('uses')->with(Packages::MCP)->andReturn(true);
341+
342+
expect($this->composer->compose())->toContain('Mcp::web');
343+
});
344+
319345
test('includes PHPUnit guidelines when Pest is not present', function (): void {
320346
$packages = new PackageCollection([
321347
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),

0 commit comments

Comments
 (0)