Turbopack: add extension alias config option to match alternate file extensions#95426
Open
mischnic wants to merge 4 commits into
Open
Turbopack: add extension alias config option to match alternate file extensions#95426mischnic wants to merge 4 commits into
mischnic wants to merge 4 commits into
Conversation
…xtension-alias.test.ts Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Contributor
Tests PassedCommit: f627c55 |
Contributor
Stats cancelledCommit: f627c55 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Recration of #95261 , original description:
Fixes #82945
Closes PACK-5449
Adds a config option that can resolve extensions with other optional extensions, matching the behavior of Webpack's
resolve.extensionAlias:TypeScript with ESM sets the expectation that you don't transform the import, so it wants to import from the compiled
.jsfile. This breaks down in Next if you have code that's shared between a Node.js server and your Next app.Most of the pieces were already in place because of other direct aliasing options for Turbopack (
resolveAlias). I did have to match 3 different prefixes ("","./","../") to cover all potential paths. This could be considered leaking internal implementation details fromImportMap::lookup...There's a new E2E test exercising this functionality.
I've looked at this a few different ways for perf concerns. Yes we're adding some wildcard matching, but I think the only new computation is at config/setup time, in a hopefully-cached turbo task.
Finally, I have identified one limitation: When the option is used, some dynamic imports with >4 sections will be too complex to match. This is already an issue with existing alias code. It will trigger a hard error with a "Complex patterns into wildcard exports fields are not implemented" message. Since this doesn't add errors if the option isn't leveraged, we should consider