Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): remark/hypePlugins options schema (#27698)
Browse files Browse the repository at this point in the history
* fix(gatsby-plugin-mdx): remark/hypePlugins options schema

* Fix typo

* Fix tests
  • Loading branch information
mxstbr authored Oct 28, 2020
1 parent fcb22eb commit 21f24f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/gatsby-plugin-mdx/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe(`pluginOptionsSchema`, () => {
`"extensions[0]" must be a string`,
`"extensions[1]" must be a string`,
`"extensions[2]" must be a string`,
`"defaultLayout" must be of type object`,
`"defaultLayouts" must be of type object`,
`"gatsbyRemarkPlugins[0]" does not match any of the allowed types`,
`"gatsbyRemarkPlugins[1]" does not match any of the allowed types`,
`"remarkPlugins" must be an array`,
Expand All @@ -19,7 +19,7 @@ describe(`pluginOptionsSchema`, () => {

const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, {
extensions: [1, 2, 3],
defaultLayout: `this should be an object`,
defaultLayouts: `this should be an object`,
gatsbyRemarkPlugins: [1, { not: `existing prop` }, `valid one`],
remarkPlugins: `this should be an array of object`,
rehypePlugins: `this should be an array of object`,
Expand All @@ -33,7 +33,7 @@ describe(`pluginOptionsSchema`, () => {
it(`should validate the schema`, async () => {
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, {
extensions: [`.mdx`, `.mdxx`],
defaultLayout: {
defaultLayouts: {
posts: `../post-layout.js`,
default: `../default-layout.js`,
},
Expand Down
24 changes: 19 additions & 5 deletions packages/gatsby-plugin-mdx/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require(`fs`)

const {
onCreateNode,
unstable_shouldOnCreateNode
unstable_shouldOnCreateNode,
} = require(`./gatsby/on-create-node`)

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) {
.description(
`Configure the file extensions that gatsby-plugin-mdx will process`
),
defaultLayout: Joi.object({})
defaultLayouts: Joi.object({})
.unknown(true)
.default({})
.description(`Set the layout components for MDX source types`),
Expand All @@ -94,17 +94,31 @@ if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) {
remarkPlugins: Joi.array()
.items(
Joi.alternatives().try(
Joi.object({}).unknown(true),
Joi.array().items(Joi.object({}).unknown(true))
Joi.alternatives().try(
Joi.function(),
Joi.object({}).unknown(true),
Joi.array().items(
Joi.alternatives().try(
Joi.object({}).unknown(true),
Joi.function()
)
)
)
)
)
.default([])
.description(`Specify remark plugins`),
rehypePlugins: Joi.array()
.items(
Joi.alternatives().try(
Joi.function(),
Joi.object({}).unknown(true),
Joi.array().items(Joi.object({}).unknown(true))
Joi.array().items(
Joi.alternatives().try(
Joi.object({}).unknown(true),
Joi.function()
)
)
)
)
.default([])
Expand Down

0 comments on commit 21f24f8

Please sign in to comment.