From 616c5b06ce5ab46e283055234a93986cb5245e61 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 20 Jul 2021 12:51:07 +0100 Subject: [PATCH] fix: remove absRoot plugin and change node-resolve config. --- src/__tests__/index.js | 6 +++--- src/index.js | 28 ++++++---------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/__tests__/index.js b/src/__tests__/index.js index ddd18dc..2439fbb 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -301,15 +301,15 @@ test('require from current directory', async () => { const mdxSource = ` # Title -import {Sample} from './other/sample-component' +import {Sample} from './sample-component' -![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] diff --git a/src/index.js b/src/index.js index 02556e8..4cf2322 100644 --- a/src/index.js +++ b/src/index.js @@ -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, @@ -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({ @@ -192,6 +174,7 @@ async function bundleMDX( return { code: `${code};return Component.default;`, frontmatter, + errors: bundled.errors, } } @@ -209,6 +192,7 @@ async function bundleMDX( return { code: `${code};return Component.default;`, frontmatter, + errors: bundled.errors, } }