kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.78k stars 75 forks source link

fix: remove basedir in resolveOptions, allow original NodeJS resolve algorithm #234

Open amoshydra opened 2 months ago

amoshydra commented 2 months ago

What:

Fix #233. Allow NodeJS original node_module algorithm to be used by @esbuild-plugins/node-resolve / resolve.

Why:

68 specified basedir to cwd which causes all node_modules resolution to start at cwd. This prevent nested node_modules to ever be resolved. See #233

Below illustrate the incorrect search paths when basedir is mapped to cwd

cwd:
- "/project"

import:
- "package-a"

caller:
- "/project/node_modules/package-c"

search_paths:
- "/project/node_modules/package-a"
- "/node_modules/package-a"

How:

By removing resolveOptions.basedir, it allow @esbuild-plugins/node-resolve / resolve to use the default NodeJS node_modules resolve algorithm where node_modules resolution starts from the directory of the caller module.

Below illustrate the correct search paths

cwd:
- "/project"

import:
- "package-a"

caller:
- "/project/node_modules/package-c"

search_paths:
- "/project/node_modules/package-c/node_modules/package-a"
- "/project/node_modules/package-a"
- "/node_modules/package-a"

Checklist: