Ensure versions prop detects use of global libvips

This commit is contained in:
Lovell Fuller
2023-10-10 09:18:25 +01:00
parent 09460d7af4
commit 7e25dd7be1
5 changed files with 33 additions and 12 deletions

View File

@@ -10,6 +10,9 @@ const is = require('./is');
const { runtimePlatformArch } = require('./libvips');
const sharp = require('./sharp');
const runtimePlatform = runtimePlatformArch();
const libvipsVersion = sharp.libvipsVersion();
/**
* An Object containing nested boolean values representing the available input and output formats/methods.
* @member
@@ -44,20 +47,25 @@ const interpolators = {
};
/**
* An Object containing the version numbers of sharp, libvips and its dependencies.
* An Object containing the version numbers of sharp, libvips
* and (when using prebuilt binaries) its dependencies.
*
* @member
* @example
* console.log(sharp.versions);
*/
let versions = {
vips: sharp.libvipsVersion()
vips: libvipsVersion.semver
};
try {
versions = require(`@sharpen/sharp-${runtimePlatformArch()}/versions`);
} catch (_) {
/* istanbul ignore next */
if (!libvipsVersion.isGlobal) {
try {
versions = require(`@sharpen/sharp-libvips-${runtimePlatformArch()}/versions`);
} catch (_) {}
versions = require(`@sharpen/sharp-${runtimePlatform}/versions`);
} catch (_) {
try {
versions = require(`@sharpen/sharp-libvips-${runtimePlatform}/versions`);
} catch (_) {}
}
}
versions.sharp = require('../package.json').version;