From 6a9348ff1cdc25ccf33d5daaada9f3f7229c219a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 01:20:22 +0000 Subject: [PATCH 1/5] chore(deps): update sharp --- packages/gatsby-plugin-manifest/package.json | 2 +- packages/gatsby-plugin-sharp/package.json | 4 +- .../package.json | 2 +- packages/gatsby-sharp/package.json | 4 +- packages/gatsby-source-shopify/package.json | 4 +- packages/gatsby-source-wordpress/package.json | 2 +- .../gatsby-transformer-sharp/package.json | 4 +- packages/gatsby/package.json | 2 +- yarn.lock | 106 ++++++------------ 9 files changed, 45 insertions(+), 85 deletions(-) diff --git a/packages/gatsby-plugin-manifest/package.json b/packages/gatsby-plugin-manifest/package.json index 1b33cf2e2d3e8..3214021ec15dd 100644 --- a/packages/gatsby-plugin-manifest/package.json +++ b/packages/gatsby-plugin-manifest/package.json @@ -11,7 +11,7 @@ "gatsby-core-utils": "^3.21.0-next.0", "gatsby-plugin-utils": "^3.15.0-next.0", "semver": "^7.3.7", - "sharp": "^0.30.3" + "sharp": "^0.30.7" }, "devDependencies": { "@babel/cli": "^7.15.4", diff --git a/packages/gatsby-plugin-sharp/package.json b/packages/gatsby-plugin-sharp/package.json index dd4cfcbcb30e0..3bcb0b60f91ee 100644 --- a/packages/gatsby-plugin-sharp/package.json +++ b/packages/gatsby-plugin-sharp/package.json @@ -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.4", "babel-preset-gatsby-package": "^2.21.0-next.0", "cross-env": "^7.0.3", "gatsby-plugin-image": "^2.21.0-next.0" diff --git a/packages/gatsby-remark-images-contentful/package.json b/packages/gatsby-remark-images-contentful/package.json index e7f8af5eb9c79..6fb6ab35d6df1 100644 --- a/packages/gatsby-remark-images-contentful/package.json +++ b/packages/gatsby-remark-images-contentful/package.json @@ -22,7 +22,7 @@ "is-relative-url": "^3.0.0", "lodash": "^4.17.21", "semver": "^7.3.7", - "sharp": "^0.30.3", + "sharp": "^0.30.7", "unist-util-select": "^3.0.4" }, "devDependencies": { diff --git a/packages/gatsby-sharp/package.json b/packages/gatsby-sharp/package.json index 7ee956efc59f1..818f327bec13a 100644 --- a/packages/gatsby-sharp/package.json +++ b/packages/gatsby-sharp/package.json @@ -14,8 +14,8 @@ "types": "dist/index.d.ts", "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-sharp#readme", "dependencies": { - "@types/sharp": "^0.30.0", - "sharp": "^0.30.3" + "@types/sharp": "^0.30.4", + "sharp": "^0.30.7" }, "devDependencies": { "@babel/cli": "^7.15.5", diff --git a/packages/gatsby-source-shopify/package.json b/packages/gatsby-source-shopify/package.json index 1c99ad2b588d6..0dae3b3cdaf46 100644 --- a/packages/gatsby-source-shopify/package.json +++ b/packages/gatsby-source-shopify/package.json @@ -28,13 +28,13 @@ "gatsby-plugin-utils": "^3.15.0-next.0", "gatsby-source-filesystem": "^4.21.0-next.0", "node-fetch": "^2.6.7", - "sharp": "^0.30.3", + "sharp": "^0.30.7", "shift-left": "^0.1.5" }, "devDependencies": { "@types/node": "^14.17.34", "@types/node-fetch": "^2.5.12", - "@types/sharp": "^0.30.0", + "@types/sharp": "^0.30.4", "cross-env": "^7.0.3", "gatsby-plugin-image": "^2.21.0-next.0", "msw": "^0.38.2", diff --git a/packages/gatsby-source-wordpress/package.json b/packages/gatsby-source-wordpress/package.json index 98a71da8eae18..398350c16bdc3 100644 --- a/packages/gatsby-source-wordpress/package.json +++ b/packages/gatsby-source-wordpress/package.json @@ -40,7 +40,7 @@ "read-chunk": "^3.2.0", "replaceall": "^0.1.6", "semver": "^7.3.7", - "sharp": "^0.30.3", + "sharp": "^0.30.7", "valid-url": "^1.0.9" }, "devDependencies": { diff --git a/packages/gatsby-transformer-sharp/package.json b/packages/gatsby-transformer-sharp/package.json index 497ac382421d7..41b5ca6316cce 100644 --- a/packages/gatsby-transformer-sharp/package.json +++ b/packages/gatsby-transformer-sharp/package.json @@ -15,12 +15,12 @@ "gatsby-plugin-utils": "^3.15.0-next.0", "probe-image-size": "^7.2.3", "semver": "^7.3.7", - "sharp": "^0.30.3" + "sharp": "^0.30.7" }, "devDependencies": { "@babel/cli": "^7.15.4", "@babel/core": "^7.15.5", - "@types/sharp": "^0.30.0", + "@types/sharp": "^0.30.4", "babel-preset-gatsby-package": "^2.21.0-next.0", "cross-env": "^7.0.3" }, diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index e1a3975cb5743..403ae2b5bfee8 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -183,7 +183,7 @@ "@types/reach__router": "^1.3.5", "@types/react-dom": "^17.0.9", "@types/semver": "^7.3.9", - "@types/sharp": "^0.30.0", + "@types/sharp": "^0.30.4", "@types/signal-exit": "^3.0.0", "@types/string-similarity": "^4.0.0", "@types/tmp": "^0.2.0", diff --git a/yarn.lock b/yarn.lock index d23414bcf9476..df8ca1c856375 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4877,10 +4877,10 @@ dependencies: "@types/node" "*" -"@types/sharp@^0.30.0": - version "0.30.0" - resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.30.0.tgz#58cb016c8fdc558b4c5771ad1f3668336685c843" - integrity sha512-bZ0Y/JVlrOyqwlBMJ2taEgnwFavjLnyZmLOLecmOesuG5kR2Lx9b2fM4osgfVjLJi8UlE+t3R1JzRVMxF6MbfA== +"@types/sharp@^0.30.4": + version "0.30.4" + resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.30.4.tgz#7430b5fcf37f35dd860112c4cf6dcd6a1ba0011b" + integrity sha512-6oJEzKt7wZeS7e+6x9QFEOWGs0T/6of00+0onZGN1zSmcSjcTDZKgIGZ6YWJnHowpaKUCFBPH52mYljWqU32Eg== dependencies: "@types/node" "*" @@ -7715,10 +7715,10 @@ color@^3.0.0, color@^3.1.1: color-convert "^1.9.1" color-string "^1.5.4" -color@^4.2.1: - version "4.2.1" - resolved "https://registry.yarnpkg.com/color/-/color-4.2.1.tgz#498aee5fce7fc982606c8875cab080ac0547c884" - integrity sha512-MFJr0uY4RvTQUKvPq7dh9grVOTYSFeXja2mBXioCGjnjJoXrAp9jJ1NQTDR73c9nwBSAQiNKloKl5zq9WB9UPw== +color@^4.2.3: + version "4.2.3" + resolved "https://registry.yarnpkg.com/color/-/color-4.2.3.tgz#d781ecb5e57224ee43ea9627560107c0e0c6463a" + integrity sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A== dependencies: color-convert "^2.0.1" color-string "^1.9.0" @@ -8622,18 +8622,7 @@ css-select@^2.0.0: domutils "^1.7.0" nth-check "^1.0.1" -css-select@^4.1.3: - version "4.1.3" - resolved "https://registry.yarnpkg.com/css-select/-/css-select-4.1.3.tgz#a70440f70317f2669118ad74ff105e65849c7067" - integrity sha512-gT3wBNd9Nj49rAbmtFHj1cljIAOLYSX1nZ8CB7TBO3INYckygm5B7LISU/szY//YmdiSLbJvDLOx9VnMVpMBxA== - dependencies: - boolbase "^1.0.0" - css-what "^5.0.0" - domhandler "^4.2.0" - domutils "^2.6.0" - nth-check "^2.0.0" - -css-select@^4.2.1: +css-select@^4.1.3, css-select@^4.2.1: version "4.3.0" resolved "https://registry.yarnpkg.com/css-select/-/css-select-4.3.0.tgz#db7129b2846662fd8628cfc496abb2b59e41529b" integrity sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ== @@ -8690,7 +8679,7 @@ css-what@2.1: version "2.1.0" resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.0.tgz#9467d032c38cfaefb9f2d79501253062f87fa1bd" -css-what@^5.0.0, css-what@^5.0.1: +css-what@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/css-what/-/css-what-5.0.1.tgz#3efa820131f4669a8ac2408f9c32e7c7de9f4cad" integrity sha512-FYDTSHb/7KXsWICVsxdmiExPjCfRC4qRFBdVwv7Ax9hMnvMmEjP9RfxTEZ3qPZGmADDn2vAKSo9UcN1jKVYscg== @@ -9679,14 +9668,7 @@ domhandler@^3.0.0: dependencies: domelementtype "^2.0.1" -domhandler@^4.0.0, domhandler@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-4.2.0.tgz#f9768a5f034be60a89a27c2e4d0f74eba0d8b059" - integrity sha512-zk7sgt970kzPks2Bf+dwT/PLzghLnsivb9CcxkvR8Mzr66Olr0Ofd8neSbglHJHaHa2MadfoSdNlKYAaafmWfA== - dependencies: - domelementtype "^2.2.0" - -domhandler@^4.3.1: +domhandler@^4.0.0, domhandler@^4.2.0, domhandler@^4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-4.3.1.tgz#8d792033416f59d68bc03a5aa7b018c1ca89279c" integrity sha512-GrwoxYN+uWlzO8uhUXRl0P+kHE4GtVPfYzVLcUxPL7KNdHKj66vvlhiweIHqYYXWlw+T8iLMp42Lm67ghw4WMQ== @@ -9717,16 +9699,7 @@ domutils@^1.5.1, domutils@^1.7.0: dom-serializer "0" domelementtype "1" -domutils@^2.0.0, domutils@^2.5.2, domutils@^2.6.0, domutils@^2.7.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/domutils/-/domutils-2.7.0.tgz#8ebaf0c41ebafcf55b0b72ec31c56323712c5442" - integrity sha512-8eaHa17IwJUPAiB+SoTYBo5mCdeMgdcAoXJ59m6DT1vw+5iLS3gNoqYaRowaBKtGVrOF1Jz4yDTgYKLK2kvfJg== - dependencies: - dom-serializer "^1.0.1" - domelementtype "^2.2.0" - domhandler "^4.2.0" - -domutils@^2.8.0: +domutils@^2.0.0, domutils@^2.5.2, domutils@^2.7.0, domutils@^2.8.0: version "2.8.0" resolved "https://registry.yarnpkg.com/domutils/-/domutils-2.8.0.tgz#4437def5db6e2d1f5d6ee859bd95ca7d02048135" integrity sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A== @@ -10888,12 +10861,7 @@ falafel@^2.1.0: isarray "0.0.1" object-keys "^1.0.6" -fast-copy@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/fast-copy/-/fast-copy-2.1.1.tgz#f5cbcf2df64215e59b8e43f0b2caabc19848083a" - integrity sha512-Qod3DdRgFZ8GUIM6ygeoZYpQ0QLW9cf/FS9KhhjlYggcSZXWAemAw8BOCO5LuYCrR3Uj3qXDVTUzOUwG8C7beQ== - -fast-copy@^2.1.3: +fast-copy@^2.1.0, fast-copy@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/fast-copy/-/fast-copy-2.1.3.tgz#bf6e05ac3cb7a9d66fbf12c51dd4440e9ddd4afb" integrity sha512-LDzYKNTHhD+XOp8wGMuCkY4eTxFZOOycmpwLBiuF3r3OjOmZnURRD8t2dUAbmKuXGbo/MGggwbSjcBdp8QT0+g== @@ -11265,12 +11233,7 @@ flush-write-stream@^1.0.0, flush-write-stream@^1.0.2: inherits "^2.0.1" readable-stream "^2.0.4" -follow-redirects@^1.10.0: - version "1.13.0" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db" - integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA== - -follow-redirects@^1.14.9: +follow-redirects@^1.10.0, follow-redirects@^1.14.9: version "1.14.9" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== @@ -17297,6 +17260,11 @@ node-addon-api@^4.3.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.3.0.tgz#52a1a0b475193e0928e98e0426a0d1254782b77f" integrity sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ== +node-addon-api@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.0.0.tgz#7d7e6f9ef89043befdb20c1989c905ebde18c501" + integrity sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA== + node-cleanup@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/node-cleanup/-/node-cleanup-2.1.2.tgz#7ac19abd297e09a7f72a71545d951b517e4dde2c" @@ -17610,7 +17578,7 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" -"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.0.1, npmlog@^4.1.2: +"npmlog@0 || 1 || 2 || 3 || 4", npmlog@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" dependencies: @@ -17632,14 +17600,7 @@ nth-check@^1.0.1, nth-check@~1.0.1: dependencies: boolbase "~1.0.0" -nth-check@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.0.0.tgz#1bb4f6dac70072fc313e8c9cd1417b5074c0a125" - integrity sha512-i4sc/Kj8htBrAiH1viZ0TgU8Y5XqCaV/FziYK6TBczxmeKm3AEFWqqF3195yKudrarqy7Zu80Ra5dobFjn9X/Q== - dependencies: - boolbase "^1.0.0" - -nth-check@^2.0.1: +nth-check@^2.0.0, nth-check@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d" integrity sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w== @@ -19399,10 +19360,10 @@ preact@^10.6.4: resolved "https://registry.yarnpkg.com/preact/-/preact-10.6.4.tgz#ad12c409ff1b4316158486e0a7b8d43636f7ced8" integrity sha512-WyosM7pxGcndU8hY0OQlLd54tOU+qmG45QXj2dAYrL11HoyU/EzOSTlpJsirbBr1QW7lICxSsVJJmcmUglovHQ== -prebuild-install@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-7.0.1.tgz#c10075727c318efe72412f333e0ef625beaf3870" - integrity sha512-QBSab31WqkyxpnMWQxubYAHR5S9B2+r81ucocew34Fkl98FhvKIF50jIJnNOBmAZfyNV7vE5T6gd3hTVWgY6tg== +prebuild-install@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-7.1.1.tgz#de97d5b34a70a0c81334fd24641f2a1702352e45" + integrity sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw== dependencies: detect-libc "^2.0.0" expand-template "^2.0.3" @@ -19411,7 +19372,6 @@ prebuild-install@^7.0.1: mkdirp-classic "^0.5.3" napi-build-utils "^1.0.1" node-abi "^3.3.0" - npmlog "^4.0.1" pump "^3.0.0" rc "^1.2.7" simple-get "^4.0.0" @@ -22391,16 +22351,16 @@ shallow-copy@~0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/shallow-copy/-/shallow-copy-0.0.1.tgz#415f42702d73d810330292cc5ee86eae1a11a170" -sharp@^0.30.3: - version "0.30.3" - resolved "https://registry.yarnpkg.com/sharp/-/sharp-0.30.3.tgz#315a1817423a4d1cde5119a21c99c234a7a6fb37" - integrity sha512-rjpfJFK58ZOFSG8sxYSo3/JQb4ej095HjXp9X7gVu7gEn1aqSG8TCW29h/Rr31+PXrFADo1H/vKfw0uhMQWFtg== +sharp@^0.30.7: + version "0.30.7" + resolved "https://registry.yarnpkg.com/sharp/-/sharp-0.30.7.tgz#7862bda98804fdd1f0d5659c85e3324b90d94c7c" + integrity sha512-G+MY2YW33jgflKPTXXptVO28HvNOo9G3j0MybYAHeEmby+QuD2U98dT6ueht9cv/XDqZspSpIhoSW+BAKJ7Hig== dependencies: - color "^4.2.1" + color "^4.2.3" detect-libc "^2.0.1" - node-addon-api "^4.3.0" - prebuild-install "^7.0.1" - semver "^7.3.5" + node-addon-api "^5.0.0" + prebuild-install "^7.1.1" + semver "^7.3.7" simple-get "^4.0.1" tar-fs "^2.1.1" tunnel-agent "^0.6.0" From 42d475a3a59db159751545d5314cf8a10963708a Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 8 Aug 2022 09:51:56 +0200 Subject: [PATCH 2/5] update @types/sharp --- packages/gatsby-plugin-sharp/package.json | 2 +- packages/gatsby-sharp/package.json | 2 +- packages/gatsby-source-shopify/package.json | 2 +- packages/gatsby-transformer-sharp/package.json | 2 +- packages/gatsby/package.json | 2 +- yarn.lock | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-plugin-sharp/package.json b/packages/gatsby-plugin-sharp/package.json index 7291306e24602..6693d8f430848 100644 --- a/packages/gatsby-plugin-sharp/package.json +++ b/packages/gatsby-plugin-sharp/package.json @@ -29,7 +29,7 @@ "devDependencies": { "@babel/cli": "^7.15.4", "@babel/core": "^7.15.5", - "@types/sharp": "^0.30.4", + "@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.1" diff --git a/packages/gatsby-sharp/package.json b/packages/gatsby-sharp/package.json index 818f327bec13a..46e20ad54dc3a 100644 --- a/packages/gatsby-sharp/package.json +++ b/packages/gatsby-sharp/package.json @@ -14,7 +14,7 @@ "types": "dist/index.d.ts", "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-sharp#readme", "dependencies": { - "@types/sharp": "^0.30.4", + "@types/sharp": "^0.30.5", "sharp": "^0.30.7" }, "devDependencies": { diff --git a/packages/gatsby-source-shopify/package.json b/packages/gatsby-source-shopify/package.json index ca970e9000b6c..1db1a32d3cdf7 100644 --- a/packages/gatsby-source-shopify/package.json +++ b/packages/gatsby-source-shopify/package.json @@ -34,7 +34,7 @@ "devDependencies": { "@types/node": "^14.17.34", "@types/node-fetch": "^2.5.12", - "@types/sharp": "^0.30.4", + "@types/sharp": "^0.30.5", "cross-env": "^7.0.3", "gatsby-plugin-image": "^2.21.0-next.1", "msw": "^0.38.2", diff --git a/packages/gatsby-transformer-sharp/package.json b/packages/gatsby-transformer-sharp/package.json index c94324d212f0d..ec16aa724ac84 100644 --- a/packages/gatsby-transformer-sharp/package.json +++ b/packages/gatsby-transformer-sharp/package.json @@ -20,7 +20,7 @@ "devDependencies": { "@babel/cli": "^7.15.4", "@babel/core": "^7.15.5", - "@types/sharp": "^0.30.4", + "@types/sharp": "^0.30.5", "babel-preset-gatsby-package": "^2.21.0-next.0", "cross-env": "^7.0.3" }, diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index 40e84edb8ec57..29dbf91a2a1ab 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -184,7 +184,7 @@ "@types/reach__router": "^1.3.5", "@types/react-dom": "^17.0.9", "@types/semver": "^7.3.10", - "@types/sharp": "^0.30.4", + "@types/sharp": "^0.30.5", "@types/signal-exit": "^3.0.0", "@types/string-similarity": "^4.0.0", "@types/tmp": "^0.2.0", diff --git a/yarn.lock b/yarn.lock index c48496a0fd48d..24f6836261c88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4922,10 +4922,10 @@ dependencies: "@types/node" "*" -"@types/sharp@^0.30.4": - version "0.30.4" - resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.30.4.tgz#7430b5fcf37f35dd860112c4cf6dcd6a1ba0011b" - integrity sha512-6oJEzKt7wZeS7e+6x9QFEOWGs0T/6of00+0onZGN1zSmcSjcTDZKgIGZ6YWJnHowpaKUCFBPH52mYljWqU32Eg== +"@types/sharp@^0.30.5": + version "0.30.5" + resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.30.5.tgz#d75d91f7acf5260525aeae229845046dcff6d17a" + integrity sha512-EhO29617AIBqxoVtpd1qdBanWpspk/kD2B6qTFRJ31Q23Rdf+DNU1xlHSwtqvwq1vgOqBwq1i38SX+HGCymIQg== dependencies: "@types/node" "*" From d2e0e4c4b19d258438a201d22cdf88044065536d Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 8 Aug 2022 12:05:40 +0200 Subject: [PATCH 3/5] convert --- packages/gatsby-plugin-sharp/README.md | 10 +- .../src/__tests__/__snapshots__/index.js.snap | 42 ++--- .../src/__tests__/plugin-options.ts | 8 +- .../gatsby-plugin-sharp/src/gatsby-node.js | 25 +++ .../gatsby-plugin-sharp/src/image-data.ts | 2 +- packages/gatsby-plugin-sharp/src/index.js | 2 +- .../{plugin-options.js => plugin-options.ts} | 147 ++++++++++++++---- .../src/{process-file.js => process-file.ts} | 82 ++++------ .../placeholder-handler.ts | 2 +- 9 files changed, 202 insertions(+), 118 deletions(-) rename packages/gatsby-plugin-sharp/src/{plugin-options.js => plugin-options.ts} (55%) rename packages/gatsby-plugin-sharp/src/{process-file.js => process-file.ts} (70%) diff --git a/packages/gatsby-plugin-sharp/README.md b/packages/gatsby-plugin-sharp/README.md index a9f30f6843982..f4b2cc082d68f 100644 --- a/packages/gatsby-plugin-sharp/README.md +++ b/packages/gatsby-plugin-sharp/README.md @@ -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 @@ -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 @@ -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 = `error`. 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. diff --git a/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap b/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap index 3429438aaca65..5f6d6a29e132b 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap +++ b/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -256,7 +256,7 @@ exports[`gatsby-plugin-sharp fluid accepts srcSet breakpoints 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -299,7 +299,7 @@ exports[`gatsby-plugin-sharp fluid adds pathPrefix if defined 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -382,7 +382,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -464,7 +464,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -546,7 +546,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -628,7 +628,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -688,7 +688,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -752,7 +752,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -816,7 +816,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -880,7 +880,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1125,7 +1125,7 @@ exports[`gatsby-plugin-sharp fluid keeps original file name 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1189,7 +1189,7 @@ exports[`gatsby-plugin-sharp fluid prevents duplicate breakpoints 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -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": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1318,7 +1318,7 @@ exports[`gatsby-plugin-sharp queueImageResizing file name works with spaces & sp "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1361,7 +1361,7 @@ exports[`gatsby-plugin-sharp queueImageResizing should round height when auto-ca "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOnError": true, + "failOn": "error", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, diff --git a/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts b/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts index e9d74afa5fcf5..02f0376579477 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts +++ b/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 }, @@ -74,7 +74,7 @@ describe(`plugin defaults`, () => { }, "backgroundColor": "rebeccapurple", "blurredOptions": Object { - "quality": 20, + "width": 20, }, "breakpoints": Array [ 100, diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index 919d9bee0c4f0..ee1d7e87a3dc4 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -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(`error`) + .description(`Level of sensitivity to invalid images`), defaults: Joi.object({ formats: Joi.array().items( Joi.string().valid(`auto`, `png`, `jpg`, `webp`, `avif`) @@ -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, + } }) diff --git a/packages/gatsby-plugin-sharp/src/image-data.ts b/packages/gatsby-plugin-sharp/src/image-data.ts index 5b6de4cf2e1d3..a6c34cb11ea02 100644 --- a/packages/gatsby-plugin-sharp/src/image-data.ts +++ b/packages/gatsby-plugin-sharp/src/image-data.ts @@ -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) diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 1e30b2445e0f5..693c7cc39c1fe 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -262,7 +262,7 @@ async function generateBase64({ file, args = {}, reporter }) { }) let pipeline try { - pipeline = !options.failOnError ? sharp({ failOnError: false }) : sharp() + pipeline = sharp({ failOn: options.failOn }) if (!options.rotate) { pipeline.rotate() diff --git a/packages/gatsby-plugin-sharp/src/plugin-options.js b/packages/gatsby-plugin-sharp/src/plugin-options.ts similarity index 55% rename from packages/gatsby-plugin-sharp/src/plugin-options.js rename to packages/gatsby-plugin-sharp/src/plugin-options.ts index 5c0f4d7844fb6..7780995e2f215 100644 --- a/packages/gatsby-plugin-sharp/src/plugin-options.js +++ b/packages/gatsby-plugin-sharp/src/plugin-options.ts @@ -1,4 +1,68 @@ -const _ = require(`lodash`) +import type { ISharpGatsbyImageArgs, Fit } from "gatsby-plugin-image" +import { pickBy, defaults, mergeWith, omitBy, isNil, identity } from "lodash" +import type { FailOnOptions, SharpOptions } from "sharp" + +export type PluginOptionsDefaults = Pick< + ISharpGatsbyImageArgs, + | "formats" + | "placeholder" + | "quality" + | "breakpoints" + | "backgroundColor" + | "tracedSVGOptions" + | "blurredOptions" + | "jpgOptions" + | "pngOptions" + | "webpOptions" + | "avifOptions" +> + +export interface ISharpPluginOptions { + base64Width?: number + forceBase64Format?: "png" | "webp" | "jpg" | string + useMozJpeg?: boolean + stripMetadata?: boolean + lazyImageGeneration?: boolean + defaultQuality?: number + failOn?: SharpOptions["failOn"] + defaults?: PluginOptionsDefaults +} + +interface IDuotoneArgs { + highlight: string + shadow: string + opacity?: number +} + +export interface ITransformArgs { + height: number + width: number + cropFocus?: number | string + toFormat: string + pngCompressionLevel?: number + quality?: number + jpegQuality?: number + pngQuality?: number + webpQuality?: number + jpegProgressive?: boolean + grayscale?: boolean + rotate?: number + trim?: number + duotone?: IDuotoneArgs + background?: string + fit?: Fit + pathPrefix?: string + maxHeight?: number + maxWidth?: number + base64Width?: number +} + +interface IGeneralArgs extends ITransformArgs { + base64: boolean + pathPrefix: string + toFormatBase64: string + pngCompressionSpeed?: number +} // Plugin options are loaded onPreBootstrap in gatsby-node const pluginDefaults = { @@ -8,44 +72,47 @@ const pluginDefaults = { stripMetadata: true, lazyImageGeneration: true, defaultQuality: 50, - failOnError: true, // matches default of the sharp api constructor (https://sharp.pixelplumbing.com/api-constructor) + failOn: `error` as FailOnOptions, } -const generalArgs = { +const generalArgs: Partial = { quality: 50, - jpegQuality: null, - pngQuality: null, - webpQuality: null, + jpegQuality: undefined, + pngQuality: undefined, + webpQuality: undefined, jpegProgressive: true, pngCompressionLevel: 9, // default is 4 (https://github.com/kornelski/pngquant/blob/4219956d5e080be7905b5581314d913d20896934/rust/bin.rs#L61) pngCompressionSpeed: 4, base64: true, grayscale: false, - duotone: false, + duotone: undefined, pathPrefix: ``, toFormat: ``, toFormatBase64: ``, rotate: 0, } -let pluginOptions = Object.assign({}, pluginDefaults) -exports.setPluginOptions = opts => { +let pluginOptions: ISharpPluginOptions = Object.assign({}, pluginDefaults) +export const setPluginOptions = ( + opts: Record +): ISharpPluginOptions => { pluginOptions = Object.assign({}, pluginOptions, opts) generalArgs.quality = pluginOptions.defaultQuality return pluginOptions } -exports.getPluginOptions = () => pluginOptions -exports.getPluginOptionsDefaults = () => pluginDefaults +export const getPluginOptions = (): ISharpPluginOptions => pluginOptions +export const getPluginOptionsDefaults = (): ISharpPluginOptions => + pluginDefaults /** * Creates a transform object - * - * @param {Partial} args */ -exports.createTransformObject = args => { +export const createTransformObject = ( + args: ITransformArgs +): Partial => { const options = { height: args.height, width: args.width, @@ -67,38 +134,50 @@ exports.createTransformObject = args => { } // get all non falsey values - return _.pickBy(options, _.identity) + return pickBy(options, identity) } /** * Used for gatsbyImageData and StaticImage only */ -exports.mergeDefaults = args => doMergeDefaults(args, pluginOptions.defaults) +export const mergeDefaults = ( + args: ISharpGatsbyImageArgs +): PluginOptionsDefaults & ISharpGatsbyImageArgs => + doMergeDefaults(args, pluginOptions.defaults) -const customizer = (objValue, srcValue) => +const customizer = (objValue: unknown, srcValue: T): T | undefined => Array.isArray(objValue) ? srcValue : undefined -function doMergeDefaults(args, defaults) { +export function doMergeDefaults( + args: ISharpGatsbyImageArgs, + defaults?: PluginOptionsDefaults +): PluginOptionsDefaults & ISharpGatsbyImageArgs { if (!defaults) { return args } - return _.mergeWith({}, defaults, args, customizer) + return mergeWith({}, defaults, args, customizer) } -exports.doMergeDefaults = doMergeDefaults - -exports.healOptions = ( - { defaultQuality: quality, base64Width }, - args, +export const healOptions = ( + { + defaultQuality: quality, + base64Width, + }: { defaultQuality: number; base64Width?: number }, + args: ITransformArgs, fileExtension = ``, defaultArgs = {} -) => { - const options = _.defaults({}, args, { quality }, defaultArgs, generalArgs) +): Partial & { + quality: number +} & ITransformArgs => { + const options = defaults({}, args, { quality }, defaultArgs, generalArgs) + // @ts-ignore - parseInt as safeguard, expects string tho options.quality = parseInt(options.quality, 10) + // @ts-ignore - parseInt as safeguard, expects string tho options.pngCompressionLevel = parseInt(options.pngCompressionLevel, 10) + // @ts-ignore - parseInt as safeguard, expects string tho options.pngCompressionSpeed = parseInt(options.pngCompressionSpeed, 10) options.toFormat = options.toFormat.toLowerCase() - options.toFormatBase64 = options.toFormatBase64.toLowerCase() + options.toFormatBase64 = options.toFormatBase64?.toLowerCase() options.base64Width = options.base64Width || base64Width // when toFormat is not set we set it based on fileExtension @@ -120,9 +199,11 @@ exports.healOptions = ( options.width = 400 } if (options.width !== undefined) { + // @ts-ignore - parseInt as safeguard, expects string tho options.width = parseInt(options.width, 10) } if (options.height !== undefined) { + // @ts-ignore - parseInt as safeguard, expects string tho options.height = parseInt(options.height, 10) } @@ -130,8 +211,10 @@ exports.healOptions = ( if (options.maxWidth === undefined && options.maxHeight === undefined) { options.maxWidth = 800 } else if (options.maxWidth !== undefined) { + // @ts-ignore - parseInt as safeguard, expects string tho options.maxWidth = parseInt(options.maxWidth, 10) } else if (options.maxHeight !== undefined) { + // @ts-ignore - parseInt as safeguard, expects string tho options.maxHeight = parseInt(options.maxHeight, 10) } @@ -147,11 +230,11 @@ exports.healOptions = ( /** * Removes all default values so we have the smallest transform args - * - * @param {Partial} args - * @param {{defaultQuality: number }} pluginOptions */ -exports.removeDefaultValues = (args, pluginOptions) => { +export const removeDefaultValues = ( + args: ITransformArgs, + pluginOptions: ISharpPluginOptions +): Partial => { const options = { height: args.height, width: args.width, @@ -179,5 +262,5 @@ exports.removeDefaultValues = (args, pluginOptions) => { background: args.background, } - return _.omitBy(options, _.isNil) + return omitBy(options, isNil) } diff --git a/packages/gatsby-plugin-sharp/src/process-file.js b/packages/gatsby-plugin-sharp/src/process-file.ts similarity index 70% rename from packages/gatsby-plugin-sharp/src/process-file.js rename to packages/gatsby-plugin-sharp/src/process-file.ts index 94587f907d262..059f27540a43b 100644 --- a/packages/gatsby-plugin-sharp/src/process-file.js +++ b/packages/gatsby-plugin-sharp/src/process-file.ts @@ -1,13 +1,17 @@ -const sharp = require(`./safe-sharp`) -const fs = require(`fs-extra`) -const path = require(`path`) -const debug = require(`debug`)(`gatsby:gatsby-plugin-sharp`) -const duotone = require(`./duotone`) -const { healOptions } = require(`./plugin-options`) -const { SharpError } = require(`./sharp-error`) -const { - createContentDigest, -} = require(`gatsby-core-utils/create-content-digest`) +import sharp from "./safe-sharp" +import fs from "fs-extra" +import path from "path" +import debug from "debug" +import { createContentDigest } from "gatsby-core-utils/create-content-digest" +import duotone from "./duotone" +import { + healOptions, + ITransformArgs, + ISharpPluginOptions, +} from "./plugin-options" +import { SharpError } from "./sharp-error" + +const log = debug(`gatsby:gatsby-plugin-sharp`) // Try to enable the use of SIMD instructions. Seems to provide a smallish // speedup on resizing heavy loads (~10%). Sharp disables this feature by @@ -18,50 +22,20 @@ sharp.simd(true) // Concurrency is handled in gatsby-worker queue instead sharp.concurrency(1) -/** - * @typedef DuotoneArgs - * @property {string} highlight - * @property {string} shadow - * @property {number} opacity - */ - -/** - * @typedef {Object} TransformArgs - * @property {number} height - * @property {number} width - * @property {number} cropFocus - * @property {string} toFormat - * @property {number} pngCompressionLevel - * @property {number} quality - * @property {number} jpegQuality - * @property {number} pngQuality - * @property {number} webpQuality - * @property {boolean} jpegProgressive - * @property {boolean} grayscale - * @property {number} rotate - * @property {number} trim - * @property {DuotoneArgs} duotone - * @property {string} background - * @property {import('sharp').FitEnum} fit - */ - -/** + - * @typedef {Object} Transform - * @property {string} outputPath - * @property {TransformArgs} args - */ - -/** - * @param {String} file - * @param {Transform[]} transforms - */ -exports.processFile = async (file, transforms, options = {}) => { +interface ITransform { + outputPath: string + args: ITransformArgs +} + +export const processFile = async ( + file: string, + transforms: Array, + options: ISharpPluginOptions = {} +): Promise> => { let pipeline try { const inputBuffer = await fs.readFile(file) - pipeline = !options.failOnError - ? sharp(inputBuffer, { failOnError: false }) - : sharp(inputBuffer) + pipeline = sharp(inputBuffer, { failOn: options.failOn }) // Keep Metadata if (!options.stripMetadata) { @@ -75,11 +49,11 @@ exports.processFile = async (file, transforms, options = {}) => { transforms.map(async transform => { try { const { outputPath, args } = transform - debug(`Start processing ${outputPath}`) + log(`Start processing ${outputPath}`) await fs.ensureDir(path.dirname(outputPath)) const transformArgs = healOptions( - { defaultQuality: options.defaultQuality }, + { defaultQuality: options.defaultQuality as number }, args ) @@ -177,7 +151,7 @@ exports.processFile = async (file, transforms, options = {}) => { ) } -exports.createArgsDigest = args => { +export const createArgsDigest = (args: unknown): string => { const argsDigest = createContentDigest(args) return argsDigest.slice(-5) diff --git a/packages/gatsby-plugin-utils/src/polyfill-remote-file/placeholder-handler.ts b/packages/gatsby-plugin-utils/src/polyfill-remote-file/placeholder-handler.ts index f206a546a78bd..f1ac0303349fd 100644 --- a/packages/gatsby-plugin-utils/src/polyfill-remote-file/placeholder-handler.ts +++ b/packages/gatsby-plugin-utils/src/polyfill-remote-file/placeholder-handler.ts @@ -88,7 +88,7 @@ const queue = Queue< } case PlaceholderType.DOMINANT_COLOR: { const fileStream = createReadStream(filePath) - const pipeline = sharp({ failOnError: false }) + const pipeline = sharp({ failOn: `none` }) fileStream.pipe(pipeline) const { dominant } = await pipeline.stats() From 3eff34d6d837245fa321d5c3decc6ef25c6346c7 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 8 Aug 2022 13:06:41 +0200 Subject: [PATCH 4/5] use correct default --- packages/gatsby-plugin-sharp/README.md | 2 +- .../src/__tests__/__snapshots__/index.js.snap | 42 +++++++++---------- .../gatsby-plugin-sharp/src/gatsby-node.js | 2 +- .../gatsby-plugin-sharp/src/plugin-options.ts | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/gatsby-plugin-sharp/README.md b/packages/gatsby-plugin-sharp/README.md index f4b2cc082d68f..6d6cbeba925d9 100644 --- a/packages/gatsby-plugin-sharp/README.md +++ b/packages/gatsby-plugin-sharp/README.md @@ -52,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). -- `failOn`: default = `error`. 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). +- `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. diff --git a/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap b/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap index 5f6d6a29e132b..ea17e500aba82 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap +++ b/packages/gatsby-plugin-sharp/src/__tests__/__snapshots__/index.js.snap @@ -85,7 +85,7 @@ exports[`gatsby-plugin-sharp fixed correctly infers the width when only the heig "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -142,7 +142,7 @@ exports[`gatsby-plugin-sharp fixed does not warn when the requested width is equ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -185,7 +185,7 @@ exports[`gatsby-plugin-sharp fixed warns when the requested width is greater tha "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -256,7 +256,7 @@ exports[`gatsby-plugin-sharp fluid accepts srcSet breakpoints 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -299,7 +299,7 @@ exports[`gatsby-plugin-sharp fluid adds pathPrefix if defined 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -382,7 +382,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -464,7 +464,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -546,7 +546,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -628,7 +628,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -688,7 +688,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -752,7 +752,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -816,7 +816,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -880,7 +880,7 @@ Array [ "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -916,7 +916,7 @@ exports[`gatsby-plugin-sharp fluid does not change the arguments object it is gi "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -987,7 +987,7 @@ exports[`gatsby-plugin-sharp fluid ensure maxWidth is in srcSet breakpoints 1`] "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1082,7 +1082,7 @@ exports[`gatsby-plugin-sharp fluid infers the maxWidth if only maxHeight is give "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1125,7 +1125,7 @@ exports[`gatsby-plugin-sharp fluid keeps original file name 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1189,7 +1189,7 @@ exports[`gatsby-plugin-sharp fluid prevents duplicate breakpoints 1`] = ` "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1260,7 +1260,7 @@ exports[`gatsby-plugin-sharp fluid reject any breakpoints larger than the origin "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1318,7 +1318,7 @@ exports[`gatsby-plugin-sharp queueImageResizing file name works with spaces & sp "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, @@ -1361,7 +1361,7 @@ exports[`gatsby-plugin-sharp queueImageResizing should round height when auto-ca "pluginOptions": Object { "base64Width": 20, "defaultQuality": 50, - "failOn": "error", + "failOn": "warning", "forceBase64Format": "", "lazyImageGeneration": true, "stripMetadata": true, diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index ee1d7e87a3dc4..e5abb86aac8ae 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -235,7 +235,7 @@ exports.pluginOptionsSchema = ({ Joi }) => failOnError: Joi.boolean().default(true), failOn: Joi.any() .valid(`none`, `truncated`, `error`, `warning`) - .default(`error`) + .default(`warning`) .description(`Level of sensitivity to invalid images`), defaults: Joi.object({ formats: Joi.array().items( diff --git a/packages/gatsby-plugin-sharp/src/plugin-options.ts b/packages/gatsby-plugin-sharp/src/plugin-options.ts index 7780995e2f215..ed191b67f3711 100644 --- a/packages/gatsby-plugin-sharp/src/plugin-options.ts +++ b/packages/gatsby-plugin-sharp/src/plugin-options.ts @@ -72,7 +72,7 @@ const pluginDefaults = { stripMetadata: true, lazyImageGeneration: true, defaultQuality: 50, - failOn: `error` as FailOnOptions, + failOn: `warning` as FailOnOptions, } const generalArgs: Partial = { From 75dfe17c390955ef47433d9162634d0d15d9ac28 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 8 Aug 2022 13:15:54 +0200 Subject: [PATCH 5/5] fix tests --- packages/gatsby-plugin-sharp/src/index.js | 2 +- packages/gatsby-plugin-sharp/src/plugin-options.ts | 4 ++-- packages/gatsby-plugin-sharp/src/process-file.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 693c7cc39c1fe..f770efd3f5912 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -262,7 +262,7 @@ async function generateBase64({ file, args = {}, reporter }) { }) let pipeline try { - pipeline = sharp({ failOn: options.failOn }) + pipeline = sharp({ failOn: pluginOptions.failOn }) if (!options.rotate) { pipeline.rotate() diff --git a/packages/gatsby-plugin-sharp/src/plugin-options.ts b/packages/gatsby-plugin-sharp/src/plugin-options.ts index ed191b67f3711..84e5663ed9f84 100644 --- a/packages/gatsby-plugin-sharp/src/plugin-options.ts +++ b/packages/gatsby-plugin-sharp/src/plugin-options.ts @@ -23,7 +23,7 @@ export interface ISharpPluginOptions { useMozJpeg?: boolean stripMetadata?: boolean lazyImageGeneration?: boolean - defaultQuality?: number + defaultQuality: number failOn?: SharpOptions["failOn"] defaults?: PluginOptionsDefaults } @@ -162,7 +162,7 @@ export const healOptions = ( { defaultQuality: quality, base64Width, - }: { defaultQuality: number; base64Width?: number }, + }: Pick, args: ITransformArgs, fileExtension = ``, defaultArgs = {} diff --git a/packages/gatsby-plugin-sharp/src/process-file.ts b/packages/gatsby-plugin-sharp/src/process-file.ts index 059f27540a43b..be848464b1f48 100644 --- a/packages/gatsby-plugin-sharp/src/process-file.ts +++ b/packages/gatsby-plugin-sharp/src/process-file.ts @@ -30,7 +30,7 @@ interface ITransform { export const processFile = async ( file: string, transforms: Array, - options: ISharpPluginOptions = {} + options = {} as ISharpPluginOptions ): Promise> => { let pipeline try {