-
Notifications
You must be signed in to change notification settings - Fork 44
Adopt UnJS/c12 instead of cosmiconfig #260
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
/mycoder can you research the current implementation using cosmiconfig and how it can be replaced with c12? |
cosmiconfig vs c12 ResearchI've researched the current implementation using cosmiconfig and how it can be replaced with c12. Here's a detailed analysis: Current ImplementationThe mycoder project currently uses cosmiconfig for configuration management in
// Initialize cosmiconfig
const explorer = cosmiconfig('mycoder', {
searchStrategy: 'global',
});
// Search for configuration file
const result = await explorer.search();
// Merge configurations with precedence: default < file < cli
const fileConfig = result?.config || {};
// Return merged configuration
const mergedConfig = {
...defaultConfig,
...removeUndefined(fileConfig),
...removeUndefined(cliOptions),
}; c12 Implementationc12 is a configuration loader from the UnJS ecosystem that offers more features than cosmiconfig. Here's how the implementation would look: import { loadConfig as loadC12Config } from 'c12';
export async function loadConfig(
cliOptions: Partial<Config> = {},
): Promise<Config> {
// Load configuration using c12
const { config } = await loadC12Config({
name: 'mycoder',
defaults: defaultConfig,
overrides: cliOptions,
// Optional: Enable .env support
// dotenv: true,
});
// Validate custom commands if present
validateCustomCommands(config);
return config as Config;
} Advantages of c12 over cosmiconfig
Migration Plan
Example ImplementationI've already created a sample implementation in ConclusionMigrating from cosmiconfig to c12 would provide several benefits without requiring significant changes to the codebase. The migration can be done incrementally, starting with a basic implementation that maintains the current functionality, then gradually introducing new features. Would you like me to proceed with implementing this migration? I can create a PR with the changes, or provide more detailed guidance on specific aspects of the migration. |
I've implemented the requested change to replace cosmiconfig with c12. You can find the PR here: #262 The implementation:
All tests are passing with the new implementation. |
# [mycoder-v1.4.0](mycoder-v1.3.1...mycoder-v1.4.0) (2025-03-14) ### Bug Fixes * perfect gpustack compatibility, fix openai edge case ([9359f62](9359f62)) ### Features * replace cosmiconfig with c12 for configuration management ([cc17315](cc17315)), closes [#260](#260) * support multiple line custom prompts in mycoder.config.js ([fa7f45e](fa7f45e)), closes [#249](#249)
🎉 This issue has been resolved in version mycoder-v1.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Docs here:
https://unjs.io/packages/c12
https://www.npmjs.com/package/c12
I believe this should allow us to support typescript in our config files, rather than only JavaScript.
The text was updated successfully, but these errors were encountered: