Skip to content

Commit

Permalink
fix: return only boolean when useGlobalLibvips is used by gyp
Browse files Browse the repository at this point in the history
The debug log is compromising the gyp variable use_global_libvips and
therefore breaks compilation when the detection adds additional output.
  • Loading branch information
project0 committed May 23, 2024
1 parent cc96c21 commit 9cbcf8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
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, quiet) => {
if (!quiet) {
log(`Detected ${reason}, skipping search for globally-installed libvips`);
}
return status;
};

const useGlobalLibvips = () => {
const useGlobalLibvips = (quiet = false) => {
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS');
return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS', quiet);
}
if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) {
return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS');
return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS', quiet);
}
/* istanbul ignore next */
if (isRosetta()) {
return skipSearch(false, 'Rosetta');
return skipSearch(false, 'Rosetta', quiet);
}
const globalVipsVersion = globalLibvipsVersion();
return !!globalVipsVersion && /* istanbul ignore next */
Expand Down
2 changes: 1 addition & 1 deletion src/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
'conditions': [
['OS != "win"', {
'pkg_config_path': '<!(node -p "require(\'../lib/libvips\').pkgConfigPath()")',
'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips()).toString()")'
'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips(true)).toString()")'
}, {
'pkg_config_path': '',
'use_global_libvips': ''
Expand Down
3 changes: 3 additions & 0 deletions test/unit/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ describe('libvips binaries', function () {
const useGlobalLibvips = libvips.useGlobalLibvips();
assert.strictEqual(true, useGlobalLibvips);

const useGlobalLibvipsQuiet = libvips.useGlobalLibvips(true);
assert.strictEqual(true, useGlobalLibvipsQuiet);

delete process.env.SHARP_FORCE_GLOBAL_LIBVIPS;
});
});
Expand Down

0 comments on commit 9cbcf8d

Please sign in to comment.