From 43dcce84784689765c644f8c8f47431ed3337137 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 11 Feb 2024 20:20:38 +0100 Subject: [PATCH] Add cache to getNpmWorkspaceRootDirPath --- .../getNpmWorkspaceRootDirPath.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.ts b/src/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.ts index 502ced5c..a51a7e8c 100644 --- a/src/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.ts +++ b/src/bin/keycloakify/buildOptions/getNpmWorkspaceRootDirPath.ts @@ -2,9 +2,26 @@ import * as child_process from "child_process"; import { join as pathJoin, resolve as pathResolve, sep as pathSep } from "path"; import { assert } from "tsafe/assert"; +let cache: + | { + reactAppRootDirPath: string; + npmWorkspaceRootDirPath: string; + } + | undefined = undefined; + export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string }) { const { reactAppRootDirPath } = params; + use_cache: { + if (cache === undefined || cache.reactAppRootDirPath !== reactAppRootDirPath) { + break use_cache; + } + + const { npmWorkspaceRootDirPath } = cache; + + return { npmWorkspaceRootDirPath }; + } + const npmWorkspaceRootDirPath = (function callee(depth: number): string { const cwd = pathResolve(pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")])); @@ -23,5 +40,10 @@ export function getNpmWorkspaceRootDirPath(params: { reactAppRootDirPath: string return cwd; })(0); + cache = { + reactAppRootDirPath, + npmWorkspaceRootDirPath + }; + return { npmWorkspaceRootDirPath }; }