@@ -36,19 +36,40 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest
3636 */
3737 async loadModifications ( ) : Promise < FileModification [ ] > {
3838 const modifications : FileModification [ ] = [ ] ;
39- const modificationModules = import . meta. glob < {
40- default : new ( logger : Logger ) => FileModification ;
41- } > ( './modifications/*.modification.ts' , { eager : true } ) ;
39+ const modificationModules = import . meta. glob < Record < string , any > > (
40+ './modifications/*.modification.ts' ,
41+ { eager : true }
42+ ) ;
4243
4344 this . logger . debug ( `Loading ${ Object . keys ( modificationModules ) . length } modifications...` ) ;
4445 for ( const path in modificationModules ) {
4546 const module = modificationModules [ path ] ;
47+
48+ // Try to load default export first
4649 if ( module . default ) {
47- this . logger . debug ( `Loading modification: ${ module . default . name } ` ) ;
50+ this . logger . debug ( `Loading default modification: ${ module . default . name } ` ) ;
4851 const ModificationClass = module . default ;
4952 const instance = new ModificationClass ( this . logger ) ;
5053 modifications . push ( instance ) ;
5154 }
55+ // If no default export, try to find the first exported class that extends FileModification
56+ else {
57+ const exportedKeys = Object . keys ( module ) . filter (
58+ ( key ) => typeof module [ key ] === 'function' && key !== '__esModule'
59+ ) ;
60+
61+ if ( exportedKeys . length > 0 ) {
62+ const firstExportKey = exportedKeys [ 0 ] ;
63+ const ExportedClass = module [ firstExportKey ] ;
64+
65+ // Check if it's a class that extends FileModification
66+ if ( ExportedClass . prototype instanceof FileModification ) {
67+ this . logger . debug ( `Loading named modification: ${ ExportedClass . name } ` ) ;
68+ const instance = new ExportedClass ( this . logger ) ;
69+ modifications . push ( instance ) ;
70+ }
71+ }
72+ }
5273 }
5374 return modifications ;
5475 }
@@ -80,10 +101,7 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest
80101 }
81102 } catch ( error ) {
82103 if ( error instanceof Error ) {
83- this . logger . error (
84- `Failed to apply modification: ${ modification . id } : ${ error . message } ` ,
85- error . stack
86- ) ;
104+ this . logger . error ( `Failed to apply modification: ${ modification . id } : %o` , error ) ;
87105 } else {
88106 this . logger . error ( `Failed to apply modification: ${ modification . id } : Unknown error` ) ;
89107 }
0 commit comments