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';
|
2020-09-30 06:40:19 +00:00
|
|
|
import { getFileList } from '../../../util/git';
|
2020-05-03 15:03:23 +00:00
|
|
|
import { getMatchingFiles } from './file-match';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { getManagerPackageFiles } from './manager-files';
|
2018-05-09 06:03:59 +00:00
|
|
|
|
2019-12-12 03:38:40 +00:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
2020-05-03 15:03:23 +00:00
|
|
|
const extractList: RenovateConfig[] = [];
|
2020-09-30 06:40:19 +00:00
|
|
|
const fileList = await getFileList();
|
2020-05-03 14:15:22 +00:00
|
|
|
for (const manager of managerList) {
|
2018-05-09 06:03:59 +00:00
|
|
|
const managerConfig = getManagerConfig(config, manager);
|
2020-05-03 15:03:23 +00:00
|
|
|
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
|
|
|
|
);
|
2020-09-30 06:40:19 +00:00
|
|
|
regexManagerConfig.fileList = getMatchingFiles(
|
|
|
|
regexManagerConfig,
|
|
|
|
fileList
|
2020-03-06 08:07:55 +00:00
|
|
|
);
|
2020-05-03 15:03:23 +00:00
|
|
|
if (regexManagerConfig.fileList.length) {
|
|
|
|
extractList.push(regexManagerConfig);
|
2020-03-06 08:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-30 06:40:19 +00:00
|
|
|
managerConfig.fileList = getMatchingFiles(managerConfig, fileList);
|
2020-05-03 15:03:23 +00:00
|
|
|
if (managerConfig.fileList.length) {
|
|
|
|
extractList.push(managerConfig);
|
|
|
|
}
|
2020-03-06 08:07:55 +00:00
|
|
|
}
|
2020-05-03 15:03:23 +00:00
|
|
|
}
|
2020-05-03 17:21:10 +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) {
|
2020-07-18 06:42:32 +00:00
|
|
|
if (packageFiles?.length) {
|
2018-05-09 06:03:59 +00:00
|
|
|
fileCount += packageFiles.length;
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.debug(`Found ${manager} package files`);
|
2020-05-03 15:03:23 +00:00
|
|
|
extractions[manager] = (extractions[manager] || []).concat(packageFiles);
|
2018-05-09 06:03:59 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-31 11:03:36 +00:00
|
|
|
logger.debug(`Found ${fileCount} package file(s)`);
|
2018-05-09 06:03:59 +00:00
|
|
|
return extractions;
|
|
|
|
}
|