Ensure SHARP_FORCE_GLOBAL_LIBVIPS option works correctly #4111

Allows the install/check script to inject a logger function,
keeping its use within binding.gyp free of additional output.

Co-authored-by: Lovell Fuller <github@lovell.info>
This commit is contained in:
Richard Hillmann 2024-05-22 11:09:46 +02:00 committed by Lovell Fuller
parent cc96c21e42
commit 56fae3eda1
5 changed files with 27 additions and 7 deletions

View File

@ -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`.

View File

@ -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

View File

@ -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');

View File

@ -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 */

View File

@ -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;
});
});