Skip to content
Snippets Groups Projects
Unverified Commit bccf0997 authored by RahulGautamSingh's avatar RahulGautamSingh Committed by GitHub
Browse files

refactor: delete cached configFilename (#20746)

parent 99c697a7
Branches
No related tags found
No related merge requests found
......@@ -3,12 +3,16 @@ import {
fs,
getConfig,
git,
logger,
mocked,
partial,
platform,
} from '../../../../test/util';
import * as _migrateAndValidate from '../../../config/migrate-validate';
import * as _migrate from '../../../config/migration';
import * as repoCache from '../../../util/cache/repository';
import { initRepoCache } from '../../../util/cache/repository/init';
import type { RepoCacheData } from '../../../util/cache/repository/types';
import {
checkForRepoConfigError,
detectRepoFileConfig,
......@@ -45,6 +49,21 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({});
});
it('returns config if not found - uses cache', async () => {
jest
.spyOn(repoCache, 'getCache')
.mockReturnValueOnce(
partial<RepoCacheData>({ configFileName: 'renovate.json' })
);
platform.getRawFile.mockRejectedValueOnce(new Error());
git.getFileList.mockResolvedValue(['package.json']);
fs.readLocalFile.mockResolvedValue('{}');
expect(await detectRepoFileConfig()).toEqual({});
expect(logger.logger.debug).toHaveBeenCalledWith(
'Existing config file no longer exists'
);
});
it('uses package.json config if found', async () => {
git.getFileList.mockResolvedValue(['package.json']);
const pJson = JSON.stringify({
......
......@@ -17,6 +17,7 @@ import {
import { logger } from '../../../logger';
import * as npmApi from '../../../modules/datasource/npm';
import { platform } from '../../../modules/platform';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { getCache } from '../../../util/cache/repository';
import { readLocalFile } from '../../../util/fs';
import { getFileList } from '../../../util/git';
......@@ -51,7 +52,16 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
const cache = getCache();
let { configFileName } = cache;
if (configFileName) {
const configFileRaw = await platform.getRawFile(configFileName);
let configFileRaw: string | null;
try {
configFileRaw = await platform.getRawFile(configFileName);
} catch (err) {
// istanbul ignore if
if (err instanceof ExternalHostError) {
throw err;
}
configFileRaw = null;
}
if (configFileRaw) {
let configFileParsed = JSON5.parse(configFileRaw);
if (configFileName !== 'package.json') {
......@@ -61,6 +71,7 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
return { configFileName, configFileParsed }; // don't return raw 'package.json'
} else {
logger.debug('Existing config file no longer exists');
delete cache.configFileName;
}
}
configFileName = (await detectConfigFile()) ?? undefined;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment