mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 02:29:51 +00:00
4b4d14ec00
* feat(manager): pass extracted constraints to updateArtifacts `extractedConstraints` were collected during extraction but only ever read by `fetch.ts` for the lookup. At artifact time every manager had to derive the same tool constraints a second time, and when the updated package file no longer carried the constraint there was nothing to fall back to. `generateBranchConfig()` now merges the `extractedConstraints` of all upgrades of a branch onto the branch config, which reaches `updateArtifacts()` through `patchConfigForArtifactsUpdate()`. `UpdateArtifactsConfig` declares the field and documents what it contains. The new `resolveToolConstraint()` helper implements the ladder once: user `constraints` > an optional artifact-time derivation > the extracted value. The derivation is ranked above the extracted value on purpose: it reads the package files as the branch changed them, so poetry (python is an updatable dependency there), composer, pipenv (`pipenv` can be a dev package) and pep621 (`requires-python` is an updatable dependency) would otherwise regress to a stale constraint. pipenv, pep621 uv/pdm, poetry and composer are migrated to the helper and keep their derivation. Behaviour change: these managers now use the extract-time constraint as a last resort instead of running unconstrained, for example on lock file maintenance where pipenv deletes `Pipfile.lock` before deriving. `execute-post-upgrade-commands.ts` is unaffected: it reads `upgrade.constraints` per upgrade, and the extracted values are kept in a separate field rather than folded into `constraints`, so post-upgrade task tool constraints still come from user config only. Not migrated, because their constraints are never extracted, so the fallback would be dead code: bundler (`ruby`/`bundler`), pixi (`pixi`), pep621 uv (`required-version`) and npm's node ladder, whose last step already reads `package.json` engines. * refactor(manager): resolve tool constraints through resolveToolConstraint() Every manager now obtains the constraint of a tool it runs through `resolveToolConstraint()` instead of reading `config.constraints` itself, so the precedence "user config, then a value derived from the updated files, then the constraints collected during extraction" applies everywhere. The helper treats an empty string as not set at every step and accepts the `PostUpdateConfig` shape, whose `constraints` may be `null`. Behaviour changes that go beyond the new fallback to extracted constraints: - `mix` applies its hardcoded erlang default only after the extracted constraint, so an erlang version collected at extraction can win over it. - `kustomize` decides `HELM_EXPERIMENTAL_OCI` from the fully resolved helm constraint; `generateHelmEnvs()` takes that value instead of the config. - `npm` (yarn): an upgrade of yarn without a new value now consults the user constraint before deriving one from package.json or the lock file. - The "Using <tool> constraint from config" debug lines in bundler, composer, copier and pip-compile are gone, as the helper is the only reader of the config now. Helpers that read the config synchronously became async: bundler `getBundlerConstraint()`, copier `getPythonVersionConstraint()` and `getCopierVersionConstraint()`, pip-compile `get*VersionConstraint()` and `getToolVersionConstraint()`, gomod `deriveGoToolchainConstraints()` and `getUpdateImportPathCmds()`, mise `getMiseLockToolConstraints()`. composer `getPhpConstraint()` is removed. Each converted manager has a test showing the extracted constraint reaching the executed tool, and, where a derive callback exists, that the derived value still wins over it. * refactor(linters): add prefer-resolve-tool-constraint rule Reports member reads and destructuring of `constraints` and `extractedConstraints` from a manager config in `lib/modules/manager/**`, so that tool constraints are resolved through `resolveToolConstraint()` in `lib/modules/manager/util.ts` only. Writes and the same properties on package files, which extraction has to populate, are not reported. The helper itself and spec files are exempt in `.oxlintrc.json`. * refactor(manager): inline thin resolveToolConstraint wrappers Drop copier/utils.ts and the pip-compile getPipToolsVersionConstraint / getUvVersionConstraint helpers, which only forwarded to resolveToolConstraint(). Callers now call it directly. * docs(development): note lock file maintenance in tool constraints section * refactor(manager): address review on tool constraint resolution composer only runs extractConstraints() when a user constraint is missing, via Lazy. UpdateArtifactsConfig no longer re-declares constraints and extractedConstraints, which ToolConstraintsConfig already provides.
178 lines
5.4 KiB
TypeScript
178 lines
5.4 KiB
TypeScript
import { isEmptyArray } from '@sindresorhus/is';
|
|
import { quote } from 'shlex';
|
|
import upath from 'upath';
|
|
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 {
|
|
deleteLocalFile,
|
|
readLocalFile,
|
|
writeLocalFile,
|
|
} from '../../../util/fs/index.ts';
|
|
import * as hostRules from '../../../util/host-rules.ts';
|
|
import { processHostRules } from '../npm/post-update/rules.ts';
|
|
import {
|
|
getNpmrcContent,
|
|
resetNpmrcContent,
|
|
updateNpmrcContent,
|
|
} from '../npm/utils.ts';
|
|
import type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';
|
|
import { resolveToolConstraint } from '../util.ts';
|
|
import type { DenoManagerData } from './types.ts';
|
|
|
|
export async function updateArtifacts(
|
|
updateArtifact: UpdateArtifact<DenoManagerData>,
|
|
): Promise<UpdateArtifactsResult[] | null> {
|
|
const { packageFileName, updatedDeps, newPackageFileContent, config } =
|
|
updateArtifact;
|
|
logger.debug(`deno.updateArtifacts(${packageFileName})`);
|
|
const isLockFileMaintenance = config.updateType === 'lockFileMaintenance';
|
|
|
|
if (isEmptyArray(updatedDeps) && !isLockFileMaintenance) {
|
|
logger.debug('No updated deno deps - returning null');
|
|
return null;
|
|
}
|
|
|
|
// falling back for lockFileMaintenance
|
|
const lockFileName = updatedDeps[0]?.lockFiles?.[0] ?? config.lockFiles?.[0];
|
|
|
|
if (!lockFileName) {
|
|
logger.debug('No lock file found. Skipping artifact update.');
|
|
return null;
|
|
}
|
|
|
|
const oldLockFileContent = await readLocalFile(lockFileName);
|
|
if (!oldLockFileContent) {
|
|
logger.debug(`Failed to read ${lockFileName}. Skipping artifact update.`);
|
|
return [
|
|
{
|
|
artifactError: {
|
|
fileName: lockFileName,
|
|
stderr: `Failed to read "${lockFileName}"`,
|
|
},
|
|
},
|
|
];
|
|
}
|
|
|
|
for (const updateDep of updatedDeps) {
|
|
if (
|
|
updateDep.depType === 'tasks' ||
|
|
updateDep.depType === 'tasks.command'
|
|
) {
|
|
logger.warn(
|
|
{
|
|
depType: updateDep.depType,
|
|
depName: updateDep.depName,
|
|
lockFileName,
|
|
},
|
|
"Dependency can't be updated with a lock file",
|
|
);
|
|
return [
|
|
{
|
|
artifactError: {
|
|
fileName: lockFileName,
|
|
stderr: `depType: "${updateDep.depType}", depName: "${updateDep.depName}" can't be updated with a lock file: "${lockFileName}"`,
|
|
},
|
|
},
|
|
];
|
|
}
|
|
}
|
|
|
|
const pkgFileDir = upath.dirname(packageFileName);
|
|
const { additionalNpmrcContent } = processHostRules();
|
|
const npmrcContent = await getNpmrcContent(pkgFileDir);
|
|
await updateNpmrcContent(pkgFileDir, npmrcContent, additionalNpmrcContent);
|
|
|
|
try {
|
|
await writeLocalFile(packageFileName, newPackageFileContent);
|
|
|
|
if (isLockFileMaintenance) {
|
|
await deleteLocalFile(lockFileName);
|
|
}
|
|
|
|
// run from its referred deno.json/deno.jsonc location if import map is used
|
|
const importMapReferrerDep = updatedDeps.find(
|
|
(dep) => dep.managerData?.importMapReferrer,
|
|
);
|
|
const cwdFile =
|
|
importMapReferrerDep?.managerData?.importMapReferrer ?? packageFileName;
|
|
|
|
const execOptions: ExecOptions = {
|
|
cwdFile,
|
|
docker: {},
|
|
toolConstraints: [
|
|
{
|
|
toolName: 'deno',
|
|
constraint: await resolveToolConstraint(config, 'deno'),
|
|
},
|
|
],
|
|
};
|
|
|
|
// "deno install" don't execute lifecycle scripts of package.json by default
|
|
// https://docs.deno.com/runtime/reference/cli/install/#native-node.js-addons
|
|
// deno.json(c) could have the `lock.frozen` field
|
|
// we should always override the `frozen` flag due to if it would be specified true
|
|
let command = 'deno install --frozen=false';
|
|
|
|
// defaults as per https://docs.deno.com/runtime/fundamentals/security/#importing-from-the-web
|
|
const defaultImportHosts = [
|
|
'deno.land:443',
|
|
'esm.sh:443',
|
|
'jsr.io:443',
|
|
'cdn.jsdelivr.net:443',
|
|
'raw.githubusercontent.com:443',
|
|
'gist.githubusercontent.com:443',
|
|
];
|
|
const additionalImportHosts = hostRules
|
|
.findAll({ hostType: 'npm' })
|
|
.filter((rule) => rule.resolvedHost)
|
|
.map((rule) => rule.resolvedHost);
|
|
|
|
if (additionalImportHosts.length > 0) {
|
|
// combine default and additional import hosts, removing duplicates
|
|
const importHosts = [
|
|
...new Set([...defaultImportHosts, ...additionalImportHosts]),
|
|
].join(',');
|
|
|
|
command += ` --allow-import=${quote(importHosts)}`;
|
|
}
|
|
|
|
// TODO: appending `--lockfile-only` is better to reduce disk usage
|
|
// https://docs.deno.com/runtime/reference/cli/install/#options-lockfile-only
|
|
await exec(command, execOptions);
|
|
await resetNpmrcContent(pkgFileDir, npmrcContent);
|
|
|
|
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: {
|
|
fileName: lockFileName,
|
|
stderr: err.message,
|
|
},
|
|
},
|
|
];
|
|
}
|
|
}
|