fix: break 3-file import cycle in cli/project-files - #1170
Conversation
|
Good, focused change. Importing One nitpick: the test file references Worth porting as long as the test assertions are validated against the actual config dir resolution logic across platforms/CI. |
project-files.ts -> auth.ts -> logger.ts -> project-files.ts Import getConfigDir directly from config-dir instead of auth to break the circular dependency. config-dir.ts exports the identical function (auth.ts just wraps it). anonymous-id.ts already imports from config-dir directly. Add getProjectDataDir tests to exercise the fixed import path.
b486a4e to
fc81d4e
Compare
|
Thanks for the review and the "worth porting" label!
Fixed. The test now imports Verified |
Summary
Breaks the circular import dependency between
project-files.ts,auth.ts, andlogger.ts.The cycle:
project-files.tsimportedgetConfigDirfrom./utils/auth, which importslogger, which importsgetCurrentChatDirandgetProjectRootback from../project-files— creating a 3-file circular dependency.The fix: Import
getConfigDirdirectly from./utils/config-dir, which has no dependency onauth.ts,logger.ts, orproject-files.ts.Maintainer Feedback Addressed
Same signature? Yes —
config-dir.ts:14exports the identicalgetConfigDirfunction.auth.ts:37is a thin wrapper:export const getConfigDir = (): string => getConfigDirBase(). No behavior change.Does the cycle cause a real problem? Yes — circular dependencies can cause
undefinedvalues at import time depending on module load order, especially in bundlers or when tree-shaking.Test coverage — Added two tests for
getProjectDataDirinproject-files-chat-id.test.tsto exercise the fixed import path.Notes
anonymous-id.tsalready importsgetConfigDirdirectly fromconfig-dir(this PR alignsproject-files.tswith that pattern)getConfigDirreturns the same value either way