Comparing version 1.3.0 to 1.4.0
@@ -46,48 +46,9 @@ /** | ||
export function createProcessor(options?: ProcessorOptions): Processor; | ||
export type VFileCompatible = string | import("vfile").VFile | import("vfile").VFileOptions | Uint8Array; | ||
export type VFileCompatible = import("vfile").VFileCompatible; | ||
export type VFile = import("vfile").VFile; | ||
export type Processor = unified.Processor<unified.Settings>; | ||
export type PluggableList = unified.Pluggable<any[], unified.Settings>[]; | ||
export type RecmaDocumentOptions = { | ||
/** | ||
* Semihidden option which here results in failing on imports and adding a top-level return statement instead of an export. | ||
*/ | ||
contain?: boolean; | ||
/** | ||
* Pragma for JSX (used in classic runtime) | ||
*/ | ||
pragma?: string; | ||
/** | ||
* Pragma for JSX fragments (used in classic runtime) | ||
*/ | ||
pragmaFrag?: string; | ||
/** | ||
* Where to import the identifier of `pragma` from (used in classic runtime) | ||
*/ | ||
pragmaImportSource?: string; | ||
/** | ||
* Place to import automatic JSX runtimes from (used in automatic runtime) | ||
*/ | ||
jsxImportSource?: string; | ||
/** | ||
* JSX runtime to use | ||
*/ | ||
jsxRuntime?: "automatic" | "classic"; | ||
}; | ||
export type RecmaStringifyOptions = { | ||
/** | ||
* Generate a source map by passing a `SourceMapGenerator` from `source-map` in | ||
*/ | ||
SourceMapGenerator?: typeof import("source-map").SourceMapGenerator; | ||
}; | ||
export type RecmaJsxRewriteOptions = { | ||
/** | ||
* Semihidden option which here results in getting `useMDXComponents` from `arguments[0]` instead of importing it | ||
*/ | ||
contain?: boolean; | ||
/** | ||
* Place to import a provider from | ||
*/ | ||
providerImportSource?: string; | ||
}; | ||
export type Processor = import("unified").Processor; | ||
export type PluggableList = import("unified").PluggableList; | ||
export type RecmaDocumentOptions = import("./recma-document").RecmaDocumentOptions; | ||
export type RecmaStringifyOptions = import("./recma-stringify").RecmaStringifyOptions; | ||
export type RecmaJsxRewriteOptions = import("./recma-jsx-rewrite").RecmaJsxRewriteOptions; | ||
export type BaseProcessorOptions = { | ||
@@ -101,11 +62,11 @@ /** | ||
*/ | ||
recmaPlugins?: unified.PluggableList<unified.Settings>; | ||
recmaPlugins?: PluggableList; | ||
/** | ||
* List of remark (mdast, markdown) plugins | ||
*/ | ||
remarkPlugins?: unified.PluggableList<unified.Settings>; | ||
remarkPlugins?: PluggableList; | ||
/** | ||
* List of rehype (hast, HTML) plugins | ||
*/ | ||
rehypePlugins?: unified.PluggableList<unified.Settings>; | ||
rehypePlugins?: PluggableList; | ||
/** | ||
@@ -116,52 +77,2 @@ * Semihidden option | ||
}; | ||
export type ProcessorOptions = { | ||
/** | ||
* Pragma for JSX (used in classic runtime) | ||
*/ | ||
pragma?: string; | ||
/** | ||
* Pragma for JSX fragments (used in classic runtime) | ||
*/ | ||
pragmaFrag?: string; | ||
/** | ||
* Where to import the identifier of `pragma` from (used in classic runtime) | ||
*/ | ||
pragmaImportSource?: string; | ||
/** | ||
* Place to import automatic JSX runtimes from (used in automatic runtime) | ||
*/ | ||
jsxImportSource?: string; | ||
/** | ||
* JSX runtime to use | ||
*/ | ||
jsxRuntime?: "automatic" | "classic"; | ||
/** | ||
* Place to import a provider from | ||
*/ | ||
providerImportSource?: string; | ||
/** | ||
* Generate a source map by passing a `SourceMapGenerator` from `source-map` in | ||
*/ | ||
SourceMapGenerator?: typeof import("source-map").SourceMapGenerator; | ||
/** | ||
* Whether to keep JSX | ||
*/ | ||
jsx?: boolean; | ||
/** | ||
* List of recma (esast, JavaScript) plugins | ||
*/ | ||
recmaPlugins?: unified.PluggableList<unified.Settings>; | ||
/** | ||
* List of remark (mdast, markdown) plugins | ||
*/ | ||
remarkPlugins?: unified.PluggableList<unified.Settings>; | ||
/** | ||
* List of rehype (hast, HTML) plugins | ||
*/ | ||
rehypePlugins?: unified.PluggableList<unified.Settings>; | ||
/** | ||
* Semihidden option | ||
*/ | ||
_contain?: boolean; | ||
}; | ||
import unified from "unified/types/ts3.4/"; | ||
export type ProcessorOptions = Omit<RecmaDocumentOptions & RecmaStringifyOptions & RecmaJsxRewriteOptions & BaseProcessorOptions, "contain">; |
@@ -12,52 +12,3 @@ /** | ||
export function esbuild(options?: ProcessorOptions): Plugin; | ||
export type ProcessorOptions = { | ||
/** | ||
* Pragma for JSX (used in classic runtime) | ||
*/ | ||
pragma?: string; | ||
/** | ||
* Pragma for JSX fragments (used in classic runtime) | ||
*/ | ||
pragmaFrag?: string; | ||
/** | ||
* Where to import the identifier of `pragma` from (used in classic runtime) | ||
*/ | ||
pragmaImportSource?: string; | ||
/** | ||
* Place to import automatic JSX runtimes from (used in automatic runtime) | ||
*/ | ||
jsxImportSource?: string; | ||
/** | ||
* JSX runtime to use | ||
*/ | ||
jsxRuntime?: "automatic" | "classic"; | ||
/** | ||
* Place to import a provider from | ||
*/ | ||
providerImportSource?: string; | ||
/** | ||
* Generate a source map by passing a `SourceMapGenerator` from `source-map` in | ||
*/ | ||
SourceMapGenerator?: typeof import("source-map").SourceMapGenerator; | ||
/** | ||
* Whether to keep JSX | ||
*/ | ||
jsx?: boolean; | ||
/** | ||
* List of recma (esast, JavaScript) plugins | ||
*/ | ||
recmaPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of remark (mdast, markdown) plugins | ||
*/ | ||
remarkPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of rehype (hast, HTML) plugins | ||
*/ | ||
rehypePlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* Semihidden option | ||
*/ | ||
_contain?: boolean; | ||
}; | ||
export type Plugin = import("esbuild").Plugin; | ||
export type ProcessorOptions = import('./core.js').ProcessorOptions; | ||
export type Plugin = import('esbuild').Plugin; |
@@ -34,25 +34,4 @@ /** | ||
export function evaluateSync(file: VFileCompatible, options: ProcessorAndRunnerOptions): ExportMap; | ||
export type VFileCompatible = string | import("vfile").VFile | import("vfile").VFileOptions | Uint8Array; | ||
export type BaseProcessorOptions = { | ||
/** | ||
* Whether to keep JSX | ||
*/ | ||
jsx?: boolean; | ||
/** | ||
* List of recma (esast, JavaScript) plugins | ||
*/ | ||
recmaPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of remark (mdast, markdown) plugins | ||
*/ | ||
remarkPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of rehype (hast, HTML) plugins | ||
*/ | ||
rehypePlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* Semihidden option | ||
*/ | ||
_contain?: boolean; | ||
}; | ||
export type VFileCompatible = import("vfile").VFileCompatible; | ||
export type BaseProcessorOptions = import('./core.js').BaseProcessorOptions; | ||
export type RunnerOptions = { | ||
@@ -76,17 +55,4 @@ /** | ||
}; | ||
export type ProcessorOptions = { | ||
/** | ||
* List of recma (esast, JavaScript) plugins | ||
*/ | ||
recmaPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of remark (mdast, markdown) plugins | ||
*/ | ||
remarkPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of rehype (hast, HTML) plugins | ||
*/ | ||
rehypePlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
}; | ||
export type ProcessorAndRunnerOptions = Pick<import("./core.js").BaseProcessorOptions, "recmaPlugins" | "remarkPlugins" | "rehypePlugins"> & RunnerOptions; | ||
export type ProcessorOptions = Omit<BaseProcessorOptions, "jsx" | "_contain">; | ||
export type ProcessorAndRunnerOptions = ProcessorOptions & RunnerOptions; | ||
export type ComponentMap = { | ||
@@ -93,0 +59,0 @@ [name: string]: any; |
@@ -20,54 +20,5 @@ /** | ||
export function rollup(options?: ProcessorAndRollupOptions): Plugin; | ||
export type ProcessorOptions = { | ||
/** | ||
* Pragma for JSX (used in classic runtime) | ||
*/ | ||
pragma?: string; | ||
/** | ||
* Pragma for JSX fragments (used in classic runtime) | ||
*/ | ||
pragmaFrag?: string; | ||
/** | ||
* Where to import the identifier of `pragma` from (used in classic runtime) | ||
*/ | ||
pragmaImportSource?: string; | ||
/** | ||
* Place to import automatic JSX runtimes from (used in automatic runtime) | ||
*/ | ||
jsxImportSource?: string; | ||
/** | ||
* JSX runtime to use | ||
*/ | ||
jsxRuntime?: "automatic" | "classic"; | ||
/** | ||
* Place to import a provider from | ||
*/ | ||
providerImportSource?: string; | ||
/** | ||
* Generate a source map by passing a `SourceMapGenerator` from `source-map` in | ||
*/ | ||
SourceMapGenerator?: typeof import("source-map").SourceMapGenerator; | ||
/** | ||
* Whether to keep JSX | ||
*/ | ||
jsx?: boolean; | ||
/** | ||
* List of recma (esast, JavaScript) plugins | ||
*/ | ||
recmaPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of remark (mdast, markdown) plugins | ||
*/ | ||
remarkPlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* List of rehype (hast, HTML) plugins | ||
*/ | ||
rehypePlugins?: import("unified/types/ts3.4/").PluggableList<import("unified/types/ts3.4/").Settings>; | ||
/** | ||
* Semihidden option | ||
*/ | ||
_contain?: boolean; | ||
}; | ||
export type FilterPattern = string | RegExp | readonly (string | RegExp)[]; | ||
export type Plugin = import("rollup").Plugin; | ||
export type ProcessorOptions = import('./core.js').ProcessorOptions; | ||
export type FilterPattern = import('@rollup/pluginutils').FilterPattern; | ||
export type Plugin = import('rollup').Plugin; | ||
export type RollupPluginOptions = { | ||
@@ -87,2 +38,2 @@ /** | ||
}; | ||
export type ProcessorAndRollupOptions = Pick<import("./recma-document.js").RecmaDocumentOptions & import("./recma-stringify.js").RecmaStringifyOptions & import("./recma-jsx-rewrite.js").RecmaJsxRewriteOptions & import("./core.js").BaseProcessorOptions, "pragma" | "pragmaFrag" | "pragmaImportSource" | "jsxImportSource" | "jsxRuntime" | "providerImportSource" | "SourceMapGenerator" | "jsx" | "recmaPlugins" | "remarkPlugins" | "rehypePlugins" | "_contain"> & RollupPluginOptions; | ||
export type ProcessorAndRollupOptions = ProcessorOptions & RollupPluginOptions; |
{ | ||
"name": "xdm", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "an MDX compiler", | ||
@@ -30,4 +30,6 @@ "license": "MIT", | ||
"esbuild.d.ts", | ||
"esm-loader.js", | ||
"index.js", | ||
"index.d.ts", | ||
"register.cjs", | ||
"rollup.js", | ||
@@ -40,2 +42,3 @@ "rollup.d.ts", | ||
"astring": "^1.6.0", | ||
"deasync": "^0.1.0", | ||
"estree-util-build-jsx": "^1.1.0", | ||
@@ -102,4 +105,4 @@ "estree-util-is-identifier-name": "^1.0.0", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --experimental-modules test/index.js", | ||
"test-api": "node --experimental-loader=./esm-loader.js test/index.js && node test/register.cjs", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --experimental-modules --experimental-loader=./esm-loader.js test/index.js", | ||
"prebuild": "rimraf \"*.d.ts\" \"{lib,test}/**/*.d.ts\"", | ||
@@ -106,0 +109,0 @@ "build": "tsc", |
103
readme.md
@@ -18,2 +18,4 @@ # xdm | ||
There are also some cool experimental features in [👩🔬 lab][lab]! | ||
## Install | ||
@@ -52,2 +54,5 @@ | ||
* [`createProcessor(options)`](#createprocessoroptions) | ||
* [👩🔬 lab](#-lab) | ||
* [Importing `.mdx` files directly](#importing-mdx-files-directly) | ||
* [Requiring `.mdx` files directly](#requiring-mdx-files-directly) | ||
* [MDX syntax](#mdx-syntax) | ||
@@ -214,2 +219,5 @@ * [Markdown](#markdown) | ||
There is also `xdm/esm-loader.js` and `xdm/register.cjs`, see [👩🔬 lab][lab] | ||
for more info. | ||
### `compile(file, options?)` | ||
@@ -649,2 +657,78 @@ | ||
## 👩🔬 lab | ||
This section describes experimental features! | ||
These do not adhere to semver and could break at any time! | ||
### Importing `.mdx` files directly | ||
[ESM loaders](https://nodejs.org/api/esm.html#esm_loaders) are a very | ||
experimental feature in Node, slated to change. | ||
Still, the feature lets projects “hijack” imports, to do all sorts of fancy | ||
things! | ||
**xdm** comes with experimental support for importing `.mdx` files with | ||
on-the-fly compilation, using `xdm/esm-loader.js`: | ||
Assuming `example.mdx` from [§ Use][use] exists, and our module `example.js` | ||
looks as follows: | ||
```js | ||
import {renderToStaticMarkup} from 'react-dom/server.js' | ||
import React from 'react' | ||
import Content from './example.mdx' | ||
console.log(renderToStaticMarkup(React.createElement(Content))) | ||
``` | ||
Running that with: | ||
```sh | ||
node --experimental-loader=xdm/esm-loader.js example.js | ||
``` | ||
…yields: | ||
```html | ||
<h1>Hello, World!</h1> | ||
``` | ||
Currently, no options are supported. | ||
### Requiring `.mdx` files directly | ||
[`require.extensions`](https://nodejs.org/api/modules.html#modules_require_extensions) | ||
is a deprecated feature in Node. | ||
Still, the feature lets projects “hijack” `require` calls, to do all sorts of | ||
fancy things! | ||
**xdm** comes with support for requiring `.mdx` files with on-the-fly | ||
evaluation, using `xdm/register.cjs`: | ||
Assuming `example.mdx` from [§ Use][use] exists, and our script `example.cjs` | ||
looks as follows: | ||
```js | ||
var React = require('react') | ||
var {renderToStaticMarkup} = require('react-dom/server.js') | ||
var Content = require('./example.mdx') | ||
console.log(renderToStaticMarkup(React.createElement(Content))) | ||
``` | ||
Running that with: | ||
```sh | ||
node -r xdm/register.cjs example.cjs | ||
``` | ||
…yields: | ||
```html | ||
<h1>Hello, World!</h1> | ||
``` | ||
Currently, no options are supported. | ||
The register hook uses [`evaluate`][eval]. | ||
That means `import` (and `export … from`) are not supported in `.mdx` files. | ||
## MDX syntax | ||
@@ -1018,2 +1102,17 @@ | ||
Note that `webpack-cli` doesn’t support loaders in ESM directly or even | ||
*indirectly*. | ||
Because `xdm` itself is ESM, this means the `xdm/webpack.cjs` loader (even | ||
though it’s CJS) doesn’t work with `webpack-cli` (it does work when using the | ||
webpack API). | ||
To use this loader with `webpack-cli`, set the `DISABLE_V8_COMPILE_CACHE=1` | ||
environment variable. | ||
See | ||
[#11](https://github.com/wooorm/xdm/issues/11#issuecomment-785043772) for | ||
details. | ||
```sh | ||
DISABLE_V8_COMPILE_CACHE=1 webpack | ||
``` | ||
### Build systems | ||
@@ -1892,3 +1991,3 @@ | ||
After markdown, we go to [hast](https://github.com/syntax-tree/hast) (HTML). | ||
This transormation is done by | ||
This transformation is done by | ||
[`mdast-util-to-hast`](https://github.com/syntax-tree/mdast-util-to-hast). | ||
@@ -2029,1 +2128,3 @@ Wait, why, what does HTML have to do with it? | ||
[pico]: https://github.com/micromatch/picomatch#globbing-features | ||
[lab]: #-lab |
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
40
2124
118300
18
1703
3
+ Addeddeasync@^0.1.0
+ Addedbindings@1.5.0(transitive)
+ Addeddeasync@0.1.30(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addednode-addon-api@1.7.2(transitive)