mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
refactor: move nested function to module scope (#17361)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
parent
57ade2b33e
commit
33e3bf7ce2
1 changed files with 23 additions and 19 deletions
|
@ -20,15 +20,11 @@ export const validMatchFields = [
|
|||
|
||||
type ValidMatchFields = typeof validMatchFields[number];
|
||||
|
||||
export function createDependency(
|
||||
extractionTemplate: ExtractionTemplate,
|
||||
config: CustomExtractConfig,
|
||||
dep?: PackageDependency
|
||||
): PackageDependency | null {
|
||||
const dependency = dep ?? {};
|
||||
const { groups, replaceString } = extractionTemplate;
|
||||
|
||||
function updateDependency(field: ValidMatchFields, value: string): void {
|
||||
function updateDependency(
|
||||
dependency: PackageDependency,
|
||||
field: ValidMatchFields,
|
||||
value: string
|
||||
): void {
|
||||
switch (field) {
|
||||
case 'registryUrl':
|
||||
// check if URL is valid and pack inside an array
|
||||
|
@ -43,7 +39,15 @@ export function createDependency(
|
|||
dependency[field] = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createDependency(
|
||||
extractionTemplate: ExtractionTemplate,
|
||||
config: CustomExtractConfig,
|
||||
dep?: PackageDependency
|
||||
): PackageDependency | null {
|
||||
const dependency = dep ?? {};
|
||||
const { groups, replaceString } = extractionTemplate;
|
||||
|
||||
for (const field of validMatchFields) {
|
||||
const fieldTemplate = `${field}Template` as keyof RegexManagerTemplates;
|
||||
|
@ -51,7 +55,7 @@ export function createDependency(
|
|||
if (tmpl) {
|
||||
try {
|
||||
const compiled = template.compile(tmpl, groups, false);
|
||||
updateDependency(field, compiled);
|
||||
updateDependency(dependency, field, compiled);
|
||||
} catch (err) {
|
||||
logger.warn(
|
||||
{ template: tmpl },
|
||||
|
@ -60,7 +64,7 @@ export function createDependency(
|
|||
return null;
|
||||
}
|
||||
} else if (groups[field]) {
|
||||
updateDependency(field, groups[field]);
|
||||
updateDependency(dependency, field, groups[field]);
|
||||
}
|
||||
}
|
||||
dependency.replaceString = replaceString;
|
||||
|
|
Loading…
Reference in a new issue