@@ -53,6 +53,7 @@ import { getAffectedGraphNodes } from '../affected/affected';
5353import { readFileMapCache } from '../../project-graph/nx-deps-cache' ;
5454import { filterUsingGlobPatterns } from '../../hasher/task-hasher' ;
5555import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration-utils' ;
56+ import { findMatchingProjects } from '../../utils/find-matching-projects' ;
5657
5758import { createTaskHasher } from '../../hasher/create-task-hasher' ;
5859import { ProjectGraphError } from '../../project-graph/error-types' ;
@@ -351,19 +352,23 @@ export async function generateGraph(
351352 affectedProjects = [ ] ;
352353 }
353354
354- if ( args . exclude ) {
355- const invalidExcludes : string [ ] = [ ] ;
356-
357- args . exclude . forEach ( ( project ) => {
358- if ( ! projectExists ( projects , project ) ) {
359- invalidExcludes . push ( project ) ;
355+ let excludePatterns : string [ ] = [ ] ;
356+ if ( args . exclude && args . exclude . length > 0 ) {
357+ try {
358+ // Use findMatchingProjects to expand patterns (supports globs, tags, directories, etc.)
359+ excludePatterns = findMatchingProjects ( args . exclude , prunedGraph . nodes ) ;
360+
361+ // If no projects matched any of the exclude patterns, show a warning
362+ if ( excludePatterns . length === 0 ) {
363+ output . warn ( {
364+ title : `No projects matched the following exclude patterns:` ,
365+ bodyLines : args . exclude ,
366+ } ) ;
360367 }
361- } ) ;
362-
363- if ( invalidExcludes . length > 0 ) {
368+ } catch ( e ) {
364369 output . error ( {
365- title : `The following projects provided to -- exclude do not exist :` ,
366- bodyLines : invalidExcludes ,
370+ title : `Invalid exclude pattern :` ,
371+ bodyLines : [ e . message ] ,
367372 } ) ;
368373 process . exit ( 1 ) ;
369374 }
@@ -374,11 +379,7 @@ export async function generateGraph(
374379 'utf-8'
375380 ) ;
376381
377- prunedGraph = filterGraph (
378- prunedGraph ,
379- args . focus || null ,
380- args . exclude || [ ]
381- ) ;
382+ prunedGraph = filterGraph ( prunedGraph , args . focus || null , excludePatterns ) ;
382383
383384 if ( args . print || args . file === 'stdout' ) {
384385 console . log (
@@ -435,7 +436,7 @@ export async function generateGraph(
435436 ) ;
436437
437438 const environmentJs = buildEnvironmentJs (
438- args . exclude || [ ] ,
439+ excludePatterns ,
439440 args . watch ,
440441 ! ! args . file && args . file . endsWith ( 'html' ) ? 'build' : 'serve' ,
441442 projectGraphClientResponse ,
@@ -481,7 +482,7 @@ export async function generateGraph(
481482 process . exit ( 0 ) ;
482483 } else {
483484 const environmentJs = buildEnvironmentJs (
484- args . exclude || [ ] ,
485+ excludePatterns ,
485486 args . watch ,
486487 ! ! args . file && args . file . endsWith ( 'html' ) ? 'build' : 'serve'
487488 ) ;
@@ -498,7 +499,7 @@ export async function generateGraph(
498499 affectedProjects ,
499500 args . focus ,
500501 args . groupByFolder ,
501- args . exclude
502+ excludePatterns
502503 ) ;
503504 app = result . app ;
504505 url = result . url ;
@@ -624,7 +625,11 @@ async function startServer(
624625 }
625626
626627 const { projectGraphClientResponse, sourceMapResponse } =
627- await createProjectGraphAndSourceMapClientResponse ( affected ) ;
628+ await createProjectGraphAndSourceMapClientResponse (
629+ affected ,
630+ focus ,
631+ exclude
632+ ) ;
628633
629634 currentProjectGraphClientResponse = projectGraphClientResponse ;
630635 currentProjectGraphClientResponse . focus = focus ;
@@ -824,7 +829,11 @@ function createFileWatcher() {
824829 output . note ( { title : 'Recalculating project graph...' } ) ;
825830
826831 const { projectGraphClientResponse, sourceMapResponse } =
827- await createProjectGraphAndSourceMapClientResponse ( ) ;
832+ await createProjectGraphAndSourceMapClientResponse (
833+ [ ] ,
834+ currentProjectGraphClientResponse . focus ,
835+ currentProjectGraphClientResponse . exclude
836+ ) ;
828837
829838 if (
830839 projectGraphClientResponse . hash !==
@@ -861,7 +870,9 @@ function createFileWatcher() {
861870}
862871
863872async function createProjectGraphAndSourceMapClientResponse (
864- affected : string [ ] = [ ]
873+ affected : string [ ] = [ ] ,
874+ focus : string = null ,
875+ exclude : string [ ] = [ ]
865876) : Promise < {
866877 projectGraphClientResponse : ProjectGraphClientResponse ;
867878 sourceMapResponse : ConfigurationSourceMaps ;
@@ -905,6 +916,10 @@ async function createProjectGraphAndSourceMapClientResponse(
905916 }
906917
907918 let graph = pruneExternalNodes ( projectGraph ) ;
919+
920+ // Apply focus and exclude filters
921+ graph = filterGraph ( graph , focus , exclude ) ;
922+
908923 const fileMap : ProjectFileMap =
909924 readFileMapCache ( ) ?. fileMap . projectFileMap || { } ;
910925 performance . mark ( 'project graph watch calculation:end' ) ;
0 commit comments