Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for configuring 'failOnError' for Sharp engine #5

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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