Skip to content

Commit 96b51f9

Browse files
committedOct 18, 2023
mdx: remove inferral of development from NODE_ENV
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.
1 parent 5a13d73 commit 96b51f9

File tree

10 files changed

+19
-40
lines changed

10 files changed

+19
-40
lines changed
 

‎docs/guides/mdx-on-demand.mdx

-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ On the server:
3030
import {compile} from '@mdx-js/mdx'
3131

3232
const code = String(await compile('# hi', {
33-
development: false
34-
// ^-- Generate code for production.
35-
// `false` if you use `/jsx-runtime` on client, `true` if you use
36-
// `/jsx-dev-runtime`.
3733
outputFormat: 'function-body',
3834
/* …otherOptions */
3935
}))
@@ -93,10 +89,6 @@ export default function Page({code}) {
9389
export async function getStaticProps() {
9490
const code = String(
9591
await compile('# hi', {
96-
development: false,
97-
// ^-- Generate code for production.
98-
// `false` if you use `/jsx-runtime` on client, `true` if you use
99-
// `/jsx-dev-runtime`.
10092
outputFormat: 'function-body',
10193
/* …otherOptions */
10294
})

‎docs/migrating/v2.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ You can update your code as follows:
386386

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

391391
export default function () {
392392
return <Content components={components} />

‎packages/mdx/lib/condition.node.js

-3
This file was deleted.

‎packages/mdx/lib/core.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {rehypeRecma} from './plugin/rehype-recma.js'
5252
import {rehypeRemoveRaw} from './plugin/rehype-remove-raw.js'
5353
import {remarkMarkAndUnravel} from './plugin/remark-mark-and-unravel.js'
5454
import {nodeTypes} from './node-types.js'
55-
import {development as defaultDevelopment} from '#condition'
5655

5756
const removedOptions = [
5857
'compilers',
@@ -91,10 +90,6 @@ export function createProcessor(options) {
9190
SourceMapGenerator,
9291
...rest
9392
} = options || {}
94-
const dev =
95-
development === null || development === undefined
96-
? defaultDevelopment
97-
: development
9893
let index = -1
9994

10095
while (++index < removedOptions.length) {
@@ -144,13 +139,13 @@ export function createProcessor(options) {
144139
.use(rehypeRecma, {elementAttributeNameCase, stylePropertyNameCase})
145140
.use(recmaDocument, {...rest, outputFormat})
146141
.use(recmaJsxRewrite, {
147-
development: dev,
142+
development,
148143
providerImportSource,
149144
outputFormat
150145
})
151146

152147
if (!jsx) {
153-
pipeline.use(recmaJsxBuild, {development: dev, outputFormat})
148+
pipeline.use(recmaJsxBuild, {development, outputFormat})
154149
}
155150

156151
pipeline.use(recmaStringify, {SourceMapGenerator}).use(recmaPlugins || [])

‎packages/mdx/package.json

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
"./internal-extnames-to-regex": "./lib/util/extnames-to-regex.js",
3838
"./internal-resolve-evaluate-options": "./lib/util/resolve-evaluate-options.js"
3939
},
40-
"imports": {
41-
"#condition": {
42-
"node": "./lib/condition.node.js",
43-
"default": "./lib/condition.default.js"
44-
}
45-
},
4640
"files": [
4741
"lib/",
4842
"index.d.ts",

‎packages/mdx/readme.md

+4-14
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,6 @@ Typically, `import` (or `export … from`) do not work here.
789789
They can be compiled to dynamic `import()` by passing
790790
[`options.useDynamicImport`][usedynamicimport].
791791

792-
> ☢️ **Danger**: you likely must set `development: boolean`.
793-
794792
###### `file`
795793

796794
See [`compile`][compile].
@@ -814,7 +812,7 @@ exceptions:
814812
###### `options.Fragment`
815813

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

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

826-
const {default: Content} = await evaluate('# hi', {
827-
development: false,
828-
...otherOptions,
829-
...runtime
830-
})
824+
const {default: Content} = await evaluate('# hi', {...otherOptions, ...runtime})
831825
```
832826

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

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

871-
console.log(await evaluate(file, {...runtime, development: false}))
864+
console.log(await evaluate(file, runtime))
872865
```
873866

874867
…yields:
@@ -930,10 +923,7 @@ On the server:
930923
```tsx
931924
import {compile} from '@mdx-js/mdx'
932925

933-
const code = String(await compile('# hi', {
934-
development: false,
935-
outputFormat: 'function-body'
936-
}))
926+
const code = String(await compile('# hi', {outputFormat: 'function-body'}))
937927
// To do: send `code` to the client somehow.
938928
```
939929

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const development = true

‎packages/node-loader/lib/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import fs from 'node:fs/promises'
66
import {createFormatAwareProcessors} from '@mdx-js/mdx/internal-create-format-aware-processors'
77
import {extnamesToRegex} from '@mdx-js/mdx/internal-extnames-to-regex'
88
import {VFile} from 'vfile'
9+
import {development as defaultDevelopment} from '#condition'
910

1011
/**
1112
* Create a loader to handle markdown and MDX.
@@ -17,7 +18,10 @@ import {VFile} from 'vfile'
1718
*/
1819
export function createLoader(options) {
1920
const options_ = options || {}
20-
const {extnames, process} = createFormatAwareProcessors(options_)
21+
const {extnames, process} = createFormatAwareProcessors({
22+
development: defaultDevelopment,
23+
...options_
24+
})
2125
const regex = extnamesToRegex(extnames)
2226

2327
return {load}

‎packages/node-loader/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
"type": "module",
3131
"sideEffects": false,
3232
"exports": "./index.js",
33+
"imports": {
34+
"#condition": {
35+
"development": "./lib/condition.development.js",
36+
"default": "./lib/condition.default.js"
37+
}
38+
},
3339
"files": [
3440
"lib/",
3541
"index.d.ts",

1 commit comments

Comments
 (1)

vercel[bot] commented on Oct 18, 2023

@vercel[bot]

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.