renovate/lib/workers/repository/extract/index.ts

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-05-03 14:15:22 +00:00
import is from '@sindresorhus/is';
2020-03-06 08:07:55 +00:00
import {
2020-05-01 16:03:48 +00:00
RenovateConfig,
2020-03-06 08:07:55 +00:00
getManagerConfig,
mergeChildConfig,
} from '../../../config';
2020-05-01 16:03:48 +00:00
import { logger } from '../../../logger';
import { getManagerList } from '../../../manager';
2021-03-02 20:44:55 +00:00
import type { PackageFile } from '../../../manager/types';
import { getFileList } from '../../../util/git';
import { getMatchingFiles } from './file-match';
2020-05-01 16:03:48 +00:00
import { getManagerPackageFiles } from './manager-files';
export async function extractAllDependencies(
config: RenovateConfig
): Promise<Record<string, PackageFile[]>> {
2020-05-03 14:15:22 +00:00
let managerList = getManagerList();
if (is.nonEmptyArray(config.enabledManagers)) {
logger.debug('Applying enabledManagers filtering');
managerList = managerList.filter((manager) =>
config.enabledManagers.includes(manager)
);
}
const extractList: RenovateConfig[] = [];
const fileList = await getFileList();
2020-05-03 14:15:22 +00:00
for (const manager of managerList) {
const managerConfig = getManagerConfig(config, manager);
managerConfig.manager = manager;
2020-03-06 08:07:55 +00:00
if (manager === 'regex') {
for (const regexManager of config.regexManagers) {
const regexManagerConfig = mergeChildConfig(
managerConfig,
regexManager
);
regexManagerConfig.fileList = getMatchingFiles(
regexManagerConfig,
fileList
2020-03-06 08:07:55 +00:00
);
if (regexManagerConfig.fileList.length) {
extractList.push(regexManagerConfig);
2020-03-06 08:07:55 +00:00
}
}
} else {
managerConfig.fileList = getMatchingFiles(managerConfig, fileList);
if (managerConfig.fileList.length) {
extractList.push(managerConfig);
}
2020-03-06 08:07:55 +00:00
}
}
const extractResults = await Promise.all(
extractList.map(async (managerConfig) => {
const packageFiles = await getManagerPackageFiles(managerConfig);
return { manager: managerConfig.manager, packageFiles };
})
);
2020-05-03 15:27:35 +00:00
const extractions: Record<string, PackageFile[]> = {};
let fileCount = 0;
for (const { manager, packageFiles } of extractResults) {
if (packageFiles?.length) {
fileCount += packageFiles.length;
logger.debug(`Found ${manager} package files`);
extractions[manager] = (extractions[manager] || []).concat(packageFiles);
}
}
2018-05-31 11:03:36 +00:00
logger.debug(`Found ${fileCount} package file(s)`);
return extractions;
}