Skip to content

Commit 7b8e546

Browse files
authored
fix: with cwd the fake entry point can't exist (#33)
1 parent 1065373 commit 7b8e546

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/__tests__/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ import Demo from './demo'
148148
assert.equal(
149149
error.message,
150150
`Build failed with 1 error:
151-
__mdx_bundler_fake_dir__/index.mdx:2:17: error: Could not resolve "./demo"`,
151+
__mdx_bundler_fake_dir__/_mdx_bundler_entry_point.mdx:2:17: error: Could not resolve "./demo"`,
152152
)
153153
})
154154

@@ -188,7 +188,7 @@ import Demo from './demo.blah'
188188
assert.equal(
189189
error.message,
190190
`Build failed with 1 error:
191-
__mdx_bundler_fake_dir__/index.mdx:2:17: error: [plugin: JavaScript plugins] Invalid loader: "blah" (valid: js, jsx, ts, tsx, css, json, text, base64, dataurl, file, binary)`,
191+
__mdx_bundler_fake_dir__/_mdx_bundler_entry_point.mdx:2:17: error: [plugin: JavaScript plugins] Invalid loader: "blah" (valid: js, jsx, ts, tsx, css, json, text, base64, dataurl, file, binary)`,
192192
)
193193
})
194194

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ import {NodeResolvePlugin} from '@esbuild-plugins/node-resolve'
88
import {globalExternals} from '@fal-works/esbuild-plugin-global-externals'
99
import dirnameMessedUp from './dirname-messed-up.cjs'
1010

11-
if (dirnameMessedUp && !process.env.ESBUILD_BINARY_PATH) {
12-
console.warn(
13-
`mdx-bundler warning: esbuild maybe unable to find its binary, if your build fails you'll need to set ESBUILD_BINARY_PATH. Learn more: https://github.com/kentcdodds/mdx-bundler/blob/main/README.md#nextjs-esbuild-enoent`,
14-
)
15-
}
16-
1711
/**
1812
*
1913
* @param {string} mdxSource - A string of mdx source code
@@ -30,6 +24,12 @@ async function bundleMDX(
3024
cwd = path.join(process.cwd(), `__mdx_bundler_fake_dir__`),
3125
} = {},
3226
) {
27+
if (dirnameMessedUp && !process.env.ESBUILD_BINARY_PATH) {
28+
console.warn(
29+
`mdx-bundler warning: esbuild maybe unable to find its binary, if your build fails you'll need to set ESBUILD_BINARY_PATH. Learn more: https://github.com/kentcdodds/mdx-bundler/blob/main/README.md#nextjs-esbuild-enoent`,
30+
)
31+
}
32+
3333
// xdm is a native ESM, and we're running in a CJS context. This is the
3434
// only way to import ESM within CJS
3535
const [{compile: compileMDX}, {default: xdmESBuild}] = await Promise.all([
@@ -39,7 +39,7 @@ async function bundleMDX(
3939
// extract the frontmatter
4040
const {data: frontmatter} = matter(mdxSource)
4141

42-
const entryPath = path.join(cwd, './index.mdx')
42+
const entryPath = path.join(cwd, './_mdx_bundler_entry_point.mdx')
4343

4444
/** @type Record<string, string> */
4545
const absoluteFiles = {[entryPath]: mdxSource}

0 commit comments

Comments
 (0)