Skip to content

Commit 751972a

Browse files
committed
Add laravel echo and other first party packages
1 parent f11b815 commit 751972a

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

src/Support/Npm.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ class Npm
1212
'@laravel',
1313
];
1414

15+
/** @var array<int, string> */
16+
public const FIRST_PARTY_PACKAGES = [
17+
'laravel-echo',
18+
'laravel-precognition',
19+
'laravel-vite-plugin'
20+
];
21+
1522
public static function isFirstPartyPackage(string $npmName): bool
1623
{
17-
foreach (self::FIRST_PARTY_SCOPES as $scope) {
18-
if (str_starts_with($npmName, $scope.'/')) {
19-
return true;
20-
}
21-
}
22-
23-
return false;
24+
return array_any(self::FIRST_PARTY_SCOPES, fn (string $scope): bool => str_starts_with($npmName, $scope.'/'))
25+
|| in_array($npmName, self::FIRST_PARTY_PACKAGES, true);
2426
}
2527

2628
/**

tests/Unit/Support/NpmTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,55 @@
117117

118118
expect(Npm::packages())->toBe([]);
119119
});
120+
121+
it('returns non-scoped package directories with boost guidelines', function (): void {
122+
file_put_contents(base_path('package.json'), json_encode([
123+
'dependencies' => [
124+
'laravel-echo' => '^2.0.0',
125+
'axios' => '^1.0.0',
126+
],
127+
]));
128+
129+
$withGuidelines = base_path(implode(DIRECTORY_SEPARATOR, [
130+
'node_modules', 'laravel-echo', 'resources', 'boost', 'guidelines',
131+
]));
132+
File::ensureDirectoryExists($withGuidelines);
133+
134+
$withoutGuidelines = base_path(implode(DIRECTORY_SEPARATOR, [
135+
'node_modules', 'axios',
136+
]));
137+
File::ensureDirectoryExists($withoutGuidelines);
138+
139+
$result = Npm::packagesDirectoriesWithBoostGuidelines();
140+
141+
expect($result)
142+
->toHaveKey('laravel-echo')
143+
->not->toHaveKey('axios');
144+
});
145+
146+
it('returns non-scoped package directories with boost skills', function (): void {
147+
file_put_contents(base_path('package.json'), json_encode([
148+
'dependencies' => [
149+
'laravel-echo' => '^2.0.0',
150+
],
151+
]));
152+
153+
$withSkills = base_path(implode(DIRECTORY_SEPARATOR, [
154+
'node_modules', 'laravel-echo', 'resources', 'boost', 'skills',
155+
]));
156+
File::ensureDirectoryExists($withSkills);
157+
158+
$result = Npm::packagesDirectoriesWithBoostSkills();
159+
160+
expect($result)->toHaveKey('laravel-echo');
161+
});
162+
163+
it('identifies non-scoped first party packages', function (): void {
164+
expect(Npm::isFirstPartyPackage('laravel-echo'))->toBeTrue();
165+
});
166+
167+
it('does not identify unknown packages as first party', function (): void {
168+
expect(Npm::isFirstPartyPackage('axios'))->toBeFalse()
169+
->and(Npm::isFirstPartyPackage('lodash'))->toBeFalse()
170+
->and(Npm::isFirstPartyPackage('unknown-package'))->toBeFalse();
171+
});

0 commit comments

Comments
 (0)