From 7788f068eab193ea20786aa12b8d838fa6dbbb91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Tue, 22 Dec 2020 12:16:05 +0100 Subject: [PATCH] make gatsby-plugin-image a dependency again and warn users about the beta feature --- .../gatsby-source-contentful/package.json | 1 + .../src/extend-node-type.js | 26 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/gatsby-source-contentful/package.json b/packages/gatsby-source-contentful/package.json index 5bbdd99da6ddb..aedfb34f9ea26 100644 --- a/packages/gatsby-source-contentful/package.json +++ b/packages/gatsby-source-contentful/package.json @@ -18,6 +18,7 @@ "contentful": "^7.14.12", "fs-extra": "^9.0.1", "gatsby-core-utils": "^1.8.0-next.0", + "gatsby-plugin-image": "^0.4.0-next.3", "gatsby-plugin-utils": "^0.7.0-next.1", "gatsby-source-filesystem": "^2.9.0-next.1", "is-online": "^8.5.1", diff --git a/packages/gatsby-source-contentful/src/extend-node-type.js b/packages/gatsby-source-contentful/src/extend-node-type.js index 132e793d59954..608357ce9d88f 100644 --- a/packages/gatsby-source-contentful/src/extend-node-type.js +++ b/packages/gatsby-source-contentful/src/extend-node-type.js @@ -13,6 +13,9 @@ const { } = require(`gatsby/graphql`) const qs = require(`qs`) const base64Img = require(`base64-img`) +const { generateImageData } = require(`gatsby-plugin-image`) +const { getGatsbyImageFieldConfig } = require(`gatsby-plugin-image/graphql`) +const { stripIndent } = require(`common-tags`) const cacheImage = require(`./cache-image`) @@ -190,7 +193,6 @@ const fitMap = new Map([ ]) const resolveGatsbyImageData = async (image, options) => { - const { generateImageData } = require(`gatsby-plugin-image`) const { baseUrl, ...sourceMetadata } = getBasicImageProps(image, options) return generateImageData({ @@ -646,7 +648,9 @@ const fluidNodeType = ({ name, getTracedSVG }) => { } } -exports.extendNodeType = ({ type, store }) => { +let warnedForBeta = false + +exports.extendNodeType = ({ type, store, reporter }) => { if (type.name !== `ContentfulAsset`) { return {} } @@ -690,19 +694,15 @@ exports.extendNodeType = ({ type, store }) => { const sizesNode = fluidNodeType({ name: `ContentfulSizes`, getTracedSVG }) sizesNode.deprecationReason = `Sizes was deprecated in Gatsby v2. It's been renamed to "fluid" https://example.com/write-docs-and-fix-this-example-link` - // gatsby-pugin-image + // gatsby-plugin-image const getGatsbyImageData = () => { - // @todo check if gatsby-plugin-image is enabled - const gatsbyImageEnabled = false - if (!gatsbyImageEnabled) { - return { - type: GraphQLString, - deprecated: true, - deprecationReason: `Enable gatsby-plugin-image to use this field.`, - resolve: () => 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 { getGatsbyImageFieldConfig } = require(`gatsby-plugin-image/graphql`) return getGatsbyImageFieldConfig(resolveGatsbyImageData, { jpegProgressive: {