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

fix(validation): allow non-object params to remark/rehype plugins #6977

Merged
merged 1 commit into from
Mar 24, 2022

Conversation

aloisklink
Copy link
Contributor

Remark and Rehype plugins allow having options as a non-object type, such as a string.

For instance, the official MDX docs even have an example of this:

import {compile} from '@mdx-js/mdx'
// ...
import remarkFrontmatter from 'remark-frontmatter'
// ...
const file = '# hi'
// ...
// A plugin with options:
await compile(file, {remarkPlugins: [[remarkFrontmatter, 'toml']]})

Copied from https://mdxjs.com/docs/extending-mdx/#using-plugins

This describes an official remarkjs plugin: remarkjs/remark-frontmatter, which allows passing a string (e.g. "toml") as the options arg, instead of an object.

Apparently it may also be possible for a unified plugin to have multiple option parameters (see docs), however:

  • the docs explicitly discourage this, and
  • I'm not sure if this applies to remark/rehype plugins, since I've never seen a remark/rehype plugin that supports this

Motivation

Docusaurus validation is too strict for remarkPlugins and rehypePlugins.

Have you read the Contributing Guidelines on pull requests?

Yes ✔️

Test Plan

I've added a test case in packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts

Additionally, I've also tested by doing the following:

npx create-docusaurus@latest my-website classic
cd my-website
# version 4+ is ESM only, so require() doesn't work
npm install remark-frontmatter@3
# add to docusaurus.confing.js: remarkPlugins: [[require("remark-frontmatter"), "toml"]],
vim docusaurus.config.js
# doesn't work due to 
# [ERROR] ValidationError: "remarkPlugins[0]" does not match any of the allowed types
npm start

However, once I modified the node_modules/@docusaurus/utils-validation/lib/validationSchemas.js to match this PR, npm start worked!

Related PRs

#4412 would have made this bug a lot easier to debug.

Additionally, #4412 (comment) has some discussion about whether:

is correct. From my research, I also agree that it's unlikely that it will work too (but I'm not certain)

Remark and Rehype plugins allow having options as a non-object type,
such as a string.

For instance, the official MDX docs even have an example of this:
See https://mdxjs.com/docs/extending-mdx/#using-plugins

The official plugin `remarkjs/remark-frontmatter` allows passing
a string, e.g. `"toml"` as the options arg, instead of an object.
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 24, 2022
@netlify
Copy link

netlify bot commented Mar 24, 2022

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit b67185b
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/623bc2ce5864ec000851f078
😎 Deploy Preview https://deploy-preview-6977--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 57
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6977--docusaurus-2.netlify.app/

Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

Thanks!

@Josh-Cena Josh-Cena merged commit 4d2ab82 into facebook:main Mar 24, 2022
@Josh-Cena Josh-Cena added the pr: bug fix This PR fixes a bug in a past release. label Mar 24, 2022
@aloisklink aloisklink deleted the fix-markdown-plugins-schema branch March 24, 2022 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants