Skip to content

Commit ca15ef3

Browse files
lovellpieh
andauthored
chore(deps): upgrade sharp to latest v0.32.6 (#38374)
* chore(deps): upgrade sharp to latest v0.32.5 Ensures some PNG-related test snapshots use deterministic raw pixel data rather than non-deterministic compressed byte streams. * chore(deps): upgrade sharp to latest v0.32.6 --------- Co-authored-by: Michal Piechowiak <[email protected]>
1 parent e86b36b commit ca15ef3

File tree

17 files changed

+118
-35
lines changed

17 files changed

+118
-35
lines changed

benchmarks/source-strapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"prop-types": "^15.7.2",
1515
"react": "^16.12.0",
1616
"react-dom": "^16.12.0",
17-
"sharp": "^0.26.3"
17+
"sharp": "^0.32.6"
1818
},
1919
"devDependencies": {
2020
"prettier": "2.0.5"

packages/gatsby-plugin-manifest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"gatsby-core-utils": "^4.13.0-next.0",
1212
"gatsby-plugin-utils": "^4.13.0-next.0",
1313
"semver": "^7.5.3",
14-
"sharp": "^0.32.1"
14+
"sharp": "^0.32.6"
1515
},
1616
"devDependencies": {
1717
"@babel/cli": "^7.20.7",

packages/gatsby-plugin-sharp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"lodash": "^4.17.21",
1919
"probe-image-size": "^7.2.3",
2020
"semver": "^7.5.3",
21-
"sharp": "^0.32.1"
21+
"sharp": "^0.32.6"
2222
},
2323
"devDependencies": {
2424
"@babel/cli": "^7.20.7",

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

Lines changed: 12 additions & 6 deletions
Large diffs are not rendered by default.

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const sharp = require(`sharp`)
1818
fs.ensureDirSync = jest.fn()
1919
fs.existsSync = jest.fn().mockReturnValue(false)
2020

21+
const decodeBase64PngAsRaw = async png =>
22+
sharp(Buffer.from(png.replace(`data:image/png;base64,`, ``), `base64`))
23+
.raw()
24+
.toBuffer()
25+
2126
const {
2227
base64,
2328
generateBase64,
@@ -136,10 +141,13 @@ describe(`gatsby-plugin-sharp`, () => {
136141
})
137142

138143
it(`includes responsive image properties, e.g. sizes, srcset, etc.`, async () => {
139-
const result = await fluid({ file })
144+
const { base64, ...result } = await fluid({ file })
140145

141146
expect(actions.createJobV2).toHaveBeenCalledTimes(1)
142147
expect(result).toMatchSnapshot()
148+
149+
const rawPixelData = await decodeBase64PngAsRaw(base64)
150+
expect(rawPixelData.toString(`hex`)).toMatchSnapshot()
143151
})
144152

145153
it(`adds pathPrefix if defined`, async () => {
@@ -400,12 +408,15 @@ describe(`gatsby-plugin-sharp`, () => {
400408

401409
describe(`base64`, () => {
402410
it(`converts image to base64`, async () => {
403-
const result = await base64({
411+
const { src, ...result } = await base64({
404412
file,
405413
args,
406414
})
407415

408416
expect(result).toMatchSnapshot()
417+
418+
const rawPixelData = await decodeBase64PngAsRaw(src)
419+
expect(rawPixelData.toString(`hex`)).toMatchSnapshot()
409420
})
410421

411422
it(`should cache same image`, async () => {
@@ -597,25 +608,31 @@ describe(`gatsby-plugin-sharp`, () => {
597608
base64: false,
598609
}
599610

600-
const fixedSvg = await fixed({
611+
const { tracedSVG: fixedTracedSVG, ...fixedSvg } = await fixed({
601612
file,
602613
args,
603614
})
604615

605616
expect(fixedSvg).toMatchSnapshot(`fixed`)
606617

607-
expect(fixedSvg.tracedSVG).toMatch(`data:image/png;base64`)
608-
expect(fixedSvg.tracedSVG).not.toMatch(`data:image/svg+xml`)
618+
expect(fixedTracedSVG).toMatch(`data:image/png;base64`)
619+
expect(fixedTracedSVG).not.toMatch(`data:image/svg+xml`)
620+
621+
const fixedRawPixelData = await decodeBase64PngAsRaw(fixedTracedSVG)
622+
expect(fixedRawPixelData.toString(`hex`)).toMatchSnapshot()
609623

610-
const fluidSvg = await fluid({
624+
const { tracedSVG: fluidTracedSVG, ...fluidSvg } = await fluid({
611625
file,
612626
args,
613627
})
614628

615629
expect(fluidSvg).toMatchSnapshot(`fluid`)
616630

617-
expect(fluidSvg.tracedSVG).toMatch(`data:image/png;base64`)
618-
expect(fluidSvg.tracedSVG).not.toMatch(`data:image/svg+xml`)
631+
expect(fluidTracedSVG).toMatch(`data:image/png;base64`)
632+
expect(fluidTracedSVG).not.toMatch(`data:image/svg+xml`)
633+
634+
const fluidRawPixelData = await decodeBase64PngAsRaw(fluidTracedSVG)
635+
expect(fluidRawPixelData.toString(`hex`)).toMatchSnapshot()
619636
})
620637
})
621638

@@ -627,13 +644,20 @@ describe(`gatsby-plugin-sharp`, () => {
627644
}
628645

629646
it(`fixed`, async () => {
630-
const result = await fixed({ file, args })
647+
const { base64, ...result } = await fixed({ file, args })
648+
631649
expect(result).toMatchSnapshot()
650+
651+
const rawPixelData = await decodeBase64PngAsRaw(base64)
652+
expect(rawPixelData.toString(`hex`)).toMatchSnapshot()
632653
})
633654

634655
it(`fluid`, async () => {
635-
const result = await fluid({ file, args })
656+
const { base64, ...result } = await fluid({ file, args })
636657
expect(result).toMatchSnapshot()
658+
659+
const rawPixelData = await decodeBase64PngAsRaw(base64)
660+
expect(rawPixelData.toString(`hex`)).toMatchSnapshot()
637661
})
638662

639663
it(`creates two different images for different duotone settings`, async () => {

packages/gatsby-remark-images-contentful/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"is-relative-url": "^3.0.0",
2323
"lodash": "^4.17.21",
2424
"semver": "^7.5.3",
25-
"sharp": "^0.32.1",
25+
"sharp": "^0.32.6",
2626
"unist-util-select": "^3.0.4"
2727
},
2828
"devDependencies": {

packages/gatsby-sharp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"types": "dist/index.d.ts",
1515
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-sharp#readme",
1616
"dependencies": {
17-
"sharp": "^0.32.1"
17+
"sharp": "^0.32.6"
1818
},
1919
"devDependencies": {
2020
"@babel/cli": "^7.20.7",

packages/gatsby-source-contentful/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"gatsby": "^5.0.0-next",
4545
"gatsby-plugin-image": "^3.0.0-next",
4646
"gatsby-plugin-sharp": "^5.0.0-next",
47-
"sharp": "^0.30.1"
47+
"sharp": "^0.32.6"
4848
},
4949
"repository": {
5050
"type": "git",
0 Bytes
Loading
0 Bytes
Loading

0 commit comments

Comments
 (0)