From 84d4e3cf8fce751485637d28d3873af4cfdd4501 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 30 Apr 2021 20:42:46 +0100 Subject: [PATCH] Require specific semver functions, aids tree-shaking --- install/libvips.js | 9 +++++---- lib/libvips.js | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/install/libvips.js b/install/libvips.js index 2dd86a72..a2d1b5e5 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -7,7 +7,8 @@ const stream = require('stream'); const zlib = require('zlib'); const detectLibc = require('detect-libc'); -const semver = require('semver'); +const semverLessThan = require('semver/functions/lt'); +const semverSatisfies = require('semver/functions/satisfies'); const simpleGet = require('simple-get'); const tarFs = require('tar-fs'); @@ -96,18 +97,18 @@ try { throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`); } if (detectLibc.family === detectLibc.GLIBC && detectLibc.version) { - if (semver.lt(`${detectLibc.version}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { + if (semverLessThan(`${detectLibc.version}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) { throw new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`); } } if (detectLibc.family === detectLibc.MUSL && detectLibc.version) { - if (semver.lt(detectLibc.version, '1.1.24')) { + if (semverLessThan(detectLibc.version, '1.1.24')) { throw new Error(`Use with musl ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`); } } const supportedNodeVersion = process.env.npm_package_engines_node || require('../package.json').engines.node; - if (!semver.satisfies(process.versions.node, supportedNodeVersion)) { + if (!semverSatisfies(process.versions.node, supportedNodeVersion)) { throw new Error(`Expected Node.js version ${supportedNodeVersion} but found ${process.versions.node}`); } diff --git a/lib/libvips.js b/lib/libvips.js index 8a6dac2d..4b007ba4 100644 --- a/lib/libvips.js +++ b/lib/libvips.js @@ -4,13 +4,15 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const spawnSync = require('child_process').spawnSync; -const semver = require('semver'); +const semverCoerce = require('semver/functions/coerce'); +const semverGreaterThanOrEqualTo = require('semver/functions/gte'); + const platform = require('./platform'); const env = process.env; const minimumLibvipsVersionLabelled = env.npm_package_config_libvips || /* istanbul ignore next */ require('../package.json').config.libvips; -const minimumLibvipsVersion = semver.coerce(minimumLibvipsVersionLabelled).version; +const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version; const spawnSyncOptions = { encoding: 'utf8', @@ -105,7 +107,7 @@ const useGlobalLibvips = function () { } const globalVipsVersion = globalLibvipsVersion(); return !!globalVipsVersion && /* istanbul ignore next */ - semver.gte(globalVipsVersion, minimumLibvipsVersion); + semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion); }; module.exports = {