Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): Add root to plugin validation (#29010)
Browse files Browse the repository at this point in the history
* add root and a TODO notice

* Update packages/gatsby-plugin-mdx/gatsby-node.js
  • Loading branch information
LekoArts committed Jan 18, 2021
1 parent 6233382 commit 3163ca6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-mdx/__tests__/gatsby-node.js
Expand Up @@ -16,6 +16,7 @@ describe(`pluginOptionsSchema`, () => {
`"mediaTypes[0]" must be a string`,
`"mediaTypes[1]" must be a string`,
`"shouldBlockNodeFromTransformation" must have an arity lesser or equal to 1`,
`"root" must be a string`,
]

const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, {
Expand All @@ -27,6 +28,7 @@ describe(`pluginOptionsSchema`, () => {
plugins: [2],
mediaTypes: [1, 2],
shouldBlockNodeFromTransformation: (wrong, number) => null,
root: 1,
})

expect(errors).toEqual(expectedErrors)
Expand Down Expand Up @@ -60,6 +62,7 @@ describe(`pluginOptionsSchema`, () => {
],
mediaTypes: [`text/markdown`, `text/x-markdown`, `custom-media/type`],
shouldBlockNodeFromTransformation: node => Boolean(node),
root: `james-holden`,
})

expect(isValid).toBe(true)
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-mdx/gatsby-node.js
Expand Up @@ -122,5 +122,8 @@ exports.pluginOptionsSchema = function ({ Joi }) {
.description(
`Disable MDX transformation for nodes where this function returns true`
),
root: Joi.string()
.default(process.cwd())
.description(`[deprecated] This is a legacy option that used to define root directory of the project. It was needed to generate a cache directory location. It currently has no effect.`)
})
}
1 change: 1 addition & 0 deletions packages/gatsby-plugin-mdx/utils/default-options.js
Expand Up @@ -17,6 +17,7 @@ module.exports = ({ mdPlugins, hastPlugins, ...pluginOptions }) => {
plugins: [],
root: process.cwd(),
gatsbyRemarkPlugins: [],
// TODO: Remove globalScope option in next major as it's deprecated in favor of shortcodes, see https://github.com/ChristopherBiscardi/gatsby-mdx/issues/239#issuecomment-507322221
globalScope: `export default {}`,
shouldBlockNodeFromTransformation: () => false,
},
Expand Down

0 comments on commit 3163ca6

Please sign in to comment.