diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 2ce391e580a..c249bb0dfe4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -91,7 +91,7 @@ This serves two purposes: - **Replaced Laravel Mix with Vite for frontend asset compilation** in https://github.com/hydephp/develop/pull/2010 - **Breaking:** You must now use `npm run build` to compile your assets, instead of `npm run prod` - Bundled assets are now compiled directly into the `_media` folder, and will not be copied to the `_site/media` folder by the NPM command in https://github.com/hydephp/develop/pull/2011 - +- The realtime compiler now only serves assets from the media source directory (`_media`), and no longer checks the site output directory (`_site/media`) in https://github.com/hydephp/develop/pull/2012 ### Deprecated @@ -124,6 +124,12 @@ This serves two purposes: - in case of vulnerabilities. +### Package updates + +#### Realtime Compiler + +- Simplified the asset file locator to only serve files from the media source directory in https://github.com/hydephp/develop/pull/2012 + ### Upgrade Guide Please see the "Breaking changes & upgrade guide" section below for more information. diff --git a/packages/realtime-compiler/src/Actions/AssetFileLocator.php b/packages/realtime-compiler/src/Actions/AssetFileLocator.php index d7ad8c57165..5805306c26d 100644 --- a/packages/realtime-compiler/src/Actions/AssetFileLocator.php +++ b/packages/realtime-compiler/src/Actions/AssetFileLocator.php @@ -4,8 +4,6 @@ namespace Hyde\RealtimeCompiler\Actions; -use Illuminate\Support\Str; - /** * Locate a static file to proxy. */ @@ -15,19 +13,8 @@ public static function find(string $path): ?string { $path = trim($path, '/'); - $strategies = [ - BASE_PATH.'/_site/'.$path, - BASE_PATH.'/_media/'.$path, - BASE_PATH.'/_site/'.Str::after($path, 'media/'), - BASE_PATH.'/_media/'.Str::after($path, 'media/'), - ]; - - foreach ($strategies as $strategy) { - if (file_exists($strategy)) { - return $strategy; - } - } + $file = BASE_PATH.'/_media/'.str_replace('media/', '', $path); - return null; + return file_exists($file) ? $file : null; } } diff --git a/packages/realtime-compiler/tests/RealtimeCompilerTest.php b/packages/realtime-compiler/tests/RealtimeCompilerTest.php index 45e78abd550..c40358ce39f 100644 --- a/packages/realtime-compiler/tests/RealtimeCompilerTest.php +++ b/packages/realtime-compiler/tests/RealtimeCompilerTest.php @@ -85,7 +85,8 @@ public function testHandlesRoutesPagesWithHtmlExtension() public function testHandlesRoutesStaticAssets() { - $this->mockRoute('media/app.css'); + $this->mockRoute('media/test.css'); + Filesystem::put('_media/test.css', 'test'); $kernel = new HttpKernel(); $response = $kernel->handle(new Request()); @@ -93,7 +94,25 @@ public function testHandlesRoutesStaticAssets() $this->assertInstanceOf(Response::class, $response); $this->assertEquals(200, $response->statusCode); $this->assertEquals('OK', $response->statusMessage); - $this->assertEquals(file_get_contents(\Hyde\Hyde::path('_media/app.css')), $response->body); + $this->assertEquals('test', $response->body); + + Filesystem::unlink('_media/test.css'); + } + + public function testNormalizesMediaPath() + { + $this->mockRoute('media/test.css'); + Filesystem::put('_media/test.css', 'test'); + + $kernel = new HttpKernel(); + $response = $kernel->handle(new Request()); + + $this->assertInstanceOf(Response::class, $response); + $this->assertEquals(200, $response->statusCode); + $this->assertEquals('OK', $response->statusMessage); + $this->assertEquals('test', $response->body); + + Filesystem::unlink('_media/test.css'); } public function testThrowsRouteNotFoundExceptionForMissingRoute()