Skip to content

Commit

Permalink
feat(laravel): add getManifestPath convenience method
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Feb 3, 2022
1 parent 9945c31 commit fd083dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,28 @@ public function __construct(

/**
* Returns the manifest, reading it from the disk if necessary.
*
* @throws NoBuildPathException
*/
public function getManifest(): ?Manifest
{
if (!$this->config('build_path')) {
throw new NoBuildPathException($this->name);
}

$path = public_path(sprintf('%s/%s', trim($this->config('build_path'), '/\\'), 'manifest.json'));
return $this->manifest ??= Manifest::read($this->getManifestPath());
}

return $this->manifest ??= Manifest::read($path);
/**
* Returns the manifest path.
*/
public function getManifestPath(): string
{
return str_replace(
['\\', '//'],
'/',
public_path(sprintf('%s/%s', trim($this->config('build_path'), '/\\'), 'manifest.json'))
);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Features/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@
vite()->getTags();
})->throws(NoBuildPathException::class);

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

set_vite_config('default', ['build_path' => '']);
expect(vite()->getManifestPath())->toBe(str_replace('\\', '/', public_path('manifest.json')));

set_vite_config('default', ['build_path' => '/']);
expect(vite()->getManifestPath())->toBe(str_replace('\\', '/', public_path('manifest.json')));

set_vite_config('default', ['build_path' => '/build']);
expect(vite()->getManifestPath())->toBe(str_replace('\\', '/', public_path('build/manifest.json')));

set_vite_config('default', ['build_path' => '/build/']);
expect(vite()->getManifestPath())->toBe(str_replace('\\', '/', public_path('build/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 fd083dd

Please # to comment.