Skip to content

Commit

Permalink
Merge pull request #5 from paras20xx/master
Browse files Browse the repository at this point in the history
Added support for configuring 'failOnError' for Sharp engine
  • Loading branch information
papandreou authored Sep 21, 2021
2 parents ec467a0 + f67e55b commit b1932c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Impro.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = class Impro {
'maxOutputPixels',
'sharpCache',
'svgAssetPath',
'sharpFailOnError',
];

this.restrictedOptions = ['svgAssetPath'];
Expand Down
12 changes: 11 additions & 1 deletion src/engines/sharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ module.exports = {
options = options ? { ...options } : {};
const impro = pipeline.impro;
const cache = pipeline.options.sharpCache || options.cache;
const failOnError = (() => {
// TODO: Switch to using "Nullish coalescing operator (??)" once only Node.js 14 onwards are supported
if (typeof pipeline.options.sharpFailOnError !== 'undefined') {
return pipeline.options.sharpFailOnError;
} else if (typeof options.failOnError !== 'undefined') {
return options.failOnError;
} else {
return true;
}
})();
// Would make sense to move the _sharpCacheSet property to the type, but that breaks some test scenarios:
if (cache !== 'undefined' && !impro._sharpCacheSet) {
sharp.cache(cache);
Expand Down Expand Up @@ -280,7 +290,7 @@ module.exports = {
});

// ensure at least one option is present
options = { failOnError: true, ...options };
options = { failOnError, ...options };

if (pipeline.options.maxInputPixels) {
options.limitInputPixels = pipeline.options.maxInputPixels;
Expand Down

0 comments on commit b1932c0

Please sign in to comment.