Skip to content

Commit

Permalink
refactor(lib/update): flatten code around cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Mar 6, 2024
1 parent 156fbf1 commit 48204a9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ export async function resolveLatestVersion(
dependency: Dependency,
options?: { cache?: boolean },
): Promise<UpdatedDependency | undefined> {
using cache = new LatestVersionCache(dependency.name);
if (options?.cache) {
const cached = cache.get(dependency.name);
if (cached) {
return { ...cached, path: dependency.path };
}
if (cached === null) {
// The dependency is already found to be up to date or unable to resolve.
return;
}
using cache = options?.cache
? new LatestVersionCache(dependency.name)
: undefined;
const cached = cache?.get(dependency.name);
if (cached) {
return { ...cached, path: dependency.path };
}
if (cached === null) {
// The dependency is already found to be up to date or unable to resolve.
return;
}
const constraint = dependency.version
? SemVer.tryParseRange(dependency.version)
Expand All @@ -169,9 +169,7 @@ export async function resolveLatestVersion(
return;
}
const result = await _resolveLatestVersion(dependency);
if (options?.cache) {
cache.set(dependency.name, result ?? null);
}
cache?.set(dependency.name, result ?? null);
return result;
}

Expand Down

0 comments on commit 48204a9

Please sign in to comment.