@@ -164,6 +164,23 @@ export class Application extends Koa {
164
164
this . router [ method ] ( path , route )
165
165
}
166
166
167
+ fixModuleClassNames ( modules ) {
168
+ // Naming fix for a weird vite 6 bug where the model classes are sometimes
169
+ // prefixed with `_`, but only when imported in `vite.config.js`.
170
+ if ( isPlainObject ( modules ) ) {
171
+ for ( const [ key , module ] of Object . entries ( modules ) ) {
172
+ if ( module ?. name ?. match ( / ^ _ ( .* ) $ / ) ?. [ 1 ] === key ) {
173
+ Object . defineProperty ( module , 'name' , {
174
+ value : key ,
175
+ writable : false ,
176
+ enumerable : false ,
177
+ configurable : true
178
+ } )
179
+ }
180
+ }
181
+ }
182
+ }
183
+
167
184
getStorage ( name ) {
168
185
return this . storages [ name ] || null
169
186
}
@@ -190,8 +207,9 @@ export class Application extends Koa {
190
207
}
191
208
192
209
addStorages ( storages ) {
193
- for ( const [ name , config ] of Object . entries ( storages ) ) {
194
- this . addStorage ( config , name )
210
+ this . fixModuleClassNames ( storages )
211
+ for ( const [ key , config ] of Object . entries ( storages ) ) {
212
+ this . addStorage ( config , key )
195
213
}
196
214
}
197
215
@@ -230,8 +248,9 @@ export class Application extends Koa {
230
248
}
231
249
232
250
addServices ( services ) {
233
- for ( const [ name , service ] of Object . entries ( services ) ) {
234
- this . addService ( service , name )
251
+ this . fixModuleClassNames ( services )
252
+ for ( const [ key , service ] of Object . entries ( services ) ) {
253
+ this . addService ( service , key )
235
254
}
236
255
}
237
256
@@ -275,6 +294,7 @@ export class Application extends Koa {
275
294
}
276
295
277
296
addModels ( models ) {
297
+ this . fixModuleClassNames ( models )
278
298
models = Object . values ( models )
279
299
// First, add all models to the application, so that they can be referenced
280
300
// by other models, e.g. in `jsonSchema` and `relationMappings`:
@@ -365,6 +385,7 @@ export class Application extends Koa {
365
385
}
366
386
367
387
addControllers ( controllers , namespace ) {
388
+ this . fixModuleClassNames ( controllers )
368
389
for ( const [ key , value ] of Object . entries ( controllers ) ) {
369
390
if ( isModule ( value ) || isPlainObject ( value ) ) {
370
391
this . addControllers ( value , namespace ? `${ namespace } /${ key } ` : key )
0 commit comments