diff --git a/packages/nx/src/daemon/client/client.ts b/packages/nx/src/daemon/client/client.ts index f3a8bc8918234..a11f69f04dfd0 100644 --- a/packages/nx/src/daemon/client/client.ts +++ b/packages/nx/src/daemon/client/client.ts @@ -106,7 +106,8 @@ export class DaemonClient { async registerFileWatcher( config: { watchProjects: string[] | 'all'; - includeGlobalWorkspaceFiles: boolean; + includeGlobalWorkspaceFiles?: boolean; + includeDependentProjects?: boolean; }, callback: ( error: Error | null | 'closed', diff --git a/packages/nx/src/daemon/server/file-watching/file-watcher-sockets.ts b/packages/nx/src/daemon/server/file-watching/file-watcher-sockets.ts index 38a86a0e94b0c..6a794c1ce2c60 100644 --- a/packages/nx/src/daemon/server/file-watching/file-watcher-sockets.ts +++ b/packages/nx/src/daemon/server/file-watching/file-watcher-sockets.ts @@ -1,6 +1,8 @@ import { Socket } from 'net'; -import { ProjectGraphCache } from '../../../project-graph/nx-deps-cache'; +import { ProjectGraph } from '../../../config/project-graph'; +import { findAllProjectNodeDependencies } from '../../../utils/project-graph-utils'; import { PromisedBasedQueue } from '../../../utils/promised-based-queue'; +import { currentProjectGraphCache } from '../project-graph-incremental-recomputation'; import { handleResult } from '../server'; import { getProjectsAndGlobalChanges } from './changed-projects'; @@ -11,6 +13,7 @@ export let registeredFileWatcherSockets: { config: { watchProjects: string[] | 'all'; includeGlobalWorkspaceFiles: boolean; + includeDependentProjects: boolean; }; }[] = []; @@ -52,7 +55,20 @@ export function notifyFileWatcherSockets( changedFiles.push(...projectFiles); } } else { - for (const watchedProject of config.watchProjects) { + const watchedProjects = [...config.watchProjects]; + + if (config.includeDependentProjects) { + for (const project of watchedProjects) { + watchedProjects.push( + ...findAllProjectNodeDependencies( + project, + currentProjectGraphCache as ProjectGraph + ) + ); + } + } + + for (const watchedProject of new Set(watchedProjects)) { if (!!projectAndGlobalChanges.projects[watchedProject]) { changedProjects.push(watchedProject); diff --git a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts index dab493015f546..c935ca6e28ae3 100644 --- a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts +++ b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts @@ -24,7 +24,7 @@ let cachedSerializedProjectGraphPromise: Promise<{ export let projectFileMapWithFiles: | { projectFileMap: ProjectFileMap; allWorkspaceFiles: FileData[] } | undefined; -let currentProjectGraphCache: ProjectGraphCache | undefined; +export let currentProjectGraphCache: ProjectGraphCache | undefined; const collectedUpdatedFiles = new Set(); const collectedDeletedFiles = new Set();