diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateBuildManifest.php b/packages/framework/src/Actions/PostBuildTasks/GenerateBuildManifest.php index eb42a1a2191..0351f74ab8a 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateBuildManifest.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateBuildManifest.php @@ -7,8 +7,13 @@ use Illuminate\Console\OutputStyle; use Illuminate\Support\Collection; +/** + * @see \Hyde\Framework\Testing\Unit\GenerateBuildManifestTest + */ class GenerateBuildManifest extends AbstractBuildTask { + public static string $description = 'Generating build manifest'; + public function __construct(?OutputStyle $output = null) { parent::__construct($output); @@ -23,8 +28,8 @@ public function run(): void foreach (Hyde::pages() as $page) { $manifest->push([ 'page' => $page->getSourcePath(), - 'source_hash' => md5(Hyde::path($page->getSourcePath())), - 'output_hash' => md5(Hyde::path($page->getOutputPath())), + 'source_hash' => md5_file(Hyde::path($page->getSourcePath())), + 'output_hash' => $this->hashOutputPath(Hyde::getSiteOutputPath($page->getOutputPath())), ]); } @@ -32,4 +37,9 @@ public function run(): void 'storage/framework/cache/build-manifest.json') ), $manifest->toJson()); } + + protected function hashOutputPath(string $path): ?string + { + return file_exists($path) ? md5_file($path) : null; + } } diff --git a/packages/framework/tests/Unit/GenerateBuildManifestTest.php b/packages/framework/tests/Unit/GenerateBuildManifestTest.php new file mode 100644 index 00000000000..ed7dfdc9e72 --- /dev/null +++ b/packages/framework/tests/Unit/GenerateBuildManifestTest.php @@ -0,0 +1,32 @@ +run(); + + $this->assertFileExists(Hyde::path('storage/framework/cache/build-manifest.json')); + + $manifest = json_decode(file_get_contents(Hyde::path('storage/framework/cache/build-manifest.json')), true); + + $this->assertIsArray($manifest); + $this->assertCount(2, $manifest); + + $this->assertArrayHasKey('page', $manifest[0]); + $this->assertArrayHasKey('source_hash', $manifest[0]); + $this->assertArrayHasKey('output_hash', $manifest[0]); + + $this->assertStringContainsString('_pages/404.blade.php', $manifest[0]['page']); + $this->assertStringContainsString('_pages/index.blade.php', $manifest[1]['page']); + } +}