Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"illuminate/support": "^10.49.0|^11.45.3|^12.28.1",
"laravel/mcp": "^0.2.0",
"laravel/prompts": "0.1.25|^0.3.6",
"laravel/roster": "^0.2.7"
"laravel/roster": "^0.2.8"
},
"require-dev": {
"laravel/pint": "1.20",
Expand Down
19 changes: 15 additions & 4 deletions src/Install/GuidelineComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;
use Laravel\Roster\Enums\Packages;
use Laravel\Roster\Package;
use Laravel\Roster\Roster;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
use Symfony\Component\Finder\Finder;
Expand All @@ -30,6 +31,16 @@ class GuidelineComposer
*/
protected array $packagePriorities;

/**
* Only include guidelines for these package names if they're a direct requirement.
* This fixes every Boost user getting the MCP guidelines due to indirect import.
*
* @var array<int, Packages>
* */
protected array $mustBeDirect = [
Packages::MCP,
];

public function __construct(protected Roster $roster, protected Herd $herd)
{
$this->packagePriorities = [
Expand Down Expand Up @@ -131,7 +142,7 @@ protected function find(): Collection
// We don't add guidelines for packages unsupported by Roster right now
foreach ($this->roster->packages() as $package) {
// Skip packages that should be excluded due to priority rules
if ($this->shouldExcludePackage($package->package()->value)) {
if ($this->shouldExcludePackage($package)) {
continue;
}

Expand Down Expand Up @@ -173,18 +184,18 @@ protected function find(): Collection
/**
* Determines if a package should be excluded from guidelines based on priority rules.
*/
protected function shouldExcludePackage(string $packageName): bool
protected function shouldExcludePackage(Package $package): bool
{
foreach ($this->packagePriorities as $priorityPackage => $excludedPackages) {
if (in_array($packageName, $excludedPackages, true)) {
if (in_array($package->package()->value, $excludedPackages, true)) {
$priorityEnum = Packages::from($priorityPackage);
if ($this->roster->uses($priorityEnum)) {
return true;
}
}
}

return false;
return $package->indirect() && in_array($package->package(), $this->mustBeDirect, true);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/Install/GuidelineComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,32 @@
->not->toContain('=== phpunit/core rules ===');
});

test('excludes laravel/mcp guidelines when indirectly required', function (): void {
$packages = new PackageCollection([
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
(new Package(Packages::MCP, 'laravel/mcp', '0.2.2'))->setDirect(false),
]);

$this->roster->shouldReceive('packages')->andReturn($packages);
$this->roster->shouldReceive('uses')->with(Packages::LARAVEL)->andReturn(true);
$this->roster->shouldReceive('uses')->with(Packages::MCP)->andReturn(true);

expect($this->composer->compose())->not->toContain('Mcp::web');
});

test('includes laravel/mcp guidelines when directly required', function (): void {
$packages = new PackageCollection([
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
(new Package(Packages::MCP, 'laravel/mcp', '0.2.2'))->setDirect(true),
]);

$this->roster->shouldReceive('packages')->andReturn($packages);
$this->roster->shouldReceive('uses')->with(Packages::LARAVEL)->andReturn(true);
$this->roster->shouldReceive('uses')->with(Packages::MCP)->andReturn(true);

expect($this->composer->compose())->toContain('Mcp::web');
});

test('includes PHPUnit guidelines when Pest is not present', function (): void {
$packages = new PackageCollection([
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
Expand Down
Loading