@@ -132,18 +132,46 @@ function getReleventConfigs(target: string, options: Options) {
132
132
133
133
onlyTargets = onlyTargets
134
134
. filter ( ( individualOnly ) => {
135
- return individualOnly . indexOf ( `${ target } :` ) === 0 ;
135
+ return individualOnly . startsWith ( `${ target } :` ) ;
136
136
} )
137
137
. map ( ( individualOnly ) => {
138
138
return individualOnly . replace ( `${ target } :` , "" ) ;
139
139
} ) ;
140
140
141
- return targetConfigs . filter ( ( config : any ) => {
142
- if ( target === "functions" ) {
143
- return onlyTargets . includes ( config . codebase ) ;
141
+ if ( target === "functions" ) {
142
+ let onlyConfigs = [ ] ;
143
+ const matched = onlyTargets . reduce (
144
+ ( matched : object , target : string ) => ( { ...matched , [ target ] : false } ) ,
145
+ { }
146
+ ) ;
147
+ for ( const config of targetConfigs ) {
148
+ if ( ! config . codebase ) {
149
+ onlyConfigs . push ( config ) ;
150
+ } else {
151
+ const found = onlyTargets . find (
152
+ ( individualOnly ) => config . codebase === individualOnly . split ( ":" ) [ 0 ]
153
+ ) ;
154
+ if ( found ) {
155
+ onlyConfigs . push ( config ) ;
156
+ matched [ found ] = true ;
157
+ }
158
+ }
144
159
}
145
- return ! config . target || onlyTargets . includes ( config . target ) ;
146
- } ) ;
160
+ // if there are --only targets that failed to match, we assume that the target is a
161
+ // individually specified function and so we run lifecycle hooks for all codebases.
162
+ // However, this also means that codebases or functions that don't exist will also run
163
+ // the all codebase lifecycle hooks. Until we can significantly refactor the way we
164
+ // identify which functions are in which codebase in the predeploy phase, we have to live
165
+ // with this default behavior.
166
+ if ( ! Object . values ( matched ) . every ( ( matched ) => matched ) ) {
167
+ onlyConfigs = targetConfigs ;
168
+ }
169
+ return onlyConfigs ;
170
+ } else {
171
+ return targetConfigs . filter ( ( config : any ) => {
172
+ return ! config . target || onlyTargets . includes ( config . target ) ;
173
+ } ) ;
174
+ }
147
175
}
148
176
149
177
export function lifecycleHooks (
0 commit comments