Skip to content

Commit

Permalink
feat(laravel): implement getHash
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Feb 3, 2022
1 parent fd083dd commit 251f766
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public function getManifestPath(): string
);
}

/**
* Returns the manifest's md5.
*/
public function getHash(): string|null
{
if (!file_exists($path = $this->getManifestPath())) {
return null;
}

return md5_file($path) ?: null;
}

/**
* Gets the tag for the given entry.
*/
Expand Down
16 changes: 15 additions & 1 deletion tests/Features/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
vite()->getTags();
})->throws(NoBuildPathException::class);

it('fins the manifest path', function () {
it('finds the manifest path', function () {
set_fixtures_path('builds');
set_env('production');

Expand All @@ -76,6 +76,20 @@
expect(vite()->getManifestPath())->toBe(str_replace('\\', '/', public_path('build/manifest.json')));
});

it('finds the manifest version', function () {
set_fixtures_path('builds');
set_env('production');

set_vite_config('default', ['build_path' => '']);
expect(vite()->getHash())->toBeNull();

set_vite_config('default', ['build_path' => 'with-css']);
expect(vite()->getHash())->toBe(md5_file(fixtures_path('builds/public/with-css/manifest.json')));

set_vite_config('default', ['build_path' => 'with-integrity']);
expect(vite()->getHash())->toBe(md5_file(fixtures_path('builds/public/with-integrity/manifest.json')));
});

it('finds a configured entrypoint by its name in development', function () {
with_dev_server();
set_fixtures_path('');
Expand Down

0 comments on commit 251f766

Please # to comment.