Skip to content

Commit

Permalink
Fix optimize command when vendor import starts with forward slash
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Feb 2, 2024
1 parent 139b788 commit 4e17a78
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Commands/OptimizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function handle(Importmap $importmap): int
$optimizedImports = collect($imports['imports'])
->reject(fn (string $url) => Str::startsWith($url, ['http://', 'https://']))
->map(function (string $file) use ($importmap) {
$sourceFile = $importmap->rootPath.(str_starts_with($file, 'vendor/') ? '/public/' : '/resources/').trim($file, '/');
$sourceFile = $importmap->rootPath.(str_starts_with(trim($file, '/'), 'vendor/') ? '/public/' : '/resources/').trim($file, '/');
$sourceReplacement = $importmap->rootPath.'/public/dist/'.trim($this->digest($file, $sourceFile), '/');

File::ensureDirectoryExists(dirname($sourceReplacement));
Expand Down
1 change: 1 addition & 0 deletions tests/OptimizeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected function setUp(): void
$this->map->pin('app');
$this->map->pin('md5', to: 'https://cdn.skypack.dev/md5', preload: true);
$this->map->pin('my_lib', to: 'vendor/nova/my_lib.js', preload: true);
$this->map->pin('my_other_lib', to: '/vendor/nova/my_other_lib.js', preload: true);

if (File::isDirectory($this->distPath = $this->rootPath.'/public/dist/')) {
File::cleanDirectory($this->distPath);
Expand Down
Empty file.

0 comments on commit 4e17a78

Please sign in to comment.