@@ -68,6 +68,19 @@ export interface CacheEntry {
68
68
output : File [ ] ;
69
69
}
70
70
71
+ interface ActionMeta {
72
+ isWatchActive : boolean ;
73
+ subscriptions : Set < Subscription > ;
74
+ logs : LogEntry [ ] ;
75
+ inputHandler ?: MetaInputHandler ;
76
+ onDestroyHandler ?: ( ) => void ;
77
+ outputPath ?: string ;
78
+ }
79
+
80
+ interface BatchActionMeta {
81
+ onDestroyHandler ?: ( ) => void ;
82
+ }
83
+
71
84
export type MetaInputHandler =
72
85
| { type : 'single' ; fn : InputFnCallBack }
73
86
| { type : 'multi' ; fn : InputFnCallBack < File [ ] > } ;
@@ -190,17 +203,7 @@ async function garmentFromWorkspace(
190
203
const getSnapshotId = ( hash : string ) => `action-${ hash } ` ;
191
204
192
205
// The map to store an information related to each action, so it can be reused between action executions
193
- const metaByAction = new Map <
194
- Action ,
195
- {
196
- isWatchActive : boolean ;
197
- subscriptions : Set < Subscription > ;
198
- logs : LogEntry [ ] ;
199
- inputHandler ?: MetaInputHandler ;
200
- onDestroyHandler ?: ( ) => void ;
201
- outputPath ?: string ;
202
- }
203
- > ( ) ;
206
+ const metaByAction = new Map < Action , ActionMeta > ( ) ;
204
207
205
208
let allSubscriptionsCached : Subscription [ ] = [ ] ;
206
209
@@ -875,6 +878,7 @@ async function garmentFromWorkspace(
875
878
_ => _ . watch
876
879
) ;
877
880
881
+ const batchMetaByAction = new Map < Action , BatchActionMeta > ( ) ;
878
882
if ( batchActionsToExecute . length ) {
879
883
await runActionsInBatch ( batchActionsToExecute , {
880
884
runnerOptions
@@ -896,6 +900,12 @@ async function garmentFromWorkspace(
896
900
watch : true ,
897
901
runnerOptions
898
902
} ) ;
903
+ } else {
904
+ if ( ! watcherStarted ) {
905
+ for ( const meta of batchMetaByAction . values ( ) ) {
906
+ meta ?. onDestroyHandler ?.( ) ;
907
+ }
908
+ }
899
909
}
900
910
901
911
async function startWatcher ( ) {
@@ -1008,13 +1018,19 @@ async function garmentFromWorkspace(
1008
1018
{
1009
1019
runner : RunnerMeta ;
1010
1020
batch : { project : Project ; options : any } [ ] ;
1021
+ batchMeta ?: BatchActionMeta ;
1011
1022
}
1012
1023
> ( ) ;
1013
1024
for ( const action of actions ) {
1014
1025
if ( ! batchesByRunner . has ( action . runner . handlerPath ) ) {
1026
+ /**We don't want more than one meta per runner, since longRunning should be invoked once for all projects.
1027
+ * In the future we may want a meta for each action.
1028
+ */
1029
+ batchMetaByAction . set ( action , { } ) ;
1015
1030
batchesByRunner . set ( action . runner . handlerPath , {
1016
1031
runner : action . runner ,
1017
- batch : [ ]
1032
+ batch : [ ] ,
1033
+ batchMeta : batchMetaByAction . get ( action )
1018
1034
} ) ;
1019
1035
}
1020
1036
const { batch } = batchesByRunner . get ( action . runner . handlerPath ) ! ;
@@ -1029,7 +1045,7 @@ async function garmentFromWorkspace(
1029
1045
} )
1030
1046
} ) ;
1031
1047
}
1032
- for ( const { runner, batch } of batchesByRunner . values ( ) ) {
1048
+ for ( const { runner, batch, batchMeta } of batchesByRunner . values ( ) ) {
1033
1049
onUpdate ( { type : 'before-batch' , runner, batch } ) ;
1034
1050
1035
1051
const options = {
@@ -1066,7 +1082,12 @@ async function garmentFromWorkspace(
1066
1082
dependsOnFile ( ) { } ,
1067
1083
cacheProvider,
1068
1084
batch,
1069
- logger
1085
+ logger,
1086
+ longRunning ( onDestroy ) {
1087
+ if ( batchMeta ) {
1088
+ batchMeta . onDestroyHandler = onDestroy ;
1089
+ }
1090
+ }
1070
1091
} ) ;
1071
1092
1072
1093
const handler = watch ? getWatcher ( runner ) : getHandler ( runner ) ;
0 commit comments