Skip to content

Commit ea44b58

Browse files
sgtcoolguymprobst
authored andcommitted
fix: fall back to darwin_x64 if available on darwin_arm64
1 parent 8692057 commit ea44b58

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Diff for: index.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,29 @@ function main() {
168168
*/
169169
function getNativeBinary() {
170170
let nativeBinary;
171-
172-
if (os.platform() === 'win32') {
171+
const platform = os.platform();
172+
const arch = os.arch();
173+
if (platform === 'win32') {
173174
nativeBinary = `${__dirname}/bin/win32/clang-format.exe`;
174175
} else {
175-
nativeBinary = `${__dirname}/bin/${os.platform()}_${os.arch()}/clang-format`;
176+
nativeBinary = `${__dirname}/bin/${platform}_${arch}/clang-format`;
176177
}
177178

178-
if (!fs.existsSync(nativeBinary)) {
179-
const message = 'This module doesn\'t bundle the clang-format executable for your platform. ' +
180-
`(${os.platform()}_${os.arch()})\n` +
181-
'Consider installing it with your native package manager instead.\n';
182-
throw new Error(message);
179+
if (fs.existsSync(nativeBinary)) {
180+
return nativeBinary;
183181
}
184182

185-
return nativeBinary;
183+
// Let arm64 macOS fall back to x64
184+
if (platform === 'darwin' && arch === 'arm64') {
185+
nativeBinary = `${__dirname}/bin/darwin_x64/clang-format`;
186+
if (fs.existsSync(nativeBinary)) {
187+
return nativeBinary;
188+
}
189+
}
190+
const message = 'This module doesn\'t bundle the clang-format executable for your platform. ' +
191+
`(${platform}_${arch})\n` +
192+
'Consider installing it with your native package manager instead.\n';
193+
throw new Error(message);
186194
}
187195

188196
/**

0 commit comments

Comments
 (0)