diff --git a/keyserver/src/utils/import-json.js b/keyserver/src/utils/import-json.js --- a/keyserver/src/utils/import-json.js +++ b/keyserver/src/utils/import-json.js @@ -8,18 +8,21 @@ if (cached !== undefined) { return cached; } + const json = await getJSON(path); + if (!cachedJSON.has(path)) { + cachedJSON.set(path, json); + } + return cachedJSON.get(path); +} + +async function getJSON(path: string): Promise { try { // $FlowFixMe const importedJSON = await import(`../../${path}`); - if (!cachedJSON.has(path)) { - cachedJSON.set(path, importedJSON.default); - } + return importedJSON.default; } catch { - if (!cachedJSON.has(path)) { - cachedJSON.set(path, null); - } + return null; } - return cachedJSON.get(path); } export { importJSON };