@@ -10,6 +10,9 @@ export type BiomeLoaderOptions = {
1010 alwaysFormat ?: boolean ;
1111} ;
1212
13+ // Track warnings shown per file extension to avoid spam
14+ const shownWarnings = new Set < string > ( ) ;
15+
1316export default function createBiomeLoader (
1417 options : BiomeLoaderOptions ,
1518) : ILoader < string , string > {
@@ -46,32 +49,57 @@ async function formatDataWithBiome(
4649 filePath : string ,
4750 options : BiomeLoaderOptions ,
4851) : Promise < string > {
52+ let configPath : string | null = null ;
53+
4954 try {
5055 const biome = await Biome . create ( {
5156 distribution : Distribution . NODE ,
5257 } ) ;
5358
59+ // Open a project (required in v3.0.0+)
60+ const openResult = biome . openProject ( "." ) ;
61+ const projectKey = openResult . projectKey ;
62+
5463 // Load config from biome.json/biome.jsonc if exists
55- const configPath = await findBiomeConfig ( filePath ) ;
64+ configPath = await findBiomeConfig ( filePath ) ;
5665 if ( ! configPath && ! options . alwaysFormat ) {
5766 return data ; // Skip if no config and not forced
5867 }
5968
6069 if ( configPath ) {
6170 const configContent = await fs . readFile ( configPath , "utf-8" ) ;
62- biome . applyConfiguration ( JSON . parse ( configContent ) ) ;
71+ try {
72+ const config = JSON . parse ( configContent ) ;
73+ biome . applyConfiguration ( projectKey , config ) ;
74+ } catch ( parseError ) {
75+ throw new Error (
76+ `Invalid Biome configuration in ${ configPath } : ${ parseError instanceof Error ? parseError . message : "JSON parse error" } ` ,
77+ ) ;
78+ }
6379 }
6480
65- const formatted = biome . formatContent ( data , {
81+ const formatted = biome . formatContent ( projectKey , data , {
6682 filePath,
6783 } ) ;
6884
6985 return formatted . content ;
7086 } catch ( error ) {
71- if ( error instanceof Error ) {
87+ const ext = path . extname ( filePath ) ;
88+
89+ // Only show warning once per file extension
90+ if ( ! shownWarnings . has ( ext ) ) {
91+ shownWarnings . add ( ext ) ;
92+
7293 console . log ( ) ;
73- console . log ( "⚠️ Biome formatting failed:" , error . message ) ;
94+ console . log (
95+ `⚠️ Biome does not support ${ ext } files - skipping formatting` ,
96+ ) ;
97+
98+ if ( error instanceof Error && error . message ) {
99+ console . log ( ` ${ error . message } ` ) ;
100+ }
74101 }
102+
75103 return data ; // Fallback to unformatted
76104 }
77105}
0 commit comments