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

chore(gatsby-plugin-manifest): add pluginOptionsSchema #27421

Merged
merged 2 commits into from
Oct 16, 2020
Merged
Changes from all 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
41 changes: 41 additions & 0 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,49 @@ async function checkCache(cache, icon, srcIcon, srcIconDigest, callback) {
}
}

if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) {
exports.pluginOptionsSchema = ({ Joi }) => {
Joi.object({
name: Joi.string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering, shouldn't we always provide a description of the option in the schema - at least for plugins living in the monorepo?

Copy link
Contributor Author

@mxstbr mxstbr Oct 13, 2020

Choose a reason for hiding this comment

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

100% but it's kinda hard to provide descriptions for all of these as they simply correspond to the standard web app manifest options (https://web.dev/add-manifest/) or require extensive understanding of the docs 😬

short_name: Joi.string(),
description: Joi.string(),
lang: Joi.string(),
localize: Joi.array().items(
Joi.object({
start_url: Joi.string(),
name: Joi.string(),
short_name: Joi.string(),
description: Joi.string(),
lang: Joi.string(),
})
),
start_url: Joi.string(),
background_color: Joi.string(),
theme_color: Joi.string(),
display: Joi.string(),
legacy: Joi.boolean(),
include_favicon: Joi.boolean(),
icon: Joi.string(),
theme_color_in_head: Joi.boolean(),
crossOrigin: Joi.string().valid(`use-credentials`, `anonymous`),
cache_busting_mode: Joi.string().valid(`query`, `name`, `none`),
icons: Joi.array().items(
Joi.object({
src: Joi.string(),
sizes: Joi.string(),
type: Joi.string(),
})
),
icon_options: Joi.object({
purpose: Joi.string(),
}),
})
}
}

/**
* Setup pluginOption defaults
* TODO: Remove once pluginOptionsSchema is stable
*/
exports.onPreInit = (_, pluginOptions) => {
pluginOptions.cache_busting_mode = pluginOptions.cache_busting_mode ?? `query`
Expand Down