@@ -95,7 +95,7 @@ private function getBinaryPath(): string
95
95
return $ this ->binaryPath ;
96
96
}
97
97
98
- $ this ->binaryPath = $ this ->binaryDownloadDir .'/ ' .$ this ->getVersion ().'/ ' .self ::getBinaryName ();
98
+ $ this ->binaryPath = $ this ->binaryDownloadDir .'/ ' .$ this ->getVersion ().'/ ' .self ::getBinaryName ($ this -> getRawVersion () );
99
99
100
100
if (!is_file ($ this ->binaryPath )) {
101
101
$ this ->downloadExecutable ();
@@ -106,15 +106,16 @@ private function getBinaryPath(): string
106
106
107
107
private function downloadExecutable (): void
108
108
{
109
- $ url = \sprintf ('https://github.com/tailwindlabs/tailwindcss/releases/download/%s/%s ' , $ this ->getVersion (), self ::getBinaryName ());
109
+ $ binaryName = self ::getBinaryName ($ this ->getRawVersion ());
110
+ $ url = \sprintf ('https://github.com/tailwindlabs/tailwindcss/releases/download/%s/%s ' , $ this ->getVersion (), $ binaryName );
110
111
111
112
$ this ->output ?->note(\sprintf ('Downloading TailwindCSS binary from %s ' , $ url ));
112
113
113
114
if (!is_dir ($ this ->binaryDownloadDir .'/ ' .$ this ->getVersion ())) {
114
115
mkdir ($ this ->binaryDownloadDir .'/ ' .$ this ->getVersion (), 0777 , true );
115
116
}
116
117
117
- $ targetPath = $ this ->binaryDownloadDir .'/ ' .$ this ->getVersion ().'/ ' .self :: getBinaryName () ;
118
+ $ targetPath = $ this ->binaryDownloadDir .'/ ' .$ this ->getVersion ().'/ ' .$ binaryName ;
118
119
$ progressBar = null ;
119
120
120
121
$ response = $ this ->httpClient ->request ('GET ' , $ url , [
@@ -145,47 +146,53 @@ private function downloadExecutable(): void
145
146
/**
146
147
* @internal
147
148
*/
148
- public static function getBinaryName (): string
149
+ public static function getBinaryName (string $ version ): string
149
150
{
150
151
$ os = strtolower (\PHP_OS );
151
152
$ machine = strtolower (php_uname ('m ' ));
152
153
153
- if (str_contains ($ os , 'darwin ' )) {
154
- if ('arm64 ' === $ machine ) {
155
- return 'tailwindcss-macos-arm64 ' ;
154
+ $ systems = [
155
+ 'linux ' => 'linux ' ,
156
+ 'darwin ' => 'macos ' ,
157
+ 'win ' => 'windows ' ,
158
+ ];
159
+
160
+ $ architectures = [
161
+ 'arm64 ' => 'arm64 ' ,
162
+ 'aarch64 ' => 'arm64 ' ,
163
+ 'armv7 ' => 'armv7 ' ,
164
+ 'x86_64 ' => 'x64 ' ,
165
+ 'amd64 ' => 'x64 ' ,
166
+ ];
167
+
168
+ // Detect the current system
169
+ $ system = null ;
170
+ foreach ($ systems as $ key => $ name ) {
171
+ if (str_contains ($ os , $ key )) {
172
+ $ system = $ name ;
173
+ break ;
156
174
}
157
- if ('x86_64 ' === $ machine ) {
158
- return 'tailwindcss-macos-x64 ' ;
159
- }
160
-
161
- throw new \Exception (\sprintf ('No matching machine found for Darwin platform (Machine: %s). ' , $ machine ));
162
175
}
163
176
164
- if (str_contains ($ os , 'linux ' )) {
165
- if ('arm64 ' === $ machine || 'aarch64 ' === $ machine ) {
166
- return 'tailwindcss-linux-arm64 ' ;
167
- }
168
- if ('armv7 ' === $ machine ) {
169
- return 'tailwindcss-linux-armv7 ' ;
170
- }
171
- if ('x86_64 ' === $ machine ) {
172
- return 'tailwindcss-linux-x64 ' ;
173
- }
177
+ // Detect the current architecture
178
+ $ arch = $ architectures [$ machine ] ?? null ;
174
179
175
- throw new \Exception (\sprintf ('No matching machine found for Linux platform (Machine: %s). ' , $ machine ));
180
+ if (!$ system || !$ arch ) {
181
+ throw new \Exception (\sprintf ('Unknown platform or architecture (OS: %s, Machine: %s). ' , $ os , $ machine ));
176
182
}
177
183
178
- if (str_contains ($ os , 'win ' )) {
179
- if ('arm64 ' === $ machine ) {
180
- return 'tailwindcss-windows-arm64.exe ' ;
181
- }
182
- if ('x86_64 ' === $ machine || 'amd64 ' === $ machine ) {
183
- return 'tailwindcss-windows-x64.exe ' ;
184
- }
184
+ // Detect MUSL only when version >= 4.0.0
185
+ if ('linux ' === $ system && version_compare ($ version , '4.0.0 ' , '>= ' )) {
186
+ $ libs = [
187
+ 'x64 ' => 'x86_64 ' ,
188
+ 'arm64 ' => 'aarch64 ' ,
189
+ ];
190
+
191
+ $ isMusl = isset ($ libs [$ arch ]) && file_exists ("/lib/ld-musl- {$ libs [$ arch ]}.so.1 " );
185
192
186
- throw new \ Exception ( \sprintf ( ' No matching machine found for Windows platform (Machine: %s). ' , $ machine ) );
193
+ return " tailwindcss- { $ system } - { $ arch }" .( $ isMusl ? ' -musl ' : '' );
187
194
}
188
195
189
- throw new \ Exception ( \sprintf ( ' Unknown platform or architecture (OS: %s, Machine: %s). ' , $ os , $ machine ) );
196
+ return " tailwindcss- { $ system } - { $ arch }" .(( ' windows ' === $ system ) ? ' .exe ' : '' );
190
197
}
191
198
}
0 commit comments