Skip to content

Commit

Permalink
Merge pull request #10223 from rileylnapier/patch-3
Browse files Browse the repository at this point in the history
Storyshots: Fix mdx transform
  • Loading branch information
Hypnosphi authored and shilman committed Mar 31, 2020
1 parent 23e91d5 commit 6fb4266
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions addons/docs/jest-transform-mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ const createCompiler = require('./mdx-compiler-plugin');

const compilers = [createCompiler({})];

const getNextTransformer = (filename, config) => {
const extension = path.extname(filename);
const jsFileName = `${filename.slice(0, -extension.length)}.js`;
const self = config.transform.find(([pattern]) => new RegExp(pattern).test(filename));
const jsTransforms = config.transform.filter(([pattern]) => new RegExp(pattern).test(jsFileName));
return new ScriptTransformer({
...config,
transform: [
...config.transform.filter(entry => entry !== self),
...jsTransforms.map(([pattern, ...rest]) => [self[0], ...rest]),
],
});
};

module.exports = {
process(src, filename, config, { instrument }) {
const result = dedent`
Expand All @@ -29,6 +15,10 @@ module.exports = {
import { mdx } from '@mdx-js/react'
${mdx.sync(src, { compilers, filepath: filename })}
`;
return getNextTransformer(filename, config).transformSource(filename, result, instrument);

const extension = path.extname(filename);
const jsFileName = `${filename.slice(0, -extension.length)}.js`;

return new ScriptTransformer(config).transformSource(jsFileName, result, instrument);
},
};

0 comments on commit 6fb4266

Please sign in to comment.