Skip to content

Commit

Permalink
Ensure SHARP_FORCE_GLOBAL_LIBVIPS option works correctly #4111
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
project0 and lovell committed May 24, 2024
1 parent cc96c21 commit 56fae3e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions docs/humans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion install/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
14 changes: 8 additions & 6 deletions lib/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 9 additions & 0 deletions test/unit/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
Expand Down

0 comments on commit 56fae3e

Please sign in to comment.