Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): babel.transform requires filename field now (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Oct 6, 2020
1 parent 17cdc22 commit 8e07dfd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-mdx/gatsby/on-create-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = async ({ page, actions }, pluginOptions) => {
})

// grab the exported frontmatter
const { frontmatter } = extractExports(code)
const { frontmatter } = extractExports(code, page.component)

deletePage(page)
createPage(
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-mdx/utils/create-mdx-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ module.exports = async ({ id, node, content }) => {
}

// extract all the exports
const { frontmatter, ...nodeExports } = extractExports(code)
const { frontmatter, ...nodeExports } = extractExports(
code,
node.absolutePath
)

const mdxNode = {
id,
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-mdx/utils/extract-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const objRestSpread = require(`@babel/plugin-proposal-object-rest-spread`)
const BabelPluginGatherExports = require(`./babel-plugin-gather-exports`)

// grab all the export values
module.exports = code => {
module.exports = (code, filename) => {
const instance = new BabelPluginGatherExports()
babel.transform(code, {
// Note: filename is a mandatory field
filename,
presets: [babelReact],
plugins: [instance.plugin, objRestSpread],
})
Expand Down

0 comments on commit 8e07dfd

Please sign in to comment.