import { logger } from '../../../logger/index.ts'; import { getSiblingFileName, readLocalFile, writeLocalFile, } from '../../../util/fs/index.ts'; import type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts'; import { updateBazelLockfile } from './lockfile.ts'; export async function updateArtifacts({ packageFileName, updatedDeps, newPackageFileContent, config, }: UpdateArtifact): Promise { logger.debug(`bazel-module.updateArtifacts(${packageFileName})`); const { isLockFileMaintenance } = config; if (!updatedDeps.length && !isLockFileMaintenance) { logger.debug('No updated bazel-module deps - returning null'); return null; } const lockFileName = getSiblingFileName(packageFileName, 'MODULE.bazel.lock'); const existingLockContent = await readLocalFile(lockFileName, 'utf8'); if (!existingLockContent) { logger.debug('No MODULE.bazel.lock found - skipping artifact update'); return null; } await writeLocalFile(packageFileName, newPackageFileContent); return await updateBazelLockfile( lockFileName, packageFileName, isLockFileMaintenance, config.constraints?.bazelisk, ); }