Skip to content

Commit

Permalink
chore: Deprecate gatsby-image and old image resolvers (#29667)
Browse files Browse the repository at this point in the history
* chore: Deprecate gatsby-image and old image resolvers

* Add plugin name
  • Loading branch information
ascorbic committed Feb 22, 2021
1 parent b95a199 commit 3ffc210
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/gatsby-image/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## :warning: This package is now deprecated

The `gatsby-image` package is now deprecated. The new [Gatsby image plugin](https://www.gatsbyjs.com/plugins/gatsby-plugin-image) has better performance, cool new features and a simpler API. See [the migration guide](https://www.gatsbyjs.com/docs/reference/release-notes/image-migration-guide/) to learn how to upgrade.

# gatsby-image

Speedy, optimized images without the work.
Expand Down
4 changes: 1 addition & 3 deletions packages/gatsby-plugin-image/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# gatsby-plugin-image (beta)

_The new Gatsby Image plugin is currently in beta, but you can try it out now_
# gatsby-plugin-image

Adding responsive images to your site while maintaining high performance scores can be difficult to do manually. The Gatsby Image plugin handles the hard parts of producing images in multiple sizes and formats for you!

Expand Down
23 changes: 14 additions & 9 deletions packages/gatsby-transformer-sharp/src/customize-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const {
const { stripIndent } = require(`common-tags`)
const { prefixId, CODES } = require(`./error-utils`)

let warnedForDeprecation = false

function warnForDeprecation() {
if (warnedForDeprecation) {
return
}
warnedForDeprecation = true
console.warn(
`[gatsby-transformer-sharp] The "fixed" and "fluid" resolvers are now deprecated. Switch to "gatsby-plugin-image" for better performance and a simpler API. See https://gatsby.dev/migrate-images to learn how.`
)
}

function toArray(buf) {
const arr = new Array(buf.length)

Expand Down Expand Up @@ -200,6 +212,7 @@ const fixedNodeType = ({
},
},
resolve: (image, fieldArgs, context) => {
warnForDeprecation()
const file = getNodeAndSavePathDependency(image.parent, context.path)
const args = { ...fieldArgs, pathPrefix }
return Promise.resolve(
Expand Down Expand Up @@ -366,6 +379,7 @@ const fluidNodeType = ({
},
},
resolve: (image, fieldArgs, context) => {
warnForDeprecation()
const file = getNodeAndSavePathDependency(image.parent, context.path)
const args = { ...fieldArgs, pathPrefix }
return Promise.resolve(
Expand All @@ -386,8 +400,6 @@ const fluidNodeType = ({
}
}

let warnedForBeta = false

const imageNodeType = ({
pathPrefix,
getNodeAndSavePathDependency,
Expand Down Expand Up @@ -515,13 +527,6 @@ const imageNodeType = ({
reporter.warn(`Please upgrade gatsby-plugin-sharp`)
return null
}
if (!warnedForBeta) {
reporter.warn(
stripIndent`
Thank you for trying the beta version of the \`gatsbyImageData\` API. Please provide feedback and report any issues at: https://github.com/gatsbyjs/gatsby/discussions/27950`
)
warnedForBeta = true
}
const imageData = await generateImageData({
file,
args: fieldArgs,
Expand Down

0 comments on commit 3ffc210

Please sign in to comment.