diff --git a/lib/config/migrations/custom/regex-managers-migration.spec.ts b/lib/config/migrations/custom/regex-managers-migration.spec.ts index 8311265bd50e55..be49c6bcf3c077 100644 --- a/lib/config/migrations/custom/regex-managers-migration.spec.ts +++ b/lib/config/migrations/custom/regex-managers-migration.spec.ts @@ -1,5 +1,5 @@ import { partial } from '../../../../test/util'; -import type { CustomManager } from '../../types'; +import type { CustomManager } from '../../../modules/manager/custom/types'; import { RegexManagersMigration } from './regex-managers-migration'; describe('config/migrations/custom/regex-managers-migration', () => { diff --git a/lib/config/migrations/custom/regex-managers-migration.ts b/lib/config/migrations/custom/regex-managers-migration.ts index ee23c0f6da01d3..afaad6c80537b2 100644 --- a/lib/config/migrations/custom/regex-managers-migration.ts +++ b/lib/config/migrations/custom/regex-managers-migration.ts @@ -1,5 +1,5 @@ import is from '@sindresorhus/is'; -import type { CustomManager } from '../../types'; +import type { CustomManager } from '../../../modules/manager/custom/types'; import { AbstractMigration } from '../base/abstract-migration'; export class RegexManagersMigration extends AbstractMigration { diff --git a/lib/config/types.ts b/lib/config/types.ts index e849702b44b66d..ac6fa1788f70db 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -1,5 +1,6 @@ import type { LogLevel } from 'bunyan'; import type { PlatformId } from '../constants'; +import type { CustomManager } from '../modules/manager/custom/types'; import type { HostRule } from '../types'; import type { GitNoVerifyOption } from '../util/git/types'; import type { MergeConfidence } from '../util/merge-confidence/types'; @@ -184,26 +185,6 @@ export type RenovateRepository = repository: string; secrets?: Record; }; -export interface RegexManagerTemplates { - depNameTemplate?: string; - packageNameTemplate?: string; - datasourceTemplate?: string; - versioningTemplate?: string; - depTypeTemplate?: string; - currentValueTemplate?: string; - currentDigestTemplate?: string; - extractVersionTemplate?: string; - registryUrlTemplate?: string; -} - -export type CustomManagerName = 'regex'; -export interface CustomManager extends RegexManagerTemplates { - customType: CustomManagerName; - fileMatch: string[]; - matchStrings: string[]; - matchStringsStrategy?: MatchStringsStrategy; - autoReplaceStringTemplate?: string; -} export type UseBaseBranchConfigType = 'merge' | 'none'; export type ConstraintsFilter = 'strict' | 'none'; diff --git a/lib/config/validation.ts b/lib/config/validation.ts index 7679a7379a3dd7..d63a47aaaa2cbf 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -1,7 +1,11 @@ import is from '@sindresorhus/is'; import { allManagersList, getManagerList } from '../modules/manager'; import { isCustomManager } from '../modules/manager/custom'; -import type { RegexManagerConfig } from '../modules/manager/custom/regex/types'; +import type { + RegexManagerConfig, + RegexManagerTemplates, +} from '../modules/manager/custom/regex/types'; +import type { CustomManager } from '../modules/manager/custom/types'; import { configRegexPredicate, isConfigRegex, regEx } from '../util/regex'; import * as template from '../util/template'; import { @@ -12,8 +16,6 @@ import { migrateConfig } from './migration'; import { getOptions } from './options'; import { resolveConfigPresets } from './presets'; import type { - CustomManager, - RegexManagerTemplates, RenovateConfig, RenovateOptions, ValidationMessage, @@ -657,7 +659,7 @@ export async function validateConfig( } function validateRegexManagerFields( - regexManager: RegexManagerConfig, + regexManager: Partial, currentPath: string, errors: ValidationMessage[] ): void { @@ -684,7 +686,7 @@ function validateRegexManagerFields( const templateField = `${field}Template` as keyof RegexManagerTemplates; if ( !regexManager[templateField] && - !regexManager.matchStrings.some((matchString) => + !regexManager.matchStrings?.some((matchString) => matchString.includes(`(?<${field}>`) ) ) { diff --git a/lib/modules/manager/custom/regex/index.spec.ts b/lib/modules/manager/custom/regex/index.spec.ts index e3fe7d34261279..608ba97fadb830 100644 --- a/lib/modules/manager/custom/regex/index.spec.ts +++ b/lib/modules/manager/custom/regex/index.spec.ts @@ -1,7 +1,7 @@ import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../../test/fixtures'; import { logger } from '../../../../logger'; -import type { CustomExtractConfig } from '../../types'; +import type { CustomExtractConfig } from '../types'; import { defaultConfig, displayName, extractPackageFile } from '.'; const dockerfileContent = Fixtures.get(`Dockerfile`); diff --git a/lib/modules/manager/custom/regex/index.ts b/lib/modules/manager/custom/regex/index.ts index 58a36d3b748f32..2860ba4bc3887f 100644 --- a/lib/modules/manager/custom/regex/index.ts +++ b/lib/modules/manager/custom/regex/index.ts @@ -1,5 +1,4 @@ import is from '@sindresorhus/is'; -import type { RegexManagerTemplates } from '../../../../config/types'; import type { ExtractConfig, PackageDependency, @@ -7,7 +6,7 @@ import type { Result, } from '../../types'; import { handleAny, handleCombination, handleRecursive } from './strategies'; -import type { RegexManagerConfig } from './types'; +import type { RegexManagerConfig, RegexManagerTemplates } from './types'; import { validMatchFields } from './utils'; export const defaultConfig = { diff --git a/lib/modules/manager/custom/regex/types.ts b/lib/modules/manager/custom/regex/types.ts index 2f9682ce8c0ab7..ed5f3105e10eb9 100644 --- a/lib/modules/manager/custom/regex/types.ts +++ b/lib/modules/manager/custom/regex/types.ts @@ -1,19 +1,33 @@ -import type { CustomExtractConfig } from '../../types'; +import type { MatchStringsStrategy } from '../../../../config/types'; export interface ExtractionTemplate { groups: Record; replaceString: string | undefined; } +export interface RegexManagerTemplates { + depNameTemplate?: string; + packageNameTemplate?: string; + datasourceTemplate?: string; + versioningTemplate?: string; + depTypeTemplate?: string; + currentValueTemplate?: string; + currentDigestTemplate?: string; + extractVersionTemplate?: string; + registryUrlTemplate?: string; +} + +export interface RegexManagerConfig extends RegexManagerTemplates { + matchStrings: string[]; + matchStringsStrategy?: MatchStringsStrategy; + autoReplaceStringTemplate?: string; +} + export interface RecursionParameter { content: string; packageFile: string; - config: CustomExtractConfig; + config: RegexManagerConfig; regexes: RegExp[]; index: number; combinedGroups: Record; } - -export interface RegexManagerConfig extends CustomExtractConfig { - matchStrings: string[]; -} diff --git a/lib/modules/manager/custom/regex/utils.ts b/lib/modules/manager/custom/regex/utils.ts index 1f30b592e80153..37759af74f8a82 100644 --- a/lib/modules/manager/custom/regex/utils.ts +++ b/lib/modules/manager/custom/regex/utils.ts @@ -1,11 +1,14 @@ import { URL } from 'node:url'; import is from '@sindresorhus/is'; import { migrateDatasource } from '../../../../config/migrations/custom/datasource-migration'; -import type { RegexManagerTemplates } from '../../../../config/types'; import { logger } from '../../../../logger'; import * as template from '../../../../util/template'; -import type { CustomExtractConfig, PackageDependency } from '../../types'; -import type { ExtractionTemplate } from './types'; +import type { PackageDependency } from '../../types'; +import type { + ExtractionTemplate, + RegexManagerConfig, + RegexManagerTemplates, +} from './types'; export const validMatchFields = [ 'depName', @@ -51,7 +54,7 @@ function updateDependency( export function createDependency( extractionTemplate: ExtractionTemplate, - config: CustomExtractConfig, + config: RegexManagerConfig, dep?: PackageDependency ): PackageDependency | null { const dependency = dep ?? {}; diff --git a/lib/modules/manager/custom/types.ts b/lib/modules/manager/custom/types.ts new file mode 100644 index 00000000000000..de387685f80717 --- /dev/null +++ b/lib/modules/manager/custom/types.ts @@ -0,0 +1,13 @@ +import type { RegexManagerConfig } from './regex/types'; + +export interface CustomExtractConfig extends Partial {} + +export type CustomManagerName = 'regex'; + +export interface CustomManager extends Partial { + customType: CustomManagerName; + fileMatch: string[]; +} + +// NOTE: +// the two interfaces might seem similar but they have different usage similar to ManagerConfig and ExtractConfig diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 9312bcd6069166..8cfdba235b92ee 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -1,7 +1,6 @@ import type { ReleaseType } from 'semver'; import type { MatchStringsStrategy, - RegexManagerTemplates, UpdateType, ValidationMessage, } from '../../config/types'; @@ -9,6 +8,7 @@ import type { Category } from '../../constants'; import type { ModuleApi, RangeStrategy, SkipReason } from '../../types'; import type { FileChange } from '../../util/git/types'; import type { MergeConfidence } from '../../util/merge-confidence/types'; +import type { CustomExtractConfig } from './custom/types'; export type Result = T | Promise; @@ -23,12 +23,6 @@ export interface ExtractConfig extends CustomExtractConfig { skipInstalls?: boolean | null; } -export interface CustomExtractConfig extends RegexManagerTemplates { - autoReplaceStringTemplate?: string; - matchStrings?: string[]; - matchStringsStrategy?: MatchStringsStrategy; -} - export interface UpdateArtifactsConfig { isLockFileMaintenance?: boolean; constraints?: Record; diff --git a/lib/workers/repository/extract/extract-fingerprint-config.ts b/lib/workers/repository/extract/extract-fingerprint-config.ts index 8f17505cee8582..8f3bf56a2fbf33 100644 --- a/lib/workers/repository/extract/extract-fingerprint-config.ts +++ b/lib/workers/repository/extract/extract-fingerprint-config.ts @@ -1,12 +1,10 @@ import { getManagerConfig, mergeChildConfig } from '../../../config'; -import type { - RegexManagerTemplates, - RenovateConfig, -} from '../../../config/types'; +import type { RenovateConfig } from '../../../config/types'; import { allManagersList } from '../../../modules/manager'; import { isCustomManager } from '../../../modules/manager/custom'; +import type { RegexManagerTemplates } from '../../../modules/manager/custom/regex/types'; import { validMatchFields } from '../../../modules/manager/custom/regex/utils'; -import type { CustomExtractConfig } from '../../../modules/manager/types'; +import type { CustomExtractConfig } from '../../../modules/manager/custom/types'; import type { WorkerExtractConfig } from '../../types'; export interface FingerprintExtractConfig {