Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 18, 2024
0 parents commit b1f6f89
Show file tree
Hide file tree
Showing 63 changed files with 3,774 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
13 changes: 13 additions & 0 deletions .github/workflows/bb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: unifiedjs/beep-boop-beta@main
with:
repo-token: ${{secrets.GITHUB_TOKEN}}
name: bb
on:
issues:
types: [closed, edited, labeled, opened, reopened, unlabeled]
pull_request_target:
types: [closed, edited, labeled, opened, reopened, unlabeled]
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v4
strategy:
matrix:
node:
- lts/hydrogen
- node
name: main
on:
- pull_request
- push
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.d.ts
*.log
*.map
*.tsbuildinfo
.DS_Store
coverage/
node_modules/
yarn.lock
!/packages/recma-build-jsx/index.d.ts
!/packages/recma-jsx/index.d.ts
!/packages/recma-parse/index.d.ts
!/packages/recma-stringify/index.d.ts
!/packages/recma/index.d.ts
!/packages/rehype-recma/index.d.ts
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-scripts=true
package-lock=false
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.md
coverage/
test/fixtures/*/result.js
95 changes: 95 additions & 0 deletions doc/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Plugins

**recma** is a tool that transforms JavaScript with plugins.
See [the monorepo readme][github-recma] for info on what the recma ecosystem
is.
This page lists existing plugins.

## Contents

* [List of plugins](#list-of-plugins)
* [List of utilities](#list-of-utilities)
* [Use plugins](#use-plugins)
* [Create plugins](#create-plugins)

## List of plugins

Plugins can be found on GitHub tagged with the
[`recma-plugin` topic][github-topic-plugin].

The list of plugins:

* [`recma-build-jsx`](https://github.com/mdx-js/recma/tree/main/packages/recma-build-jsx)
— add support for turning JSX into function calls
* [`recma-jsx`](https://github.com/mdx-js/recma/tree/main/packages/recma-jsx)
— add support for JSX
* [`recma-mdx-escape-missing-components`](https://github.com/ipikuka/recma-mdx-escape-missing-components)
— set the default `() => null` for missing components in MDX
* [`recma-mdx-is-mdx-component`](https://github.com/remcohaszing/recma-mdx-is-mdx-component)
— define an `isMdxComponent` property on MDX components
* [`recma-nextjs-static-props`](https://github.com/remcohaszing/recma-nextjs-static-props)
— expose top-level identifiers in Next.js `app.js`

## List of utilities

See [esast][github-esast-utilities] for a list of utilities that work with the
syntax tree.
See [unist][github-unist-utilities] for other utilities which work with
esast/estree and other syntax trees too.
Finally,
see [vfile][github-vfile-utilities] for a list of utilities working with
virtual files.

## Use plugins

To use a plugin programmatically,
call the [`use()`][github-unified-use] function.

## Create plugins

To create a plugin,
first read up on the [concept of plugins][github-unified-plugins].
Then,
read the
[guide on “Creating a plugin with unified”][unified-guide-create-a-plugin].
Finally,
take one of existing plugins,
which looks similar to what you’re about to make,
and work from there.
If you get stuck,
[discussions][github-mdx-discussions] is a good place to get help.

You should pick a name prefixed by `'recma-'` (such as `recma-format`).
**Do not use the `recma-` prefix** if the thing you create doesn’t work with
`recma().use()`: it isn’t a “plugin” and will confuse users.
If it works with esast or estree,
use `'esast-util-'` or `estree-util`,
if it works with any unist tree,
use `unist-util-`,
and if it works with virtual files,
use `vfile-`.

Use default exports to expose plugins from your packages,
add `recma-plugin` keywords in `package.json`,
add a `recma-plugin` topic to your repo on GitHub,
and create a pull request to add the plugin here on this page!

<!--Definitions:-->

[github-esast-utilities]: https://github.com/syntax-tree/esast#list-of-utilities

[github-mdx-discussions]: https://github.com/mdx-js/recma/discussions

[github-recma]: https://github.com/mdx-js/recma

[github-topic-plugin]: https://github.com/topics/recma-plugin

[github-unified-plugins]: https://github.com/unifiedjs/unified#plugin

[github-unified-use]: https://github.com/unifiedjs/unified#processoruseplugin-options

[github-unist-utilities]: https://github.com/syntax-tree/unist#unist-utilities

[github-vfile-utilities]: https://github.com/vfile/vfile#utilities

[unified-guide-create-a-plugin]: https://unifiedjs.com/learn/guide/create-a-plugin/
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(The MIT License)

Copyright (c) Titus Wormer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
88 changes: 88 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"bugs": "https://github.com/mdx-js/recma/issues",
"devDependencies": {
"@types/node": "^22.0.0",
"c8": "^10.0.0",
"estree-util-visit": "^2.0.0",
"prettier": "^3.0.0",
"rehype-parse": "^9.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unified": "^11.0.0",
"vfile": "^6.0.0",
"xo": "^0.59.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"homepage": "https://github.com/mdx-js/recma",
"license": "MIT",
"name": "recma",
"prettier": {
"bracketSpacing": false,
"singleQuote": true,
"semi": false,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"private": true,
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"repository": "mdx-js/recma",
"scripts": {
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --check-coverage --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"type": "module",
"workspaces": [
"packages/recma-build-jsx/",
"packages/recma-jsx/",
"packages/recma-parse/",
"packages/recma-stringify/",
"packages/recma/",
"packages/rehype-recma/"
],
"xo": {
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"no-await-in-loop": "off"
}
},
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/triple-slash-reference": "off"
}
}
],
"prettier": true,
"rules": {
"logical-assignment-operators": "off",
"unicorn/no-this-assignment": "off"
}
}
}
2 changes: 2 additions & 0 deletions packages/recma-build-jsx/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-scripts=true
package-lock=false
11 changes: 11 additions & 0 deletions packages/recma-build-jsx/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type {Options as BuildJsxOptions} from 'estree-util-build-jsx'

export interface Options extends BuildJsxOptions {
/**
* Automatically handled;
* not needed to pass in `recma-build-jsx`
*/
filePath?: never
}

export {default} from './lib/index.js'
2 changes: 2 additions & 0 deletions packages/recma-build-jsx/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Note: types exposed from `index.d.ts`.
export {default} from './lib/index.js'
29 changes: 29 additions & 0 deletions packages/recma-build-jsx/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @import {Program} from 'estree'
* @import {Options} from 'recma-build-jsx'
* @import {VFile} from 'vfile'
*/

import {buildJsx} from 'estree-util-build-jsx'

/**
* Plugin to build JSX.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns
* Transform.
*/
export default function recmaJsx(options) {
/**
* @param {Program} tree
* Tree.
* @param {VFile} file
* File.
* @returns {undefined}
* Nothing.
*/
return function (tree, file) {
buildJsx(tree, {filePath: file.history[0], ...options})
}
}
21 changes: 21 additions & 0 deletions packages/recma-build-jsx/license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(The MIT License)

Copyright (c) Titus Wormer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
52 changes: 52 additions & 0 deletions packages/recma-build-jsx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
"bugs": "https://github.com/mdx-js/recma/issues",
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"description": "recma plugin to add support for parsing and serializing JSX",
"dependencies": {
"@types/estree": "^1.0.0",
"estree-util-build-jsx": "^3.0.0",
"vfile": "^6.0.0"
},
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"homepage": "https://github.com/mdx-js/recma",
"keywords": [
"abstract",
"ast",
"build",
"compile",
"javascript",
"jsx",
"plugin",
"recma-plugin",
"recma",
"runtime",
"syntax",
"tree",
"unified"
],
"license": "MIT",
"name": "recma-build-jsx",
"repository": "https://github.com/mdx-js/recma/tree/main/packages/recma-build-jsx",
"scripts": {},
"sideEffects": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
},
"type": "module",
"version": "0.0.0"
}
Loading

0 comments on commit b1f6f89

Please sign in to comment.