From 3b4323e973592382510a6c77a66468b0ce196eff Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Thu, 7 Jul 2022 13:01:48 -0700 Subject: [PATCH 1/3] feat: add suppport for `.mjs` and `.cjs` configs --- packages/remix-dev/config.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 4318375d793..8cdd140cdef 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -282,15 +282,18 @@ export async function readConfig( } let rootDirectory = path.resolve(remixRoot); - let configFile = path.resolve(rootDirectory, "remix.config.js"); - - let appConfig: AppConfig; - try { - appConfig = require(configFile); - } catch (error) { - throw new Error( - `Error loading Remix config in ${configFile}\n${String(error)}` - ); + let configFile = findConfig(rootDirectory, "remix.config"); + + let appConfig: AppConfig = {}; + if (configFile) { + try { + let appConfigModule = await import(configFile); + appConfig = appConfigModule?.default || appConfig; + } catch (error) { + throw new Error( + `Error loading Remix config in ${configFile}\n${String(error)}` + ); + } } let customServerEntryPoint = appConfig.server; @@ -466,3 +469,14 @@ function findEntry(dir: string, basename: string): string | undefined { return undefined; } + +const configExts = [".js", ".cjs", ".mjs"]; + +function findConfig(dir: string, basename: string): string | undefined { + for (let ext of configExts) { + let file = path.resolve(dir, basename + ext); + if (fse.existsSync(file)) return path.relative(dir, file); + } + + return undefined; +} From d356c7ad27421e8d8e9d8d012648291e9bb5fec2 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Wed, 3 Aug 2022 16:03:14 -0700 Subject: [PATCH 2/3] use absolute config path --- packages/remix-dev/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 3d9f3eeee2b..0ac1ce51893 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -296,7 +296,7 @@ export async function readConfig( appConfig = appConfigModule?.default || appConfig; } catch (error) { throw new Error( - `Error loading Remix config in ${configFile}\n${String(error)}` + `Error loading Remix config at ${configFile}\n${String(error)}` ); } } @@ -484,7 +484,7 @@ const configExts = [".js", ".cjs", ".mjs"]; function findConfig(dir: string, basename: string): string | undefined { for (let ext of configExts) { let file = path.resolve(dir, basename + ext); - if (fse.existsSync(file)) return path.relative(dir, file); + if (fse.existsSync(file)) return file; } return undefined; From da2d69d0244623f0e37ac0c7b45da0d9a3435886 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Wed, 3 Aug 2022 16:04:39 -0700 Subject: [PATCH 3/3] add changeset --- .changeset/afraid-peaches-accept.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/afraid-peaches-accept.md diff --git a/.changeset/afraid-peaches-accept.md b/.changeset/afraid-peaches-accept.md new file mode 100644 index 00000000000..8774b45b891 --- /dev/null +++ b/.changeset/afraid-peaches-accept.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +Add support for .mjs and .cjs remix.config files.