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

feat(gatsby): add opt out flag SKIP_PLUGIN_OPTION_VALIDATION to bypass validation #27885

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/docs/configuring-usage-with-plugin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ describe(`pluginOptionsSchema`, () => {
})
```

### Opting out of plugin option validation

If you are running your site and run into an error trying to develop or build your site due to plugin options failing that are undocumented or seem erroneous, you can add the `SKIP_PLUGIN_OPTION_VALIDATION` flag set to `true`. It can be prepended to your develop and build scripts, included as an [environment variable](/docs/environment-variables/) in a .env file, or included before your `gatsby develop` command like this:

```shell
SKIP_PLUGIN_OPTION_VALIDATION=true gatsby develop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding, feel free to ignore/postpone

I'd rather not add this to the docs so explicitly because we don't really want people to use this unless they have a blocking error.

I would prefer if we add that information to the error log if they have an error with an ominous warning, for example something like:

success open and validate gatsby-configs - 0.017s

 ERROR #11331  PLUGIN

Invalid plugin options for "gatsby-plugin-manifest":

- "name" must be a string

If you are certain your configuration is correct, you can disable configuration validation with the SKIP_PLUGIN_OPTION_VALIDATION environment variable. Be careful, this could have unintended side effects!

not finished load plugins - 2.391s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, this is a fun one. Ya, I totally see what you mean. At the same time, how often do people skip error messages and go googling? No strong feelings, just a weird thought exercise.

```

gillkyle marked this conversation as resolved.
Show resolved Hide resolved
## Additional resources

- [Example Gatsby site using plugin options with a local plugin](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-plugin-options)
Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby/src/bootstrap/load-plugins/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ export async function validateConfigPluginsOptions(
rootDir: string | null
): Promise<void> {
if (!config.plugins) return
if (process.env.SKIP_PLUGIN_OPTION_VALIDATION) {
reporter.warn(`you have enabled the SKIP_PLUGIN_OPTION_VALIDATION flag,`)
reporter.warn(
`meaning Gatsby will not enforce types based on plugin's option schemas.`
gillkyle marked this conversation as resolved.
Show resolved Hide resolved
)
return
}

const { errors, plugins } = await validatePluginsOptions(
config.plugins,
Expand Down