fix(history): use dirname() for correct config path calculation#22
Merged
fix(history): use dirname() for correct config path calculation#22
Conversation
leaperone-bot
approved these changes
Mar 31, 2026
leaperone-bot
left a comment
There was a problem hiding this comment.
🤖 Code Review 🟢
代码审查:使用 dirname() 替代 join(path, '..') 计算配置目录
变更概述
将 history.ts 中的 join(process.cwd(), options.config, '..') 替换为 dirname(configPath),与 load.ts 中已有的模式保持一致。
分析
正确性 ✅
- 虽然在大多数实际场景中
join(path, '..')和dirname(path)的结果是等价的(经过实际验证),但dirname()是获取父目录的标准、语义化做法。join(path, '..')依赖路径拼接再归一化来间接获取父目录,意图不如dirname()清晰。 - 修复后的代码还复用了已计算好的
configPath(dirname(configPath)),而不是重复拼接process.cwd()和options.config,消除了冗余,减少了两处表达式不一致的风险。
一致性 ✅
load.ts已使用dirname()模式,此修改使history.ts与之对齐,保持了代码库的统一风格。
旧代码的潜在问题
- 旧代码中
configDir的计算独立于configPath,如果未来有人修改了其中一处的默认值逻辑而忘记另一处,就会产生不一致的 bug。新代码通过dirname(configPath)直接复用configPath,从根本上消除了这种风险。
小建议(非阻塞)
-
options.config的默认值冗余:configPath中的options.config || './envx.config.yaml'实际上不需要 fallback,因为 Commander 的.option()已经定义了默认值'./envx.config.yaml'。可以考虑简化为join(process.cwd(), options.config!)。这不在本 PR 范围内,仅供参考。 -
缺少测试覆盖:项目目前没有测试文件。建议后续为
history命令添加单元测试,特别是路径计算逻辑。
结论
改动最小、意图明确,提升了代码的可读性和可维护性。可以合并。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8
Summary
join(path, '..')withdirname()for calculating config directory.envx/envx.dbis found in the correct location