Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export function resolveConfigPlugins(
if (
typeof plugin === "string" &&
!plugin.startsWith(".") &&
!path.isAbsolute(plugin)
!path.isAbsolute(plugin) &&
!plugin.startsWith("file://")
Comment on lines +46 to +47
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check !plugin.startsWith("file://") prevents file:// URLs from being resolved as node modules, but these URLs may not be usable by Prettier's plugin loader. Node.js require() expects file paths, not file:// URLs.

Consider converting file:// URLs to file paths:

if (typeof plugin === "string") {
  if (plugin.startsWith("file://")) {
    return require("url").fileURLToPath(plugin);
  }
  if (!plugin.startsWith(".") && !path.isAbsolute(plugin)) {
    return resolveNodeModule(plugin, { paths: [fileName] }) || plugin;
  }
}
return plugin;

This would handle file:// URLs by converting them to file paths before they reach Prettier's plugin loading logic.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new file:// URL handling logic lacks test coverage. Consider adding tests to verify that:

  1. Plugins with file:// URLs are not resolved as node modules
  2. file:// URLs are properly handled and can be loaded by Prettier
  3. The behavior works correctly in both isolated and pnpm/workspace scenarios

Example test:

test("it handles file:// URLs in plugin paths", async () => {
  const config = {
    plugins: ["file:///path/to/plugin"]
  };
  const result = resolveConfigPlugins(config, "/test/file.js");
  // Assert expected behavior
});

Copilot uses AI. Check for mistakes.
) {
return resolveNodeModule(plugin, { paths: [fileName] }) || plugin;
}
Expand Down