From eab31ffa9654463afa8d046de85bd5d4c5347179 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Tue, 31 May 2022 16:52:28 +0300 Subject: [PATCH] refactor(cache): Enable strict null checks (#15804) Co-authored-by: Michael Kriese <michael.kriese@visualon.de> --- lib/workers/repository/cache.ts | 20 ++++++++++++++------ tsconfig.strict.json | 2 -- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index 0baba8a62a..49f0deb3bf 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -28,10 +28,9 @@ function generateBranchUpgradeCache( newDigest, sourceUrl, } = upgrade; - return { + const result: BranchUpgradeCache = { datasource, depName, - packageName, fixedVersion, currentVersion, newVersion, @@ -39,9 +38,15 @@ function generateBranchUpgradeCache( newDigest, sourceUrl, }; + if (packageName) { + result.packageName = packageName; + } + return result; } -async function generateBranchCache(branch: BranchConfig): Promise<BranchCache> { +async function generateBranchCache( + branch: BranchConfig +): Promise<BranchCache | null> { const { branchName } = branch; try { const sha = getBranchCommit(branchName) || null; @@ -89,9 +94,12 @@ async function generateBranchCache(branch: BranchConfig): Promise<BranchCache> { } export async function setBranchCache(branches: BranchConfig[]): Promise<void> { - const branchCache: BranchCache[] = []; + const branchCaches: BranchCache[] = []; for (const branch of branches) { - branchCache.push(await generateBranchCache(branch)); + const branchCache = await generateBranchCache(branch); + if (branchCache) { + branchCaches.push(branchCache); + } } - getCache().branches = branchCache.filter(Boolean); + getCache().branches = branchCaches; } diff --git a/tsconfig.strict.json b/tsconfig.strict.json index 3e42df22a6..85ef1dd9a1 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -30,7 +30,6 @@ "lib/workers/global/config/parse/index.ts", "lib/workers/global/index.ts", "lib/workers/global/initialize.ts", - "lib/workers/repository/cache.ts", "lib/workers/repository/changelog/index.ts", "lib/workers/repository/error-config.ts", "lib/workers/repository/error.ts", @@ -41,7 +40,6 @@ "lib/workers/repository/finalise/prune.ts", "lib/workers/repository/index.ts", "lib/workers/repository/init/apis.ts", - "lib/workers/repository/init/cache.ts", "lib/workers/repository/init/config.ts", "lib/workers/repository/init/index.ts", "lib/workers/repository/init/semantic.ts", -- GitLab