diff --git a/.changeset/old-pigs-dance.md b/.changeset/old-pigs-dance.md new file mode 100644 index 0000000..95a0442 --- /dev/null +++ b/.changeset/old-pigs-dance.md @@ -0,0 +1,5 @@ +--- +'@emigrate/cli': patch +--- + +Handle the case where the config is returned as an object with a nested `default` property diff --git a/packages/cli/src/get-config.ts b/packages/cli/src/get-config.ts index 4db33a7..f70fac9 100644 --- a/packages/cli/src/get-config.ts +++ b/packages/cli/src/get-config.ts @@ -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 => { 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];