Skip to content

Commit

Permalink
mdx: remove inferral of development from NODE_ENV
Browse files Browse the repository at this point in the history
Now only `@mdx-js/node-loader` will switch to development, but based on which
condition is used (so do `--conditions development` to get development mode).

Closes GH-2367.
  • Loading branch information
wooorm committed Oct 18, 2023
1 parent 5a13d73 commit 96b51f9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 40 deletions.
8 changes: 0 additions & 8 deletions docs/guides/mdx-on-demand.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ On the server:
import {compile} from '@mdx-js/mdx'

const code = String(await compile('# hi', {
development: false
// ^-- Generate code for production.
// `false` if you use `/jsx-runtime` on client, `true` if you use
// `/jsx-dev-runtime`.
outputFormat: 'function-body',
/* …otherOptions */
}))
Expand Down Expand Up @@ -93,10 +89,6 @@ export default function Page({code}) {
export async function getStaticProps() {
const code = String(
await compile('# hi', {
development: false,
// ^-- Generate code for production.
// `false` if you use `/jsx-runtime` on client, `true` if you use
// `/jsx-dev-runtime`.
outputFormat: 'function-body',
/* …otherOptions */
})
Expand Down
2 changes: 1 addition & 1 deletion docs/migrating/v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ You can update your code as follows:

const components = {/**/}
const value = '# hi'
const {default: Content} = await evaluate(value, {...provider, ...runtime, development: false})
const {default: Content} = await evaluate(value, {...provider, ...runtime})

export default function () {
return <Content components={components} />
Expand Down
3 changes: 0 additions & 3 deletions packages/mdx/lib/condition.node.js

This file was deleted.

9 changes: 2 additions & 7 deletions packages/mdx/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {rehypeRecma} from './plugin/rehype-recma.js'
import {rehypeRemoveRaw} from './plugin/rehype-remove-raw.js'
import {remarkMarkAndUnravel} from './plugin/remark-mark-and-unravel.js'
import {nodeTypes} from './node-types.js'
import {development as defaultDevelopment} from '#condition'

const removedOptions = [
'compilers',
Expand Down Expand Up @@ -91,10 +90,6 @@ export function createProcessor(options) {
SourceMapGenerator,
...rest
} = options || {}
const dev =
development === null || development === undefined
? defaultDevelopment
: development
let index = -1

while (++index < removedOptions.length) {
Expand Down Expand Up @@ -144,13 +139,13 @@ export function createProcessor(options) {
.use(rehypeRecma, {elementAttributeNameCase, stylePropertyNameCase})
.use(recmaDocument, {...rest, outputFormat})
.use(recmaJsxRewrite, {
development: dev,
development,
providerImportSource,
outputFormat
})

if (!jsx) {
pipeline.use(recmaJsxBuild, {development: dev, outputFormat})
pipeline.use(recmaJsxBuild, {development, outputFormat})
}

pipeline.use(recmaStringify, {SourceMapGenerator}).use(recmaPlugins || [])
Expand Down
6 changes: 0 additions & 6 deletions packages/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
"./internal-extnames-to-regex": "./lib/util/extnames-to-regex.js",
"./internal-resolve-evaluate-options": "./lib/util/resolve-evaluate-options.js"
},
"imports": {
"#condition": {
"node": "./lib/condition.node.js",
"default": "./lib/condition.default.js"
}
},
"files": [
"lib/",
"index.d.ts",
Expand Down
18 changes: 4 additions & 14 deletions packages/mdx/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,6 @@ Typically, `import` (or `export … from`) do not work here.
They can be compiled to dynamic `import()` by passing
[`options.useDynamicImport`][usedynamicimport].

> ☢️ **Danger**: you likely must set `development: boolean`.
###### `file`

See [`compile`][compile].
Expand All @@ -814,7 +812,7 @@ exceptions:
###### `options.Fragment`

These options are required: `Fragment` always, when `development: true`
then `jsx` and `jsxs`, when `development: false` then `jsxDEV`.
then `jsxDEV`, when `development: false` then `jsx` and `jsxs`.
They come from an automatic JSX runtime that you must import yourself.

<details>
Expand All @@ -823,11 +821,7 @@ They come from an automatic JSX runtime that you must import yourself.
```tsx
import * as runtime from 'react/jsx-runtime'

const {default: Content} = await evaluate('# hi', {
development: false,
...otherOptions,
...runtime
})
const {default: Content} = await evaluate('# hi', {...otherOptions, ...runtime})
```

</details>
Expand All @@ -844,7 +838,6 @@ import * as provider from '@mdx-js/react'
import * as runtime from 'react/jsx-runtime'

const {default: Content} = await evaluate('# hi', {
development: false,
...otherOptions,
...provider,
...runtime
Expand All @@ -868,7 +861,7 @@ Assuming the contents of `example.mdx` from [§ Use][use] was in `file`, then:
import * as runtime from 'react/jsx-runtime'
import {evaluate} from '@mdx-js/mdx'

console.log(await evaluate(file, {...runtime, development: false}))
console.log(await evaluate(file, runtime))
```

…yields:
Expand Down Expand Up @@ -930,10 +923,7 @@ On the server:
```tsx
import {compile} from '@mdx-js/mdx'

const code = String(await compile('# hi', {
development: false,
outputFormat: 'function-body'
}))
const code = String(await compile('# hi', {outputFormat: 'function-body'}))
// To do: send `code` to the client somehow.
```

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/node-loader/lib/condition.development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const development = true
6 changes: 5 additions & 1 deletion packages/node-loader/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fs from 'node:fs/promises'
import {createFormatAwareProcessors} from '@mdx-js/mdx/internal-create-format-aware-processors'
import {extnamesToRegex} from '@mdx-js/mdx/internal-extnames-to-regex'
import {VFile} from 'vfile'
import {development as defaultDevelopment} from '#condition'

/**
* Create a loader to handle markdown and MDX.
Expand All @@ -17,7 +18,10 @@ import {VFile} from 'vfile'
*/
export function createLoader(options) {
const options_ = options || {}
const {extnames, process} = createFormatAwareProcessors(options_)
const {extnames, process} = createFormatAwareProcessors({
development: defaultDevelopment,
...options_
})
const regex = extnamesToRegex(extnames)

return {load}
Expand Down
6 changes: 6 additions & 0 deletions packages/node-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"type": "module",
"sideEffects": false,
"exports": "./index.js",
"imports": {
"#condition": {
"development": "./lib/condition.development.js",
"default": "./lib/condition.default.js"
}
},
"files": [
"lib/",
"index.d.ts",
Expand Down

1 comment on commit 96b51f9

@vercel
Copy link

@vercel vercel bot commented on 96b51f9 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mdx – ./

mdxjs.com
mdx-git-main-mdx.vercel.app
mdx-mdx.vercel.app
v2.mdxjs.com

Please sign in to comment.