From eee27f6b873c5d4f8bf9ea94162cec4e19ded21c Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 17:05:40 -0300 Subject: [PATCH 1/6] No need to remove the config (as that no longer comes installed) --- src/Commands/InstallCommand.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index aa15309..2de2eb6 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -28,7 +28,6 @@ public function handle() $this->installMiddleware('\Tonysm\TailwindCss\Http\Middleware\AddLinkHeaderForPreloadedAssets::class'); $this->addIngoreLines(); $this->runFirstBuild(); - $this->removeUnusedFiles(); $this->newLine(); @@ -39,7 +38,7 @@ public function handle() protected function phpBinary() { - return (new PhpExecutableFinder())->find(false) ?: 'php'; + return (new PhpExecutableFinder)->find(false) ?: 'php'; } private function ensureTailwindConfigExists() @@ -115,7 +114,7 @@ private function appendTailwindStylesToLayouts() $this->existingLayoutFiles() ->each(fn ($file) => File::put( $file, - (new AppendTailwindTag())(File::get($file)), + (new AppendTailwindTag)(File::get($file)), )); } @@ -184,17 +183,6 @@ private function runFirstBuild() }); } - private function removeUnusedFiles() - { - $files = [ - base_path('tailwind.config.js'), - ]; - - foreach ($files as $file) { - File::exists($file) && File::delete($file); - } - } - private function mainCssIsDefault($appCssFilePath): bool { return trim(File::get($appCssFilePath)) === trim(<<<'CSS' From a6d1dd696e90bd5ff2acbf1c4048fdaa57709715 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 17:09:37 -0300 Subject: [PATCH 2/6] Support Laravel 12 --- .github/workflows/run-tests.yml | 21 +++++------- composer.json | 10 +++--- rector.php | 22 +++++++++++++ src/Actions/AppendTailwindTag.php | 2 +- src/Commands/BuildCommand.php | 14 +++++--- src/Commands/DownloadCommand.php | 8 +++-- src/Commands/InstallCommand.php | 33 +++++++++---------- .../AddLinkHeaderForPreloadedAssets.php | 10 +++--- src/Manifest.php | 5 ++- src/TailwindCssServiceProvider.php | 2 +- src/Testing/InteractsWithTailwind.php | 4 +-- src/helpers.php | 2 -- tests/AppendTailwindTagTest.php | 4 +-- tests/PreloadingHeaderTest.php | 16 ++++----- tests/TestCase.php | 4 +-- tests/WorksWithoutCompiledManifestTest.php | 12 +++---- 16 files changed, 92 insertions(+), 77 deletions(-) create mode 100644 rector.php diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5101e1f..b65a087 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,28 +10,23 @@ on: jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: fail-fast: true matrix: - # os: [ubuntu-latest, windows-latest] - os: [ubuntu-latest] - php: [8.1, 8.2] - laravel: [10.*, 11.*] + php: [8.2, 8.3, 8.4] + laravel: [11.*, 12.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 10.* - testbench: 8.* - collision: ^6.0 - laravel: 11.* testbench: ^9.0 collision: ^8.1 - exclude: - - laravel: 11.* - php: 8.1 + - laravel: 12.* + testbench: ^10.0 + collision: ^9.0 - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} steps: - name: Checkout code @@ -51,7 +46,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nunomaduro/collision:${{ matrix.collision }}" "nesbot/carbon:^2.64.1" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nunomaduro/collision:${{ matrix.collision }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests diff --git a/composer.json b/composer.json index 8122216..aff5985 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,14 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "spatie/laravel-package-tools": "^1.16", - "illuminate/contracts": "^10.0|^11.0" + "illuminate/contracts": "^11.0|^12.0" }, "require-dev": { - "nunomaduro/collision": "^6.0|^8.1", - "orchestra/testbench": "^8.0|^9.0", - "phpunit/phpunit": "^10.5" + "nunomaduro/collision": "^8.1|^9.0", + "orchestra/testbench": "^9.0|^10.0", + "phpunit/phpunit": "^10.5|^11.0" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..0283c1f --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + ) + ->withAttributesSets() + ->withPhpSets() + ->withPhpVersion(PhpVersion::PHP_82); diff --git a/src/Actions/AppendTailwindTag.php b/src/Actions/AppendTailwindTag.php index 7cc5dee..93d6615 100644 --- a/src/Actions/AppendTailwindTag.php +++ b/src/Actions/AppendTailwindTag.php @@ -4,7 +4,7 @@ class AppendTailwindTag { - public function __invoke(string $contents) + public function __invoke(string $contents): ?string { if (str_contains($contents, '{{ tailwindcss(')) { return $contents; diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 79e6e21..3ff7714 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -20,7 +20,7 @@ class BuildCommand extends Command protected $description = 'Generates a new build of Tailwind CSS for your project.'; - public function handle() + public function handle(): int { $binFile = config('tailwindcss.bin_path'); @@ -57,7 +57,7 @@ public function handle() '-o', $destinationFileAbsolutePath, $this->option('watch') ? '--watch=always' : null, $this->shouldMinify() ? '-m' : null, - ]), function ($type, $output) { + ]), function ($type, $output): void { $this->output->write($output); }); @@ -106,11 +106,17 @@ private function fixOsFilePathToUriPath(string $path): string private function shouldVersion(): bool { - return $this->option('digest') || $this->option('prod'); + if ($this->option('digest')) { + return true; + } + return (bool) $this->option('prod'); } private function shouldMinify(): bool { - return $this->option('minify') || $this->option('prod'); + if ($this->option('minify')) { + return true; + } + return (bool) $this->option('prod'); } } diff --git a/src/Commands/DownloadCommand.php b/src/Commands/DownloadCommand.php index ea37638..f77df3b 100644 --- a/src/Commands/DownloadCommand.php +++ b/src/Commands/DownloadCommand.php @@ -16,7 +16,7 @@ class DownloadCommand extends Command protected $description = 'Downloads the Tailwind CSS binary for the version specified in your config/tailwindcss.php.'; - public function handle() + public function handle(): int { $os = php_uname('s'); $cpu = php_uname('m'); @@ -57,8 +57,10 @@ public function handle() return self::FAILURE; } - File::ensureDirectoryExists(dirname($targetPath)); - File::exists($targetPath) && File::delete($targetPath); + File::ensureDirectoryExists(dirname((string) $targetPath)); + if (File::exists($targetPath)) { + File::delete($targetPath); + } File::put($targetPath, $contents); File::chmod($targetPath, 0755); diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 2de2eb6..7359acc 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -20,7 +20,7 @@ class InstallCommand extends Command protected $description = 'Installs the Tailwind CSS scaffolding for new Laravel applications.'; - public function handle() + public function handle(): int { $this->ensureTailwindConfigExists(); $this->ensureTailwindCliBinaryExists(); @@ -31,24 +31,24 @@ public function handle() $this->newLine(); - $this->components->info('TailwindCSS Laravel was installed successfully.'); + $this->components->info('Tailwind CSS Laravel was installed successfully.'); return self::SUCCESS; } - protected function phpBinary() + protected function phpBinary(): string { return (new PhpExecutableFinder)->find(false) ?: 'php'; } - private function ensureTailwindConfigExists() + private function ensureTailwindConfigExists(): void { $this->copyStubToApp( stub: __DIR__ . '/../../stubs/postcss.config.js', to: base_path('postcss.config.js'), ); - if (! File::exists($appCssFilePath = resource_path('css/app.css')) || empty(trim(File::get($appCssFilePath))) || $this->mainCssIsDefault($appCssFilePath)) { + if (! File::exists($appCssFilePath = resource_path('css/app.css')) || in_array(trim(File::get($appCssFilePath)), ['', '0'], true) || $this->mainCssIsDefault($appCssFilePath)) { $this->copyStubToApp( stub: __DIR__ . '/../../stubs/resources/css/app.css', to: $appCssFilePath, @@ -56,7 +56,7 @@ private function ensureTailwindConfigExists() } } - private function ensureTailwindCliBinaryExists() + private function ensureTailwindCliBinaryExists(): void { if (! File::exists(config('tailwindcss.bin_path')) || $this->option('download')) { Process::forever()->tty(SymfonyProcess::isTtySupported())->run([ @@ -65,7 +65,7 @@ private function ensureTailwindCliBinaryExists() 'tailwindcss:download', '--cli-version', $this->option('cli-version') ?: config('tailwindcss.version'), - ], function ($_type, $output) { + ], function ($_type, $output): void { $this->output->write($output); }); } @@ -80,12 +80,9 @@ private function copyStubToApp(string $stub, string $to): void /** * Install the middleware to a group in the application Http Kernel. * - * @param string $after - * @param string $name * @param string $group - * @return void */ - private function installMiddlewareAfter($after, $name, $group = 'web') + private function installMiddlewareAfter(string $after, string $name, $group = 'web'): void { $httpKernel = file_get_contents(app_path('Http/Kernel.php')); @@ -109,7 +106,7 @@ private function installMiddlewareAfter($after, $name, $group = 'web') )); } - private function appendTailwindStylesToLayouts() + private function appendTailwindStylesToLayouts(): void { $this->existingLayoutFiles() ->each(fn ($file) => File::put( @@ -125,7 +122,7 @@ private function existingLayoutFiles() ->filter(fn ($file) => File::exists($file)); } - private function installMiddleware(string $middleware) + private function installMiddleware(string $middleware): void { if (file_exists(app_path('Http/Kernel.php'))) { $this->installMiddlewareAfter('SubstituteBindings::class', $middleware); @@ -134,7 +131,7 @@ private function installMiddleware(string $middleware) } } - private function installMiddlewareToBootstrap(string $middleware, string $group = 'web', string $modifier = 'append') + private function installMiddlewareToBootstrap(string $middleware, string $group = 'web', string $modifier = 'append'): void { $bootstrapApp = file_get_contents(base_path('bootstrap/app.php')); @@ -155,9 +152,9 @@ private function installMiddlewareToBootstrap(string $middleware, string $group file_put_contents(base_path('bootstrap/app.php'), $bootstrapApp); } - private function addIngoreLines() + private function addIngoreLines(): void { - $binary = basename(config('tailwindcss.bin_path')); + $binary = basename((string) config('tailwindcss.bin_path')); if (str_contains(File::get(base_path('.gitignore')), $binary)) { return; @@ -172,13 +169,13 @@ private function addIngoreLines() LINES); } - private function runFirstBuild() + private function runFirstBuild(): void { Process::forever()->tty(SymfonyProcess::isTtySupported())->run([ $this->phpBinary(), 'artisan', 'tailwindcss:build', - ], function ($_type, $output) { + ], function ($_type, $output): void { $this->output->write($output); }); } diff --git a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php index 69ae176..cdc1514 100644 --- a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php +++ b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php @@ -6,20 +6,20 @@ class AddLinkHeaderForPreloadedAssets { - public function __construct(private Manifest $manifest) + public function __construct(private readonly Manifest $manifest) { } public function handle($request, $next) { - return tap($next($request), function ($response) { - if (count($assets = $this->manifest->assetsForPreloading()) > 0) { + return tap($next($request), function ($response): void { + if (($assets = $this->manifest->assetsForPreloading()) !== []) { $response->header('Link', trim(implode(', ', array_filter(array_merge( [$response->headers->get('Link', null)], - collect($assets)->map(fn ($attributes, $asset) => implode('; ', array_merge( + collect($assets)->map(fn ($attributes, $asset): string => implode('; ', array_merge( ["<$asset>"], collect(array_merge(['rel' => 'preload', 'as' => 'style'], $attributes)) - ->map(fn ($value, $key) => "{$key}={$value}") + ->map(fn ($value, $key): string => "{$key}={$value}") ->all(), )))->all(), ))))); diff --git a/src/Manifest.php b/src/Manifest.php index a364bf6..9657841 100644 --- a/src/Manifest.php +++ b/src/Manifest.php @@ -25,7 +25,7 @@ public static function path(): string return config('tailwindcss.build.manifest_file_path'); } - public function __invoke(string $path, $preload = true) + public function __invoke(string $path, $preload = true): string|\Illuminate\Support\HtmlString { static $manifests = []; @@ -52,9 +52,8 @@ public function __invoke(string $path, $preload = true) report($exception); return $path; - } else { - throw $exception; } + throw $exception; } $asset = asset($manifest[$path]); diff --git a/src/TailwindCssServiceProvider.php b/src/TailwindCssServiceProvider.php index 9f11a74..421c12e 100644 --- a/src/TailwindCssServiceProvider.php +++ b/src/TailwindCssServiceProvider.php @@ -25,7 +25,7 @@ public function configurePackage(Package $package): void ]); } - public function packageRegistered() + public function packageRegistered(): void { $this->app->scoped(Manifest::class); } diff --git a/src/Testing/InteractsWithTailwind.php b/src/Testing/InteractsWithTailwind.php index 6cdd159..2be05b7 100644 --- a/src/Testing/InteractsWithTailwind.php +++ b/src/Testing/InteractsWithTailwind.php @@ -12,9 +12,7 @@ trait InteractsWithTailwind */ protected function withoutTailwind(): static { - $this->swap(Manifest::class, function () { - return new HtmlString(''); - }); + $this->swap(Manifest::class, fn(): \Illuminate\Support\HtmlString => new HtmlString('')); return $this; } diff --git a/src/helpers.php b/src/helpers.php index ce701e0..9767eec 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -7,9 +7,7 @@ /** * Get the path to a versioned TailwindCSS file. * - * @param string $path * @param bool|array $preload - * @return \Illuminate\Support\HtmlString|string */ function tailwindcss(string $path, $preload = true): HtmlString|string { diff --git a/tests/AppendTailwindTagTest.php b/tests/AppendTailwindTagTest.php index 6ccc6a1..3210443 100644 --- a/tests/AppendTailwindTagTest.php +++ b/tests/AppendTailwindTagTest.php @@ -6,8 +6,8 @@ class AppendTailwindTagTest extends TestCase { - /** @test */ - public function append_tailwind_tag_before_closing_head_tag() + #[\PHPUnit\Framework\Attributes\Test] + public function append_tailwind_tag_before_closing_head_tag(): void { $contents = <<<'BLADE' diff --git a/tests/PreloadingHeaderTest.php b/tests/PreloadingHeaderTest.php index 9c8edf9..cebce08 100644 --- a/tests/PreloadingHeaderTest.php +++ b/tests/PreloadingHeaderTest.php @@ -7,8 +7,8 @@ class PreloadingHeaderTest extends TestCase { - /** @test */ - public function no_link_header_when_not_preloading() + #[\PHPUnit\Framework\Attributes\Test] + public function no_link_header_when_not_preloading(): void { config()->set('tailwindcss.build.manifest_file_path', __DIR__.'/stubs/test-manifest.json'); @@ -24,8 +24,8 @@ public function no_link_header_when_not_preloading() $this->assertNull($response->headers->get('Link', null)); } - /** @test */ - public function adds_link_header_when_preloading() + #[\PHPUnit\Framework\Attributes\Test] + public function adds_link_header_when_preloading(): void { config()->set('tailwindcss.build.manifest_file_path', __DIR__.'/stubs/test-manifest.json'); @@ -41,8 +41,8 @@ public function adds_link_header_when_preloading() $this->assertEquals("<{$asset}>; rel=preload; as=style", $response->headers->get('Link', null)); } - /** @test */ - public function keeps_existing_preloading_link_header() + #[\PHPUnit\Framework\Attributes\Test] + public function keeps_existing_preloading_link_header(): void { config()->set('tailwindcss.build.manifest_file_path', __DIR__.'/stubs/test-manifest.json'); @@ -60,8 +60,8 @@ public function keeps_existing_preloading_link_header() $this->assertEquals("; rel=modulepreload, <{$asset}>; rel=preload; as=style", $response->headers->get('Link', null)); } - /** @test */ - public function adds_link_header_when_preloading_custom_attributes() + #[\PHPUnit\Framework\Attributes\Test] + public function adds_link_header_when_preloading_custom_attributes(): void { config()->set('tailwindcss.build.manifest_file_path', __DIR__.'/stubs/test-manifest.json'); diff --git a/tests/TestCase.php b/tests/TestCase.php index a0eb903..c9603bb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,7 +15,7 @@ protected function setUp(): void parent::setUp(); Factory::guessFactoryNamesUsing( - fn (string $modelName) => 'Tonysm\\TailwindCss\\Database\\Factories\\'.class_basename($modelName).'Factory' + fn (string $modelName): string => 'Tonysm\\TailwindCss\\Database\\Factories\\'.class_basename($modelName).'Factory' ); if (File::exists($manifestFile = Manifest::path())) { @@ -30,7 +30,7 @@ protected function getPackageProviders($app) ]; } - public function getEnvironmentSetUp($app) + public function getEnvironmentSetUp($app): void { config()->set('database.default', 'testing'); config()->set('app.url', 'http://localhost'); diff --git a/tests/WorksWithoutCompiledManifestTest.php b/tests/WorksWithoutCompiledManifestTest.php index d7372c2..c859f35 100644 --- a/tests/WorksWithoutCompiledManifestTest.php +++ b/tests/WorksWithoutCompiledManifestTest.php @@ -15,13 +15,11 @@ protected function setUp(): void { parent::setUp(); - Route::get('_testing/missing-manifest', function () { - return View::file(__DIR__ . '/stubs/welcome.blade.php'); - }); + Route::get('_testing/missing-manifest', fn() => View::file(__DIR__ . '/stubs/welcome.blade.php')); } - /** @test */ - public function throws_exception_when_missing_manifest() + #[\PHPUnit\Framework\Attributes\Test] + public function throws_exception_when_missing_manifest(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('The Tailwind CSS manifest does not exist.'); @@ -32,8 +30,8 @@ public function throws_exception_when_missing_manifest() $this->fail('Expected an exception to be thrown, but it did not.'); } - /** @test */ - public function works_without_compiled_manifest_file() + #[\PHPUnit\Framework\Attributes\Test] + public function works_without_compiled_manifest_file(): void { $this->withoutTailwind() ->get('_testing/missing-manifest') From 0df19070c63babddd029fdc6a915d46fc85759cf Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 17:10:39 -0300 Subject: [PATCH 3/6] Pint --- src/Actions/AppendTailwindTag.php | 2 +- src/Commands/BuildCommand.php | 4 +++- src/Commands/InstallCommand.php | 16 ++++++++-------- .../AddLinkHeaderForPreloadedAssets.php | 4 +--- src/Testing/InteractsWithTailwind.php | 2 +- src/helpers.php | 2 +- tests/AppendTailwindTagTest.php | 2 +- tests/WorksWithoutCompiledManifestTest.php | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Actions/AppendTailwindTag.php b/src/Actions/AppendTailwindTag.php index 93d6615..fb865d7 100644 --- a/src/Actions/AppendTailwindTag.php +++ b/src/Actions/AppendTailwindTag.php @@ -12,7 +12,7 @@ public function __invoke(string $contents): ?string return preg_replace( '/(\s*)(<\/head>)/', - PHP_EOL."\\1 ". + PHP_EOL.'\\1 '. "\\1 \\1\\2", $contents, ); diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 3ff7714..145fa32 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -35,7 +35,7 @@ public function handle(): int $sourcePath = $this->fixFilePathForOs(config('tailwindcss.build.source_file_path')); $sourceRelativePath = str_replace(rtrim(resource_path(), DIRECTORY_SEPARATOR), '', $sourcePath); $destinationPath = $this->fixFilePathForOs(config('tailwindcss.build.destination_path')); - $destinationFileAbsolutePath = $destinationPath . DIRECTORY_SEPARATOR . trim($sourceRelativePath, DIRECTORY_SEPARATOR); + $destinationFileAbsolutePath = $destinationPath.DIRECTORY_SEPARATOR.trim($sourceRelativePath, DIRECTORY_SEPARATOR); $destinationFileRelativePath = str_replace(rtrim(public_path(), DIRECTORY_SEPARATOR), '', $destinationFileAbsolutePath); File::ensureDirectoryExists(dirname($destinationFileAbsolutePath)); @@ -109,6 +109,7 @@ private function shouldVersion(): bool if ($this->option('digest')) { return true; } + return (bool) $this->option('prod'); } @@ -117,6 +118,7 @@ private function shouldMinify(): bool if ($this->option('minify')) { return true; } + return (bool) $this->option('prod'); } } diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 7359acc..9bdf941 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -44,13 +44,13 @@ protected function phpBinary(): string private function ensureTailwindConfigExists(): void { $this->copyStubToApp( - stub: __DIR__ . '/../../stubs/postcss.config.js', + stub: __DIR__.'/../../stubs/postcss.config.js', to: base_path('postcss.config.js'), ); if (! File::exists($appCssFilePath = resource_path('css/app.css')) || in_array(trim(File::get($appCssFilePath)), ['', '0'], true) || $this->mainCssIsDefault($appCssFilePath)) { $this->copyStubToApp( - stub: __DIR__ . '/../../stubs/resources/css/app.css', + stub: __DIR__.'/../../stubs/resources/css/app.css', to: $appCssFilePath, ); } @@ -94,8 +94,8 @@ private function installMiddlewareAfter(string $after, string $name, $group = 'w } $modifiedMiddlewareGroup = str_replace( - $after . ',', - $after . ',' . PHP_EOL . ' ' . $name . ',', + $after.',', + $after.','.PHP_EOL.' '.$name.',', $middlewareGroup, ); @@ -142,10 +142,10 @@ private function installMiddlewareToBootstrap(string $middleware, string $group $bootstrapApp = str_replace( '->withMiddleware(function (Middleware $middleware) {', '->withMiddleware(function (Middleware $middleware) {' - . PHP_EOL . " \$middleware->{$group}({$modifier}: [" - . PHP_EOL . " {$middleware}," - . PHP_EOL . ' ]);' - . PHP_EOL, + .PHP_EOL." \$middleware->{$group}({$modifier}: [" + .PHP_EOL." {$middleware}," + .PHP_EOL.' ]);' + .PHP_EOL, $bootstrapApp, ); diff --git a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php index cdc1514..b98c7ae 100644 --- a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php +++ b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php @@ -6,9 +6,7 @@ class AddLinkHeaderForPreloadedAssets { - public function __construct(private readonly Manifest $manifest) - { - } + public function __construct(private readonly Manifest $manifest) {} public function handle($request, $next) { diff --git a/src/Testing/InteractsWithTailwind.php b/src/Testing/InteractsWithTailwind.php index 2be05b7..110b00e 100644 --- a/src/Testing/InteractsWithTailwind.php +++ b/src/Testing/InteractsWithTailwind.php @@ -12,7 +12,7 @@ trait InteractsWithTailwind */ protected function withoutTailwind(): static { - $this->swap(Manifest::class, fn(): \Illuminate\Support\HtmlString => new HtmlString('')); + $this->swap(Manifest::class, fn (): \Illuminate\Support\HtmlString => new HtmlString('')); return $this; } diff --git a/src/helpers.php b/src/helpers.php index 9767eec..36e9109 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -7,7 +7,7 @@ /** * Get the path to a versioned TailwindCSS file. * - * @param bool|array $preload + * @param bool|array $preload */ function tailwindcss(string $path, $preload = true): HtmlString|string { diff --git a/tests/AppendTailwindTagTest.php b/tests/AppendTailwindTagTest.php index 3210443..9a80acf 100644 --- a/tests/AppendTailwindTagTest.php +++ b/tests/AppendTailwindTagTest.php @@ -40,6 +40,6 @@ public function append_tailwind_tag_before_closing_head_tag(): void BLADE; - $this->assertEquals($expected, (new AppendTailwindTag())($contents)); + $this->assertEquals($expected, (new AppendTailwindTag)($contents)); } } diff --git a/tests/WorksWithoutCompiledManifestTest.php b/tests/WorksWithoutCompiledManifestTest.php index c859f35..c055a19 100644 --- a/tests/WorksWithoutCompiledManifestTest.php +++ b/tests/WorksWithoutCompiledManifestTest.php @@ -15,7 +15,7 @@ protected function setUp(): void { parent::setUp(); - Route::get('_testing/missing-manifest', fn() => View::file(__DIR__ . '/stubs/welcome.blade.php')); + Route::get('_testing/missing-manifest', fn () => View::file(__DIR__.'/stubs/welcome.blade.php')); } #[\PHPUnit\Framework\Attributes\Test] From 2d3f2af8002ecba67dda1b65c9ed597fac832867 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 17:13:10 -0300 Subject: [PATCH 4/6] Remove unnecessary dependencies --- .github/workflows/run-tests.yml | 6 +----- composer.json | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b65a087..7d8d2e2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -5,8 +5,6 @@ on: branches: - main pull_request: - branches: - - main jobs: test: @@ -21,10 +19,8 @@ jobs: include: - laravel: 11.* testbench: ^9.0 - collision: ^8.1 - laravel: 12.* testbench: ^10.0 - collision: ^9.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} @@ -46,7 +42,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nunomaduro/collision:${{ matrix.collision }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests diff --git a/composer.json b/composer.json index aff5985..3b13f5f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,6 @@ "illuminate/contracts": "^11.0|^12.0" }, "require-dev": { - "nunomaduro/collision": "^8.1|^9.0", "orchestra/testbench": "^9.0|^10.0", "phpunit/phpunit": "^10.5|^11.0" }, From c4cdc366ff08352457e8c4ffeaa6ea2d031663b9 Mon Sep 17 00:00:00 2001 From: tonysm <1178621+tonysm@users.noreply.github.com> Date: Sun, 2 Mar 2025 20:14:19 +0000 Subject: [PATCH 5/6] Fix styling --- src/Commands/InstallCommand.php | 4 ++-- src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php | 4 +++- src/Manifest.php | 1 + tests/AppendTailwindTagTest.php | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 9bdf941..c600d0e 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -38,7 +38,7 @@ public function handle(): int protected function phpBinary(): string { - return (new PhpExecutableFinder)->find(false) ?: 'php'; + return (new PhpExecutableFinder())->find(false) ?: 'php'; } private function ensureTailwindConfigExists(): void @@ -111,7 +111,7 @@ private function appendTailwindStylesToLayouts(): void $this->existingLayoutFiles() ->each(fn ($file) => File::put( $file, - (new AppendTailwindTag)(File::get($file)), + (new AppendTailwindTag())(File::get($file)), )); } diff --git a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php index b98c7ae..cdc1514 100644 --- a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php +++ b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php @@ -6,7 +6,9 @@ class AddLinkHeaderForPreloadedAssets { - public function __construct(private readonly Manifest $manifest) {} + public function __construct(private readonly Manifest $manifest) + { + } public function handle($request, $next) { diff --git a/src/Manifest.php b/src/Manifest.php index 9657841..b7d6c92 100644 --- a/src/Manifest.php +++ b/src/Manifest.php @@ -53,6 +53,7 @@ public function __invoke(string $path, $preload = true): string|\Illuminate\Supp return $path; } + throw $exception; } diff --git a/tests/AppendTailwindTagTest.php b/tests/AppendTailwindTagTest.php index 9a80acf..3210443 100644 --- a/tests/AppendTailwindTagTest.php +++ b/tests/AppendTailwindTagTest.php @@ -40,6 +40,6 @@ public function append_tailwind_tag_before_closing_head_tag(): void BLADE; - $this->assertEquals($expected, (new AppendTailwindTag)($contents)); + $this->assertEquals($expected, (new AppendTailwindTag())($contents)); } } From 960f35f19c61ceef9144914be109ed844b91e523 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 2 Mar 2025 17:19:16 -0300 Subject: [PATCH 6/6] Run Pint instead of PHP-CS-Fixer --- .github/workflows/{php-cs-fixer.yml => linting.yml} | 4 +--- src/Commands/InstallCommand.php | 4 ++-- src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php | 4 +--- tests/AppendTailwindTagTest.php | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) rename .github/workflows/{php-cs-fixer.yml => linting.yml} (75%) diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/linting.yml similarity index 75% rename from .github/workflows/php-cs-fixer.yml rename to .github/workflows/linting.yml index fbec801..590fdba 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/linting.yml @@ -13,9 +13,7 @@ jobs: ref: ${{ github.head_ref }} - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php_cs.dist.php --allow-risky=yes + uses: aglipanci/laravel-pint-action@2.3.0 - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v5 diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index c600d0e..9bdf941 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -38,7 +38,7 @@ public function handle(): int protected function phpBinary(): string { - return (new PhpExecutableFinder())->find(false) ?: 'php'; + return (new PhpExecutableFinder)->find(false) ?: 'php'; } private function ensureTailwindConfigExists(): void @@ -111,7 +111,7 @@ private function appendTailwindStylesToLayouts(): void $this->existingLayoutFiles() ->each(fn ($file) => File::put( $file, - (new AppendTailwindTag())(File::get($file)), + (new AppendTailwindTag)(File::get($file)), )); } diff --git a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php index cdc1514..b98c7ae 100644 --- a/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php +++ b/src/Http/Middleware/AddLinkHeaderForPreloadedAssets.php @@ -6,9 +6,7 @@ class AddLinkHeaderForPreloadedAssets { - public function __construct(private readonly Manifest $manifest) - { - } + public function __construct(private readonly Manifest $manifest) {} public function handle($request, $next) { diff --git a/tests/AppendTailwindTagTest.php b/tests/AppendTailwindTagTest.php index 3210443..9a80acf 100644 --- a/tests/AppendTailwindTagTest.php +++ b/tests/AppendTailwindTagTest.php @@ -40,6 +40,6 @@ public function append_tailwind_tag_before_closing_head_tag(): void BLADE; - $this->assertEquals($expected, (new AppendTailwindTag())($contents)); + $this->assertEquals($expected, (new AppendTailwindTag)($contents)); } }