diff --git a/packages/node-loader/index.js b/packages/node-loader/index.js index 203e81745..67d01f4be 100644 --- a/packages/node-loader/index.js +++ b/packages/node-loader/index.js @@ -1,5 +1,5 @@ /** - * @typedef {import('./lib/index.js').CompileOptions} Options + * @typedef {import('./lib/index.js').Options} Options */ import {createLoader} from './lib/index.js' diff --git a/packages/node-loader/lib/index.js b/packages/node-loader/lib/index.js index 30cb879a2..3530fb42a 100644 --- a/packages/node-loader/lib/index.js +++ b/packages/node-loader/lib/index.js @@ -1,18 +1,5 @@ /** - * @typedef {import('@mdx-js/mdx/lib/compile.js').CompileOptions} CompileOptions - */ - -/** - * @typedef LoaderOptions - * Extra configuration. - * @property {boolean | null | undefined} [fixRuntimeWithoutExportMap=true] - * Several JSX runtimes, notably React below 18 and Emotion below 11.10.0, - * don’t yet have a proper export map set up (default: `true`). - * Export maps are needed to map `xxx/jsx-runtime` to an actual file in ESM. - * This option fixes React et al by turning those into `xxx/jsx-runtime.js`. - * - * @typedef {CompileOptions & LoaderOptions} Options - * Configuration. + * @typedef {import('@mdx-js/mdx/lib/compile.js').CompileOptions} Options */ import fs from 'node:fs/promises' @@ -32,14 +19,6 @@ export function createLoader(options) { const options_ = options || {} const {extnames, process} = createFormatAwareProcessors(options_) const regex = extnamesToRegex(extnames) - let fixRuntimeWithoutExportMap = options_.fixRuntimeWithoutExportMap - - if ( - fixRuntimeWithoutExportMap === null || - fixRuntimeWithoutExportMap === undefined - ) { - fixRuntimeWithoutExportMap = true - } return {load, getFormat, transformSource} @@ -60,14 +39,8 @@ export function createLoader(options) { if (url.protocol === 'file:' && regex.test(url.pathname)) { const value = await fs.readFile(url) const file = await process(new VFile({value, path: url})) - let source = String(file) - - /* c8 ignore next 3 -- to do: remove. */ - if (fixRuntimeWithoutExportMap) { - source = String(file).replace(/\/jsx-runtime(?=["'])/, '$&.js') - } - return {format: 'module', shortCircuit: true, source} + return {format: 'module', shortCircuit: true, source: String(file)} } return defaultLoad(href, context, defaultLoad) @@ -113,13 +86,7 @@ export function createLoader(options) { if (url.protocol === 'file:' && regex.test(url.pathname)) { const file = await process(new VFile({path: new URL(context.url), value})) - let source = String(file) - - if (fixRuntimeWithoutExportMap) { - source = String(file).replace(/\/jsx-runtime(?=["'])/, '$&.js') - } - - return {source} + return {source: String(file)} } return defaultTransformSource(value, context, defaultTransformSource) diff --git a/packages/node-loader/package.json b/packages/node-loader/package.json index 05c86d7f5..5c41d8d8d 100644 --- a/packages/node-loader/package.json +++ b/packages/node-loader/package.json @@ -43,7 +43,7 @@ "devDependencies": {}, "scripts": { "test": "npm run test-coverage", - "test-api": "node --conditions development --loader=./test/react-18-node-loader.js test/index.js", + "test-api": "node --conditions development --loader=@mdx-js/node-loader test/index.js", "test-coverage": "c8 --100 --reporter lcov npm run test-api" }, "xo": { diff --git a/packages/node-loader/readme.md b/packages/node-loader/readme.md index 115b86887..0fd67555c 100644 --- a/packages/node-loader/readme.md +++ b/packages/node-loader/readme.md @@ -112,20 +112,6 @@ Create a Node ESM loader to compile MDX to JS. `options` are the same as [`compile` from `@mdx-js/mdx`][options]. One extra field is supported: -###### `options.fixRuntimeWithoutExportMap` - -Fix broken export maps (`boolean`, default: `true`). - -Several JSX runtimes, notably React below 18 and Emotion below 11.10.0, don’t -have a proper export map set up. -Export maps are needed to map `xxx/jsx-runtime` to an actual file in ESM. -This option fixes React et al by turning those into `xxx/jsx-runtime.js`. - -> 👉 **Note**: If you are using recent React, or other proper packages, you -> have to turn this field off. -> See the example below on how to configure your loader. -> Pass `fixRuntimeWithoutExportMap: false` in options to it. - ###### Example `my-loader.js`: diff --git a/packages/node-loader/test/index.js b/packages/node-loader/test/index.js index 3e21fb170..e01b11b17 100644 --- a/packages/node-loader/test/index.js +++ b/packages/node-loader/test/index.js @@ -38,7 +38,7 @@ test('@mdx-js/node-loader', async function (t) { await fs.rm(mdxUrl) throw new Error( - 'Please run Node with `--loader=./test/react-18-node-loader.js` to test the ESM loader' + 'Please run Node with `--loader=@mdx-js/node-loader` to test the ESM loader' ) } diff --git a/packages/node-loader/test/react-18-node-loader.js b/packages/node-loader/test/react-18-node-loader.js deleted file mode 100644 index 3281fdce1..000000000 --- a/packages/node-loader/test/react-18-node-loader.js +++ /dev/null @@ -1,6 +0,0 @@ -import {createLoader} from '@mdx-js/node-loader' - -// To do: break to not fix by default, remove this file. -const {load} = createLoader({fixRuntimeWithoutExportMap: false}) - -export {load} diff --git a/website/mdx-config.js b/website/mdx-config.js index 61772a1bf..ba9f7dc5e 100644 --- a/website/mdx-config.js +++ b/website/mdx-config.js @@ -48,8 +48,6 @@ import {config} from '../docs/_config.js' /** @type {Readonly} */ const options = { - // To do: remove. - fixRuntimeWithoutExportMap: false, recmaPlugins: [recmaInjectMeta], rehypePlugins: [ rehypePrettyCodeBlocks,