Skip to content

Provide a CLI based on unified-args #2378

Closed as not planned
Closed as not planned
@remcohaszing

Description

@remcohaszing

Initial checklist

Problem

The unified ecosystem has some CLIs based on unified-args that can be used for linting and formatting. Since MDX is based on remark, remark-cli can support MDX, but it’s not obvious. By default remark-cli doesn’t contain remark-mdx, not does it check .mdx files by default.

It would be nice if there is a simple blessed way to lint MDX files.

Solution

Create a new package remark-mdx-cli. This registers the remark-mdx command.

#!/usr/bin/env node

/**
 * @typedef Pack
 * @property {string} name
 * @property {string} version
 * @property {string} description
 */

import fs from 'node:fs/promises'
import {remark} from 'remark'
import remarkMdx from 'remark-mdx'
import {args} from 'unified-args'

/** @type {Pack} */
const cli = JSON.parse(
  String(await fs.readFile(new URL('package.json', import.meta.url)))
)

args({
  description: cli.description,
  extensions: ['mdx'],
  ignoreName: '.remarkmdxignore',
  name: 'remark-mdx',
  packageField: 'remarkmdxConfig',
  pluginPrefix: 'remark',
  processor: remark.use(remarkMdx),
  rcName: '.remarkmdxrc',
  version: cli.name + ': ' + cli.version
})

This will also be accompanied by a language server (remark-mdx-language-server) and VSCode plugin (unifiedjs.vscode-remark-mdx) based on unified-language-server.

Alternatives

There are plenty of variations possible on the names of various parameters. I.e. should the package name be scoped? Should the command be different? Should it use .remarkignore instead of .remarkmdxignore?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions