Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): Fix not passing file path to remark plugins (#…
Browse files Browse the repository at this point in the history
…26914)

* Fix gatsby-plugin-mdx not passing file path to remark plugins

* Add comments for the test
  • Loading branch information
kevin940726 committed Sep 23, 2020
1 parent 18944ce commit 5d39594
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions e2e-tests/mdx/gatsby-config.js
Expand Up @@ -17,13 +17,27 @@ module.exports = {
path: `${__dirname}/src/posts`,
},
},
{resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.mdx`, `.md`],
defaultLayouts: {
default: require.resolve("./src/components/layout.js"),
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.mdx`, `.md`],
defaultLayouts: {
default: require.resolve("./src/components/layout.js"),
},
remarkPlugins: [remarkRequireFilePathPlugin],
},
}
},
},
],
}

/**
* This is a test to ensure that `gatsby-plugin-mdx` correctly pass the `file` argument to the underlying remark plugins.
* See #26914 for more info.
*/
function remarkRequireFilePathPlugin() {
return function transformer(tree, file) {
if (!file.dirname) {
throw new Error("No directory name for this markdown file!")
}
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-mdx/utils/gen-mdx.js
Expand Up @@ -241,7 +241,7 @@ async function findImports({
}

let mdast = await compiler.parse(fileOpts)
mdast = await compiler.run(mdast)
mdast = await compiler.run(mdast, fileOpts)

// Assuming valid code, identifiers must be unique (they are consts) so
// we don't need to dedupe the symbols here.
Expand Down

0 comments on commit 5d39594

Please sign in to comment.