mirror of
https://github.com/renovatebot/renovate.git
synced 2024-12-22 13:38:32 +00:00
98 lines
2.6 KiB
TypeScript
98 lines
2.6 KiB
TypeScript
import is from '@sindresorhus/is';
|
|
import { GlobalConfig } from '../../../config/global';
|
|
import { TEMPORARY_ERROR } from '../../../constants/error-messages';
|
|
import { logger } from '../../../logger';
|
|
import { exec } from '../../../util/exec';
|
|
import type { ExecOptions } from '../../../util/exec/types';
|
|
import {
|
|
deleteLocalFile,
|
|
readLocalFile,
|
|
writeLocalFile,
|
|
} from '../../../util/fs';
|
|
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
|
|
|
|
export async function updateArtifacts(
|
|
updateArtifact: UpdateArtifact,
|
|
): Promise<UpdateArtifactsResult[] | null> {
|
|
const { packageFileName, updatedDeps, newPackageFileContent, config } =
|
|
updateArtifact;
|
|
logger.debug(`bun.updateArtifacts(${packageFileName})`);
|
|
const isLockFileMaintenance = config.updateType === 'lockFileMaintenance';
|
|
|
|
if (is.emptyArray(updatedDeps) && !isLockFileMaintenance) {
|
|
logger.debug('No updated bun deps - returning null');
|
|
return null;
|
|
}
|
|
|
|
// Find the first bun dependency in order to handle mixed manager updates
|
|
const lockFileName = updatedDeps.find((dep) => dep.manager === 'bun')
|
|
?.lockFiles?.[0];
|
|
|
|
if (!lockFileName) {
|
|
logger.debug(`No ${lockFileName} found`);
|
|
return null;
|
|
}
|
|
|
|
const oldLockFileContent = await readLocalFile(lockFileName);
|
|
if (!oldLockFileContent) {
|
|
logger.debug(`No ${lockFileName} found`);
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
await writeLocalFile(packageFileName, newPackageFileContent);
|
|
if (isLockFileMaintenance) {
|
|
await deleteLocalFile(lockFileName);
|
|
}
|
|
|
|
let cmd = 'bun install';
|
|
|
|
if (!GlobalConfig.get('allowScripts') || config.ignoreScripts) {
|
|
cmd += ' --ignore-scripts';
|
|
}
|
|
|
|
const execOptions: ExecOptions = {
|
|
userConfiguredEnv: config.env,
|
|
cwdFile: packageFileName,
|
|
docker: {},
|
|
toolConstraints: [
|
|
{
|
|
toolName: 'bun',
|
|
constraint: updateArtifact?.config?.constraints?.bun,
|
|
},
|
|
],
|
|
};
|
|
|
|
await exec(cmd, execOptions);
|
|
const newLockFileContent = await readLocalFile(lockFileName);
|
|
if (
|
|
!newLockFileContent ||
|
|
Buffer.compare(oldLockFileContent, newLockFileContent) === 0
|
|
) {
|
|
return null;
|
|
}
|
|
return [
|
|
{
|
|
file: {
|
|
type: 'addition',
|
|
path: lockFileName,
|
|
contents: newLockFileContent,
|
|
},
|
|
},
|
|
];
|
|
} catch (err) {
|
|
if (err.message === TEMPORARY_ERROR) {
|
|
throw err;
|
|
}
|
|
logger.warn({ lockfile: lockFileName, err }, `Failed to update lock file`);
|
|
return [
|
|
{
|
|
artifactError: {
|
|
lockFile: lockFileName,
|
|
stderr: err.message,
|
|
},
|
|
},
|
|
];
|
|
}
|
|
}
|