From eb72b51817f893652114eaf24f87e0ebb7c0aab3 Mon Sep 17 00:00:00 2001 From: Guillaume <3765057+guillaumervls@users.noreply.github.com> Date: Mon, 21 Jun 2021 13:10:23 +0200 Subject: [PATCH 1/3] Support .cjs config files Hello, This is a quick* fix the use of JS config files in projects where `"type": "module"` is used in `package.json` (which will me more and more frequent now that Node 10 obsolete). Cheers! *The right way might be to support it via `import` --- src/commands/_common.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/_common.ts b/src/commands/_common.ts index 971c2dd..cf14eee 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_GMRCCJS_PATH = `${DEFAULT_GMRC_PATH}.cjs`; /** * Represents the option flags that are valid for all commands (see @@ -86,7 +87,7 @@ export async function getSettings(options: Options = {}): Promise { throw new Error(`Failed to import '${configFile}': file not found`); } - if (configFile.endsWith(".js")) { + if (configFile.endsWith(".js") || configFile.endsWith(".cjs")) { return tryRequire(configFile); } else { return await getSettingsFromJSON(configFile); @@ -95,6 +96,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_GMRCCJS_PATH)) { + return tryRequire(DEFAULT_GMRCCJS_PATH); } else { throw new Error( "No .gmrc file found; please run `graphile-migrate init` first.", From c87dea9c6ad575c651ed764d8d406dabaafac2ed Mon Sep 17 00:00:00 2001 From: Guillaume <3765057+guillaumervls@users.noreply.github.com> Date: Fri, 2 Jul 2021 13:33:28 +0200 Subject: [PATCH 2/3] Update _common.ts --- src/commands/_common.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/commands/_common.ts b/src/commands/_common.ts index cf14eee..7b58490 100644 --- a/src/commands/_common.ts +++ b/src/commands/_common.ts @@ -8,6 +8,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_GMRCCJS_PATH = `${DEFAULT_GMRC_PATH}.cjs`; +export const DEFAULT_GMRCMJS_PATH = `${DEFAULT_GMRC_PATH}.mjs`; /** * Represents the option flags that are valid for all commands (see @@ -71,7 +72,7 @@ export async function getSettings(options: Options = {}): Promise { const relativePath = resolve(process.cwd(), path); try { - return require(relativePath); + return relativePath.endsWith(".mjs") ? import(relativePath) : require(relativePath); } catch (e) { throw new Error( `Failed to import '${relativePath}'; error:\n ${e.stack.replace( @@ -87,7 +88,7 @@ export async function getSettings(options: Options = {}): Promise { throw new Error(`Failed to import '${configFile}': file not found`); } - if (configFile.endsWith(".js") || configFile.endsWith(".cjs")) { + if (configFile.endsWith(".js") || configFile.endsWith(".cjs") || configFile.endsWith(".mjs")) { return tryRequire(configFile); } else { return await getSettingsFromJSON(configFile); @@ -98,6 +99,8 @@ export async function getSettings(options: Options = {}): Promise { return tryRequire(DEFAULT_GMRCJS_PATH); } else if (await exists(DEFAULT_GMRCCJS_PATH)) { return tryRequire(DEFAULT_GMRCCJS_PATH); + } else if (await exists(DEFAULT_GMRCMJS_PATH)) { + return tryRequire(DEFAULT_GMRCMJS_PATH); } else { throw new Error( "No .gmrc file found; please run `graphile-migrate init` first.", From 67b06b2d9e30917be9b6b24f3e77a6e1a4f95910 Mon Sep 17 00:00:00 2001 From: Guillaume <3765057+guillaumervls@users.noreply.github.com> Date: Fri, 2 Jul 2021 18:04:38 +0200 Subject: [PATCH 3/3] Update src/commands/_common.ts Co-authored-by: Benjie Gillam --- src/commands/_common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/_common.ts b/src/commands/_common.ts index 7b58490..c27cd25 100644 --- a/src/commands/_common.ts +++ b/src/commands/_common.ts @@ -72,7 +72,7 @@ export async function getSettings(options: Options = {}): Promise { const relativePath = resolve(process.cwd(), path); try { - return relativePath.endsWith(".mjs") ? import(relativePath) : require(relativePath); + return relativePath.endsWith(".mjs") ? await import(relativePath) : require(relativePath); } catch (e) { throw new Error( `Failed to import '${relativePath}'; error:\n ${e.stack.replace(