Skip to content

Commit

Permalink
Use asset resolver instead manually resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Jan 6, 2024
1 parent e1ae1f0 commit 8cf7981
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Http/Middleware/AddLinkHeadersForPreloadedPins.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tonysm\ImportmapLaravel\Http\Middleware;

use Tonysm\ImportmapLaravel\AssetResolver;
use Tonysm\ImportmapLaravel\Facades\Importmap;

class AddLinkHeadersForPreloadedPins
Expand All @@ -16,7 +17,9 @@ class AddLinkHeadersForPreloadedPins
public function handle($request, $next)
{
return tap($next($request), function ($response) {
if ($preloaded = Importmap::preloadedModulePaths(fn ($file) => asset($file))) {
$resolver = new AssetResolver();

if ($preloaded = Importmap::preloadedModulePaths($resolver)) {
$response->header('Link', collect($preloaded)
->map(fn ($url) => "<{$url}>; rel=\"modulepreload\"")
->join(', '));
Expand Down
2 changes: 1 addition & 1 deletion tests/PreloadingWithLinkHeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function sets_link_header_when_pins_are_preloaded(): void
});

$this->assertEquals(

Check failure on line 41 in tests/PreloadingWithLinkHeadersTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-lowest - ubuntu-latest

Failed asserting that two strings are equal.
'<http://localhost/js/app.js>; rel="modulepreload", <http://localhost/js/app.js>; rel="modulepreload", <http://localhost/js/controllers/hello_controller.js>; rel="modulepreload", <http://localhost/js/controllers/index.js>; rel="modulepreload", <http://localhost/js/controllers/utilities/md5_controller.js>; rel="modulepreload", <http://localhost/js/helpers/requests/index.js>; rel="modulepreload", <http://localhost/js/libs/vendor/alpine.js>; rel="modulepreload", <http://localhost/js/spina/controllers/another_controller.js>; rel="modulepreload", <http://localhost/js/spina/controllers/deeper/again_controller.js>; rel="modulepreload"',
'<http://localhost/js/app.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/app.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/controllers/hello_controller.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/controllers/index.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/controllers/utilities/md5_controller.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/helpers/requests/index.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/libs/vendor/alpine.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/spina/controllers/another_controller.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload", <http://localhost/js/spina/controllers/deeper/again_controller.js?digest=da39a3ee5e6b4b0d3255bfef95601890afd80709>; rel="modulepreload"',
$response->headers->get('Link'),

Check failure on line 43 in tests/PreloadingWithLinkHeadersTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-lowest - ubuntu-latest

Failed asserting that two strings are equal.
);
}
Expand Down

0 comments on commit 8cf7981

Please sign in to comment.