Use TOML 1.0.0 compliant library for parsing (#47)

iarna/toml is unmaintained.
Replaced by smol-toml which is maintained and has the same api
This commit is contained in:
Kevin Stillhammer
2025-01-16 17:20:40 +01:00
committed by GitHub
parent 0c24450c01
commit 9071a7b1c3
6 changed files with 1139 additions and 2442 deletions
+18 -5
View File
@@ -1,15 +1,28 @@
import * as fs from "node:fs";
import * as core from "@actions/core";
import * as toml from "@iarna/toml";
import * as toml from "smol-toml";
export function getRuffVersionFromPyproject(
filePath: string,
): string | undefined {
if (!fs.existsSync(filePath)) {
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
const pyproject = toml.parse(pyprojectContent) as {
project?: { dependencies?: string[] };
"dependency-groups"?: { dev?: string[] };
};
let pyproject:
| {
project?: { dependencies?: string[] };
"dependency-groups"?: { dev?: string[] };
}
| undefined;
try {
pyproject = toml.parse(pyprojectContent);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
const dependencies: string[] = pyproject?.project?.dependencies || [];
const devDependencies: string[] = pyproject?.["dependency-groups"]?.dev || [];