-
-
Notifications
You must be signed in to change notification settings - Fork 510
Open
Labels
staleNo recent activityNo recent activitytriage-pendingAwaiting initial triageAwaiting initial triage
Description
Problem
Plugin path resolution logic is duplicated in two places within PrettierEditService.ts:
resolvePlugins()(lines 47-100) - used during formattinggetSelectors()(lines 102-129) - used for language discovery
Both need to handle:
- Plugin objects (pass through)
- URLs (file://, data:// - pass through)
- Absolute paths (convert to file:// for v3 ESM)
- Relative paths (resolve relative to file being formatted)
- Package names (resolve via createRequire)
Proposed Solution
Create a single PluginResolver class or utility module that:
- Handles all plugin path resolution logic in one place
- Provides version-aware URL conversion (file:// for v3 ESM, absolute paths for v2)
- Caches resolved plugins per workspace to avoid repeated resolution
- Exposes clear methods for both formatting and selector use cases
Example Structure
class PluginResolver {
private cache = new Map<string, ResolvedPlugin[]>();
async resolvePlugins(
plugins: PrettierOptions['plugins'],
filePath: string,
prettierVersion: string
): Promise<ResolvedPlugin[]> {
// Unified resolution logic
}
clearCache(workspacePath?: string): void {
// Clear cache on config changes
}
}Benefits
- Single source of truth for plugin resolution
- Easier to maintain and test
- Consistent behavior across all plugin usage
- Caching improves performance
Relevant Files
src/PrettierEditService.ts-resolvePlugins()andgetSelectors()methods- Consider creating new file:
src/PluginResolver.ts
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
staleNo recent activityNo recent activitytriage-pendingAwaiting initial triageAwaiting initial triage