From 8e6ae75af841267a031a1eccb553e49e053fe8fd Mon Sep 17 00:00:00 2001 From: Christopher Trudel Date: Fri, 29 Apr 2022 11:52:43 -0230 Subject: [PATCH 1/4] feat(remix-dev): watchDirectories option for remix.config --- docs/api/conventions.md | 12 ++++++++++++ packages/remix-dev/__tests__/readConfig-test.ts | 1 + packages/remix-dev/compiler.ts | 4 ++++ packages/remix-dev/config.ts | 17 +++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/docs/api/conventions.md b/docs/api/conventions.md index ef7a9028ea2..89f34a4dc59 100644 --- a/docs/api/conventions.md +++ b/docs/api/conventions.md @@ -158,6 +158,18 @@ module.exports = { }; ``` +### watchDirectories + +A function for defining custom directories to watch while running [remix dev](https://remix.run/docs/en/v1/other-api/dev#remix-dev), in addition to [`appDirectory`](#appDirectory). + +```tsx +exports.watchDirectories = async () => { + return [ + "/some/path/*" + ]; +}; +``` + ## File Name Conventions There are a few conventions that Remix uses you should be aware of. diff --git a/packages/remix-dev/__tests__/readConfig-test.ts b/packages/remix-dev/__tests__/readConfig-test.ts index 92af7767d63..ca6cd1ecb50 100644 --- a/packages/remix-dev/__tests__/readConfig-test.ts +++ b/packages/remix-dev/__tests__/readConfig-test.ts @@ -48,6 +48,7 @@ describe("readConfig", () => { "serverMode": "production", "serverModuleFormat": "cjs", "serverPlatform": "node", + "watchDirectories": Array [], } ` ); diff --git a/packages/remix-dev/compiler.ts b/packages/remix-dev/compiler.ts index 39209f2bc3e..80a476f6e0d 100644 --- a/packages/remix-dev/compiler.ts +++ b/packages/remix-dev/compiler.ts @@ -221,6 +221,10 @@ export async function watch( if (config.serverEntryPoint) { toWatch.push(config.serverEntryPoint); } + + config.watchDirectories?.forEach((directory) => { + toWatch.push(directory); + }); let watcher = chokidar .watch(toWatch, { diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index fae6c171bf0..29f077f931e 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -147,6 +147,11 @@ export interface AppConfig { * in a CJS build. */ serverDependenciesToBundle?: Array; + + /** + * A function for defining custom directories to watch while running `remix dev`, in addition to `appDirectory`. + */ + watchDirectories?: () => Promise; } /** @@ -250,6 +255,11 @@ export interface RemixConfig { * in a CJS build. */ serverDependenciesToBundle: Array; + + /** + * A list of directories to watch. + */ + watchDirectories: string[]; } /** @@ -395,6 +405,12 @@ export async function readConfig( } } + let watchDirectories: string[] = []; + if (appConfig.watchDirectories) { + let directories = await appConfig.watchDirectories(); + watchDirectories = watchDirectories.concat(Array.isArray(directories) ? directories : [directories]); + } + let serverBuildTargetEntryModule = `export * from ${JSON.stringify( serverBuildVirtualModule.id )};`; @@ -421,6 +437,7 @@ export async function readConfig( serverEntryPoint: customServerEntryPoint, serverDependenciesToBundle, mdx, + watchDirectories, }; } From 15e26e682f62f8e7228fb377af9ec0628a773365 Mon Sep 17 00:00:00 2001 From: Christopher Trudel Date: Fri, 13 May 2022 17:22:39 -0230 Subject: [PATCH 2/4] Update contributors.yml --- contributors.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.yml b/contributors.yml index a708c85daf8..1aaefc48072 100644 --- a/contributors.yml +++ b/contributors.yml @@ -62,6 +62,7 @@ - chenxsan - chiangs - christianhg +- christophertrudel - christophgockel - clarkmitchell - cliffordfajardo From 64f8b7b3e72ae127cc23f232c3a34518e1a78c27 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Thu, 30 Jun 2022 13:22:52 -0700 Subject: [PATCH 3/4] rename to watchPaths --- docs/api/conventions.md | 4 ++-- packages/remix-dev/__tests__/readConfig-test.ts | 2 +- packages/remix-dev/compiler.ts | 4 ++-- packages/remix-dev/config.ts | 16 +++++++++------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/api/conventions.md b/docs/api/conventions.md index 89f34a4dc59..7ededcc0074 100644 --- a/docs/api/conventions.md +++ b/docs/api/conventions.md @@ -158,12 +158,12 @@ module.exports = { }; ``` -### watchDirectories +### watchPaths A function for defining custom directories to watch while running [remix dev](https://remix.run/docs/en/v1/other-api/dev#remix-dev), in addition to [`appDirectory`](#appDirectory). ```tsx -exports.watchDirectories = async () => { +exports.watchPaths = async () => { return [ "/some/path/*" ]; diff --git a/packages/remix-dev/__tests__/readConfig-test.ts b/packages/remix-dev/__tests__/readConfig-test.ts index ca6cd1ecb50..5164cc96066 100644 --- a/packages/remix-dev/__tests__/readConfig-test.ts +++ b/packages/remix-dev/__tests__/readConfig-test.ts @@ -48,7 +48,7 @@ describe("readConfig", () => { "serverMode": "production", "serverModuleFormat": "cjs", "serverPlatform": "node", - "watchDirectories": Array [], + "watchPaths": Array [], } ` ); diff --git a/packages/remix-dev/compiler.ts b/packages/remix-dev/compiler.ts index 80a476f6e0d..61b828427bc 100644 --- a/packages/remix-dev/compiler.ts +++ b/packages/remix-dev/compiler.ts @@ -222,8 +222,8 @@ export async function watch( toWatch.push(config.serverEntryPoint); } - config.watchDirectories?.forEach((directory) => { - toWatch.push(directory); + config.watchPaths?.forEach((watchPath) => { + toWatch.push(watchPath); }); let watcher = chokidar diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 29f077f931e..1eeb1ef9bbf 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -151,7 +151,7 @@ export interface AppConfig { /** * A function for defining custom directories to watch while running `remix dev`, in addition to `appDirectory`. */ - watchDirectories?: () => Promise; + watchPaths?: () => Promise; } /** @@ -259,7 +259,7 @@ export interface RemixConfig { /** * A list of directories to watch. */ - watchDirectories: string[]; + watchPaths: string[]; } /** @@ -405,10 +405,12 @@ export async function readConfig( } } - let watchDirectories: string[] = []; - if (appConfig.watchDirectories) { - let directories = await appConfig.watchDirectories(); - watchDirectories = watchDirectories.concat(Array.isArray(directories) ? directories : [directories]); + let watchPaths: string[] = []; + if (appConfig.watchPaths) { + let directories = await appConfig.watchPaths(); + watchPaths = watchPaths.concat( + Array.isArray(directories) ? directories : [directories] + ); } let serverBuildTargetEntryModule = `export * from ${JSON.stringify( @@ -437,7 +439,7 @@ export async function readConfig( serverEntryPoint: customServerEntryPoint, serverDependenciesToBundle, mdx, - watchDirectories, + watchPaths, }; } From 34f61161217f13486e428b9b1cd670778454f1e5 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Thu, 30 Jun 2022 15:46:21 -0700 Subject: [PATCH 4/4] updated to be func or value --- packages/remix-dev/config.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 1eeb1ef9bbf..4318375d793 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -151,7 +151,10 @@ export interface AppConfig { /** * A function for defining custom directories to watch while running `remix dev`, in addition to `appDirectory`. */ - watchPaths?: () => Promise; + watchPaths?: + | string + | string[] + | (() => Promise | string | string[]); } /** @@ -406,11 +409,17 @@ export async function readConfig( } let watchPaths: string[] = []; - if (appConfig.watchPaths) { + if (typeof appConfig.watchPaths === "function") { let directories = await appConfig.watchPaths(); watchPaths = watchPaths.concat( Array.isArray(directories) ? directories : [directories] ); + } else if (appConfig.watchPaths) { + watchPaths = watchPaths.concat( + Array.isArray(appConfig.watchPaths) + ? appConfig.watchPaths + : [appConfig.watchPaths] + ); } let serverBuildTargetEntryModule = `export * from ${JSON.stringify(