From e1f1de938000e7a1bf40d2b3231c5f8c6118d3c3 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Fri, 19 May 2023 16:03:12 +0100 Subject: [PATCH] fix(web): file watcher should only watch files in its project #17085 --- .../executors/file-server/file-server.impl.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/web/src/executors/file-server/file-server.impl.ts b/packages/web/src/executors/file-server/file-server.impl.ts index b998060c392d9..d4a05f8cf7d50 100644 --- a/packages/web/src/executors/file-server/file-server.impl.ts +++ b/packages/web/src/executors/file-server/file-server.impl.ts @@ -5,7 +5,6 @@ import { joinPathFragments, parseTargetString, readTargetOptions, - workspaceLayout, } from '@nx/devkit'; import ignore from 'ignore'; import { copyFileSync, readFileSync, unlinkSync } from 'fs'; @@ -106,21 +105,15 @@ function getIgnoredGlobs(root: string) { function createFileWatcher( root: string, + projectRoot: string, changeHandler: () => void ): () => void { const ignoredGlobs = getIgnoredGlobs(root); - const layout = workspaceLayout(); - - const watcher = watch( - [ - joinPathFragments(layout.appsDir, '**'), - joinPathFragments(layout.libsDir, '**'), - ], - { - cwd: root, - ignoreInitial: true, - } - ); + + const watcher = watch([joinPathFragments(projectRoot, '**')], { + cwd: root, + ignoreInitial: true, + }); watcher.on('all', (_event: string, path: string) => { if (ignoredGlobs.ignores(path)) return; changeHandler(); @@ -154,7 +147,9 @@ export default async function* fileServerExecutor( let disposeWatch: () => void; if (options.watch) { - disposeWatch = createFileWatcher(context.root, run); + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; + disposeWatch = createFileWatcher(context.root, projectRoot, run); } // perform initial run