diff --git a/src/cli.ts b/src/cli.ts index 6d8f975..170777d 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -83,7 +83,7 @@ yargs alias: "c", type: "string", description: "Optional path to gmrc file", - defaultDescription: ".gmrc[.js]", + defaultDescription: ".gmrc[.js|.cjs]", }) .completion("completion", "Generate shell completion script.") diff --git a/src/commands/_common.ts b/src/commands/_common.ts index 971c2dd..95d0436 100644 --- a/src/commands/_common.ts +++ b/src/commands/_common.ts @@ -7,6 +7,7 @@ import { Settings } from "../settings"; export const DEFAULT_GMRC_PATH = `${process.cwd()}/.gmrc`; export const DEFAULT_GMRCJS_PATH = `${DEFAULT_GMRC_PATH}.js`; +export const DEFAULT_GMRC_COMMONJS_PATH = `${DEFAULT_GMRC_PATH}.cjs`; /** * Represents the option flags that are valid for all commands (see @@ -86,7 +87,13 @@ export async function getSettings(options: Options = {}): Promise { throw new Error(`Failed to import '${configFile}': file not found`); } - if (configFile.endsWith(".js")) { + if (configFile.endsWith(".mjs")) { + throw new Error( + `ES module imports aren't currently supported, change your config extension to .cjs.`, + ); + } + + if (configFile.endsWith(".js") || configFile.endsWith(".cjs")) { return tryRequire(configFile); } else { return await getSettingsFromJSON(configFile); @@ -95,6 +102,8 @@ export async function getSettings(options: Options = {}): Promise { return await getSettingsFromJSON(DEFAULT_GMRC_PATH); } else if (await exists(DEFAULT_GMRCJS_PATH)) { return tryRequire(DEFAULT_GMRCJS_PATH); + } else if (await exists(DEFAULT_GMRC_COMMONJS_PATH)) { + return tryRequire(DEFAULT_GMRC_COMMONJS_PATH); } else { throw new Error( "No .gmrc file found; please run `graphile-migrate init` first.",