From 884947a0697b02bea3ef8e6b2c23b147ebba17a7 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 19 Jan 2022 11:27:24 +0000 Subject: [PATCH] Upgrade to modern detect-libc --- install/libvips.js | 14 ++++++++------ lib/platform.js | 2 +- lib/utility.js | 2 +- package.json | 2 +- test/unit/beforeEach.js | 5 +++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/install/libvips.js b/install/libvips.js index f5c3bc5a..62176eb6 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -132,14 +132,16 @@ try { throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`); } // Linux libc version check - if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && minimumGlibcVersionByArch[arch]) { - if (semverLessThan(`${detectLibc.version}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { - handleError(new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); + const libcFamily = detectLibc.familySync(); + const libcVersion = detectLibc.versionSync(); + if (libcFamily === detectLibc.GLIBC && libcVersion && minimumGlibcVersionByArch[arch]) { + if (semverLessThan(`${libcVersion}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { + handleError(new Error(`Use with glibc ${libcVersion} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); } } - if (detectLibc.family === detectLibc.MUSL && detectLibc.version) { - if (semverLessThan(detectLibc.version, '1.1.24')) { - handleError(new Error(`Use with musl ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); + if (libcFamily === detectLibc.MUSL && libcVersion) { + if (semverLessThan(libcVersion, '1.1.24')) { + handleError(new Error(`Use with musl ${libcVersion} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); } } // Node.js minimum version check diff --git a/lib/platform.js b/lib/platform.js index 383e6b6a..185d7d77 100644 --- a/lib/platform.js +++ b/lib/platform.js @@ -8,7 +8,7 @@ module.exports = function () { const arch = env.npm_config_arch || process.arch; const platform = env.npm_config_platform || process.platform; /* istanbul ignore next */ - const libc = (platform === 'linux' && detectLibc.isNonGlibcLinux) ? detectLibc.family : ''; + const libc = (platform === 'linux' && detectLibc.isNonGlibcLinuxSync()) ? detectLibc.familySync() : ''; const platformId = [`${platform}${libc}`]; diff --git a/lib/utility.js b/lib/utility.js index 74fe4ef7..5ed6ba65 100644 --- a/lib/utility.js +++ b/lib/utility.js @@ -128,7 +128,7 @@ function concurrency (concurrency) { return sharp.concurrency(is.integer(concurrency) ? concurrency : null); } /* istanbul ignore next */ -if (detectLibc.family === detectLibc.GLIBC && !sharp._isUsingJemalloc()) { +if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) { // Reduce default concurrency to 1 when using glibc memory allocator sharp.concurrency(1); } diff --git a/package.json b/package.json index eb96abe1..d702104a 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ ], "dependencies": { "color": "^4.2.0", - "detect-libc": "^1.0.3", + "detect-libc": "^2.0.0", "node-addon-api": "^4.2.0", "prebuild-install": "^7.0.0", "semver": "^7.3.5", diff --git a/test/unit/beforeEach.js b/test/unit/beforeEach.js index e2fe4fcb..f2b82e51 100644 --- a/test/unit/beforeEach.js +++ b/test/unit/beforeEach.js @@ -3,10 +3,11 @@ const detectLibc = require('detect-libc'); const sharp = require('../../'); -const usingCache = detectLibc.family !== detectLibc.MUSL; +const libcFamily = detectLibc.familySync(); +const usingCache = libcFamily !== detectLibc.MUSL; const usingSimd = !process.env.G_DEBUG; const concurrency = - detectLibc.family === detectLibc.MUSL || process.arch === 'arm' + libcFamily === detectLibc.MUSL || process.arch === 'arm' ? 1 : undefined;