Files
renovate/lib/modules/manager/gleam/artifacts.ts
Sebastian Poxhofer 9fc451c44d refactor(manager): share the lock file updateArtifacts skeleton (#46093)
Migrate pub, gleam, helmfile, pixi, mise, poetry, pep621/pdm and
pep621/uv onto `updateLockFile()`, so each manager keeps only its
command and `ExecOptions` construction.

Behaviour changes:

- Artifact error text now comes from `artifactErrorMessageFromExecError`,
  i.e. a non-blank `err.stderr`, else a non-blank `err.stdout`, else
  `err.message`. Previously pixi used `${err}` ("Error: " prefix), mise
  joined stdout, stderr and message, and poetry rendered
  "<stdout>\n<stderr>" (literally "undefined\nundefined" when the error
  carried neither).
- helmfile, pixi, poetry, pdm and uv now return null instead of an
  addition when the lock file is missing or empty after the run, which
  is what gleam and mise already did.
- Unchanged/missing lock file debug messages are now uniformly
  "<lockFileName> is unchanged" / "No <lockFileName> found". pub gains
  such a message, mise loses "Returning updated mise lock file" and
  poetry loses "Returning updated <lockFileName>".
2026-09-16 13:13:42 +00:00

72 lines
2.3 KiB
TypeScript

import { isEmptyArray, isString } from '@sindresorhus/is';
import { quote } from 'shlex';
import { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';
import { logger } from '../../../logger/index.ts';
import { exec } from '../../../util/exec/index.ts';
import type { ExecOptions } from '../../../util/exec/types.ts';
import { getSiblingFileName, readLocalFile } from '../../../util/fs/index.ts';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';
import {
artifactErrorResult,
resolveToolConstraint,
updateLockFile,
} from '../util.ts';
export async function updateArtifacts(
updateArtifact: UpdateArtifact,
): Promise<UpdateArtifactsResult[] | null> {
const { packageFileName, updatedDeps, newPackageFileContent, config } =
updateArtifact;
logger.debug(`gleam.updateArtifacts(${packageFileName})`);
const { isLockFileMaintenance } = config;
if (isEmptyArray(updatedDeps) && !isLockFileMaintenance) {
logger.debug('No updated gleam deps - returning null');
return null;
}
const lockFileName = getSiblingFileName(packageFileName, 'manifest.toml');
const oldLockFileContent = await readLocalFile(lockFileName, 'utf8');
if (!oldLockFileContent) {
logger.debug(`No ${lockFileName} found`);
return null;
}
try {
const execOptions: ExecOptions = {
cwdFile: packageFileName,
docker: {},
toolConstraints: [
{
toolName: 'gleam',
constraint: await resolveToolConstraint(config, 'gleam'),
},
],
};
// `gleam deps update` with no packages rebuilds the lock file
const packagesToUpdate = isLockFileMaintenance
? []
: updatedDeps.map((dep) => dep.depName).filter(isString);
const updateCommand = [
'gleam deps update',
...packagesToUpdate.map(quote),
].join(' ');
return await updateLockFile({
lockFileName,
existingLockFileContent: oldLockFileContent,
packageFile: { path: packageFileName, contents: newPackageFileContent },
deleteLockFile: isLockFileMaintenance,
run: () => exec(updateCommand, execOptions),
});
} catch (err) {
if (err.message === TEMPORARY_ERROR) {
throw err;
}
logger.warn({ lockfile: lockFileName, err }, `Failed to update lock file`);
return artifactErrorResult(lockFileName, err);
}
}