fix(cli): handle the case where the config is returned as an object with a nested default property

This commit is contained in:
Joakim Carlstein 2024-02-19 09:25:56 +01:00 committed by Joakim Carlstein
parent 6763f338ce
commit 41522094dd
2 changed files with 18 additions and 1 deletions

View file

@ -6,6 +6,18 @@ const commands = ['up', 'list', 'new', 'remove'] as const;
type Command = (typeof commands)[number];
const canImportTypeScriptAsIs = Boolean(process.isBun) || typeof Deno !== 'undefined';
const getEmigrateConfig = (config: any): EmigrateConfig => {
if ('default' in config && typeof config.default === 'object' && config.default !== null) {
return config.default as EmigrateConfig;
}
if (typeof config === 'object' && config !== null) {
return config as EmigrateConfig;
}
return {};
};
export const getConfig = async (command: Command, forceImportTypeScriptAsIs = false): Promise<Config> => {
const explorer = cosmiconfig('emigrate', {
// eslint-disable-next-line @typescript-eslint/naming-convention
@ -18,7 +30,7 @@ export const getConfig = async (command: Command, forceImportTypeScriptAsIs = fa
return {};
}
const config = result.config as EmigrateConfig;
const config = getEmigrateConfig(result.config);
const commandConfig = config[command];