Skip to content

Commit a9132a5

Browse files
chore(deps): update sharp (#35539)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Lennart <[email protected]>
1 parent bc80c23 commit a9132a5

File tree

18 files changed

+240
-152
lines changed

18 files changed

+240
-152
lines changed

packages/gatsby-plugin-manifest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"gatsby-core-utils": "^3.21.0-next.2",
1212
"gatsby-plugin-utils": "^3.15.0-next.2",
1313
"semver": "^7.3.7",
14-
"sharp": "^0.30.3"
14+
"sharp": "^0.30.7"
1515
},
1616
"devDependencies": {
1717
"@babel/cli": "^7.15.4",

packages/gatsby-plugin-sharp/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ of PNGs then it can significantly reduce build times.
2020

2121
## Install
2222

23-
`npm install gatsby-plugin-sharp`
23+
```shell
24+
npm install gatsby-plugin-sharp
25+
```
2426

2527
## How to use
2628

@@ -32,8 +34,8 @@ plugins: [
3234
options: {
3335
// Defaults used for gatsbyImageData and StaticImage
3436
defaults: {},
35-
// Set to false to allow builds to continue on image errors
36-
failOnError: true,
37+
// Set to none to allow builds to continue on image errors
38+
failOn: `none`,
3739
// deprecated options and their defaults:
3840
base64Width: 20,
3941
forceBase64Format: ``, // valid formats: png,jpg,webp
@@ -50,7 +52,7 @@ plugins: [
5052
- `defaults`: default values used for `gatsbyImageData` and `StaticImage` from [gatsby-plugin-image](https://www.gatsbyjs.com/plugins/gatsby-plugin-image).
5153
Available options are: `formats`,`placeholder`,`quality`,`breakpoints`,`backgroundColor`,`tracedSVGOptions`,`blurredOptions`,`jpgOptions`,`pngOptions`,`webpOptions`,`avifOptions`.
5254
For details of these, see [the reference guide](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image).
53-
- `failOnError`: default = `true`. By default builds will fail if there is a corrupted image. Set to false to continue the build on error. The image will return `undefined`.
55+
- `failOn`: default = `warning`. By default builds will fail if there is a corrupted image. Set to `none` to continue the build on error. The image will return `undefined`. You can customize this option, see [`options.failOn`](https://sharp.pixelplumbing.com/api-constructor#parameters).
5456

5557
Other options are deprecated, and should only be used for the legacy `fixed` and `fluid` functions.
5658

packages/gatsby-plugin-sharp/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
"probe-image-size": "^7.2.3",
2424
"progress": "^2.0.3",
2525
"semver": "^7.3.7",
26-
"sharp": "^0.30.3",
26+
"sharp": "^0.30.7",
2727
"svgo": "1.3.2"
2828
},
2929
"devDependencies": {
3030
"@babel/cli": "^7.15.4",
3131
"@babel/core": "^7.15.5",
32-
"@types/sharp": "^0.30.0",
32+
"@types/sharp": "^0.30.5",
3333
"babel-preset-gatsby-package": "^2.21.0-next.0",
3434
"cross-env": "^7.0.3",
3535
"gatsby-plugin-image": "^2.21.0-next.2"

packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap

+21-21
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ exports[`gatsby-plugin-sharp fixed correctly infers the width when only the heig
8585
"pluginOptions": Object {
8686
"base64Width": 20,
8787
"defaultQuality": 50,
88-
"failOnError": true,
88+
"failOn": "warning",
8989
"forceBase64Format": "",
9090
"lazyImageGeneration": true,
9191
"stripMetadata": true,
@@ -142,7 +142,7 @@ exports[`gatsby-plugin-sharp fixed does not warn when the requested width is equ
142142
"pluginOptions": Object {
143143
"base64Width": 20,
144144
"defaultQuality": 50,
145-
"failOnError": true,
145+
"failOn": "warning",
146146
"forceBase64Format": "",
147147
"lazyImageGeneration": true,
148148
"stripMetadata": true,
@@ -185,7 +185,7 @@ exports[`gatsby-plugin-sharp fixed warns when the requested width is greater tha
185185
"pluginOptions": Object {
186186
"base64Width": 20,
187187
"defaultQuality": 50,
188-
"failOnError": true,
188+
"failOn": "warning",
189189
"forceBase64Format": "",
190190
"lazyImageGeneration": true,
191191
"stripMetadata": true,
@@ -256,7 +256,7 @@ exports[`gatsby-plugin-sharp fluid accepts srcSet breakpoints 1`] = `
256256
"pluginOptions": Object {
257257
"base64Width": 20,
258258
"defaultQuality": 50,
259-
"failOnError": true,
259+
"failOn": "warning",
260260
"forceBase64Format": "",
261261
"lazyImageGeneration": true,
262262
"stripMetadata": true,
@@ -299,7 +299,7 @@ exports[`gatsby-plugin-sharp fluid adds pathPrefix if defined 1`] = `
299299
"pluginOptions": Object {
300300
"base64Width": 20,
301301
"defaultQuality": 50,
302-
"failOnError": true,
302+
"failOn": "warning",
303303
"forceBase64Format": "",
304304
"lazyImageGeneration": true,
305305
"stripMetadata": true,
@@ -382,7 +382,7 @@ Array [
382382
"pluginOptions": Object {
383383
"base64Width": 20,
384384
"defaultQuality": 50,
385-
"failOnError": true,
385+
"failOn": "warning",
386386
"forceBase64Format": "",
387387
"lazyImageGeneration": true,
388388
"stripMetadata": true,
@@ -464,7 +464,7 @@ Array [
464464
"pluginOptions": Object {
465465
"base64Width": 20,
466466
"defaultQuality": 50,
467-
"failOnError": true,
467+
"failOn": "warning",
468468
"forceBase64Format": "",
469469
"lazyImageGeneration": true,
470470
"stripMetadata": true,
@@ -546,7 +546,7 @@ Array [
546546
"pluginOptions": Object {
547547
"base64Width": 20,
548548
"defaultQuality": 50,
549-
"failOnError": true,
549+
"failOn": "warning",
550550
"forceBase64Format": "",
551551
"lazyImageGeneration": true,
552552
"stripMetadata": true,
@@ -628,7 +628,7 @@ Array [
628628
"pluginOptions": Object {
629629
"base64Width": 20,
630630
"defaultQuality": 50,
631-
"failOnError": true,
631+
"failOn": "warning",
632632
"forceBase64Format": "",
633633
"lazyImageGeneration": true,
634634
"stripMetadata": true,
@@ -688,7 +688,7 @@ Array [
688688
"pluginOptions": Object {
689689
"base64Width": 20,
690690
"defaultQuality": 50,
691-
"failOnError": true,
691+
"failOn": "warning",
692692
"forceBase64Format": "",
693693
"lazyImageGeneration": true,
694694
"stripMetadata": true,
@@ -752,7 +752,7 @@ Array [
752752
"pluginOptions": Object {
753753
"base64Width": 20,
754754
"defaultQuality": 50,
755-
"failOnError": true,
755+
"failOn": "warning",
756756
"forceBase64Format": "",
757757
"lazyImageGeneration": true,
758758
"stripMetadata": true,
@@ -816,7 +816,7 @@ Array [
816816
"pluginOptions": Object {
817817
"base64Width": 20,
818818
"defaultQuality": 50,
819-
"failOnError": true,
819+
"failOn": "warning",
820820
"forceBase64Format": "",
821821
"lazyImageGeneration": true,
822822
"stripMetadata": true,
@@ -880,7 +880,7 @@ Array [
880880
"pluginOptions": Object {
881881
"base64Width": 20,
882882
"defaultQuality": 50,
883-
"failOnError": true,
883+
"failOn": "warning",
884884
"forceBase64Format": "",
885885
"lazyImageGeneration": true,
886886
"stripMetadata": true,
@@ -916,7 +916,7 @@ exports[`gatsby-plugin-sharp fluid does not change the arguments object it is gi
916916
"pluginOptions": Object {
917917
"base64Width": 20,
918918
"defaultQuality": 50,
919-
"failOnError": true,
919+
"failOn": "warning",
920920
"forceBase64Format": "",
921921
"lazyImageGeneration": true,
922922
"stripMetadata": true,
@@ -987,7 +987,7 @@ exports[`gatsby-plugin-sharp fluid ensure maxWidth is in srcSet breakpoints 1`]
987987
"pluginOptions": Object {
988988
"base64Width": 20,
989989
"defaultQuality": 50,
990-
"failOnError": true,
990+
"failOn": "warning",
991991
"forceBase64Format": "",
992992
"lazyImageGeneration": true,
993993
"stripMetadata": true,
@@ -1082,7 +1082,7 @@ exports[`gatsby-plugin-sharp fluid infers the maxWidth if only maxHeight is give
10821082
"pluginOptions": Object {
10831083
"base64Width": 20,
10841084
"defaultQuality": 50,
1085-
"failOnError": true,
1085+
"failOn": "warning",
10861086
"forceBase64Format": "",
10871087
"lazyImageGeneration": true,
10881088
"stripMetadata": true,
@@ -1125,7 +1125,7 @@ exports[`gatsby-plugin-sharp fluid keeps original file name 1`] = `
11251125
"pluginOptions": Object {
11261126
"base64Width": 20,
11271127
"defaultQuality": 50,
1128-
"failOnError": true,
1128+
"failOn": "warning",
11291129
"forceBase64Format": "",
11301130
"lazyImageGeneration": true,
11311131
"stripMetadata": true,
@@ -1189,7 +1189,7 @@ exports[`gatsby-plugin-sharp fluid prevents duplicate breakpoints 1`] = `
11891189
"pluginOptions": Object {
11901190
"base64Width": 20,
11911191
"defaultQuality": 50,
1192-
"failOnError": true,
1192+
"failOn": "warning",
11931193
"forceBase64Format": "",
11941194
"lazyImageGeneration": true,
11951195
"stripMetadata": true,
@@ -1260,7 +1260,7 @@ exports[`gatsby-plugin-sharp fluid reject any breakpoints larger than the origin
12601260
"pluginOptions": Object {
12611261
"base64Width": 20,
12621262
"defaultQuality": 50,
1263-
"failOnError": true,
1263+
"failOn": "warning",
12641264
"forceBase64Format": "",
12651265
"lazyImageGeneration": true,
12661266
"stripMetadata": true,
@@ -1318,7 +1318,7 @@ exports[`gatsby-plugin-sharp queueImageResizing file name works with spaces & sp
13181318
"pluginOptions": Object {
13191319
"base64Width": 20,
13201320
"defaultQuality": 50,
1321-
"failOnError": true,
1321+
"failOn": "warning",
13221322
"forceBase64Format": "",
13231323
"lazyImageGeneration": true,
13241324
"stripMetadata": true,
@@ -1361,7 +1361,7 @@ exports[`gatsby-plugin-sharp queueImageResizing should round height when auto-ca
13611361
"pluginOptions": Object {
13621362
"base64Width": 20,
13631363
"defaultQuality": 50,
1364-
"failOnError": true,
1364+
"failOn": "warning",
13651365
"forceBase64Format": "",
13661366
"lazyImageGeneration": true,
13671367
"stripMetadata": true,

packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { testPluginOptionsSchema } from "gatsby-plugin-utils"
22
import { pluginOptionsSchema } from "../../gatsby-node"
3-
import { doMergeDefaults } from "../plugin-options"
3+
import { doMergeDefaults, PluginOptionsDefaults } from "../plugin-options"
44

5-
const defaults = {
5+
const defaults: PluginOptionsDefaults = {
66
formats: [`auto`, `webp`],
77
placeholder: `dominantColor`,
88
quality: 50,
99
breakpoints: [100, 200],
1010
backgroundColor: `rebeccapurple`,
1111
tracedSVGOptions: {},
12-
blurredOptions: { quality: 20 },
12+
blurredOptions: { width: 20 },
1313
jpgOptions: { quality: 20 },
1414
pngOptions: { quality: 20 },
1515
webpOptions: { quality: 20 },
@@ -74,7 +74,7 @@ describe(`plugin defaults`, () => {
7474
},
7575
"backgroundColor": "rebeccapurple",
7676
"blurredOptions": Object {
77-
"quality": 20,
77+
"width": 20,
7878
},
7979
"breakpoints": Array [
8080
100,

packages/gatsby-plugin-sharp/src/gatsby-node.js

+25
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ exports.pluginOptionsSchema = ({ Joi }) =>
231231
),
232232
stripMetadata: Joi.boolean().default(true),
233233
defaultQuality: Joi.number().default(50),
234+
// TODO(v5): Remove deprecated failOnError option
234235
failOnError: Joi.boolean().default(true),
236+
failOn: Joi.any()
237+
.valid(`none`, `truncated`, `error`, `warning`)
238+
.default(`warning`)
239+
.description(`Level of sensitivity to invalid images`),
235240
defaults: Joi.object({
236241
formats: Joi.array().items(
237242
Joi.string().valid(`auto`, `png`, `jpg`, `webp`, `avif`)
@@ -255,4 +260,24 @@ exports.pluginOptionsSchema = ({ Joi }) =>
255260
}).description(
256261
`Default options used by gatsby-plugin-image. \nSee https://gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/`
257262
),
263+
}).custom(value => {
264+
const shouldNotFailOnError = !value.failOnError
265+
266+
if (shouldNotFailOnError) {
267+
// show this warning only once in main process
268+
if (!process.env.GATSBY_WORKER_ID) {
269+
console.warn(
270+
`[gatsby-plugin-sharp]: The "failOnError" option is deprecated. Please use "failOn" instead.`
271+
)
272+
}
273+
274+
return {
275+
...value,
276+
failOn: `none`,
277+
}
278+
}
279+
280+
return {
281+
...value,
282+
}
258283
})

packages/gatsby-plugin-sharp/src/image-data.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function getImageMetadata(
6262
}
6363

6464
try {
65-
const pipeline = sharp({ failOnError: !!getPluginOptions().failOnError })
65+
const pipeline = sharp({ failOn: getPluginOptions().failOn })
6666

6767
fs.createReadStream(file.absolutePath).pipe(pipeline)
6868

packages/gatsby-plugin-sharp/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ async function generateBase64({ file, args = {}, reporter }) {
262262
})
263263
let pipeline
264264
try {
265-
pipeline = !options.failOnError ? sharp({ failOnError: false }) : sharp()
265+
pipeline = sharp({ failOn: pluginOptions.failOn })
266266

267267
if (!options.rotate) {
268268
pipeline.rotate()

0 commit comments

Comments
 (0)