feat(resolve): support subpath imports#10929
Closed
aleclarson wants to merge 9 commits intovitejs:mainfrom
Closed
Conversation
Closes vitejs#4439 More context: vitejs#10504
Bug introduced in vitejs#10683 Some packages use "require" instead of "default" for CJS entry
…in the `getInlineConditions` function.
…and avoid breaking certain `tryFsResolve` calls too (like with `es5-ext`)
The "{id}/package.json" lookup done by `resolvePackageData` is insufficient for certain edge cases, like when "node_modules/{dep}" is linked to a directory without a package.json in it. With this PR, you can now import any file from node_modules even if it has no package.json file associated with it. This mirrors the same capability in Node's resolution algorithm.
In addition to supporting more edge cases, this new implementation might also be faster in some cases, since we are doing less lookups than compared to the previous behavior of calling `resolvePackageData` for every path in the `possiblePkgIds` array.
benmccann
reviewed
Nov 15, 2022
benmccann
reviewed
Nov 15, 2022
Contributor
Author
|
@benmccann You might want to look at only b3ef8f3 if you want to review this PR, as there are other PRs it depends on, thereby adding a bunch of noise to the "Files changed" tab. |
benmccann
reviewed
Nov 15, 2022
| } | ||
|
|
||
| // Find the importer's nearest package.json with a "name" field. | ||
| // Some projects (like Svelte) have nameless package.json files to |
Collaborator
There was a problem hiding this comment.
this will probably change in the future with Svelte 4 when we drop support for old versions of Node, so worth including the version here
Suggested change
| // Some projects (like Svelte) have nameless package.json files to | |
| // Some projects (like Svelte 3) have nameless package.json files to |
9 tasks
benmccann
reviewed
Feb 22, 2023
| "postcss-load-config": "^4.0.1", | ||
| "postcss-modules": "^5.0.0", | ||
| "resolve.exports": "^1.1.0", | ||
| "resolve.exports": "npm:@alloc/resolve.exports@^1.1.0", |
Collaborator
There was a problem hiding this comment.
we don't need to change this to use a fork. the current resolve.exports version used by Vite supports subpath imports
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.
Description
This uses
resolveExportsto resolve subpath imports. To do so, it has to replace the leading#with./to mimic anexportsmapping field. With each path returned byresolveExports, we callthis.resolveto support mapping to external packages (the Node.js docs say this is valid).Additional context
Closes #7385
TODO: Write tests or copy them over from #7770
What is the purpose of this pull request?