Memoize getImplementThemeTypes
This commit is contained in:
parent
3a976d08d2
commit
f6dc8f0741
@ -4,9 +4,22 @@ import * as fs from "fs";
|
||||
import { type ThemeType } from "./constants";
|
||||
import { getThemeSrcDirPath } from "./getThemeSrcDirPath";
|
||||
|
||||
type ImplementedThemeTypes = Readonly<Record<ThemeType | "email", boolean>>;
|
||||
|
||||
let cache:
|
||||
| { projectDirPath: string; implementedThemeTypes: ImplementedThemeTypes }
|
||||
| undefined;
|
||||
|
||||
export function getImplementedThemeTypes(params: { projectDirPath: string }) {
|
||||
const { projectDirPath } = params;
|
||||
|
||||
if (cache !== undefined && cache.projectDirPath === projectDirPath) {
|
||||
const { implementedThemeTypes } = cache;
|
||||
return { implementedThemeTypes };
|
||||
}
|
||||
|
||||
cache = undefined;
|
||||
|
||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
||||
projectDirPath
|
||||
});
|
||||
@ -19,5 +32,7 @@ export function getImplementedThemeTypes(params: { projectDirPath: string }) {
|
||||
])
|
||||
);
|
||||
|
||||
cache = { projectDirPath, implementedThemeTypes };
|
||||
|
||||
return { implementedThemeTypes };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user