From 22757875e5c404a3ba7fa42db86766e34608db0e Mon Sep 17 00:00:00 2001 From: QWp6t Date: Mon, 20 Dec 2021 09:17:58 -0800 Subject: [PATCH] fix(assets): throw exception when manifest is missing (#153) --- src/Roots/Acorn/Application.php | 2 +- .../Contracts/ManifestNotFoundException.php | 10 +++++++ src/Roots/Acorn/Assets/Manager.php | 7 ++++- tests/Application/ApplicationTest.php | 9 ++++++ tests/Assets/ManagerTest.php | 29 +++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/Roots/Acorn/Assets/Contracts/ManifestNotFoundException.php diff --git a/src/Roots/Acorn/Application.php b/src/Roots/Acorn/Application.php index 1ac0584b..32ebcc4b 100644 --- a/src/Roots/Acorn/Application.php +++ b/src/Roots/Acorn/Application.php @@ -120,7 +120,7 @@ public function usePaths(array $paths) throw new Exception("The {$path_type} path type is not supported."); } - if (! is_dir($path) || ! is_readable($path)) { + if ($path_type !== 'public' && (! is_dir($path) || ! is_readable($path))) { throw new Exception("The {$path} directory must be present."); } diff --git a/src/Roots/Acorn/Assets/Contracts/ManifestNotFoundException.php b/src/Roots/Acorn/Assets/Contracts/ManifestNotFoundException.php new file mode 100644 index 00000000..582c9173 --- /dev/null +++ b/src/Roots/Acorn/Assets/Contracts/ManifestNotFoundException.php @@ -0,0 +1,10 @@ +throws(Exception::class); +it('allows invalid public path', function () { + $app = new Application(); + + $app->usePaths([ + 'app' => $this->fixture('use_paths/app'), + 'public' => __DIR__ . '/this/does/not/exist', + ]); +})->not->throws(Exception::class); + it('accepts an array of custom paths', function () { $app = new Application(temp('base_path')); diff --git a/tests/Assets/ManagerTest.php b/tests/Assets/ManagerTest.php index 04074f0b..71f60d17 100644 --- a/tests/Assets/ManagerTest.php +++ b/tests/Assets/ManagerTest.php @@ -1,6 +1,7 @@ manifest('theme'))->toBeInstanceOf(ManifestContract::class); }); +it('throws an error if an assets manifest does not exist', function () { + $assets = new Manager([ + 'manifests' => [ + 'theme' => [ + 'path' => $this->fixture('bud_single_runtime'), + 'url' => 'https://k.jo', + 'assets' => __DIR__ . '/does/not/exist/manifest.json', + ] + ] + ]); + + $assets->manifest('theme')->asset('app.css')->uri(); +})->throws(ManifestNotFoundException::class); + it('reads an assets manifest', function () { $assets = new Manager([ 'manifests' => [ @@ -48,6 +63,20 @@ assertMatchesSnapshot($assets->manifest('theme')->asset('app.js')->uri()); }); +it('throws an error if a bundles manifest does not exist', function () { + $assets = new Manager([ + 'manifests' => [ + 'theme' => [ + 'path' => $this->fixture('bud_single_runtime'), + 'url' => 'https://k.jo', + 'bundles' => __DIR__ . '/does/not/exist/entrypoints.json', + ] + ] + ]); + + $assets->manifest('theme')->bundle('app')->js()->toJson(); +})->throws(ManifestNotFoundException::class); + it('reads a bundles manifest', function () { $assets = new Manager([ 'manifests' => [