2022-03-03 09:35:26 +00:00
|
|
|
import { logger } from '../../../logger';
|
2021-12-23 10:54:36 +00:00
|
|
|
import type { UpdateLockedConfig, UpdateLockedResult } from '../types';
|
|
|
|
import { extractLockFileEntries } from './locked-version';
|
|
|
|
|
|
|
|
export function updateLockedDependency(
|
|
|
|
config: UpdateLockedConfig
|
|
|
|
): UpdateLockedResult {
|
|
|
|
const { depName, currentVersion, newVersion, lockFile, lockFileContent } =
|
|
|
|
config;
|
|
|
|
logger.debug(
|
2022-10-21 15:29:39 +00:00
|
|
|
`bundler.updateLockedDependency: ${depName}@${currentVersion} -> ${newVersion} [${lockFile}]`
|
2021-12-23 10:54:36 +00:00
|
|
|
);
|
|
|
|
try {
|
2022-10-19 12:59:32 +00:00
|
|
|
const locked = extractLockFileEntries(lockFileContent ?? '');
|
|
|
|
if (locked.get(depName ?? '') === newVersion) {
|
2021-12-23 10:54:36 +00:00
|
|
|
return { status: 'already-updated' };
|
|
|
|
}
|
|
|
|
return { status: 'unsupported' };
|
2022-10-19 12:59:32 +00:00
|
|
|
} catch (err) {
|
2022-03-14 16:56:09 +00:00
|
|
|
logger.debug({ err }, 'bundler.updateLockedDependency() error');
|
2021-12-23 10:54:36 +00:00
|
|
|
return { status: 'update-failed' };
|
|
|
|
}
|
|
|
|
}
|