Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
11 changes: 10 additions & 1 deletion src/commands/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +87,13 @@ export async function getSettings(options: Options = {}): Promise<Settings> {
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);
Expand All @@ -95,6 +102,8 @@ export async function getSettings(options: Options = {}): Promise<Settings> {
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.",
Expand Down