Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-mdx): babel.transform requires filename field now #27305

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-mdx/gatsby/on-create-page.js
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
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
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