fix: Enhance plugin resolution in ModuleLoader #3803
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.
Added a check to ensure that plugin paths do not start with
file://
, in addition to the existing checks for relative and absolute paths. This improves the robustness of the plugin resolution logic.I created a shared Prettier configuration via
npm
that includes plugins. However, in apnpm
project, the plugin strings fail to locate the corresponding modules unlessimport.meta.resolve
is used to resolve the module paths (see this issue).After applying this fix, the Prettier CLI works correctly to format documents.
However,
import.meta.resolve()
returns URLs that start withfile://
. Sincepath.isAbsolute(plugin)
returnsfalse
for such URLs, the path is incorrectly treated as non-absolute, leading to unexpected behavior. This can be resolved by converting the URL to a file path usingurl.fileURLToPath(import.meta.resolve('xxx'))
, which allows the plugin to work correctly with Prettier.To improve reliability, I suggest adding an explicit check to treat paths starting with
file://
as absolute paths during plugin resolution.