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

feat(gatsby-plugin-sharp): added option to allow sharp process to continue with errors #27345

Merged
merged 5 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports[`gatsby-plugin-sharp fixed correctly infers the width when only the heig
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -139,6 +140,7 @@ exports[`gatsby-plugin-sharp fixed does not warn when the requested width is equ
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -194,6 +196,7 @@ exports[`gatsby-plugin-sharp fixed should give the same result with createJob as
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -235,6 +238,7 @@ exports[`gatsby-plugin-sharp fixed warns when the requested width is greater tha
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -304,6 +308,7 @@ exports[`gatsby-plugin-sharp fluid accepts srcSet breakpoints 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -345,6 +350,7 @@ exports[`gatsby-plugin-sharp fluid adds pathPrefix if defined 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -426,6 +432,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -506,6 +513,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -586,6 +594,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -666,6 +675,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -724,6 +734,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -786,6 +797,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -848,6 +860,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -910,6 +923,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -944,6 +958,7 @@ exports[`gatsby-plugin-sharp fluid does not change the arguments object it is gi
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1013,6 +1028,7 @@ exports[`gatsby-plugin-sharp fluid ensure maxWidth is in srcSet breakpoints 1`]
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1123,6 +1139,7 @@ exports[`gatsby-plugin-sharp fluid infers the maxWidth if only maxHeight is give
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1164,6 +1181,7 @@ exports[`gatsby-plugin-sharp fluid keeps original file name 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1226,6 +1244,7 @@ exports[`gatsby-plugin-sharp fluid prevents duplicate breakpoints 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1295,6 +1314,7 @@ exports[`gatsby-plugin-sharp fluid reject any breakpoints larger than the origin
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1336,6 +1356,7 @@ exports[`gatsby-plugin-sharp fluid should give the same result with createJob as
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1392,6 +1413,7 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJob file name works w
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1435,6 +1457,7 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJob should round heig
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1478,6 +1501,7 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJobV2 file name works
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1519,6 +1543,7 @@ exports[`gatsby-plugin-sharp queueImageResizing with createJobV2 should round he
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sharp/src/plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const pluginDefaults = {
stripMetadata: true,
lazyImageGeneration: true,
defaultQuality: 50,
failOnError: true, // matches default of the sharp api constructor (https://sharp.pixelplumbing.com/api-constructor)
}

const generalArgs = {
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-sharp/src/process-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ sharp.concurrency(cpuCoreCount())
exports.processFile = (file, transforms, options = {}) => {
let pipeline
try {
pipeline = sharp(file)
pipeline = !options.failOnError
? sharp(file, { failOnError: false })
: sharp(file)
Comment on lines +64 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipeline = sharp(file, { failOnError: options.failOnError })

why not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

pipeline = sharp(file, { failOnError: !!options.failOnError })


// Keep Metadata
if (!options.stripMetadata) {
Expand Down