File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import type { FmtConfig , ResolvedFmtConfig } from './types.ts' ;
1+ import { dirname } from 'node:path' ;
2+ import type { FmtConfig , FmtConfigDefinition , ResolvedFmtConfig } from './types.ts' ;
3+
4+ type ResolveFmtConfigOptions = {
5+ definition : FmtConfigDefinition | undefined ;
6+ configFilePath : string | null ;
7+ cwd : string ;
8+ } ;
29
310/** Splits a flat config into project-level formatting options and rules. */
411const normalizeFmtConfig = ( config : FmtConfig | undefined , rootPath : string ) : ResolvedFmtConfig => {
@@ -12,4 +19,16 @@ const normalizeFmtConfig = (config: FmtConfig | undefined, rootPath: string): Re
1219 } ;
1320} ;
1421
15- export { normalizeFmtConfig } ;
22+ /** Resolves a formatter config definition and its project root. */
23+ const resolveFmtConfig = async ( {
24+ definition,
25+ configFilePath,
26+ cwd,
27+ } : ResolveFmtConfigOptions ) : Promise < ResolvedFmtConfig > => {
28+ const config = typeof definition === 'function' ? await definition ( ) : definition ;
29+ const rootPath = configFilePath ? dirname ( configFilePath ) : cwd ;
30+
31+ return normalizeFmtConfig ( config , rootPath ) ;
32+ } ;
33+
34+ export { normalizeFmtConfig , resolveFmtConfig } ;
You can’t perform that action at this time.
0 commit comments