mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 09:41:46 +00:00
930cf6633c
fix: Additional vi.mock path corrections and prettier formatting
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import { isTruthy } from '@sindresorhus/is';
|
|
import upath from 'upath';
|
|
import type { Category } from '../../../../constants/index.ts';
|
|
import { logger } from '../../../../logger/index.ts';
|
|
import type { MaybePromise } from '../../../../types/index.ts';
|
|
import type {
|
|
ExtractConfig,
|
|
PackageDependency,
|
|
PackageFileContent,
|
|
} from '../../types.ts';
|
|
import { validMatchFields } from '../utils.ts';
|
|
import { handleAny, handleCombination, handleRecursive } from './strategies.ts';
|
|
import type {
|
|
PackageFileInfo,
|
|
RegexManagerConfig,
|
|
RegexManagerTemplates,
|
|
} from './types.ts';
|
|
|
|
export const categories: Category[] = ['custom'];
|
|
|
|
export const defaultConfig = {
|
|
pinDigests: false,
|
|
};
|
|
export const supportedDatasources = ['*'];
|
|
export const displayName = 'Regex';
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
packageFile: string,
|
|
config: ExtractConfig,
|
|
): MaybePromise<PackageFileContent | null> {
|
|
let deps: PackageDependency[];
|
|
|
|
// till this stage, packageFile is the full path
|
|
// so we need to extract filename and dir before passing it for template.compile
|
|
const packageFileName = upath.basename(packageFile);
|
|
const packageFileDir = upath.dirname(packageFile);
|
|
const packageFileInfo: PackageFileInfo = {
|
|
packageFileDir,
|
|
packageFileName,
|
|
content,
|
|
packageFile,
|
|
};
|
|
|
|
switch (config.matchStringsStrategy) {
|
|
default:
|
|
case 'any':
|
|
deps = handleAny(config as RegexManagerConfig, packageFileInfo);
|
|
break;
|
|
case 'combination':
|
|
deps = handleCombination(config as RegexManagerConfig, packageFileInfo);
|
|
break;
|
|
case 'recursive':
|
|
deps = handleRecursive(config as RegexManagerConfig, packageFileInfo);
|
|
break;
|
|
}
|
|
|
|
// filter all null values
|
|
deps = deps.filter(isTruthy);
|
|
if (deps.length) {
|
|
const res: PackageFileContent & RegexManagerTemplates = {
|
|
deps,
|
|
matchStrings: config.matchStrings,
|
|
};
|
|
if (config.matchStringsStrategy) {
|
|
res.matchStringsStrategy = config.matchStringsStrategy;
|
|
}
|
|
// copy over templates for autoreplace
|
|
for (const field of validMatchFields.map(
|
|
(f) => `${f}Template` as keyof RegexManagerTemplates,
|
|
)) {
|
|
if (config[field]) {
|
|
res[field] = config[field];
|
|
}
|
|
}
|
|
if (config.autoReplaceStringTemplate) {
|
|
res.autoReplaceStringTemplate = config.autoReplaceStringTemplate;
|
|
}
|
|
return res;
|
|
}
|
|
logger.debug(
|
|
{ packageFile },
|
|
'No dependencies found in file for custom regex manager',
|
|
);
|
|
|
|
return null;
|
|
}
|