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