Install: coerce libc version to semver #3641

This commit is contained in:
Lovell Fuller 2023-04-23 11:37:43 +01:00
parent bf9bb56367
commit 4d7957a043
2 changed files with 9 additions and 5 deletions

View File

@ -29,6 +29,9 @@ Requires libvips v8.14.2
* Ensure `trim` operation works with CMYK images (regression in 0.31.0). * Ensure `trim` operation works with CMYK images (regression in 0.31.0).
[#3636](https://github.com/lovell/sharp/issues/3636) [#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 ### v0.32.0 - 24th March 2023
* Default to using sequential rather than random access read where possible. * Default to using sequential rather than random access read where possible.

View File

@ -11,6 +11,7 @@ const zlib = require('zlib');
const { createHash } = require('crypto'); const { createHash } = require('crypto');
const detectLibc = require('detect-libc'); const detectLibc = require('detect-libc');
const semverCoerce = require('semver/functions/coerce');
const semverLessThan = require('semver/functions/lt'); const semverLessThan = require('semver/functions/lt');
const semverSatisfies = require('semver/functions/satisfies'); const semverSatisfies = require('semver/functions/satisfies');
const simpleGet = require('simple-get'); const simpleGet = require('simple-get');
@ -140,16 +141,16 @@ try {
} }
// Linux libc version check // Linux libc version check
const libcFamily = detectLibc.familySync(); const libcFamily = detectLibc.familySync();
const libcVersion = detectLibc.versionSync(); const libcVersionRaw = detectLibc.versionSync();
const libcVersion = semverCoerce(libcVersionRaw).version;
if (libcFamily === detectLibc.GLIBC && libcVersion && minimumGlibcVersionByArch[arch]) { if (libcFamily === detectLibc.GLIBC && libcVersion && minimumGlibcVersionByArch[arch]) {
const libcVersionWithoutPatch = libcVersion.split('.').slice(0, 2).join('.'); if (semverLessThan(libcVersion, semverCoerce(minimumGlibcVersionByArch[arch]).version)) {
if (semverLessThan(`${libcVersionWithoutPatch}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { handleError(new Error(`Use with glibc ${libcVersionRaw} requires manual installation of libvips >= ${minimumLibvipsVersion}`));
handleError(new Error(`Use with glibc ${libcVersion} requires manual installation of libvips >= ${minimumLibvipsVersion}`));
} }
} }
if (libcFamily === detectLibc.MUSL && libcVersion) { if (libcFamily === detectLibc.MUSL && libcVersion) {
if (semverLessThan(libcVersion, '1.1.24')) { 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 // Node.js minimum version check