Skip to content

Commit

Permalink
feat: use same jsxRuntime as Gatsby by default
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Aug 5, 2022
1 parent afedd44 commit 7233c49
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-mdx/src/compile-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const compileMDXWithCustomOptions = async (
pathPrefix,
reporter,
cache,
store,
}: {
pluginOptions: PluginOptions
customOptions: Partial<IMdxPluginOptions>
Expand All @@ -79,6 +80,7 @@ export const compileMDXWithCustomOptions = async (
pathPrefix: string
reporter: NodePluginArgs["reporter"]
cache: NodePluginArgs["cache"]
store: NodePluginArgs["store"]
}
): Promise<{
processedMDX: string
Expand All @@ -96,6 +98,7 @@ export const compileMDXWithCustomOptions = async (
pathPrefix,
reporter,
cache,
store,
})

// Compile MDX and extract metadata
Expand Down
28 changes: 25 additions & 3 deletions packages/gatsby-plugin-mdx/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ import { cachedImport, createFileToMdxCacheKey } from "./cache-helpers"
*/
export const onCreateWebpackConfig: GatsbyNode["onCreateWebpackConfig"] =
async (
{ actions, loaders, getNode, getNodesByType, pathPrefix, reporter, cache },
{
actions,
loaders,
getNode,
getNodesByType,
pathPrefix,
reporter,
cache,
store,
},
pluginOptions
) => {
const options = defaultOptions(pluginOptions)
Expand All @@ -29,6 +38,7 @@ export const onCreateWebpackConfig: GatsbyNode["onCreateWebpackConfig"] =
pathPrefix,
reporter,
cache,
store,
})

const mdxLoaderOptions: IGatsbyMDXLoaderOptions = {
Expand Down Expand Up @@ -96,7 +106,7 @@ export const resolvableExtensions: GatsbyNode["resolvableExtensions"] = (
* Convert MDX to JSX so that Gatsby can extract the GraphQL queries and render the pages.
*/
export const preprocessSource: GatsbyNode["preprocessSource"] = async (
{ filename, getNode, getNodesByType, pathPrefix, reporter, cache },
{ filename, getNode, getNodesByType, pathPrefix, reporter, cache, store },
pluginOptions
) => {
const options = defaultOptions(pluginOptions)
Expand All @@ -113,6 +123,7 @@ export const preprocessSource: GatsbyNode["preprocessSource"] = async (
pathPrefix,
reporter,
cache,
store,
})

const ext = path.extname(mdxPath)
Expand Down Expand Up @@ -141,7 +152,16 @@ export const preprocessSource: GatsbyNode["preprocessSource"] = async (

export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] =
async (
{ getNode, getNodesByType, pathPrefix, reporter, cache, actions, schema },
{
getNode,
getNodesByType,
pathPrefix,
reporter,
cache,
actions,
schema,
store,
},
pluginOptions
) => {
const { createTypes } = actions
Expand Down Expand Up @@ -190,6 +210,7 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"]
pathPrefix,
reporter,
cache,
store,
}
)

Expand Down Expand Up @@ -239,6 +260,7 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"]
pathPrefix,
reporter,
cache,
store,
}
)

Expand Down
9 changes: 7 additions & 2 deletions packages/gatsby-plugin-mdx/src/plugin-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ProcessorOptions } from "@mdx-js/mdx"
import type { GatsbyCache, NodePluginArgs, PluginOptions } from "gatsby"
import type { GatsbyCache, NodePluginArgs, PluginOptions, Store } from "gatsby"
import deepmerge from "deepmerge"
import type { IPluginRefObject } from "gatsby-plugin-utils/types"
import { getSourcePluginsAsRemarkPlugins } from "./get-source-plugins-as-remark-plugins"
Expand All @@ -18,6 +18,7 @@ interface IHelpers {
pathPrefix: NodePluginArgs["pathPrefix"]
reporter: NodePluginArgs["reporter"]
cache: GatsbyCache
store: Store
}
type MdxDefaultOptions = (pluginOptions: PluginOptions) => IMdxPluginOptions

Expand All @@ -26,7 +27,6 @@ export const defaultOptions: MdxDefaultOptions = pluginOptions => {
format: `mdx`,
useDynamicImport: true,
providerImportSource: `@mdx-js/react`,
jsxRuntime: `classic`,
}
const defaults = {
extensions: [`.mdx`],
Expand All @@ -51,6 +51,11 @@ export const enhanceMdxOptions: EnhanceMdxOptions = async (
) => {
const options = defaultOptions(pluginOptions)

// Set jsxRuntime based on Gatsby project config
const { config } = helpers.store.getState()
const { jsxRuntime } = config
options.mdxOptions.jsxRuntime = jsxRuntime || `classic`

if (!options.mdxOptions.remarkPlugins) {
options.mdxOptions.remarkPlugins = []
}
Expand Down

0 comments on commit 7233c49

Please sign in to comment.