Skip to content

Commit fe0b5de

Browse files
ascorbicgillkyleLauriegatsbybot
authored
feat(gatsby-transformer-sharp): Resolver API changes (#27783)
* Add static image plugin * Parse static image files * Fix package.json * Better static analysis * Use jsx utils package * Fix typings * Typecheck fix * Fix repo fields * Helpful warning * Re-enable duotone * Update readme * Improve typings * wip fixed image fields for tracedSVG and webP * handle fluid images as well * Use require rather than JSON import * Watch files for changes, and use relative paths * Improve types * Add type * Update yarn.lock * Add lots of comments and remove unused stuff * Create and watch our own nodes * Update readme * Update deps * Only watch in develop * Rename to gatsby-plugin-image * Rearrange, ready for merger * Import @wardpeet 's gatsby-image-netxtgen * Update typings and further merge packages * Build babel plugin * More merging * Add server/browser static image variants * include webpack changes * change error message to use gatsby-plugin-image * Fix compat compilation * Fix SSR * Merge readmes * Build browser bundle * Export correctly from browser entry point * Remove hook import * Apply suggestions from code review Co-authored-by: LB <[email protected]> * Changes from review * add path prefix, static image do e2e test * Add prepare script * Apply README suggestions from code review Co-authored-by: LB <[email protected]> * Fix image component in e2e test * Better error messages * Prefer svg over base64. Warn for unsupported art direction * Fix type * Use "layout" instead of fixed/fluid * add static images to production runtime site * add path prefix tests * Reorg types. Change private prop name * initial gatsby static image tests * add test suite to circle ci * add test suite to circle ci * add test suite to circle ci * remove unused imports, use valid fluid setting * Use new fluid props syntax * Better var name * update tests * remove tests that no longer match the expected DOM * More compat-fixes * Change classname to match old version * Compat improvements * Update tests to match new classname * v0.0.1 * Add readme caveat * Update version in packages * Remove forcewrapper * wip * have static image use gatsbyImageProps function * Upgrade sharp * Fix static image type * First steps to update API * Add descriptions * TypeScript fixes * Compile ts * Add @gillkyle's calculateImageSizes util funciton * remove unused file * unbump sharp until sharp PR is merged * comment out import * update snapshots * change JSX to take image prop * static image uses new image props * Rename all the things * Turns out it wasn't all of them * Update schema * fix intrinsic issue 1px problem, still doesn't seem to reach the correct max size * Fix layout * Update readme * Fix dep * Shouldn;t be in this * Fix sharp function name * Version * What is this snapshot out of date? * Add a helper funciton * Make backgroundColor work * update layout for images * no longer using base64 so remove that test * placeholder not getting passed from static, so this is still busted * Fix passing of props * Add TODO comments * Export batch queue function * Handle the default sizes elsewhere, as it depends on layout * feat(gatsby-plugin-sharp): create image sizes helper (#27554) * wip tests and tweaks to utility * more wip tests * remove file reading from helper * fixing fluid calculations and adding more tests * tweak a little more * remove extraneous export * check that user specified dimensions are positive * remove unnecessary code from review suggestions * add warning, simplify case of no fluid dimensions * add files to warnings and clean up logic * Split into two functions and remove 3x default * Rename warn function and use reporter Co-authored-by: Matt Kane <[email protected]> * Use passed-in reporter * Use shared function to handle fit calculation * Return presentationW/H and aspect ratio from sizes function * Round sizes * Use new resizing functions * default layout wasn't passed to createImageSizes * add fixed width default and round calculated height * reversed logic for aspect ratio calculations * Correct description for outputPixelDensities resolver * Remove log * Handle null image in SSR * Version fix * fix(gatsby-plugin-utils): skip libcheck during typegen * Remove unused func * Remove dominantColor from fixed and fluid * sizing code for KG to drive refactor * remove isSmaller * fix tests * Fix sizes and srcset generation * Add object-fit * rename placeholder function for consistency * Update readme * fix path prefix images * fix sizing when larger image dimensions are requested, fix warning as well * rename file to match constrained naming * Changes from review * Add alpha warning * Change from review * fix placeholder opacity * fix placeholder bug * only change placeholder size for background color div * tests: Add visual regression tests (#27619) * tests: Add visual regression tests * Add config * Wait for images to load * Do multiple window sizes * Adjust settings for comparisons * Fix wrapper * Add 1024 window * Save reports * Update fixed image too large snapshot * Disable video * Update readme * Update element id * Force 1x pixel density * Update readme * Fix e2e test * dont flash placeholder image when removing opacity * Fix dependency * Continue moving options into options objects * Update API * Default to blurred * Fix test * Fix default * Change from review * Updates to fixed sizing * Update snapshots * fix readme, clean up unused variable * fix lint * weird readme lint issue Co-authored-by: Kyle Gill <[email protected]> Co-authored-by: Laurie <[email protected]> Co-authored-by: gatsbybot <[email protected]>
1 parent 07eeb2e commit fe0b5de

30 files changed

+345
-177
lines changed

e2e-tests/visual-regression/src/pages/images/constrained.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "cornwall.jpg" }) {
1111
childImageSharp {
12-
gatsbyImage(maxWidth: 1024, layout: CONSTRAINED) {
13-
imageData
14-
}
12+
gatsbyImageData(maxWidth: 1024, layout: CONSTRAINED)
1513
}
1614
}
1715
}

e2e-tests/visual-regression/src/pages/images/fixed-too-big.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "landsend.jpg" }) {
1111
childImageSharp {
12-
gatsbyImage(width: 500, height: 500, layout: FIXED) {
13-
imageData
14-
}
12+
gatsbyImageData(width: 500, height: 500, layout: FIXED)
1513
}
1614
}
1715
}

e2e-tests/visual-regression/src/pages/images/fixed.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "cornwall.jpg" }) {
1111
childImageSharp {
12-
gatsbyImage(width: 240, height: 100, layout: FIXED) {
13-
imageData
14-
}
12+
gatsbyImageData(width: 240, height: 100, layout: FIXED)
1513
}
1614
}
1715
}

e2e-tests/visual-regression/src/pages/images/fluid.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const Page = () => {
99
query {
1010
file(relativePath: { eq: "cornwall.jpg" }) {
1111
childImageSharp {
12-
gatsbyImage(maxWidth: 1024, layout: FLUID) {
13-
imageData
14-
}
12+
gatsbyImageData(maxWidth: 1024, layout: FLUID)
1513
}
1614
}
1715
}

e2e-tests/visual-regression/src/pages/static-images/constrained.js

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ const Page = () => {
1313
layout="constrained"
1414
alt="cornwall"
1515
maxWidth={1024}
16-
placeholder="blurred"
17-
webP
1816
/>
1917
</TestWrapper>
2018
</Layout>

packages/gatsby-plugin-image/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ export const query = graphql`
284284
childImageSharp {
285285
# Specify the image processing specifications right in the query.
286286
# Makes it trivial to update as your page's design changes.
287-
gatsbyImage(layout: FIXED, width: 125, height: 125) {
288-
imageData
289-
}
287+
gatsbyImageData(layout: FIXED, width: 125, height: 125)
290288
}
291289
}
292290
}

packages/gatsby-plugin-image/src/babel-helpers.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,17 @@ export const SHARP_ATTRIBUTES = new Set([
99
`maxWidth`,
1010
`maxHeight`,
1111
`quality`,
12-
`jpegQuality`,
13-
`pngQuality`,
14-
`webpQuality`,
15-
`grayscale`,
16-
`toFormat`,
17-
`cropFocus`,
18-
`pngCompressionSpeed`,
19-
`rotate`,
20-
`duotone`,
12+
`jpegOptions`,
13+
`pngOptions`,
14+
`webpOptions`,
15+
`blurredOptions`,
16+
`transformOptions`,
2117
`width`,
2218
`height`,
2319
`placeholder`,
2420
`tracedSVGOptions`,
25-
`webP`,
26-
`outputPixelDensities`,
2721
`sizes`,
28-
`fit`,
2922
`background`,
30-
`base64Width`,
31-
`jpegProgressive`,
32-
`toFormatBase64`,
33-
`trim`,
34-
`srcSetBreakpoints`,
3523
])
3624

3725
export function evaluateImageAttributes(

packages/gatsby-plugin-image/src/components/hooks.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ export function hasImageLoaded(cacheKey: string): boolean {
3232

3333
export type FileNode = Node & {
3434
childImageSharp?: Node & {
35-
gatsbyImage?: Node & {
36-
imageData: ISharpGatsbyImageData
37-
}
35+
gatsbyImageData?: ISharpGatsbyImageData
3836
}
3937
}
4038

4139
export const getImage = (file: FileNode): ISharpGatsbyImageData | undefined =>
42-
file?.childImageSharp?.gatsbyImage?.imageData
40+
file?.childImageSharp?.gatsbyImageData
4341

4442
export function getWrapperProps(
4543
width: number,

packages/gatsby-plugin-image/src/utils.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface ICommonImageProps {
3030
export interface IFluidImageProps extends ICommonImageProps {
3131
maxWidth?: number
3232
maxHeight?: number
33-
srcSetBreakpoints?: Array<number>
3433
fit?: number
3534
background?: number
3635
}

packages/gatsby-plugin-sharp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"devDependencies": {
3030
"@babel/cli": "^7.11.6",
3131
"@babel/core": "^7.11.6",
32+
"@types/sharp": "^0.26.0",
3233
"babel-preset-gatsby-package": "^0.6.0-next.0",
3334
"cross-env": "^7.0.2",
3435
"gatsby-plugin-image": "^0.1.0-next.0"

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

+60-12
Original file line numberDiff line numberDiff line change
@@ -292,28 +292,52 @@ describe(`calculateImageSizes (fluid & constrained)`, () => {
292292
const testsCases = [
293293
{ args: { maxWidth: 20, maxHeight: 20 }, result: [20, 20] },
294294
{
295-
args: { maxWidth: 20, maxHeight: 20, fit: sharp.fit.fill },
295+
args: {
296+
maxWidth: 20,
297+
maxHeight: 20,
298+
transformOptions: { fit: sharp.fit.fill },
299+
},
296300
result: [20, 20],
297301
},
298302
{
299-
args: { maxWidth: 20, maxHeight: 20, fit: sharp.fit.inside },
303+
args: {
304+
maxWidth: 20,
305+
maxHeight: 20,
306+
transformOptions: { fit: sharp.fit.inside },
307+
},
300308
result: [20, 10],
301309
},
302310
{
303-
args: { maxWidth: 20, maxHeight: 20, fit: sharp.fit.outside },
311+
args: {
312+
maxWidth: 20,
313+
maxHeight: 20,
314+
transformOptions: { fit: sharp.fit.outside },
315+
},
304316
result: [41, 20],
305317
},
306318
{ args: { maxWidth: 200, maxHeight: 200 }, result: [200, 200] },
307319
{
308-
args: { maxWidth: 200, maxHeight: 200, fit: sharp.fit.fill },
320+
args: {
321+
maxWidth: 200,
322+
maxHeight: 200,
323+
transformOptions: { fit: sharp.fit.fill },
324+
},
309325
result: [200, 200],
310326
},
311327
{
312-
args: { maxWidth: 200, maxHeight: 200, fit: sharp.fit.inside },
328+
args: {
329+
maxWidth: 200,
330+
maxHeight: 200,
331+
transformOptions: { fit: sharp.fit.inside },
332+
},
313333
result: [200, 97],
314334
},
315335
{
316-
args: { maxWidth: 200, maxHeight: 200, fit: sharp.fit.outside },
336+
args: {
337+
maxWidth: 200,
338+
maxHeight: 200,
339+
transformOptions: { fit: sharp.fit.outside },
340+
},
317341
result: [413, 200],
318342
},
319343
]
@@ -341,28 +365,52 @@ describe(`calculateImageSizes (fluid & constrained)`, () => {
341365
const testsCases = [
342366
{ args: { width: 20, height: 20 }, result: [20, 20] },
343367
{
344-
args: { width: 20, height: 20, fit: sharp.fit.fill },
368+
args: {
369+
width: 20,
370+
height: 20,
371+
transformOptions: { fit: sharp.fit.fill },
372+
},
345373
result: [20, 20],
346374
},
347375
{
348-
args: { width: 20, height: 20, fit: sharp.fit.inside },
376+
args: {
377+
width: 20,
378+
height: 20,
379+
transformOptions: { fit: sharp.fit.inside },
380+
},
349381
result: [20, 10],
350382
},
351383
{
352-
args: { width: 20, height: 20, fit: sharp.fit.outside },
384+
args: {
385+
width: 20,
386+
height: 20,
387+
transformOptions: { fit: sharp.fit.outside },
388+
},
353389
result: [41, 20],
354390
},
355391
{ args: { width: 200, height: 200 }, result: [200, 200] },
356392
{
357-
args: { width: 200, height: 200, fit: sharp.fit.fill },
393+
args: {
394+
width: 200,
395+
height: 200,
396+
transformOptions: { fit: sharp.fit.fill },
397+
},
358398
result: [200, 200],
359399
},
360400
{
361-
args: { width: 200, height: 200, fit: sharp.fit.inside },
401+
args: {
402+
width: 200,
403+
height: 200,
404+
transformOptions: { fit: sharp.fit.inside },
405+
},
362406
result: [200, 97],
363407
},
364408
{
365-
args: { width: 200, height: 200, fit: sharp.fit.outside },
409+
args: {
410+
width: 200,
411+
height: 200,
412+
transformOptions: { fit: sharp.fit.outside },
413+
},
366414
result: [413, 200],
367415
},
368416
]

0 commit comments

Comments
 (0)