npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docusaurus-mdx-checker-diff

v1.2.2

Published

Check modified files for Docusaurus content for MDX v2 parsing errors

Downloads

209

Readme

docusaurus-mdx-checker-diff

A CLI to report MDX v3 parsing errors found in any content modified between two git SHAs, using the same setup as Docusaurus v3 uses.

Run this command in a CI workflow job for your repo, passing in a valid git range to the -r parameter:

npx docusaurus-mdx-checker-diff -r $SHA1..$SHA2

The command will return success if all modified Markdown/MDX documents are compatible with MDX v3 (Docusaurus flavor), or return (and print) an error if any are not compatible.

This tool was created to help Docusaurus v3+ users prevent content with broken Markdown/MDX from getting into repositories.

If all content files are valid for the Docusaurus MDX parser, you should see output similar to the below:

npx docusaurus-mdx-checker-diff -r 4000e3b5355c6ee1eb0691dded9d449b9a4c2313..8e2641cb8f7bc3d732870184efd1a8add147fb1d

Getting relevant files for git range: 4000e3b5355c6ee1eb0691dded9d449b9a4c2313..8e2641cb8f7bc3d732870184efd1a8add147fb1d

Found 8 modified files in the git range 4000e3b5355c6ee1eb0691dded9d449b9a4c2313..8e2641cb8f7bc3d732870184efd1a8add147fb1d in dir /Users/andrewbeveridge/Projects/docusaurus-mdx-checker-diff, filtering for relevant files

[SUCCESS] All 1 MDX files compiled successfully!

Usage

This is a minimal CLI tool with no mandatory options. If you run it without a -r / --gitRange parameter, it will validate all files in the current directory. If you pass in a -c / --cwd parameter, it will only process files within that directory (and will use that for the git diff as well).

Usage: docusaurus-mdx-checker-diff [options]

Check MDX files changed in a git range or all files if not specified

Options:
  -c, --cwd <cwd>            the CWD dir containing your MDX files
  -r, --gitRange <gitRange>  the git range to check modified files
  -v --verbose               enables more verbose logging
  -g --globals               Attempt to report usage of unknown global variables in MDX
  -h, --help                 display help for command

Github Actions Workflow Example

The primary use case for this tool is to implement a CI job which validates any changed content files.

Here is an example Github Actions workflow to achieve this:

name: Markdown MDX Validation

on:
  workflow_call:

jobs:
  markdown-mdx-validation:
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Validate MDX files
        run: |
          npx docusaurus-mdx-checker-diff -r ${{ github.event.pull_request.base.sha }}..${{ github.sha }}

      - name: Check validation results
        run: |
          if [ $? -eq 0 ]; then
            echo "All Markdown and MDX files are valid."
          else
            echo "Some Markdown and MDX files are not valid for the MDX parser. Please check the validation output above."
            exit 1
          fi

You could also clone the repo and run the CLI with yarn run, e.g.

yarn run cli -r 4000e3b5355c6ee1eb0691dded9d449b9a4c2313..705934e3f07645a697f9f3eeb2c5425d9a015a63

You should see output similar to the below if any validation errors occur:

Getting relevant files for git range: 4000e3b5355c6ee1eb0691dded9d449b9a4c2313..705934e3f07645a697f9f3eeb2c5425d9a015a63

Found 8 modified files in the git range 4000e3b5355c6ee1eb0691dded9d449b9a4c2313..705934e3f07645a697f9f3eeb2c5425d9a015a63 in dir /tmp/test, filtering for relevant files

[ERROR] 1/1 MDX files couldn't compile!
---
Error while compiling file README.md
Details: Expected a closing tag for `<TestInvalidMDXElement>` (15:1-15:24)
---