diff --git a/lib/config/presets/github.spec.ts b/lib/config/presets/github.spec.ts index 3fd6c664ec7f689fcffe56645a8f14b84d2b08f0..3a3637ef0de5fdfc16d2b769c32c6690ca20e8aa 100644 --- a/lib/config/presets/github.spec.ts +++ b/lib/config/presets/github.spec.ts @@ -5,6 +5,7 @@ import * as _hostRules from '../../util/host-rules'; import { PLATFORM_FAILURE } from '../../constants/error-messages'; import { mocked } from '../../../test/util'; import { GotResponse } from '../../platform'; +import { clearRepoCache } from '../../util/cache'; jest.mock('../../platform/github/gh-got-wrapper'); jest.mock('../../util/got'); @@ -25,7 +26,7 @@ describe('config/presets/github', () => { }); describe('fetchJSONFile()', () => { beforeEach(() => { - delete global.repoCache.internalPresets; + clearRepoCache(); }); it('returns JSON', async () => { hostRules.find.mockReturnValueOnce({ token: 'abc' }); diff --git a/lib/config/presets/github.ts b/lib/config/presets/github.ts index 8bf562be16945006ef3fa8919ba86adb2dd40307..432a5caa620e4790a80400acc1376cd6a8ad7dd3 100644 --- a/lib/config/presets/github.ts +++ b/lib/config/presets/github.ts @@ -4,11 +4,13 @@ import { Http, HttpOptions } from '../../util/http'; import { PLATFORM_FAILURE } from '../../constants/error-messages'; import { ensureTrailingSlash } from '../../util/url'; import { PLATFORM_TYPE_GITHUB } from '../../constants/platforms'; +import { getRepoCache } from '../../util/cache'; const http = new Http(PLATFORM_TYPE_GITHUB); export function setInternalPreset(content: { body: Preset }): void { - global.repoCache.internalPresets = Promise.resolve(content); + const cache = getRepoCache(); + cache.internalPresets = Promise.resolve(content); } async function fetchInternalPreset(): Promise<Preset> { @@ -19,9 +21,9 @@ async function fetchInternalPreset(): Promise<Preset> { } function getInternalPreset(): Promise<Preset> { - global.repoCache.internalPresets = - global.repoCache.internalPresets || fetchInternalPreset(); - return global.repoCache.internalPresets; + const cache = getRepoCache(); + cache.internalPresets = cache.internalPresets || fetchInternalPreset(); + return cache.internalPresets; } export async function fetchJSONFile( diff --git a/lib/util/cache.ts b/lib/util/cache.ts new file mode 100644 index 0000000000000000000000000000000000000000..d4282d9dedd47148528190fe082b4c6b7596d3b7 --- /dev/null +++ b/lib/util/cache.ts @@ -0,0 +1,8 @@ +export function getRepoCache(): Record<string, any> { + // eslint-disable-next-line no-return-assign + return global.repoCache ?? (global.repoCache = {}); +} + +export function clearRepoCache(): void { + global.repoCache = {}; +}