5
0
mirror of https://github.com/astral-sh/setup-uv.git synced 2025-12-15 11:07:14 +00:00
Files
setup-uv/src/utils/config-file.ts
2025-10-07 16:08:30 +02:00

25 lines
649 B
TypeScript

import fs from "node:fs";
import * as toml from "smol-toml";
export function getConfigValueFromTomlFile(
filePath: string,
key: string,
): string | undefined {
if (!fs.existsSync(filePath) || !filePath.endsWith(".toml")) {
return undefined;
}
const fileContent = fs.readFileSync(filePath, "utf-8");
if (filePath.endsWith("pyproject.toml")) {
const tomlContent = toml.parse(fileContent) as {
tool?: { uv?: Record<string, string | undefined> };
};
return tomlContent?.tool?.uv?.[key];
}
const tomlContent = toml.parse(fileContent) as Record<
string,
string | undefined
>;
return tomlContent[key];
}