0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 21:48:32 +00:00
renovatebot_renovate/lib/modules/manager/npm/extract/npm.ts
2023-11-07 15:50:29 +00:00

24 lines
729 B
TypeScript

import { logger } from '../../../../logger';
import { readLocalFile } from '../../../../util/fs';
import { PackageLock } from '../schema';
import type { LockFile } from './types';
export async function getNpmLock(filePath: string): Promise<LockFile> {
const lockfileContent = await readLocalFile(filePath, 'utf8');
if (!lockfileContent) {
logger.debug({ filePath }, 'Npm: unable to read lockfile');
return { lockedVersions: {} };
}
const parsedLockfile = PackageLock.safeParse(lockfileContent);
if (!parsedLockfile.success) {
logger.debug(
{ filePath, err: parsedLockfile.error },
'Npm: unable to parse lockfile',
);
return { lockedVersions: {} };
}
return parsedLockfile.data;
}