Skip to content

Commit

Permalink
Merge pull request #1327 from hydephp/update-playcdn-integration-to-w…
Browse files Browse the repository at this point in the history
…ork-gracefully-when-there-is-no-tailwind-config-file

Update AssetService::injectTailwindConfig method to handle missing config file gracefully
  • Loading branch information
caendesilva authored Mar 18, 2023
2 parents f0dca12 + 6b293c3 commit ea035f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This release is the first since the official release of HydePHP 1.0.0. It contai
- Fixed https://github.com/hydephp/develop/issues/1320 in https://github.com/hydephp/develop/pull/1321
- Fixed https://github.com/hydephp/develop/issues/1322 in https://github.com/hydephp/develop/issues/1323
- Fixed https://github.com/hydephp/develop/issues/1324 in https://github.com/hydephp/develop/pull/1325
- Fixed https://github.com/hydephp/develop/issues/1326 in https://github.com/hydephp/develop/pull/1327
- Added missing function imports in https://github.com/hydephp/develop/pull/1309

### Security
Expand Down
4 changes: 4 additions & 0 deletions packages/framework/src/Framework/Services/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function hasMediaFile(string $file): bool

public function injectTailwindConfig(): string
{
if (! file_exists(Hyde::path('tailwind.config.js'))) {
return '';
}

$config = Str::between(file_get_contents(Hyde::path('tailwind.config.js')), '{', '}');

// Remove the plugins array, as it is not used in the frontend.
Expand Down
9 changes: 9 additions & 0 deletions packages/framework/tests/Unit/AssetServiceUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hyde\Framework\Services\AssetService;
use Hyde\Testing\UnitTestCase;
use Hyde\Hyde;

/**
* @covers \Hyde\Framework\Services\AssetService
Expand Down Expand Up @@ -107,4 +108,12 @@ public function testInjectTailwindConfigReturnsExtractedTailwindConfig()
$this->assertStringContainsString('typography: {', $config);
$this->assertStringNotContainsString('plugins', $config);
}

public function testInjectTailwindConfigHandlesMissingConfigFileGracefully()
{
rename(Hyde::path('tailwind.config.js'), Hyde::path('tailwind.config.js.bak'));
$this->assertIsString((new AssetService())->injectTailwindConfig());
$this->assertSame('', (new AssetService())->injectTailwindConfig());
rename(Hyde::path('tailwind.config.js.bak'), Hyde::path('tailwind.config.js'));
}
}

0 comments on commit ea035f1

Please sign in to comment.