refactor(kit,nuxi): resolve module paths using node algorithm#19537
Merged
Conversation
|
|
Member
|
This is a really lovely initiative! Only I think we should use mlly.resolvePath that wraps same package internally for less deps, more consistency and path normalizations. |
import-meta-resolve to resolve module paths
Merged
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.
🔗 Linked issue
#18431 (comment)
❓ Type of change
📚 Description
The linked issue is caused by us trying to resolve an ESM module's path by CJS utilities, and then import it with native ESM.
This refactors our internal CJS utils in kit + nuxi to use
resolvePathfrommllywhich usesimport-meta-resolveunder the hood (a polyfill for the Node built-in). To decrease the change surface, I've restricted changes to places where we have a single search path (e.g. rootDir or cwd) and have kept the existing behaviour where we have multiple paths (e.g. wherenuxt.options.modulesDiris used).I would be up for refactoring the remaining usage of CJS utils as well, but am also happy to defer that to a subsequent PR.
As part of this, the behaviour of
tryResolveModule(exposed by kit) has changed (it is now async, it now returns a file URL, and it takes a single string as a second argument rather than an object). However, I think this is safe as it was a deprecated internal module and not used outside of nuxt itself.I've also decreased the number of internal utilities we are exposing from the CJS part of kit as a number of them are not being used elsewhere in the repo.
📝 Checklist