mdast-util-mdxjs-esm
Advanced tools
Comparing version 1.3.1 to 2.0.0
import type {Program} from 'estree-jsx' | ||
import type {Literal as HastLiteral} from 'hast' | ||
import type {Literal as MdastLiteral} from 'mdast' | ||
import type {Data as HastData, Literal as HastLiteral} from 'hast' | ||
import type {Data as MdastData, Literal as MdastLiteral} from 'mdast' | ||
@@ -10,3 +10,2 @@ export {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from './lib/index.js' | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxjsEsm extends MdastLiteral { | ||
@@ -19,18 +18,16 @@ /** | ||
/** | ||
* Data. | ||
* Data associated with mdast MDX.js ESM. | ||
*/ | ||
data?: { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
estree?: Program | null | undefined | ||
} | ||
data?: MdxjsEsmData | undefined | ||
} | ||
/** | ||
* Deprecated: use the `MdxjsEsm` type instead. | ||
* Info associated with mdast MDX.js ESM nodes by the ecosystem. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type MDXJSEsm = MdxjsEsm | ||
export interface MdxjsEsmData extends MdastData { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
estree?: Program | null | undefined | ||
} | ||
@@ -40,3 +37,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface MdxjsEsmHast extends HastLiteral { | ||
@@ -49,16 +45,19 @@ /** | ||
/** | ||
* Data. | ||
* Data associated with hast MDX.js ESM. | ||
*/ | ||
data?: { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
estree?: Program | null | undefined | ||
} | ||
data?: MdxjsEsmHastData | undefined | ||
} | ||
/** | ||
* Info associated with hast MDX.js ESM nodes by the ecosystem. | ||
*/ | ||
export interface MdxjsEsmHastData extends MdastData { | ||
/** | ||
* Program node from estree. | ||
*/ | ||
estree?: Program | null | undefined | ||
} | ||
// Add nodes to mdast content. | ||
declare module 'mdast' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface FrontmatterContentMap { | ||
@@ -70,2 +69,9 @@ /** | ||
} | ||
interface RootContentMap { | ||
/** | ||
* MDX ESM. | ||
*/ | ||
mdxjsEsm: MdxjsEsm | ||
} | ||
} | ||
@@ -75,3 +81,2 @@ | ||
declare module 'hast' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface RootContentMap { | ||
@@ -78,0 +83,0 @@ /** |
/** | ||
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext | ||
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension | ||
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle | ||
* Create an extension for `mdast-util-from-markdown` to enable MDX.js ESM in | ||
* markdown. | ||
* | ||
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle | ||
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension | ||
* When using the micromark syntax extension with `addResult`, nodes will have | ||
* a `data.estree` field set to an ESTree [`Program`][program] node. | ||
* | ||
* @typedef {import('estree-jsx').Program} Program | ||
* | ||
* @typedef {import('../index.js').MdxjsEsm} MdxjsEsm | ||
* @returns {FromMarkdownExtension} | ||
* Extension for `mdast-util-from-markdown` to enable MDX.js ESM. | ||
*/ | ||
export function mdxjsEsmFromMarkdown(): FromMarkdownExtension | ||
/** | ||
* Extension for `mdast-util-from-markdown` to enable MDX ESM. | ||
* Create an extension for `mdast-util-to-markdown` to enable MDX.js ESM in | ||
* markdown. | ||
* | ||
* When using the syntax extension with `addResult`, nodes will have a | ||
* `data.estree` field set to an ESTree `Program` node. | ||
* | ||
* @type {FromMarkdownExtension} | ||
* @returns {ToMarkdownExtension} | ||
* Extension for `mdast-util-to-markdown` to enable MDX.js ESM. | ||
*/ | ||
export const mdxjsEsmFromMarkdown: FromMarkdownExtension | ||
/** | ||
* Extension for `mdast-util-to-markdown` to enable MDX ESM. | ||
* | ||
* @type {ToMarkdownExtension} | ||
*/ | ||
export const mdxjsEsmToMarkdown: ToMarkdownExtension | ||
export function mdxjsEsmToMarkdown(): ToMarkdownExtension | ||
export type CompileContext = import('mdast-util-from-markdown').CompileContext | ||
@@ -33,3 +25,2 @@ export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension | ||
export type ToMarkdownExtension = import('mdast-util-to-markdown').Options | ||
export type Program = import('estree-jsx').Program | ||
export type MdxjsEsm = import('../index.js').MdxjsEsm |
@@ -9,4 +9,2 @@ /** | ||
* | ||
* @typedef {import('estree-jsx').Program} Program | ||
* | ||
* @typedef {import('../index.js').MdxjsEsm} MdxjsEsm | ||
@@ -16,22 +14,31 @@ */ | ||
// To do: next major: expose functions. | ||
import {ok as assert} from 'devlop' | ||
/** | ||
* Extension for `mdast-util-from-markdown` to enable MDX ESM. | ||
* Create an extension for `mdast-util-from-markdown` to enable MDX.js ESM in | ||
* markdown. | ||
* | ||
* When using the syntax extension with `addResult`, nodes will have a | ||
* `data.estree` field set to an ESTree `Program` node. | ||
* When using the micromark syntax extension with `addResult`, nodes will have | ||
* a `data.estree` field set to an ESTree [`Program`][program] node. | ||
* | ||
* @type {FromMarkdownExtension} | ||
* @returns {FromMarkdownExtension} | ||
* Extension for `mdast-util-from-markdown` to enable MDX.js ESM. | ||
*/ | ||
export const mdxjsEsmFromMarkdown = { | ||
enter: {mdxjsEsm: enterMdxjsEsm}, | ||
exit: {mdxjsEsm: exitMdxjsEsm, mdxjsEsmData: exitMdxjsEsmData} | ||
export function mdxjsEsmFromMarkdown() { | ||
return { | ||
enter: {mdxjsEsm: enterMdxjsEsm}, | ||
exit: {mdxjsEsm: exitMdxjsEsm, mdxjsEsmData: exitMdxjsEsmData} | ||
} | ||
} | ||
/** | ||
* Extension for `mdast-util-to-markdown` to enable MDX ESM. | ||
* Create an extension for `mdast-util-to-markdown` to enable MDX.js ESM in | ||
* markdown. | ||
* | ||
* @type {ToMarkdownExtension} | ||
* @returns {ToMarkdownExtension} | ||
* Extension for `mdast-util-to-markdown` to enable MDX.js ESM. | ||
*/ | ||
export const mdxjsEsmToMarkdown = {handlers: {mdxjsEsm: handleMdxjsEsm}} | ||
export function mdxjsEsmToMarkdown() { | ||
return {handlers: {mdxjsEsm: handleMdxjsEsm}} | ||
} | ||
@@ -53,5 +60,7 @@ /** | ||
const value = this.resume() | ||
const node = /** @type {MdxjsEsm} */ (this.exit(token)) | ||
/** @type {Program | undefined} */ | ||
// @ts-expect-error: custom. | ||
const node = this.stack[this.stack.length - 1] | ||
assert(node.type === 'mdxjsEsm') | ||
this.exit(token) | ||
const estree = token.estree | ||
@@ -58,0 +67,0 @@ |
{ | ||
"name": "mdast-util-mdxjs-esm", | ||
"version": "1.3.1", | ||
"version": "2.0.0", | ||
"description": "mdast extension to parse and serialize MDX.js ESM (import/exports)", | ||
@@ -33,7 +33,5 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
"lib/", | ||
"complex-types.d.ts", | ||
"index.d.ts", | ||
@@ -44,12 +42,13 @@ "index.js" | ||
"@types/estree-jsx": "^1.0.0", | ||
"@types/hast": "^2.0.0", | ||
"@types/mdast": "^3.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
"mdast-util-to-markdown": "^1.0.0" | ||
"@types/hast": "^3.0.0", | ||
"@types/mdast": "^4.0.0", | ||
"devlop": "^1.0.0", | ||
"mdast-util-from-markdown": "^2.0.0", | ||
"mdast-util-to-markdown": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"@types/node": "^20.0.0", | ||
"acorn": "^8.0.0", | ||
"c8": "^7.0.0", | ||
"micromark-extension-mdxjs-esm": "^1.0.0", | ||
"c8": "^8.0.0", | ||
"micromark-extension-mdxjs-esm": "^2.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -59,5 +58,5 @@ "remark-cli": "^11.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.53.0" | ||
"typescript": "^5.0.0", | ||
"unist-util-remove-position": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -68,20 +67,19 @@ "scripts": { | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test-api-prod": "node --conditions production test.js", | ||
"test-api-dev": "node --conditions development test.js", | ||
"test-api": "npm run test-api-dev && npm run test-api-prod", | ||
"test-coverage": "c8 --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -92,5 +90,19 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.ts" | ||
], | ||
"rules": { | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/consistent-type-definitions": "off" | ||
} | ||
} | ||
], | ||
"prettier": true | ||
} | ||
} |
@@ -20,4 +20,4 @@ # mdast-util-mdxjs-esm | ||
* [API](#api) | ||
* [`mdxjsEsmFromMarkdown`](#mdxjsesmfrommarkdown) | ||
* [`mdxjsEsmToMarkdown`](#mdxjsesmtomarkdown) | ||
* [`mdxjsEsmFromMarkdown()`](#mdxjsesmfrommarkdown) | ||
* [`mdxjsEsmToMarkdown()`](#mdxjsesmtomarkdown) | ||
* [`MdxjsEsm`](#mdxjsesm) | ||
@@ -64,3 +64,3 @@ * [`MdxjsEsmHast`](#mdxjsesmhast) | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -74,3 +74,3 @@ ```sh | ||
```js | ||
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@1' | ||
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2' | ||
``` | ||
@@ -82,3 +82,3 @@ | ||
<script type="module"> | ||
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@1?bundle' | ||
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2?bundle' | ||
</script> | ||
@@ -112,3 +112,3 @@ ``` | ||
extensions: [mdxjsEsm({acorn, addResult: true})], | ||
mdastExtensions: [mdxjsEsmFromMarkdown] | ||
mdastExtensions: [mdxjsEsmFromMarkdown()] | ||
}) | ||
@@ -118,3 +118,3 @@ | ||
const out = toMarkdown(tree, {extensions: [mdxjsEsmToMarkdown]}) | ||
const out = toMarkdown(tree, {extensions: [mdxjsEsmToMarkdown()]}) | ||
@@ -187,6 +187,6 @@ console.log(out) | ||
### `mdxjsEsmFromMarkdown` | ||
### `mdxjsEsmFromMarkdown()` | ||
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable | ||
MDX ESM. | ||
Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] | ||
to enable MDX.js ESM in markdown. | ||
@@ -196,7 +196,17 @@ When using the [micromark syntax extension][extension] with `addResult`, nodes | ||
### `mdxjsEsmToMarkdown` | ||
###### Returns | ||
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable MDX | ||
ESM. | ||
Extension for `mdast-util-from-markdown` to enable MDX.js ESM | ||
([`FromMarkdownExtension`][from-markdown-extension]). | ||
### `mdxjsEsmToMarkdown()` | ||
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] | ||
to enable MDX.js ESM in markdown. | ||
###### Returns | ||
Extension for `mdast-util-to-markdown` to enable MDX.js ESM | ||
([`ToMarkdownExtension`][to-markdown-extension]). | ||
### `MdxjsEsm` | ||
@@ -210,8 +220,12 @@ | ||
import type {Program} from 'estree-jsx' | ||
import type {Literal} from 'mdast' | ||
import type {Data, Literal} from 'mdast' | ||
interface MdxjsEsm extends Literal { | ||
type: 'mdxjsEsm' | ||
data?: {estree?: Program | null | undefined} | ||
data?: MdxjsEsmData | undefined | ||
} | ||
export interface MdxjsEsmData extends Data { | ||
estree?: Program | null | undefined | ||
} | ||
``` | ||
@@ -228,8 +242,12 @@ | ||
import type {Program} from 'estree-jsx' | ||
import type {Literal} from 'hast' | ||
import type {Data, Literal} from 'hast' | ||
interface MdxjsEsm extends Literal { | ||
interface MdxjsEsmHast extends Literal { | ||
type: 'mdxjsEsm' | ||
data?: {estree?: Program | null | undefined} | ||
data?: MdxjsEsmHastData | undefined | ||
} | ||
export interface MdxjsEsmHastData extends Data { | ||
estree?: Program | null | undefined | ||
} | ||
``` | ||
@@ -313,3 +331,3 @@ | ||
visit(tree, (node) => { | ||
visit(tree, function (node) { | ||
// `node` can now be an ESM node. | ||
@@ -321,10 +339,13 @@ }) | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
This plugin works with `mdast-util-from-markdown` version 1+ and | ||
`mdast-util-to-markdown` version 1+. | ||
When we cut a new major release, we drop support for unmaintained versions of | ||
Node. | ||
This means we try to keep the current release line, `mdast-util-mdxjs-esm@^2`, | ||
compatible with Node.js 16. | ||
This utility works with `mdast-util-from-markdown` version 2+ and | ||
`mdast-util-to-markdown` version 2+. | ||
## Related | ||
@@ -367,5 +388,5 @@ | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-mdxjs-esm.svg | ||
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-mdxjs-esm | ||
[size]: https://bundlephobia.com/result?p=mdast-util-mdxjs-esm | ||
[size]: https://bundlejs.com/?q=mdast-util-mdxjs-esm | ||
@@ -428,2 +449,6 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension | ||
[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options | ||
[dfn-flow-content]: #flowcontent-mdxjs-esm | ||
@@ -430,0 +455,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20280
449
0
6
7
175
+ Addeddevlop@^1.0.0
+ Added@types/hast@3.0.4(transitive)
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addeddevlop@1.1.0(transitive)
+ Addedmdast-util-from-markdown@2.0.2(transitive)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedmdast-util-to-markdown@2.1.2(transitive)
+ Addedmdast-util-to-string@4.0.0(transitive)
+ Addedmicromark@4.0.0(transitive)
+ Addedmicromark-core-commonmark@2.0.1(transitive)
+ Addedmicromark-factory-destination@2.0.0(transitive)
+ Addedmicromark-factory-label@2.0.0(transitive)
+ Addedmicromark-factory-space@2.0.0(transitive)
+ Addedmicromark-factory-title@2.0.0(transitive)
+ Addedmicromark-factory-whitespace@2.0.0(transitive)
+ Addedmicromark-util-character@2.1.0(transitive)
+ Addedmicromark-util-chunked@2.0.0(transitive)
+ Addedmicromark-util-classify-character@2.0.0(transitive)
+ Addedmicromark-util-combine-extensions@2.0.0(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@2.0.1(transitive)
+ Addedmicromark-util-decode-string@2.0.0(transitive)
+ Addedmicromark-util-encode@2.0.0(transitive)
+ Addedmicromark-util-html-tag-name@2.0.0(transitive)
+ Addedmicromark-util-normalize-identifier@2.0.0(transitive)
+ Addedmicromark-util-resolve-all@2.0.0(transitive)
+ Addedmicromark-util-sanitize-uri@2.0.0(transitive)
+ Addedmicromark-util-subtokenize@2.0.1(transitive)
+ Addedmicromark-util-symbol@2.0.0(transitive)
+ Addedmicromark-util-types@2.0.0(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
- Removed@types/hast@2.3.10(transitive)
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removeddiff@5.2.0(transitive)
- Removedkleur@4.1.5(transitive)
- Removedmdast-util-from-markdown@1.3.1(transitive)
- Removedmdast-util-phrasing@3.0.1(transitive)
- Removedmdast-util-to-markdown@1.5.0(transitive)
- Removedmdast-util-to-string@3.2.0(transitive)
- Removedmicromark@3.2.0(transitive)
- Removedmicromark-core-commonmark@1.1.0(transitive)
- Removedmicromark-factory-destination@1.1.0(transitive)
- Removedmicromark-factory-label@1.1.0(transitive)
- Removedmicromark-factory-space@1.1.0(transitive)
- Removedmicromark-factory-title@1.1.0(transitive)
- Removedmicromark-factory-whitespace@1.1.0(transitive)
- Removedmicromark-util-character@1.2.0(transitive)
- Removedmicromark-util-chunked@1.1.0(transitive)
- Removedmicromark-util-classify-character@1.1.0(transitive)
- Removedmicromark-util-combine-extensions@1.1.0(transitive)
- Removedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
- Removedmicromark-util-decode-string@1.1.0(transitive)
- Removedmicromark-util-encode@1.1.0(transitive)
- Removedmicromark-util-html-tag-name@1.2.0(transitive)
- Removedmicromark-util-normalize-identifier@1.1.0(transitive)
- Removedmicromark-util-resolve-all@1.1.0(transitive)
- Removedmicromark-util-sanitize-uri@1.2.0(transitive)
- Removedmicromark-util-subtokenize@1.1.0(transitive)
- Removedmicromark-util-symbol@1.1.0(transitive)
- Removedmicromark-util-types@1.1.0(transitive)
- Removedmri@1.2.0(transitive)
- Removedsade@1.8.1(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-stringify-position@3.0.3(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
- Removeduvu@0.5.6(transitive)
Updated@types/hast@^3.0.0
Updated@types/mdast@^4.0.0