From 21f24f8d833a01bae7ac9a8573c41b37315b4fcc Mon Sep 17 00:00:00 2001 From: Max Stoiber Date: Wed, 28 Oct 2020 22:38:04 +0100 Subject: [PATCH] fix(gatsby-plugin-mdx): remark/hypePlugins options schema (#27698) * fix(gatsby-plugin-mdx): remark/hypePlugins options schema * Fix typo * Fix tests --- .../__tests__/gatsby-node.js | 6 ++--- packages/gatsby-plugin-mdx/gatsby-node.js | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js b/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js index 18c798689f8c4..a67121edb6699 100644 --- a/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js @@ -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`, @@ -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`, @@ -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`, }, diff --git a/packages/gatsby-plugin-mdx/gatsby-node.js b/packages/gatsby-plugin-mdx/gatsby-node.js index e39974ed0a1c9..e7667755a8f2c 100644 --- a/packages/gatsby-plugin-mdx/gatsby-node.js +++ b/packages/gatsby-plugin-mdx/gatsby-node.js @@ -6,7 +6,7 @@ const fs = require(`fs`) const { onCreateNode, - unstable_shouldOnCreateNode + unstable_shouldOnCreateNode, } = require(`./gatsby/on-create-node`) /** @@ -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`), @@ -94,8 +94,16 @@ 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([]) @@ -103,8 +111,14 @@ if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) { 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([])