Skip to content

Commit 6eb3c0e

Browse files
Don't include mcp always (#273)
* feat: update laravel/roster constraint to 0.2.8 * 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. * fix array shape on mustBeDirect * Fix Linting changes Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com> * Fix code styling * Formatting Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com> --------- Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com> Co-authored-by: Pushpak Chhajed <pushpak1300@gmail.com> Co-authored-by: pushpak1300 <31663512+pushpak1300@users.noreply.github.com>
1 parent 8f7494c commit 6eb3c0e

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"illuminate/support": "^10.49.0|^11.45.3|^12.28.1",
2222
"laravel/mcp": "^0.2.0",
2323
"laravel/prompts": "0.1.25|^0.3.6",
24-
"laravel/roster": "^0.2.7"
24+
"laravel/roster": "^0.2.8"
2525
},
2626
"require-dev": {
2727
"laravel/pint": "1.20",

src/Install/GuidelineComposer.php

Lines changed: 15 additions & 4 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,6 +31,16 @@ 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, Packages>
39+
* */
40+
protected array $mustBeDirect = [
41+
Packages::MCP,
42+
];
43+
3344
public function __construct(protected Roster $roster, protected Herd $herd)
3445
{
3546
$this->packagePriorities = [
@@ -131,7 +142,7 @@ protected function find(): Collection
131142
// We don't add guidelines for packages unsupported by Roster right now
132143
foreach ($this->roster->packages() as $package) {
133144
// Skip packages that should be excluded due to priority rules
134-
if ($this->shouldExcludePackage($package->package()->value)) {
145+
if ($this->shouldExcludePackage($package)) {
135146
continue;
136147
}
137148

@@ -173,18 +184,18 @@ protected function find(): Collection
173184
/**
174185
* Determines if a package should be excluded from guidelines based on priority rules.
175186
*/
176-
protected function shouldExcludePackage(string $packageName): bool
187+
protected function shouldExcludePackage(Package $package): bool
177188
{
178189
foreach ($this->packagePriorities as $priorityPackage => $excludedPackages) {
179-
if (in_array($packageName, $excludedPackages, true)) {
190+
if (in_array($package->package()->value, $excludedPackages, true)) {
180191
$priorityEnum = Packages::from($priorityPackage);
181192
if ($this->roster->uses($priorityEnum)) {
182193
return true;
183194
}
184195
}
185196
}
186197

187-
return false;
198+
return $package->indirect() && in_array($package->package(), $this->mustBeDirect, true);
188199
}
189200

190201
/**

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)