diff --git a/docs/changelog.md b/docs/changelog.md index 3cdd9384..e4ff7dc9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,12 @@ Requires libvips v8.15.2 +### v0.33.5 - TBD + +* Ensure option to force use of a globally-installed libvips works correctly. + [#4111](https://github.com/lovell/sharp/pull/4111) + [@project0](https://github.com/project0) + ### v0.33.4 - 16th May 2024 * Remove experimental status from `pipelineColourspace`. diff --git a/docs/humans.txt b/docs/humans.txt index 42f0323d..20a9fa8e 100644 --- a/docs/humans.txt +++ b/docs/humans.txt @@ -293,3 +293,6 @@ GitHub: https://github.com/mertalev Name: Adriaan Meuris GitHub: https://github.com/adriaanmeuris + +Name: Richard Hillmann +GitHub: https://github.com/project0 diff --git a/install/check.js b/install/check.js index f140cc5e..51bb3932 100644 --- a/install/check.js +++ b/install/check.js @@ -30,7 +30,7 @@ try { } }; - if (useGlobalLibvips()) { + if (useGlobalLibvips(log)) { buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`); } else if (process.env.npm_config_build_from_source) { buildFromSource('Detected --build-from-source flag'); diff --git a/lib/libvips.js b/lib/libvips.js index cf2cc3ee..d509650d 100644 --- a/lib/libvips.js +++ b/lib/libvips.js @@ -162,21 +162,23 @@ const pkgConfigPath = () => { } }; -const skipSearch = (status, reason) => { - log(`Detected ${reason}, skipping search for globally-installed libvips`); +const skipSearch = (status, reason, logger) => { + if (logger) { + logger(`Detected ${reason}, skipping search for globally-installed libvips`); + } return status; }; -const useGlobalLibvips = () => { +const useGlobalLibvips = (logger) => { if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) { - return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS'); + return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS', logger); } if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) { - return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS'); + return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS', logger); } /* istanbul ignore next */ if (isRosetta()) { - return skipSearch(false, 'Rosetta'); + return skipSearch(false, 'Rosetta', logger); } const globalVipsVersion = globalLibvipsVersion(); return !!globalVipsVersion && /* istanbul ignore next */ diff --git a/test/unit/libvips.js b/test/unit/libvips.js index 4cbc3c9d..2d763fbd 100644 --- a/test/unit/libvips.js +++ b/test/unit/libvips.js @@ -72,6 +72,15 @@ describe('libvips binaries', function () { const useGlobalLibvips = libvips.useGlobalLibvips(); assert.strictEqual(true, useGlobalLibvips); + let logged = false; + const logger = function (message) { + assert.strictEqual(message, 'Detected SHARP_FORCE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips'); + logged = true; + }; + const useGlobalLibvipsWithLogger = libvips.useGlobalLibvips(logger); + assert.strictEqual(true, useGlobalLibvipsWithLogger); + assert.strictEqual(true, logged); + delete process.env.SHARP_FORCE_GLOBAL_LIBVIPS; }); });