-
Notifications
You must be signed in to change notification settings - Fork 829
feat: add upward config discovery and enhanced error messages #1235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,15 @@ | ||
| import { Command } from "interactive-commander"; | ||
| import _ from "lodash"; | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { defaultConfig } from "@lingo.dev/_spec"; | ||
| import { getConfig } from "../../utils/config"; | ||
|
|
||
| export default new Command() | ||
| .command("config") | ||
| .description("Print effective i18n.json after merging with defaults") | ||
| .helpOption("-h, --help", "Show help") | ||
| .action(async (options) => { | ||
| const fileConfig = loadReplexicaFileConfig(); | ||
| const fileConfig = getConfig(false); | ||
| const config = _.merge({}, defaultConfig, fileConfig); | ||
|
|
||
| console.log(JSON.stringify(config, null, 2)); | ||
| }); | ||
|
|
||
| function loadReplexicaFileConfig(): any { | ||
| const replexicaConfigPath = path.resolve(process.cwd(), "i18n.json"); | ||
| const fileExists = fs.existsSync(replexicaConfigPath); | ||
| if (!fileExists) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const fileContent = fs.readFileSync(replexicaConfigPath, "utf-8"); | ||
| const replexicaFileConfig = JSON.parse(fileContent); | ||
| return replexicaFileConfig; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,15 +3,18 @@ import fs from "fs"; | |||||
| import path from "path"; | ||||||
| import { I18nConfig, parseI18nConfig } from "@lingo.dev/_spec"; | ||||||
|
|
||||||
| export function getConfig(resave = true): I18nConfig | null { | ||||||
| const configFilePath = _getConfigFilePath(); | ||||||
| let _cachedConfigPath: string | null = null; | ||||||
| let _cachedConfigRoot: string | null = null; | ||||||
|
|
||||||
| const configFileExists = fs.existsSync(configFilePath); | ||||||
| if (!configFileExists) { | ||||||
| export function getConfig(resave = true): I18nConfig | null { | ||||||
| const configInfo = _findConfigPath(); | ||||||
| if (!configInfo) { | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| const fileContents = fs.readFileSync(configFilePath, "utf8"); | ||||||
| const { configPath, configRoot } = configInfo; | ||||||
|
||||||
| const { configPath, configRoot } = configInfo; | |
| const { configPath } = configInfo; |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message format is inconsistent with the standard error structure used elsewhere in the codebase. Other commands use CLIError or ConfigError with message and docUrl properties (see status.ts, i18n.ts). This plain Error without a docUrl prevents users from accessing documentation links that could help resolve the issue.
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The saveConfig function will fail silently in a race condition scenario: if the config file is deleted between the _findConfigPath() check and the fs.writeFileSync() call, the write will create the file in a potentially incorrect location (wherever the last found config was). Consider using the configPath from the initial config load or validating the path still exists before writing.
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function silently skips directories starting with a dot (line 100), but this excludes legitimate use cases like .github, .vscode, or other dot-prefixed project directories that might contain i18n configs. While this is reasonable for most cases, consider documenting this behavior in the function's JSDoc or making it configurable.
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The findConfigsDownwards function has quadratic time complexity due to checking fs.existsSync() for every subdirectory individually. In a monorepo with many directories, this could cause significant performance degradation. Consider collecting all directories first, then batch-checking for config files, or using a more efficient traversal strategy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module-level cache variables can become stale when process.chdir() is called (which happens in CI flows at packages/cli/src/cli/cmd/ci/flows/in-branch.ts line 131 and packages/cli/src/cli/cmd/ci/platforms/gitlab.ts line 14). After a directory change, the cached path would still point to the old location relative to the new cwd, causing config resolution to fail or use the wrong config file. Consider clearing the cache when the working directory changes, or store absolute paths instead of relying on process.cwd().