@@ -114,21 +114,18 @@ export class EnhancerGenerator {
114
114
115
115
if ( this . needsLogicalClient ) {
116
116
prismaTypesFixed = true ;
117
- resultPrismaTypeImport = ` ${ LOGICAL_CLIENT_GENERATION_PATH } /index-fixed` ;
117
+ resultPrismaTypeImport = LOGICAL_CLIENT_GENERATION_PATH ;
118
118
const result = await this . generateLogicalPrisma ( ) ;
119
119
dmmf = result . dmmf ;
120
120
}
121
121
122
122
// reexport PrismaClient types (original or fixed)
123
- const modelsDts = this . project . createSourceFile (
124
- path . join ( this . outDir , 'models.d. ts' ) ,
123
+ const modelsTs = this . project . createSourceFile (
124
+ path . join ( this . outDir , 'models.ts' ) ,
125
125
`export * from '${ resultPrismaTypeImport } ';` ,
126
126
{ overwrite : true }
127
127
) ;
128
- await modelsDts . save ( ) ;
129
-
130
- // reexport values from the original PrismaClient (enums, etc.)
131
- fs . writeFileSync ( path . join ( this . outDir , 'models.js' ) , `module.exports = require('${ prismaImport } ');` ) ;
128
+ this . saveSourceFile ( modelsTs ) ;
132
129
133
130
const authDecl = getAuthDecl ( getDataModelAndTypeDefs ( this . model ) ) ;
134
131
const authTypes = authDecl ? generateAuthType ( this . model , authDecl ) : '' ;
177
174
return {
178
175
dmmf,
179
176
newPrismaClientDtsPath : prismaTypesFixed
180
- ? path . resolve ( this . outDir , LOGICAL_CLIENT_GENERATION_PATH , 'index-fixed .d.ts' )
177
+ ? path . resolve ( this . outDir , LOGICAL_CLIENT_GENERATION_PATH , 'index.d.ts' )
181
178
: undefined ,
182
179
} ;
183
180
}
@@ -457,7 +454,7 @@ export type Enhanced<Client> =
457
454
}
458
455
459
456
private async processClientTypes ( prismaClientDir : string ) {
460
- // make necessary updates to the generated `index.d.ts` file and save it as `index-fixed.d.ts`
457
+ // make necessary updates to the generated `index.d.ts` file and overwrite it
461
458
const project = new Project ( ) ;
462
459
const sf = project . addSourceFileAtPath ( path . join ( prismaClientDir , 'index.d.ts' ) ) ;
463
460
@@ -472,8 +469,7 @@ export type Enhanced<Client> =
472
469
}
473
470
} ) ;
474
471
475
- // transform index.d.ts and save it into a new file (better perf than in-line editing)
476
-
472
+ // transform index.d.ts and write it into a new file (better perf than in-line editing)
477
473
const sfNew = project . createSourceFile ( path . join ( prismaClientDir , 'index-fixed.d.ts' ) , undefined , {
478
474
overwrite : true ,
479
475
} ) ;
@@ -483,6 +479,9 @@ export type Enhanced<Client> =
483
479
this . generateExtraTypes ( sfNew ) ;
484
480
485
481
sfNew . formatText ( ) ;
482
+
483
+ // Save the transformed file over the original
484
+ await sfNew . move ( sf . getFilePath ( ) , { overwrite : true } ) ;
486
485
await sfNew . save ( ) ;
487
486
}
488
487
0 commit comments