diff --git a/lib/workers/repository/extract/index.spec.ts b/lib/workers/repository/extract/index.spec.ts index bd7ca699b79e0cdc99dc58398b78812f3baaa609..9c2a6bcef18b2b2c00e5a0b9698d66dff630be71 100644 --- a/lib/workers/repository/extract/index.spec.ts +++ b/lib/workers/repository/extract/index.spec.ts @@ -23,34 +23,34 @@ describe('workers/repository/extract/index', () => { it('runs', async () => { managerFiles.getManagerPackageFiles.mockResolvedValue([{} as never]); const res = await extractAllDependencies(config); - expect(Object.keys(res)).toContain('ansible'); + expect(Object.keys(res.packageFiles)).toContain('ansible'); }); it('skips non-enabled managers', async () => { config.enabledManagers = ['npm']; managerFiles.getManagerPackageFiles.mockResolvedValue([{} as never]); const res = await extractAllDependencies(config); - expect(res).toEqual({ npm: [{}] }); + expect(res).toEqual({ packageFiles: { npm: [{}] } }); }); it('warns if no packages found for a enabled manager', async () => { config.enabledManagers = ['npm']; managerFiles.getManagerPackageFiles.mockResolvedValue([]); - expect(await extractAllDependencies(config)).toEqual({}); + expect((await extractAllDependencies(config)).packageFiles).toEqual({}); expect(logger.debug).toHaveBeenCalled(); }); it('warns if packageFiles is null', async () => { config.enabledManagers = ['npm']; managerFiles.getManagerPackageFiles.mockResolvedValue(null); - expect(await extractAllDependencies(config)).toEqual({}); + expect((await extractAllDependencies(config)).packageFiles).toEqual({}); }); it('checks custom managers', async () => { managerFiles.getManagerPackageFiles.mockResolvedValue([{} as never]); config.regexManagers = [{ fileMatch: ['README'], matchStrings: [''] }]; const res = await extractAllDependencies(config); - expect(Object.keys(res)).toContain('regex'); + expect(Object.keys(res.packageFiles)).toContain('regex'); }); }); }); diff --git a/lib/workers/repository/extract/index.ts b/lib/workers/repository/extract/index.ts index 3aa2642ac1b8fdf28030b62ebdc9d12f33122664..e3e5e18ee7c731a5b28a8d9f9060eb5c656f0ce4 100644 --- a/lib/workers/repository/extract/index.ts +++ b/lib/workers/repository/extract/index.ts @@ -3,15 +3,14 @@ import { getManagerConfig, mergeChildConfig } from '../../../config'; import type { ManagerConfig, RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; import { getManagerList } from '../../../modules/manager'; -import type { PackageFile } from '../../../modules/manager/types'; import { getFileList } from '../../../util/git'; -import type { WorkerExtractConfig } from '../../types'; +import type { ExtractResult, WorkerExtractConfig } from '../../types'; import { getMatchingFiles } from './file-match'; import { getManagerPackageFiles } from './manager-files'; export async function extractAllDependencies( config: RenovateConfig -): Promise<Record<string, PackageFile[]>> { +): Promise<ExtractResult> { let managerList = getManagerList(); const { enabledManagers } = config; if (is.nonEmptyArray(enabledManagers)) { @@ -42,19 +41,24 @@ export async function extractAllDependencies( } } + const extractResult: ExtractResult = { + packageFiles: {}, + }; + const extractResults = await Promise.all( extractList.map(async (managerConfig) => { const packageFiles = await getManagerPackageFiles(managerConfig); return { manager: managerConfig.manager, packageFiles }; }) ); - 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); + extractResult.packageFiles[manager] = ( + extractResult.packageFiles[manager] || [] + ).concat(packageFiles); } } logger.debug(`Found ${fileCount} package file(s)`); @@ -63,7 +67,7 @@ export async function extractAllDependencies( // If not, log a warning to indicate possible misconfiguration. if (is.nonEmptyArray(config.enabledManagers)) { for (const enabledManager of config.enabledManagers) { - if (!(enabledManager in extractions)) { + if (!(enabledManager in extractResult.packageFiles)) { logger.debug( { manager: enabledManager }, `Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?` @@ -72,5 +76,5 @@ export async function extractAllDependencies( } } - return extractions; + return extractResult; } diff --git a/lib/workers/repository/onboarding/branch/index.ts b/lib/workers/repository/onboarding/branch/index.ts index 0489d7e1c7adce0ecc4d103e45637e2de1a85a1e..e2b07ce4bebaaa260aaa1d7f8cd1f852d3af8dc9 100644 --- a/lib/workers/repository/onboarding/branch/index.ts +++ b/lib/workers/repository/onboarding/branch/index.ts @@ -60,7 +60,8 @@ export async function checkOnboardingBranch( onboardingBranch = mergedConfig.onboardingBranch; if ( - Object.entries(await extractAllDependencies(mergedConfig)).length === 0 + Object.entries((await extractAllDependencies(mergedConfig)).packageFiles) + .length === 0 ) { if (!config?.onboardingNoDeps) { throw new Error(REPOSITORY_NO_PACKAGE_FILES); diff --git a/lib/workers/repository/process/extract-update.ts b/lib/workers/repository/process/extract-update.ts index 07550b2ffe3bfb879be98f5293c283d32a1db904..029636be8b333929f51584bf8345ffc494158647 100644 --- a/lib/workers/repository/process/extract-update.ts +++ b/lib/workers/repository/process/extract-update.ts @@ -114,7 +114,8 @@ export async function extract( } } else { await checkoutBranch(baseBranch!); - packageFiles = await extractAllDependencies(config); + const extractResult = await extractAllDependencies(config); + packageFiles = extractResult?.packageFiles; // TODO: fix types (#7154) cache.scan[baseBranch!] = { sha: baseBranchSha!, diff --git a/lib/workers/types.ts b/lib/workers/types.ts index b1900a5977088a68d723e3bad60b3c987cfe46d0..fea5a440cd7f566a1cfc7bcb43aa930cb60a2f29 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -186,3 +186,7 @@ export interface UpgradeFingerprintConfig { packageFile?: string; replaceString?: string; } + +export interface ExtractResult { + packageFiles: Record<string, PackageFile[]>; +}