Skip to content
2 changes: 1 addition & 1 deletion .ai/foundation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- Do not change the application's dependencies without approval.

## Frontend Bundling
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `npm run build`, `npm run dev`, or `composer run dev`. Ask them.
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `{{ $assist->nodePackageManager() }} run build`, `{{ $assist->nodePackageManager() }} run dev`, or `composer run dev`. Ask them.

## Replies
- Be concise in your explanations - focus on what's important rather than explaining obvious details.
Expand Down
2 changes: 1 addition & 1 deletion .ai/laravel/core.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
- When creating tests, make use of `php artisan make:test [options] <name>` to create a feature test, and pass `--unit` to create a unit test. Most tests should be feature tests.

### Vite Error
- If you receive an "Illuminate\Foundation\ViteException: Unable to locate file in Vite manifest" error, you can run `npm run build` or ask the user to run `npm run dev` or `composer run dev`.
- If you receive an "Illuminate\Foundation\ViteException: Unable to locate file in Vite manifest" error, you can run `{{ $assist->nodePackageManager() }} run build` or ask the user to run `{{ $assist->nodePackageManager() }} run dev` or `composer run dev`.
1 change: 1 addition & 0 deletions src/BoostServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function register(): void
$lockFiles = [
base_path('composer.lock'),
base_path('package-lock.json'),
base_path('bun.lock'),
base_path('bun.lockb'),
base_path('pnpm-lock.yaml'),
base_path('yarn.lock'),
Expand Down
6 changes: 6 additions & 0 deletions src/Install/GuidelineAssist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Database\Eloquent\Model;
use Laravel\Boost\Install\Assists\Inertia;
use Laravel\Roster\Enums\NodePackageManager;
use Laravel\Roster\Enums\Packages;
use Laravel\Roster\Roster;
use ReflectionClass;
Expand Down Expand Up @@ -168,4 +169,9 @@ public function inertia(): Inertia
{
return new Inertia($this->roster);
}

public function nodePackageManager(): string
{
return $this->roster->nodePackageManager()->value ?? NodePackageManager::NPM->value;
}
}
2 changes: 1 addition & 1 deletion src/Install/GuidelineComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ protected function guideline(string $path, bool $thirdParty = false): array

protected function processBoostSnippets(string $content): string
{
return preg_replace_callback('/(?<!@)@boostsnippet\(\s*(?P<nameQuote>[\'"])(?P<name>[^\1]*?)\1(?:\s*,\s*(?P<langQuote>[\'"])(?P<lang>[^\3]*?)\3)?\s*\)(?P<content>.*?)@endboostsnippet/s', function ($matches): string {
return preg_replace_callback('/(?<!@)@boostsnippet\(\s*(?P<nameQuote>[\'"])(?P<name>[^\1]*?)\1(?:\s*,\s*(?P<langQuote>[\'"])(?P<lang>[^\3]*?)\3)?\s*\)(?P<content>.*?)@endboostsnippet/s', function (array $matches): string {
$name = $matches['name'];
$lang = empty($matches['lang']) ? 'html' : $matches['lang'];
$snippetContent = $matches['content'];
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Install/GuidelineComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
use Laravel\Boost\Install\GuidelineComposer;
use Laravel\Boost\Install\GuidelineConfig;
use Laravel\Boost\Install\Herd;
use Laravel\Roster\Enums\NodePackageManager;
use Laravel\Roster\Enums\Packages;
use Laravel\Roster\Package;
use Laravel\Roster\PackageCollection;
use Laravel\Roster\Roster;

beforeEach(function (): void {
$this->roster = Mockery::mock(Roster::class);
$this->nodePackageManager = NodePackageManager::NPM;
$this->roster->shouldReceive('nodePackageManager')->andReturnUsing(
fn (): NodePackageManager => $this->nodePackageManager
);

$this->herd = Mockery::mock(Herd::class);
$this->herd->shouldReceive('isInstalled')->andReturn(false)->byDefault();

Expand Down Expand Up @@ -357,3 +363,22 @@
->toContain('=== phpunit/core rules ===')
->not->toContain('=== pest/core rules ===');
});

test('includes correct package manager commands in guidelines based on lockfile', function (NodePackageManager $packageManager, string $expectedCommand): void {
$packages = new PackageCollection([
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
]);
$this->nodePackageManager = $packageManager;
$this->roster->shouldReceive('packages')->andReturn($packages);

$guidelines = $this->composer->compose();

expect($guidelines)
->toContain("{$expectedCommand} run build")
->toContain("{$expectedCommand} run dev");
})->with([
'npm' => [NodePackageManager::NPM, 'npm'],
'pnpm' => [NodePackageManager::PNPM, 'pnpm'],
'yarn' => [NodePackageManager::YARN, 'yarn'],
'bun' => [NodePackageManager::BUN, 'bun'],
]);