-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolver: recursive remaps (browser & tsconfig) #323
base: main
Are you sure you want to change the base?
Conversation
@evanw Have you had time to look at this ? The Looking at the resolver code from We can see that the entirety of |
9224562
to
6043b12
Compare
It looks like this PR is actually for two separate features:
|
They are indeed different mechanisms, but I grouped them together since they both concern import rewrites/remaps and the issue is not that they don't work, but that both do not work recursively (so the PR was broadly about making all rewrite/remap logic work recursively). Happy to split them out, especially if there is more debate around the
To give some context, prior to The team member who originally replaced Ultimately we need(ed) a mechanism for "deep" rewrites of imports used by modules we do not control (e.g: deps of deps installed from NPM), similar to what webpack's
Sorry if that was confusing, for the purpose of this issue it doesn't matter wether those files are This comment is a bit of a brain dump (hopefully it provides context and clears up a few things), I'll follow-up with a cleaner comment on the core issue on how it could be fixed. |
FWIW I'm planning for resolver plugins to address more advanced path alias use cases. In addition to supporting this use case, they should also be able to support even more advanced use cases that require actually executing JavaScript code to do path resolution that can't be represented as a map (e.g. Yarn PnP). This approach should be fully general-purpose. |
Recap of the previous comment: we needed a mechanism for deep remaps with I've put together a small repo to reproduce this stuff: https://github.com/AaronO/esbuild-issue-tsconfig The conclusion there is that
Unfortunately it's common for published NPM modules to ship their Root problems
If we define common categories of remap contexts as following:
fallback has the downside of sometimes behaving (for the end-user) as merged or direct, which can be perceived as annoyingly inconsistent. If we want to follow existing conventions we should correct that (turn it into direct like I was pushing to make it behave like merged as that would give us a means to express deep remaps without adding a new concept/config, whilst being more consistent than the current behaviour and a superset of the established behaviour. But your comment on custom |
Sorry for all that noisy context, I'll split out the browser part into a different PR.
That sounds great, do you have an ETA in mind ? Anything we could help with ? BTW, I was also using these "deep remaps" to workaround |
Problem
esbuild
(unlikewebpack
andtsc
I believe) does not currently allow remaps (i.e: rewriting imports) for submodules that define their own remaps even if there are no conflicts/overlaps between remaps from parent and child modules.This happens because
esbuild
resolves remaps (in a submodule) by using the remap context closest defined to the submodule.Example problem
Remapping
react-native
toreact-native-web
in the entrypoint/app module and importing a submodule that usesreact-native
and defines its own (unrelated)tsconfig.compilerOptions.paths
.Similar issues happen for
package.json
's.browser
.Solution
Enable the resolver to recursively lookup remaps in parent contexts.
This changes the effective remap context (in pseudocode) from:
to:
Effectively a merge (or union) of contexts with child-keys (closest to the submodule) taking precedence.
I don't see any downside to "merging" contexts vs the current "fallback" approach, since the "merged context" is a superset of the current "fallback context" (do let me know if I'm missing something)
Fixes #238
Tests with & without fixes
I've added two unit-tests
TestPackageJsonBrowserRecursive
andTestTsConfigPathsRecursive
that fail usingresolver.go
frommaster
and pass using this branch'sresolver.go