fix(cli): handle the case where the config is returned as an object with a nested default property
This commit is contained in:
parent
6763f338ce
commit
41522094dd
2 changed files with 18 additions and 1 deletions
5
.changeset/old-pigs-dance.md
Normal file
5
.changeset/old-pigs-dance.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@emigrate/cli': patch
|
||||
---
|
||||
|
||||
Handle the case where the config is returned as an object with a nested `default` property
|
||||
|
|
@ -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];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue