Skip to content

Commit 2b2aa85

Browse files
authored
Fix Prettier config resolution by providing file path instead of directory (#82)
1 parent d07a808 commit 2b2aa85

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/tricky-lilies-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-js': patch
3+
---
4+
5+
Fix Prettier config resolution by providing file path instead of directory

src/utils/formatCode.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mapRenderMapContentAsync, RenderMap } from '@codama/renderers-core';
1+
import { joinPath, mapRenderMapContentAsync, RenderMap } from '@codama/renderers-core';
22
import { format, Plugin, resolveConfig } from 'prettier';
33
import * as estreePlugin from 'prettier/plugins/estree';
44
import * as typeScriptPlugin from 'prettier/plugins/typescript';
@@ -43,5 +43,10 @@ async function resolvePrettierOptions(packageFolder: string | undefined): Promis
4343
}
4444

4545
if (!packageFolder) return null;
46-
return await resolveConfig(packageFolder);
46+
47+
// Prettier expects a file path to resolve, not just its directory.
48+
// Therefore we must append a filename (any will do) to ensure the
49+
// provided directory is searched for config files.
50+
const filePathToResolve = joinPath(packageFolder, 'package.json');
51+
return await resolveConfig(filePathToResolve);
4752
}

0 commit comments

Comments
 (0)