Fix: Auto-resolve binary paths in prettier.prettierPath setting #3875
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
When users configure
prettier.prettierPathto a binary executable (e.g.,/Users/user/.nvm/versions/node/v18.19.0/bin/prettierornode_modules/.bin/prettier), the extension fails withthis.prettierModule.resolveConfigFile is not a functionbecause it attempts to load the binary as a module directory.Solution
Auto-detect and resolve binary paths to their containing module directories:
Path Resolution Logic:
getModuleFromPrettierPathnode_modules/.bin/prettier→node_modules/prettier/bin/prettier.cjs)binor.binparent directoriespackage.jsonname checkSecurity:
node_modulesorprettierto prevent symlink attackshasOwnPropertychecks when parsing JSON to prevent prototype pollutionError Handling:
Backward Compatibility
Module directory paths continue to work unchanged. Binary path resolution is additive.
Related Issue
Fixes #3482
Type of Change
Checklist
npm run lintpasses)npm run prettierto format my codenpm test)Original prompt
this.prettierModule.resolveConfigFile is not a functionerror when formatting #3445💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.