@@ -1907,54 +1907,38 @@ export default class Elysia<
19071907 Object . assign ( context . store , this . store )
19081908 } )
19091909
1910- plugin . event . trace = [
1911- ...( this . event . trace || [ ] ) ,
1912- ...( plugin . event . trace || [ ] )
1913- ]
1914-
1915-
1910+ if ( plugin . event . trace . length )
1911+ plugin . event . trace . push ( ...plugin . event . trace )
19161912
19171913 if ( isScoped && ! plugin . config . prefix )
19181914 console . warn (
19191915 'When using scoped plugins it is recommended to use a prefix, else routing may not work correctly for the second scoped instance'
1920- )
1916+ )
1917+
1918+ if ( plugin . event . error . length )
1919+ plugin . event . error . push ( ...this . event . error )
19211920
1922- /* Run global error handlers after the error handlers of the plugin are done executing.
1923- TODO
1924- - should this really be handled here or is there some kind of merging failing?
1925- - should this also be applicable for other handlers?
1926- It seems like this only affects scoped changes. so it could be moved inside the below if block */
1927-
1928- plugin . event . error . push ( ...this . event . error ) ;
1929-
19301921 if ( plugin . config . aot ) plugin . compile ( )
19311922
19321923 let instance
19331924
19341925 if ( isScoped && plugin . config . prefix ) {
1935-
19361926 instance = this . mount ( plugin . config . prefix + '/' , plugin . fetch )
19371927
1938- //Ensure that when using plugins routes are correctly showing up in the .routes property. Else plugins e.g. swagger will not correctly work.
1939- //This also avoids adding routes multiple times.
1940-
1941- plugin . routes . forEach ( ( r ) => {
1928+ // Ensure that when using plugins routes are correctly showing up in the .routes property. Else plugins e.g. swagger will not correctly work.
1929+ // This also avoids adding routes multiple times.
1930+ for ( const route of plugin . routes )
19421931 this . routes . push ( {
1943- ...r ,
1944- path : `${ plugin . config . prefix } ${ r . path } ` ,
1945- //This probably has no effect as the routes object itself is not used to execute these handlers? The plugin is taking care of it.
1946- hooks : mergeHook (
1947- r . hooks ,
1948- {
1949- error : this . event . error
1950- }
1951- )
1932+ ...route ,
1933+ path : `${ plugin . config . prefix } ${ route . path } ` ,
1934+ hooks : mergeHook ( route . hooks , {
1935+ error : this . event . error
1936+ } )
19521937 } )
1953- } )
19541938 } else {
1955-
19561939 instance = this . mount ( plugin . fetch )
1957- this . routes = this . routes . concat ( instance . routes )
1940+
1941+ if ( instance . routes . length ) this . routes . push ( ...instance . routes )
19581942 }
19591943
19601944 return this
0 commit comments