@@ -37,29 +37,61 @@ function createOperations(
37
37
includePhaseDeps,
38
38
isInitial
39
39
} = context ;
40
- const operationsWithWork : Set < Operation > = new Set ( ) ;
41
40
42
41
const operations : Map < string , Operation > = new Map ( ) ;
43
42
44
43
// Create tasks for selected phases and projects
44
+ // This also creates the minimal set of dependencies needed
45
45
for ( const phase of phaseOriginal ) {
46
46
for ( const project of projectSelection ) {
47
47
getOrCreateOperation ( phase , project ) ;
48
48
}
49
49
}
50
50
51
- // Recursively expand all consumers in the `operationsWithWork` set.
51
+ // Grab all operations that were explicitly requested.
52
+ const operationsWithWork : Set < Operation > = new Set ( ) ;
53
+ for ( const operation of existingOperations ) {
54
+ const { associatedPhase, associatedProject } = operation ;
55
+ if ( ! associatedPhase || ! associatedProject ) {
56
+ // Fix this when these are required properties.
57
+ continue ;
58
+ }
59
+
60
+ if ( phaseSelection . has ( associatedPhase ) && changedProjects . has ( associatedProject ) ) {
61
+ operationsWithWork . add ( operation ) ;
62
+ }
63
+ }
64
+
65
+ // Add all operations that are selected that depend on the explicitly requested operations.
66
+ // This will mostly be relevant during watch; in initial runs it should not add any new operations.
52
67
for ( const operation of operationsWithWork ) {
53
68
for ( const consumer of operation . consumers ) {
54
69
operationsWithWork . add ( consumer ) ;
55
70
}
56
71
}
57
72
58
- for ( const operation of operations . values ( ) ) {
59
- if ( ! operationsWithWork . has ( operation ) ) {
60
- // This operation is in scope, but did not change since it was last executed by the current command.
61
- // However, we have no state tracking across executions, so treat as unknown.
62
- operation . enabled = false ;
73
+ if ( includePhaseDeps && isInitial ) {
74
+ // Add all operations that are dependencies of the operations already scheduled.
75
+ for ( const operation of operationsWithWork ) {
76
+ for ( const dependency of operation . dependencies ) {
77
+ operationsWithWork . add ( dependency ) ;
78
+ }
79
+ }
80
+ }
81
+
82
+ for ( const operation of existingOperations ) {
83
+ // Enable exactly the set of operations that are requested.
84
+ operation . enabled &&= operationsWithWork . has ( operation ) ;
85
+
86
+ if ( ! includePhaseDeps || ! isInitial ) {
87
+ const { associatedPhase, associatedProject } = operation ;
88
+ if ( ! associatedPhase || ! associatedProject ) {
89
+ // Fix this when these are required properties.
90
+ continue ;
91
+ }
92
+
93
+ // This filter makes the "unsafe" selections happen.
94
+ operation . enabled &&= phaseSelection . has ( associatedPhase ) && projectSelection . has ( associatedProject ) ;
63
95
}
64
96
}
65
97
@@ -86,17 +118,6 @@ function createOperations(
86
118
logFilenameIdentifier : logFilenameIdentifier
87
119
} ) ;
88
120
89
- if ( ! phaseSelection . has ( phase ) || ! projectSelection . has ( project ) ) {
90
- if ( includePhaseDeps && isInitial ) {
91
- operationsWithWork . add ( operation ) ;
92
- } else {
93
- // Not in scope. Mark disabled, which will report as OperationStatus.Skipped.
94
- operation . enabled = false ;
95
- }
96
- } else if ( changedProjects . has ( project ) ) {
97
- operationsWithWork . add ( operation ) ;
98
- }
99
-
100
121
operations . set ( key , operation ) ;
101
122
existingOperations . add ( operation ) ;
102
123
0 commit comments