From f67e55b9f8df3e949bb52913a700f9fb44cc522a Mon Sep 17 00:00:00 2001 From: Priyank Parashar Date: Tue, 21 Sep 2021 23:54:35 +0400 Subject: [PATCH] Added support for configuring 'failOnError' for Sharp engine --- src/Impro.js | 1 + src/engines/sharp.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Impro.js b/src/Impro.js index 1869638..2a089f3 100644 --- a/src/Impro.js +++ b/src/Impro.js @@ -30,6 +30,7 @@ module.exports = class Impro { 'maxOutputPixels', 'sharpCache', 'svgAssetPath', + 'sharpFailOnError', ]; this.restrictedOptions = ['svgAssetPath']; diff --git a/src/engines/sharp.js b/src/engines/sharp.js index b3c8f86..fc64818 100644 --- a/src/engines/sharp.js +++ b/src/engines/sharp.js @@ -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); @@ -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;