From 4d7957a0432165fdb4baf93b1cc159801535a04f Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 23 Apr 2023 11:37:43 +0100 Subject: [PATCH] Install: coerce libc version to semver #3641 --- docs/changelog.md | 3 +++ install/libvips.js | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 1bf8733b3..6f274a93a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -29,6 +29,9 @@ Requires libvips v8.14.2 * Ensure `trim` operation works with CMYK images (regression in 0.31.0). [#3636](https://github.com/lovell/sharp/issues/3636) +* Install: coerce libc version to semver. + [#3641](https://github.com/lovell/sharp/issues/3641) + ### v0.32.0 - 24th March 2023 * Default to using sequential rather than random access read where possible. diff --git a/install/libvips.js b/install/libvips.js index 0e40b274a..493c79672 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -11,6 +11,7 @@ const zlib = require('zlib'); const { createHash } = require('crypto'); const detectLibc = require('detect-libc'); +const semverCoerce = require('semver/functions/coerce'); const semverLessThan = require('semver/functions/lt'); const semverSatisfies = require('semver/functions/satisfies'); const simpleGet = require('simple-get'); @@ -140,16 +141,16 @@ try { } // Linux libc version check const libcFamily = detectLibc.familySync(); - const libcVersion = detectLibc.versionSync(); + const libcVersionRaw = detectLibc.versionSync(); + const libcVersion = semverCoerce(libcVersionRaw).version; if (libcFamily === detectLibc.GLIBC && libcVersion && minimumGlibcVersionByArch[arch]) { - const libcVersionWithoutPatch = libcVersion.split('.').slice(0, 2).join('.'); - if (semverLessThan(`${libcVersionWithoutPatch}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { - handleError(new Error(`Use with glibc ${libcVersion} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); + if (semverLessThan(libcVersion, semverCoerce(minimumGlibcVersionByArch[arch]).version)) { + handleError(new Error(`Use with glibc ${libcVersionRaw} 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}`)); + handleError(new Error(`Use with musl ${libcVersionRaw} requires manual installation of libvips >= ${minimumLibvipsVersion}`)); } } // Node.js minimum version check