Improve experience for those using Apple M1 devices #2460

- For Rosetta x64, prevent use of global ARM64 libvips
- For ARM64, improve error message when global libvips not found
This commit is contained in:
Lovell Fuller
2021-02-22 13:49:28 +00:00
parent cc37b59309
commit 4264c0577e
3 changed files with 23 additions and 2 deletions

View File

@@ -37,6 +37,15 @@ const cachePath = function () {
return libvipsCachePath;
};
const isRosetta = function () {
/* istanbul ignore next */
if (process.platform === 'darwin' && process.arch === 'x64') {
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
return (translated || '').trim() === 'sysctl.proc_translated: 1';
}
return false;
};
const globalLibvipsVersion = function () {
if (process.platform !== 'win32') {
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout;
@@ -82,7 +91,10 @@ const useGlobalLibvips = function () {
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
return false;
}
/* istanbul ignore next */
if (isRosetta()) {
return false;
}
const globalVipsVersion = globalLibvipsVersion();
return !!globalVipsVersion && /* istanbul ignore next */
semver.gte(globalVipsVersion, minimumLibvipsVersion);