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

chore(deps): update sharp #35539

Merged
merged 8 commits into from Aug 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-manifest/package.json
Expand Up @@ -11,7 +11,7 @@
"gatsby-core-utils": "^3.21.0-next.2",
"gatsby-plugin-utils": "^3.15.0-next.2",
"semver": "^7.3.7",
"sharp": "^0.30.3"
"sharp": "^0.30.7"
},
"devDependencies": {
"@babel/cli": "^7.15.4",
Expand Down
10 changes: 6 additions & 4 deletions packages/gatsby-plugin-sharp/README.md
Expand Up @@ -20,7 +20,9 @@ of PNGs then it can significantly reduce build times.

## Install

`npm install gatsby-plugin-sharp`
```shell
npm install gatsby-plugin-sharp
```

## How to use

Expand All @@ -32,8 +34,8 @@ plugins: [
options: {
// Defaults used for gatsbyImageData and StaticImage
defaults: {},
// Set to false to allow builds to continue on image errors
failOnError: true,
// Set to none to allow builds to continue on image errors
failOn: `none`,
// deprecated options and their defaults:
base64Width: 20,
forceBase64Format: ``, // valid formats: png,jpg,webp
Expand All @@ -50,7 +52,7 @@ plugins: [
- `defaults`: default values used for `gatsbyImageData` and `StaticImage` from [gatsby-plugin-image](https://www.gatsbyjs.com/plugins/gatsby-plugin-image).
Available options are: `formats`,`placeholder`,`quality`,`breakpoints`,`backgroundColor`,`tracedSVGOptions`,`blurredOptions`,`jpgOptions`,`pngOptions`,`webpOptions`,`avifOptions`.
For details of these, see [the reference guide](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image).
- `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`.
- `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).

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

Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-sharp/package.json
Expand Up @@ -23,13 +23,13 @@
"probe-image-size": "^7.2.3",
"progress": "^2.0.3",
"semver": "^7.3.7",
"sharp": "^0.30.3",
"sharp": "^0.30.7",
"svgo": "1.3.2"
},
"devDependencies": {
"@babel/cli": "^7.15.4",
"@babel/core": "^7.15.5",
"@types/sharp": "^0.30.0",
"@types/sharp": "^0.30.5",
"babel-preset-gatsby-package": "^2.21.0-next.0",
"cross-env": "^7.0.3",
"gatsby-plugin-image": "^2.21.0-next.2"
Expand Down
Expand Up @@ -85,7 +85,7 @@ exports[`gatsby-plugin-sharp fixed correctly infers the width when only the heig
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -142,7 +142,7 @@ exports[`gatsby-plugin-sharp fixed does not warn when the requested width is equ
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -185,7 +185,7 @@ exports[`gatsby-plugin-sharp fixed warns when the requested width is greater tha
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -256,7 +256,7 @@ exports[`gatsby-plugin-sharp fluid accepts srcSet breakpoints 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -299,7 +299,7 @@ exports[`gatsby-plugin-sharp fluid adds pathPrefix if defined 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -382,7 +382,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -464,7 +464,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -546,7 +546,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -628,7 +628,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -688,7 +688,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -752,7 +752,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -816,7 +816,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -880,7 +880,7 @@ Array [
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -916,7 +916,7 @@ exports[`gatsby-plugin-sharp fluid does not change the arguments object it is gi
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -987,7 +987,7 @@ exports[`gatsby-plugin-sharp fluid ensure maxWidth is in srcSet breakpoints 1`]
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1082,7 +1082,7 @@ exports[`gatsby-plugin-sharp fluid infers the maxWidth if only maxHeight is give
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1125,7 +1125,7 @@ exports[`gatsby-plugin-sharp fluid keeps original file name 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1189,7 +1189,7 @@ exports[`gatsby-plugin-sharp fluid prevents duplicate breakpoints 1`] = `
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1260,7 +1260,7 @@ exports[`gatsby-plugin-sharp fluid reject any breakpoints larger than the origin
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1318,7 +1318,7 @@ exports[`gatsby-plugin-sharp queueImageResizing file name works with spaces & sp
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down Expand Up @@ -1361,7 +1361,7 @@ exports[`gatsby-plugin-sharp queueImageResizing should round height when auto-ca
"pluginOptions": Object {
"base64Width": 20,
"defaultQuality": 50,
"failOnError": true,
"failOn": "warning",
"forceBase64Format": "",
"lazyImageGeneration": true,
"stripMetadata": true,
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts
@@ -1,15 +1,15 @@
import { testPluginOptionsSchema } from "gatsby-plugin-utils"
import { pluginOptionsSchema } from "../../gatsby-node"
import { doMergeDefaults } from "../plugin-options"
import { doMergeDefaults, PluginOptionsDefaults } from "../plugin-options"

const defaults = {
const defaults: PluginOptionsDefaults = {
formats: [`auto`, `webp`],
placeholder: `dominantColor`,
quality: 50,
breakpoints: [100, 200],
backgroundColor: `rebeccapurple`,
tracedSVGOptions: {},
blurredOptions: { quality: 20 },
blurredOptions: { width: 20 },
jpgOptions: { quality: 20 },
pngOptions: { quality: 20 },
webpOptions: { quality: 20 },
Expand Down Expand Up @@ -74,7 +74,7 @@ describe(`plugin defaults`, () => {
},
"backgroundColor": "rebeccapurple",
"blurredOptions": Object {
"quality": 20,
"width": 20,
},
"breakpoints": Array [
100,
Expand Down
25 changes: 25 additions & 0 deletions packages/gatsby-plugin-sharp/src/gatsby-node.js
Expand Up @@ -231,7 +231,12 @@ exports.pluginOptionsSchema = ({ Joi }) =>
),
stripMetadata: Joi.boolean().default(true),
defaultQuality: Joi.number().default(50),
// TODO(v5): Remove deprecated failOnError option
failOnError: Joi.boolean().default(true),
failOn: Joi.any()
.valid(`none`, `truncated`, `error`, `warning`)
.default(`warning`)
.description(`Level of sensitivity to invalid images`),
defaults: Joi.object({
formats: Joi.array().items(
Joi.string().valid(`auto`, `png`, `jpg`, `webp`, `avif`)
Expand All @@ -255,4 +260,24 @@ exports.pluginOptionsSchema = ({ Joi }) =>
}).description(
`Default options used by gatsby-plugin-image. \nSee https://gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/`
),
}).custom(value => {
const shouldNotFailOnError = !value.failOnError

if (shouldNotFailOnError) {
// show this warning only once in main process
if (!process.env.GATSBY_WORKER_ID) {
console.warn(
`[gatsby-plugin-sharp]: The "failOnError" option is deprecated. Please use "failOn" instead.`
)
}

return {
...value,
failOn: `none`,
}
}

return {
...value,
}
})
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/image-data.ts
Expand Up @@ -62,7 +62,7 @@ export async function getImageMetadata(
}

try {
const pipeline = sharp({ failOnError: !!getPluginOptions().failOnError })
const pipeline = sharp({ failOn: getPluginOptions().failOn })

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

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Expand Up @@ -262,7 +262,7 @@ async function generateBase64({ file, args = {}, reporter }) {
})
let pipeline
try {
pipeline = !options.failOnError ? sharp({ failOnError: false }) : sharp()
pipeline = sharp({ failOn: pluginOptions.failOn })

if (!options.rotate) {
pipeline.rotate()
Expand Down