renovate/lib/modules/manager/poetry/locked-version.ts
Rhys Arkins 7e2e0b3f18
feat(poetry): updateLockedDependency() (#14627)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-03-14 17:56:09 +01:00

25 lines
751 B
TypeScript

import { parse } from '@iarna/toml';
import { logger } from '../../../logger';
import type { PoetryLock } from './types';
export function extractLockFileEntries(
lockFileContent: string
): Record<string, string> {
let poetryLockfile: PoetryLock = {};
try {
poetryLockfile = parse(lockFileContent);
} catch (err) {
logger.debug({ err }, 'Error parsing poetry.lock file');
}
const lockfileMapping: Record<string, string> = {};
if (poetryLockfile?.package) {
// Create a package->version mapping
for (const poetryPackage of poetryLockfile.package) {
if (poetryPackage.name && poetryPackage.version) {
lockfileMapping[poetryPackage.name] = poetryPackage.version;
}
}
}
return lockfileMapping;
}