fix(esbuild-plugin-pnp): respect resolveDir #4569
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On-load callbacks can provide a custom
resolveDir
for virtual modules; if set, it should be used for resolving paths in that file.importer
is only guaranteed to be a file system path if the namespace isfile
.For context, see: https://esbuild.github.io/plugins/#on-resolve-arguments
What's the problem this PR addresses?
If another esbuild plugin creates virtual modules with relative imports, esbuild-plugin-pnp will incorrectly resolve them, since it assumes
importer
(the virtual module) is a real file path, and there are no such guarantees. This bug was observed after integrating esbuild-plugin-pnp into remix core and attempting to convert virtual modules to use relative imports.How did you fix it?
Updated esbuild-plugin-pnp to use resolveDir (if set):
file
namespace, this is equivalent topath.dirname(importer)
, so the behavior there is unchangedimporter
andbaseDir
Also added an end-to-end test to verify the behavior (fails on master, passes with the fix).
Checklist