c12
c12 copied to clipboard
Support update existing `.config/[name].[ext]`
Describe the feature
Hello! This issue is related to the updateConfig util
I think it'd be nice to support updating existing files in the .config/ folder using the .config/[name].[ext] format, as described here.
For example, let's say I have a config file at .config/foo.ts and I want to update this existing config, I would typically set the configFile property to 'foo.config', so that foo.config.ts is created at the project's root if no config file is detected. However, the problem is that .config/foo.ts isn't being detected because of this line:
https://github.com/unjs/c12/blob/26c97080c5ab06e32686d7f3f93f59c5ee3471c5/src/update.ts#L25
It currently expects the file to be .config/foo.config.ts, thus it doesn't detect the existing .config/foo.ts file.
Implementation
I don't know if this implementation is right for performance, and I apologize if it's not or if this is already a work in progress upstream. Adding these lines would make it work without breaking the current support
let configFile =
(await _tryResolve(
`./${opts.configFile}`,
opts.cwd,
SUPPORTED_EXTENSIONS,
)) ||
(await _tryResolve(
`./.config/${opts.configFile}`,
opts.cwd,
SUPPORTED_EXTENSIONS,
+ )) ||
+ (await _tryResolve(
+ `./.config/${opts.configFile.split(".")[0]}`,
+ opts.cwd,
+ SUPPORTED_EXTENSIONS,
+ ));
I forked it, pushed my changes here https://github.com/unjs/c12/compare/main...Yizack:c12:main, and added a test case that creates a config file before in case you want to take a look.
Best wishes!
Additional information
- [X] Would you be willing to help implement this feature?