From 1c6df03c933fbb1028b6cc906cb5a5c095e657c4 Mon Sep 17 00:00:00 2001 From: Christopher Trudel Date: Fri, 29 Apr 2022 11:52:43 -0230 Subject: [PATCH] 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 e5ac896216a..99ff6cfb1ef 100644 --- a/docs/api/conventions.md +++ b/docs/api/conventions.md @@ -162,6 +162,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 1ce772e6013..00482a32a8e 100644 --- a/packages/remix-dev/compiler.ts +++ b/packages/remix-dev/compiler.ts @@ -220,6 +220,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 ad1e87c3386..728aa947d52 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, }; }