@@ -3,7 +3,7 @@ import { performance } from 'node:perf_hooks';
33import { color , logger } from 'rslog' ;
44import { parseArgs } from '../cli/args.ts' ;
55import { printCommandHelp } from '../cli/help.ts' ;
6- import { loadRstackConfig } from '../config.ts' ;
6+ import { loadRstackConfig , type LoadedRstackConfig } from '../config.ts' ;
77import { ensureProjectCacheDir } from '../projectCache.ts' ;
88import { fmtCacheFileName } from './cacheStore.ts' ;
99import { resolveFmtConfig } from './config.ts' ;
@@ -29,6 +29,11 @@ interface ParsedFmtCLIArgs {
2929 lsp : boolean ;
3030}
3131
32+ type RunFmtCLIOptions = {
33+ /** Rstack config already loaded by the lint phase of `rs check`. */
34+ loadedConfig ?: LoadedRstackConfig ;
35+ } ;
36+
3237const parseMaxWorkers = ( value : string | undefined ) : number | undefined => {
3338 if ( value === undefined ) {
3439 return undefined ;
@@ -255,8 +260,12 @@ const logFmtResult = (
255260 }
256261} ;
257262
258- const loadFmtConfig = async ( cwd : string ) : Promise < ResolvedFmtConfig > => {
259- const { configs, filePath } = await loadRstackConfig ( { cwd } ) ;
263+ const loadFmtConfig = async (
264+ cwd : string ,
265+ loadedConfig ?: LoadedRstackConfig ,
266+ ) : Promise < ResolvedFmtConfig > => {
267+ const { configs, filePath } =
268+ loadedConfig ?? ( await loadRstackConfig ( { cwd } ) ) ;
260269
261270 return resolveFmtConfig ( {
262271 definition : configs . fmt ,
@@ -265,7 +274,10 @@ const loadFmtConfig = async (cwd: string): Promise<ResolvedFmtConfig> => {
265274 } ) ;
266275} ;
267276
268- const runFmtCLI = async ( args : string [ ] ) : Promise < void > => {
277+ const runFmtCLI = async (
278+ args : string [ ] ,
279+ { loadedConfig } : RunFmtCLIOptions = { } ,
280+ ) : Promise < void > => {
269281 const cwd = process . cwd ( ) ;
270282 const startTime = performance . now ( ) ;
271283
@@ -337,7 +349,7 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
337349 }
338350 }
339351
340- const config = await loadFmtConfig ( cwd ) ;
352+ const config = await loadFmtConfig ( cwd , loadedConfig ) ;
341353 const files = await discoverFmtFiles ( {
342354 cwd,
343355 patterns,
0 commit comments