From 28df4181aec64d21d30836ca5b10c1b9d5140025 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Mon, 22 May 2023 09:25:26 +0100 Subject: [PATCH] fix(web): file watcher should only watch files in its project #17085 (#17113) --- .../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 82d06e269b232..d2995326c9d7e 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'; @@ -103,21 +102,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(); @@ -151,7 +144,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