diff --git a/src/TailwindBinary.php b/src/TailwindBinary.php index 6cd58dc..beb75f7 100644 --- a/src/TailwindBinary.php +++ b/src/TailwindBinary.php @@ -21,7 +21,7 @@ */ class TailwindBinary { - private const VERSION = 'v3.3.5'; + private const DEFAULT_VERSION = 'v3.3.5'; private HttpClientInterface $httpClient; public function __construct( @@ -53,7 +53,7 @@ public function createProcess(array $arguments = []): Process private function downloadExecutable(): void { - $url = sprintf('https://github.com/tailwindlabs/tailwindcss/releases/download/%s/%s', self::VERSION, self::getBinaryName()); + $url = sprintf('https://github.com/tailwindlabs/tailwindcss/releases/download/%s/%s', $this->getLatestVersion(), self::getBinaryName()); $this->output?->note(sprintf('Downloading TailwindCSS binary from %s', $url)); @@ -89,6 +89,17 @@ private function downloadExecutable(): void chmod($targetPath, 0777); } + private function getLatestVersion(): string + { + try { + $response = $this->httpClient->request('GET', 'https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest'); + + return $response->toArray()['name'] ?? self::DEFAULT_VERSION; + } catch (\Throwable) { + return self::DEFAULT_VERSION; + } + } + /** * @internal */ diff --git a/tests/TailwindBinaryTest.php b/tests/TailwindBinaryTest.php index d28af54..3d38500 100644 --- a/tests/TailwindBinaryTest.php +++ b/tests/TailwindBinaryTest.php @@ -27,6 +27,7 @@ public function testBinaryIsDownloadedAndProcessCreated() $fs->mkdir($binaryDownloadDir); $client = new MockHttpClient([ + new MockResponse('{}'), new MockResponse('fake binary contents'), ]);