@@ -285,17 +285,30 @@ export class CommandsRouter {
285
285
private applyMiddlewares ( ) {
286
286
this . commands . forEach ( ( command ) => {
287
287
const commandPath = command . parentPath ;
288
- const samePathMiddlewares = Array . from ( this . middlewares . values ( ) )
289
- . filter ( ( middleware ) => {
290
- if ( middleware . global ) return true ;
291
- if ( middleware . command ) return middleware . command === command . name ;
292
- return middleware . parentPath === commandPath ;
293
- } )
288
+ const allMiddlewares = Array . from ( this . middlewares . values ( ) ) ;
289
+
290
+ const commandSpecificMiddlewares = allMiddlewares
291
+ . filter ( ( middleware ) => middleware . command === command . name )
292
+ . map ( ( middleware ) => middleware . id ) ;
293
+
294
+ const directorySpecificMiddlewares = allMiddlewares
295
+ . filter (
296
+ ( middleware ) =>
297
+ ! middleware . global &&
298
+ ! middleware . command &&
299
+ middleware . parentPath === commandPath ,
300
+ )
301
+ . map ( ( middleware ) => middleware . id ) ;
302
+
303
+ const globalMiddlewares = allMiddlewares
304
+ . filter ( ( middleware ) => middleware . global )
294
305
. map ( ( middleware ) => middleware . id ) ;
295
306
296
- command . middlewares = Array . from (
297
- new Set ( [ ...command . middlewares , ...samePathMiddlewares ] ) ,
298
- ) ;
307
+ command . middlewares = [
308
+ ...commandSpecificMiddlewares ,
309
+ ...directorySpecificMiddlewares ,
310
+ ...globalMiddlewares ,
311
+ ] ;
299
312
} ) ;
300
313
}
301
314
0 commit comments