|
| 1 | +--- |
| 2 | +authorGithub: wooorm |
| 3 | +authorTwitter: wooorm |
| 4 | +author: Titus Wormer |
| 5 | +description: Guide that shows how to share a plugin with the world. |
| 6 | +group: guide |
| 7 | +modified: 2024-08-19 |
| 8 | +published: 2024-08-19 |
| 9 | +tags: |
| 10 | + - plugin |
| 11 | + - rehype |
| 12 | + - remark |
| 13 | + - retext |
| 14 | + - unified |
| 15 | + - publish |
| 16 | +title: Publish a plugin |
| 17 | +--- |
| 18 | + |
| 19 | +## Publish a plugin |
| 20 | + |
| 21 | +This guide shows how to share a plugin with the world. |
| 22 | + |
| 23 | +> Stuck? |
| 24 | +> Have an idea for another guide? |
| 25 | +> See [`support.md`][support]. |
| 26 | +
|
| 27 | +### Contents |
| 28 | + |
| 29 | +* [Intro](#intro) |
| 30 | +* [Package name](#package-name) |
| 31 | +* [npm](#npm) |
| 32 | +* [GitHub](#github) |
| 33 | +* [Export map](#export-map) |
| 34 | +* [`export default`](#export-default) |
| 35 | +* [Docs](#docs) |
| 36 | +* [Tests](#tests) |
| 37 | +* [License](#license) |
| 38 | + |
| 39 | +### Intro |
| 40 | + |
| 41 | +You may have a [plugin][github-unified-plugin] locally, |
| 42 | +that you use in a project, |
| 43 | +and think others might find useful too. |
| 44 | + |
| 45 | +Below you’ll find some rules on how to share plugins with the world. |
| 46 | + |
| 47 | +### Package name |
| 48 | + |
| 49 | +The package name must be prefixed with `rehype-`, `remark-`, `retext-`, and so |
| 50 | +on. |
| 51 | +The name of the ecosystem. |
| 52 | +Use this prefix **only** for plugins. |
| 53 | +For presets, use `rehype-preset-`, `remark-preset-`, `retext-preset-`, |
| 54 | +and so on. |
| 55 | + |
| 56 | +### npm |
| 57 | + |
| 58 | +Plugins should be published to npm. |
| 59 | +You are free to publish them elsewhere too. |
| 60 | + |
| 61 | +You should use a keyword `rehype-plugin`, `remark-plugin`, `retext-plugin`, |
| 62 | +and so on, |
| 63 | +to tag your package. |
| 64 | + |
| 65 | +### GitHub |
| 66 | + |
| 67 | +You may use GitHub. |
| 68 | +Or an alternative. |
| 69 | + |
| 70 | +Only GitHub is crawled for the [explore][] page. |
| 71 | +You should use a topic `rehype-plugin`, `remark-plugin`, `retext-plugin`, |
| 72 | +and so on, |
| 73 | +to tag your repository. |
| 74 | + |
| 75 | +### Export map |
| 76 | + |
| 77 | +You must expose a plugin that can be imported from that package name. |
| 78 | +So, |
| 79 | +there must be a plugin at `rehype-some-plugin`. |
| 80 | + |
| 81 | +There may be several plugins in a package. |
| 82 | +One example is [`rehype-mathjax`][github-rehype-mathjax], |
| 83 | +which has plugins exposed as `rehype-mathjax/browser`, |
| 84 | +`rehype-mathjax/chtml`, |
| 85 | +`rehype-mathjax/svg`, |
| 86 | +and `rehype-mathjax` (as an alias for `rehype-mathjax/svg`). |
| 87 | +The reason for different plugins in the same project is that they each use |
| 88 | +different code. |
| 89 | +Which impact performance and bundle size. |
| 90 | + |
| 91 | +### `export default` |
| 92 | + |
| 93 | +Your package must expose a plugin at the default export. |
| 94 | +It must be a function that must work when passed as `x` to `unified().use(x)`. |
| 95 | + |
| 96 | +There may be different exports too. |
| 97 | +One example is [`remark-rehype`][github-remark-rehype], |
| 98 | +which also exposes useful things at |
| 99 | +`defaultFootnoteBackContent`, |
| 100 | +`defaultFootnoteBackLabel`, and |
| 101 | +`defaultHandlers`, |
| 102 | +but the plugin itself is exported as `default`. |
| 103 | + |
| 104 | +### Docs |
| 105 | + |
| 106 | +Write a good readme. |
| 107 | +Explain what the plugin does, |
| 108 | +when it should be used or not, |
| 109 | +how to configure it. |
| 110 | + |
| 111 | +### Tests |
| 112 | + |
| 113 | +Add thorough tests. |
| 114 | +Use a CI. |
| 115 | +You should test your project in all maintained versions of Node.js. |
| 116 | + |
| 117 | +### License |
| 118 | + |
| 119 | +Add a license. |
| 120 | +It should be MIT or ISC, |
| 121 | +as that aligns with most of the JavaScript ecosystem. |
| 122 | +It must be an open source license. |
| 123 | + |
| 124 | +[explore]: /explore/ |
| 125 | + |
| 126 | +[github-rehype-mathjax]: https://github.com/remarkjs/remark-math/tree/main/packages/rehype-mathjax |
| 127 | + |
| 128 | +[github-remark-rehype]: https://github.com/remarkjs/remark-rehype |
| 129 | + |
| 130 | +[github-unified-plugin]: https://github.com/unifiedjs/unified#plugin |
| 131 | + |
| 132 | +[support]: https://github.com/unifiedjs/.github/blob/main/support.md |
0 commit comments