From fd083dde335344743788c2c0039109ed6775eb6f Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Thu, 3 Feb 2022 01:49:15 +0100 Subject: [PATCH] feat(laravel): add `getManifestPath` convenience method --- src/Configuration.php | 16 ++++++++++++++-- tests/Features/ConfigurationTest.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index 764d597..f800930 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -30,6 +30,8 @@ public function __construct( /** * Returns the manifest, reading it from the disk if necessary. + * + * @throws NoBuildPathException */ public function getManifest(): ?Manifest { @@ -37,9 +39,19 @@ public function getManifest(): ?Manifest 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')) + ); } /** diff --git a/tests/Features/ConfigurationTest.php b/tests/Features/ConfigurationTest.php index fd505d0..834e9a1 100644 --- a/tests/Features/ConfigurationTest.php +++ b/tests/Features/ConfigurationTest.php @@ -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('');