Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a deprecation warning to a plugin? #6974

Closed
lightstrike opened this issue Aug 2, 2018 · 3 comments
Closed

How to add a deprecation warning to a plugin? #6974

lightstrike opened this issue Aug 2, 2018 · 3 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@lightstrike
Copy link
Contributor

I'd like to include some deprecation warnings in a PR I'm working on for gatsby-source-wordpress -- it seems like onPreInit could be a good place to check user-specified configuration options, but it's not clear to me if the config options are available to this step. How can I achieve something like the following:

const report = require(`gatsby-cli/lib/reporter`)

exports.onPreInit = async ( { userConfig } ) => {
  if (userConfig.useACF) {
    report.warn(
      `ACF functionality will be removed from gatsby-source-wordpress v4. Please migrate to gatsby-wordpress-acf.`
    )
  }
}  
@Chuloo Chuloo added the type: question or discussion Issue discussing or asking a question about Gatsby label Aug 2, 2018
@Chuloo
Copy link
Contributor

Chuloo commented Aug 2, 2018

Hi, @m-allanson is this something you can help with?

@m-allanson
Copy link
Contributor

👍 @lightstrike, pluginOptions should get passed in as the second argument.

Here's an example from gatsby-transformer-screenshot that uses pluginOptions at the onPreBootstrap stage, which happens just after onPreInit:

exports.onPreBootstrap = (
{ store, cache, actions, createNodeId, getNodes },
pluginOptions
) => {

There's a tutorial that runs through this in more detail at https://next.gatsbyjs.org/docs/source-plugin-tutorial/. I thought we had an issue for improving the API docs but having trouble finding it right now..

@lightstrike
Copy link
Contributor Author

Thanks @m-allanson, confirming this works perfectly inside gatsby-node.js:

const report = require(`gatsby-cli/lib/reporter`)

exports.onPreBootstrap = ( {}, pluginOptions ) => {
  if (pluginOptions.useACF) {
    report.warn(
      `\n\nACF functionality will be removed from gatsby-source-wordpress v4. Please migrate to gatsby-wordpress-acf.\n\n`
    )
  }
}

I believe #4120 is the API docs issue, I've bookmarked this comment of yours about helper functions, which has been super helpful but should definitely find its way into docs someday 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants