From 1a44422d4308d8db7e3920e764a65920971da752 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 18 Mar 2024 15:30:36 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Ensure?= =?UTF-8?q?=20Acorn=20is=20booted=20before=20throwing=20`skipProvider`=20e?= =?UTF-8?q?xceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Application.php b/src/Roots/Acorn/Application.php index 758089db..d770fb31 100644 --- a/src/Roots/Acorn/Application.php +++ b/src/Roots/Acorn/Application.php @@ -306,7 +306,7 @@ protected function skipProvider($provider, Throwable $e): ServiceProvider report($e); if ($this->environment('development', 'testing', 'local') && ! $this->runningInConsole()) { - throw $e; + $this->booted(fn () => throw $e); } return is_object($provider) ? $provider : new class($this) extends ServiceProvider From 162e6f66b5c3579f830998f16598a19bab05ae15 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 18 Mar 2024 15:31:01 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20the=20manifest=20e?= =?UTF-8?q?xception=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Assets/Manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Assets/Manager.php b/src/Roots/Acorn/Assets/Manager.php index 27719fc3..a1eabcd9 100644 --- a/src/Roots/Acorn/Assets/Manager.php +++ b/src/Roots/Acorn/Assets/Manager.php @@ -119,7 +119,7 @@ protected function pipeline(array $config): array protected function getJsonManifest(string $jsonManifest): array { if (! file_exists($jsonManifest)) { - throw new ManifestNotFoundException("The manifest [{$jsonManifest}] cannot be found."); + throw new ManifestNotFoundException("The asset manifest [{$jsonManifest}] cannot be found."); } return json_decode(file_get_contents($jsonManifest), true) ?? []; From 1a11931fa842a2f5d9391125a179e8fae1df8dab Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 18 Mar 2024 15:32:25 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20`?= =?UTF-8?q?Manifest`=20and=20`SkipProvider`=20solutions=20to=20Ignition=20?= =?UTF-8?q?(Fixes=20#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/DefaultProviders.php | 1 + .../Exceptions/ExceptionServiceProvider.php | 41 +++++++++++ .../Solutions/ManifestSolutionProvider.php | 71 +++++++++++++++++++ .../SkipProviderSolutionProvider.php | 30 ++++++++ 4 files changed, 143 insertions(+) create mode 100644 src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php create mode 100644 src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php create mode 100644 src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php diff --git a/src/Roots/Acorn/DefaultProviders.php b/src/Roots/Acorn/DefaultProviders.php index a677608e..651dc539 100644 --- a/src/Roots/Acorn/DefaultProviders.php +++ b/src/Roots/Acorn/DefaultProviders.php @@ -13,6 +13,7 @@ class DefaultProviders extends DefaultProvidersBase * @var array */ protected $acornProviders = [ + \Roots\Acorn\Exceptions\ExceptionServiceProvider::class, \Roots\Acorn\Assets\AssetsServiceProvider::class, \Roots\Acorn\Filesystem\FilesystemServiceProvider::class, \Roots\Acorn\Providers\AcornServiceProvider::class, diff --git a/src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php b/src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php new file mode 100644 index 00000000..ff2eaa82 --- /dev/null +++ b/src/Roots/Acorn/Exceptions/ExceptionServiceProvider.php @@ -0,0 +1,41 @@ +registerSolutions(); + } + + /** + * Register the exception solutions. + */ + protected function registerSolutions() + { + $this->app->make(SolutionProviderRepository::class)->registerSolutionProviders($this->solutions); + } +} diff --git a/src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php b/src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php new file mode 100644 index 00000000..51f99d30 --- /dev/null +++ b/src/Roots/Acorn/Exceptions/Solutions/ManifestSolutionProvider.php @@ -0,0 +1,71 @@ + 'https://roots.io/sage/docs/installation/', + 'Bud Documentation' => 'https://bud.js.org/learn/getting-started', + ]; + + /** + * Determine if the provider can solve the given throwable. + */ + public function canSolve(Throwable $throwable): bool + { + return Str::startsWith($throwable->getMessage(), 'The asset manifest'); + } + + /** + * Get the solutions for the given throwable. + */ + public function getSolutions(Throwable $throwable): array + { + return [$this->getSolution()]; + } + + /** + * Get the solutions for the given throwable. + */ + public function getSolution(): Solution + { + $baseCommand = collect([ + 'pnpm-lock.yaml' => 'pnpm', + 'yarn.lock' => 'yarn', + ])->first(fn ($_, $lockfile) => file_exists(base_path($lockfile)), 'npm run'); + + return app()->environment('development', 'testing', 'local') + ? $this->getLocalSolution($baseCommand) + : $this->getProductionSolution($baseCommand); + } + + /** + * Get the local solution. + */ + protected function getLocalSolution(string $baseCommand): Solution + { + return BaseSolution::create('Start the development server') + ->setSolutionDescription("Run `{$baseCommand} dev` in your terminal and refresh the page.") + ->setDocumentationLinks($this->links); + } + + /** + * Get the production solution. + */ + protected function getProductionSolution(string $baseCommand): Solution + { + return BaseSolution::create('Build the production assets') + ->setSolutionDescription("Run `{$baseCommand} build` in your deployment script.") + ->setDocumentationLinks($this->links); + } +} diff --git a/src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php b/src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php new file mode 100644 index 00000000..42882f17 --- /dev/null +++ b/src/Roots/Acorn/Exceptions/Solutions/SkipProviderSolutionProvider.php @@ -0,0 +1,30 @@ +setSolutionDescription('Run `wp acorn optimize:clear` in your terminal and refresh the page.'), + ]; + } +}