Skip to content

Commit 66af7eb

Browse files
authored
feat(fmt): resolve formatter config (#112)
1 parent 023edfd commit 66af7eb

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

packages/rstack/src/fmt/config.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
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. */
411
const 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 };

0 commit comments

Comments
 (0)