Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): Pass node API helpers from onCreateNode and s…
Browse files Browse the repository at this point in the history
…ourceNodes to remark plugins (#20879)

* [gatsby-plugin-mdx] Pass node API helpers from onCreateNode to remark plugins

* Fix sourceNodes too
  • Loading branch information
andrewbranch authored and pieh committed Jan 27, 2020
1 parent 3f2ce1e commit cd150b5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/gatsby-plugin-mdx/gatsby/on-create-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = async (
reporter,
cache,
pathPrefix,
...helpers
},
pluginOptions
) => {
Expand Down Expand Up @@ -64,6 +65,10 @@ module.exports = async (
cache,
pathPrefix,
options,
loadNodeContent,
actions,
createNodeId,
...helpers,
},
{ forceDisableCache: true }
)
Expand Down
26 changes: 24 additions & 2 deletions packages/gatsby-plugin-mdx/gatsby/source-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ async function getCounts({ mdast }) {
}

module.exports = (
{ store, pathPrefix, getNode, getNodes, cache, reporter, actions, schema },
{
store,
pathPrefix,
getNode,
getNodes,
cache,
reporter,
actions,
schema,
...helpers
},
pluginOptions
) => {
let mdxHTMLLoader
Expand Down Expand Up @@ -105,7 +115,19 @@ module.exports = (
}

const processMDX = ({ node }) =>
genMDX({ node, getNode, getNodes, reporter, cache, pathPrefix, options })
genMDX({
node,
options,
store,
pathPrefix,
getNode,
getNodes,
cache,
reporter,
actions,
schema,
...helpers,
})

// New Code // Schema
const MdxType = schema.buildObjectType({
Expand Down
13 changes: 12 additions & 1 deletion packages/gatsby-plugin-mdx/utils/gen-mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ const BabelPluginPluckImports = require(`./babel-plugin-pluck-imports`)
* */

module.exports = async function genMDX(
{ isLoader, node, options, getNode, getNodes, reporter, cache, pathPrefix },
{
isLoader,
node,
options,
getNode,
getNodes,
reporter,
cache,
pathPrefix,
...helpers
},
{ forceDisableCache = false } = {}
) {
const pathPrefixCacheStr = pathPrefix || ``
Expand Down Expand Up @@ -106,6 +116,7 @@ export const _frontmatter = ${JSON.stringify(data)}`
reporter,
cache,
pathPrefix,
...helpers,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = async function getSourcePluginsAsRemarkPlugins({
reporter,
cache,
pathPrefix,
...helpers
}) {
debug(`getSourcePluginsAsRemarkPlugins`)
let pathPlugin = undefined
Expand Down Expand Up @@ -63,6 +64,7 @@ module.exports = async function getSourcePluginsAsRemarkPlugins({
pathPrefix,
reporter,
cache,
...helpers,
},
plugin.options || {}
)
Expand Down

0 comments on commit cd150b5

Please sign in to comment.