Skip to content

Commit

Permalink
Update libvips.js
Browse files Browse the repository at this point in the history
Get the real architecture of M1 Mac regardless of Rosetta to deal with HEIC image, see lovell#3239
  • Loading branch information
Xheldon committed Jan 4, 2023
1 parent 844deaf commit 6af5f54
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/libvips.js
Expand Up @@ -56,9 +56,17 @@ const log = function (item) {

const isRosetta = function () {
/* istanbul ignore next */
log(`Installation info: arch is ${process.arch} & cputype is ${spawnSync('sysctl hw.cputype', spawnSyncOptions).stdout}`);
if (process.platform === 'darwin' && process.arch === 'x64') {
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
return (translated || '').trim() === 'sysctl.proc_translated: 1';
// here should return true if the machine is Apple M1 chip while node version is darwin x64
let result = (translated || '').trim() === 'sysctl.proc_translated: 1';
if (result) {
// Determine if it is M1 chip even the node is x64
// see: https://stackoverflow.com/questions/65346260/get-real-architecture-of-m1-mac-regardless-of-rosetta
const cputype = spawnSync('sysctl hw.cputype', spawnSyncOptions).stdout
return (cputype || '').trim() !== 'hw.cputype: 16777228';
}
}
return false;
};
Expand Down

0 comments on commit 6af5f54

Please sign in to comment.