From 4c0462652a608cf2ada6e65f4fad0f93dca7695b Mon Sep 17 00:00:00 2001 From: artisanbr Date: Thu, 4 Jan 2024 17:46:01 -0300 Subject: [PATCH 1/3] Fix Livewire v3 make command compatibility --- .../ModularizedCommandsServiceProvider.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Support/ModularizedCommandsServiceProvider.php b/src/Support/ModularizedCommandsServiceProvider.php index defd063..277f378 100644 --- a/src/Support/ModularizedCommandsServiceProvider.php +++ b/src/Support/ModularizedCommandsServiceProvider.php @@ -31,7 +31,7 @@ use InterNACHI\Modular\Console\Commands\Make\MakeRule; use InterNACHI\Modular\Console\Commands\Make\MakeSeeder; use InterNACHI\Modular\Console\Commands\Make\MakeTest; -use Livewire\Commands as Livewire; +use Livewire\Features\SupportConsoleCommands\Commands as Livewire; class ModularizedCommandsServiceProvider extends ServiceProvider { @@ -60,7 +60,7 @@ class ModularizedCommandsServiceProvider extends ServiceProvider 'command.component.make' => MakeComponent::class, 'command.seed' => SeedCommand::class, ]; - + public function register(): void { // Register our overrides via the "booted" event to ensure that we override @@ -74,7 +74,7 @@ public function register(): void }); }); } - + protected function registerMakeCommandOverrides() { foreach ($this->overrides as $alias => $class_name) { @@ -82,30 +82,30 @@ protected function registerMakeCommandOverrides() $this->app->singleton(get_parent_class($class_name), $class_name); } } - + protected function registerMigrationCommandOverrides() { // Laravel 8 $this->app->singleton('command.migrate.make', function($app) { return new MakeMigration($app['migration.creator'], $app['composer']); }); - + // Laravel 9 $this->app->singleton(OriginalMakeMigrationCommand::class, function($app) { return new MakeMigration($app['migration.creator'], $app['composer']); }); } - + protected function registerLivewireOverrides(Artisan $artisan) { // Don't register commands if Livewire isn't installed if (! class_exists(Livewire\MakeCommand::class)) { return; } - + // Replace the resolved command with our subclass $artisan->resolveCommands([MakeLivewire::class]); - + // Ensure that if 'make:livewire' or 'livewire:make' is resolved from the container // in the future, our subclass is used instead $this->app->extend(Livewire\MakeCommand::class, function() { From e10ff92db8c5db4fb2440bc3b1ac8b3a2e2874e0 Mon Sep 17 00:00:00 2001 From: artisanbr Date: Thu, 4 Jan 2024 17:59:36 -0300 Subject: [PATCH 2/3] Fix Livewire v3 make command compatibility --- src/Console/Commands/Make/MakeLivewire.php | 53 ++++++++++++---------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Console/Commands/Make/MakeLivewire.php b/src/Console/Commands/Make/MakeLivewire.php index 74e3470..1881552 100644 --- a/src/Console/Commands/Make/MakeLivewire.php +++ b/src/Console/Commands/Make/MakeLivewire.php @@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; -use Livewire\Commands\MakeCommand; +use Livewire\Features\SupportConsoleCommands\Commands\MakeCommand; use Livewire\Livewire; use Livewire\LivewireComponentsFinder; @@ -14,36 +14,39 @@ class MakeLivewire extends MakeCommand { use Modularize; - + public function getAliases(): array { return ['make:livewire', 'livewire:make']; } - + public function handle() { if ($module = $this->module()) { Config::set('livewire.class_namespace', $module->qualify('Http\\Livewire')); Config::set('livewire.view_path', $module->path('resources/views/livewire')); - + $app = $this->getLaravel(); - + $defaultManifestPath = $app['livewire']->isRunningServerless() ? '/tmp/storage/bootstrap/cache/livewire-components.php' : $app->bootstrapPath('cache/livewire-components.php'); - - $componentsFinder = new LivewireComponentsFinder( - new Filesystem(), - Config::get('livewire.manifest_path') ?? $defaultManifestPath, - $module->path('src/Http/Livewire') - ); - - $app->instance(LivewireComponentsFinder::class, $componentsFinder); + + if (class_exists(LivewireComponentsFinder::class)) { + $componentsFinder = new LivewireComponentsFinder( + new Filesystem(), + Config::get('livewire.manifest_path') ?? $defaultManifestPath, + $module->path('src/Http/Livewire') + ); + + $app->instance(LivewireComponentsFinder::class, $componentsFinder); + } + } - + parent::handle(); } - + protected function createClass($force = false, $inline = false) { if ($module = $this->module()) { @@ -51,37 +54,37 @@ protected function createClass($force = false, $inline = false) ->split('/[.\/(\\\\)]+/') ->map([Str::class, 'studly']) ->join(DIRECTORY_SEPARATOR); - + $classPath = $module->path('src/Http/Livewire/'.$name.'.php'); - + if (File::exists($classPath) && ! $force) { $this->line(" WHOOPS-IE-TOOTLES 😳 \n"); $this->line("Class already exists: {$this->parser->relativeClassPath()}"); - + return false; } - + $this->ensureDirectoryExists($classPath); - + File::put($classPath, $this->parser->classContents($inline)); - + $component_name = Str::of($name) ->explode('/') ->filter() ->map([Str::class, 'kebab']) ->implode('.'); - + $fully_qualified_component = Str::of($this->argument('name')) ->prepend('Http/Livewire/') ->split('/[.\/(\\\\)]+/') ->map([Str::class, 'studly']) ->join('\\'); - + Livewire::component("{$module->name}::{$component_name}", $module->qualify($fully_qualified_component)); - + return $classPath; } - + return parent::createClass($force, $inline); } } From 189ceddbc9848bec4e430b297b171d4a44b4decc Mon Sep 17 00:00:00 2001 From: artisanbr Date: Fri, 5 Jan 2024 22:25:57 -0300 Subject: [PATCH 3/3] Hotfix Livewire v3 make command compatibility --- src/Console/Commands/Make/MakeLivewire.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Console/Commands/Make/MakeLivewire.php b/src/Console/Commands/Make/MakeLivewire.php index 1881552..4d9daa5 100644 --- a/src/Console/Commands/Make/MakeLivewire.php +++ b/src/Console/Commands/Make/MakeLivewire.php @@ -8,7 +8,6 @@ use Illuminate\Support\Str; use Livewire\Features\SupportConsoleCommands\Commands\MakeCommand; use Livewire\Livewire; -use Livewire\LivewireComponentsFinder; if (class_exists(MakeCommand::class)) { class MakeLivewire extends MakeCommand @@ -32,14 +31,14 @@ public function handle() ? '/tmp/storage/bootstrap/cache/livewire-components.php' : $app->bootstrapPath('cache/livewire-components.php'); - if (class_exists(LivewireComponentsFinder::class)) { - $componentsFinder = new LivewireComponentsFinder( + if (class_exists("Livewire\LivewireComponentsFinder")) { + $componentsFinder = new \Livewire\LivewireComponentsFinder( new Filesystem(), Config::get('livewire.manifest_path') ?? $defaultManifestPath, $module->path('src/Http/Livewire') ); - $app->instance(LivewireComponentsFinder::class, $componentsFinder); + $app->instance(\Livewire\LivewireComponentsFinder::class, $componentsFinder); } }