Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
17 changes: 2 additions & 15 deletions packages/realtime-compiler/src/Actions/AssetFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Hyde\RealtimeCompiler\Actions;

use Illuminate\Support\Str;

/**
* Locate a static file to proxy.
*/
Expand All @@ -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;
}
}
23 changes: 21 additions & 2 deletions packages/realtime-compiler/tests/RealtimeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,34 @@ 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());

$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()
Expand Down