mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 15:36:25 +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];
|
type ValidMatchFields = typeof validMatchFields[number];
|
||||||
|
|
||||||
export function createDependency(
|
function updateDependency(
|
||||||
extractionTemplate: ExtractionTemplate,
|
dependency: PackageDependency,
|
||||||
config: CustomExtractConfig,
|
field: ValidMatchFields,
|
||||||
dep?: PackageDependency
|
value: string
|
||||||
): PackageDependency | null {
|
): void {
|
||||||
const dependency = dep ?? {};
|
|
||||||
const { groups, replaceString } = extractionTemplate;
|
|
||||||
|
|
||||||
function updateDependency(field: ValidMatchFields, value: string): void {
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'registryUrl':
|
case 'registryUrl':
|
||||||
// check if URL is valid and pack inside an array
|
// check if URL is valid and pack inside an array
|
||||||
|
@ -45,13 +41,21 @@ export function createDependency(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createDependency(
|
||||||
|
extractionTemplate: ExtractionTemplate,
|
||||||
|
config: CustomExtractConfig,
|
||||||
|
dep?: PackageDependency
|
||||||
|
): PackageDependency | null {
|
||||||
|
const dependency = dep ?? {};
|
||||||
|
const { groups, replaceString } = extractionTemplate;
|
||||||
|
|
||||||
for (const field of validMatchFields) {
|
for (const field of validMatchFields) {
|
||||||
const fieldTemplate = `${field}Template` as keyof RegexManagerTemplates;
|
const fieldTemplate = `${field}Template` as keyof RegexManagerTemplates;
|
||||||
const tmpl = config[fieldTemplate];
|
const tmpl = config[fieldTemplate];
|
||||||
if (tmpl) {
|
if (tmpl) {
|
||||||
try {
|
try {
|
||||||
const compiled = template.compile(tmpl, groups, false);
|
const compiled = template.compile(tmpl, groups, false);
|
||||||
updateDependency(field, compiled);
|
updateDependency(dependency, field, compiled);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
{ template: tmpl },
|
{ template: tmpl },
|
||||||
|
@ -60,7 +64,7 @@ export function createDependency(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else if (groups[field]) {
|
} else if (groups[field]) {
|
||||||
updateDependency(field, groups[field]);
|
updateDependency(dependency, field, groups[field]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependency.replaceString = replaceString;
|
dependency.replaceString = replaceString;
|
||||||
|
|
Loading…
Reference in a new issue