diff --git a/packages/project-config/src/configPath.ts b/packages/project-config/src/configPath.ts index 521167d2b2e3..697136284f2f 100644 --- a/packages/project-config/src/configPath.ts +++ b/packages/project-config/src/configPath.ts @@ -5,14 +5,19 @@ const CONFIG_FILE_NAME = 'redwood.toml' /** * Search the parent directories for the Redwood configuration file. */ +const getConfigPathCache = new Map() export const getConfigPath = ( cwd: string = process.env.RWJS_CWD ?? process.cwd() ): string => { + if (getConfigPathCache.has(cwd)) { + return getConfigPathCache.get(cwd) as string + } const configPath = findUp(CONFIG_FILE_NAME, cwd) if (!configPath) { throw new Error( `Could not find a "${CONFIG_FILE_NAME}" file, are you sure you're in a Redwood project?` ) } + getConfigPathCache.set(cwd, configPath) return configPath } diff --git a/packages/project-config/src/paths.ts b/packages/project-config/src/paths.ts index 52ee86691ab2..7d9e3a2d32a1 100644 --- a/packages/project-config/src/paths.ts +++ b/packages/project-config/src/paths.ts @@ -139,8 +139,12 @@ export const resolveFile = ( /** * Path constants that are relevant to a Redwood project. */ -// TODO: Make this a proxy and make it lazy. +const getPathsCache = new Map() export const getPaths = (BASE_DIR: string = getBaseDir()): Paths => { + if (getPathsCache.has(BASE_DIR)) { + return getPathsCache.get(BASE_DIR) as Paths + } + const routes = resolveFile(path.join(BASE_DIR, PATH_WEB_ROUTES)) as string const { schemaPath } = getConfig(getConfigPath(BASE_DIR)).api const schemaDir = path.dirname(schemaPath) @@ -214,6 +218,7 @@ export const getPaths = (BASE_DIR: string = getBaseDir()): Paths => { fs.mkdirSync(paths.generated.types.includes, { recursive: true }) fs.mkdirSync(paths.generated.types.mirror, { recursive: true }) + getPathsCache.set(BASE_DIR, paths) return paths }