Skip to content

Commit

Permalink
fix: remove absRoot plugin and change node-resolve config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Jul 20, 2021
1 parent 9068855 commit 616c5b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ test('require from current directory', async () => {
const mdxSource = `
# Title
import {Sample} from './other/sample-component'
import {Sample} from './sample-component'
<Sample />
![A Sample Image](./other/150.png)
![A Sample Image](./150.png)
`.trim()

const {code} = await bundleMDX(mdxSource, {
cwd: process.cwd(),
cwd: path.join(process.cwd(), 'other'),
xdmOptions: options => {
options.remarkPlugins = [remarkMdxImages]

Expand Down
28 changes: 6 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,6 @@ async function bundleMDX(
},
}

/** @type import('esbuild').Plugin */
const absRootPlugin = {
name: 'absRoot',
setup: ({onResolve}) => {
onResolve({filter: /.*/}, ({path: filePath, importer}) => {
const modulePath = path.resolve(path.dirname(importer), filePath)

if (
modulePath.includes('__mdx_bundler_fake_dir__') ||
modulePath === entryPath
) {
return
}

// eslint-disable-next-line consistent-return
return {path: modulePath}
})
},
}

const buildOptions = esbuildOptions({
entryPoints: [entryPath],
write: false,
Expand All @@ -164,8 +144,10 @@ async function bundleMDX(
},
}),
// eslint-disable-next-line @babel/new-cap
NodeResolvePlugin({extensions: ['.js', '.ts', '.jsx', '.tsx']}),
absRootPlugin,
NodeResolvePlugin({
extensions: ['.js', '.ts', '.jsx', '.tsx'],
resolveOptions: {basedir: cwd},
}),
inMemoryPlugin,
xdmESBuild(
xdmOptions({
Expand All @@ -192,6 +174,7 @@ async function bundleMDX(
return {
code: `${code};return Component.default;`,
frontmatter,
errors: bundled.errors,
}
}

Expand All @@ -209,6 +192,7 @@ async function bundleMDX(
return {
code: `${code};return Component.default;`,
frontmatter,
errors: bundled.errors,
}
}

Expand Down

0 comments on commit 616c5b0

Please sign in to comment.