File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ export function createProgram() {
125125 . addOption ( new Option ( '--without-plugins <plugins...>' , 'exclude specific plugins' ) )
126126 . addOption ( new Option ( '--no-default-plugins' , 'do not run default plugins' ) )
127127 . addOption ( new Option ( '--no-compile' , 'do not compile the output of core plugins' ) )
128+ . addOption ( new Option ( '--esm' , 'generate output for ESM instead of CommonJS' ) )
128129 . addOption ( noVersionCheckOption )
129130 . addOption ( noDependencyCheckOption )
130131 . addOption ( offlineOption )
Original file line number Diff line number Diff line change @@ -128,7 +128,12 @@ export class EnhancerGenerator {
128128 await modelsDts . save ( ) ;
129129
130130 // reexport values from the original PrismaClient (enums, etc.)
131- fs . writeFileSync ( path . join ( this . outDir , 'models.js' ) , `module.exports = require('${ prismaImport } ');` ) ;
131+ const modelsBody =
132+ this . options . esm ?? false
133+ ? `export * from '${ prismaImport } ';`
134+ : `module.exports = require('${ prismaImport } ');` ;
135+
136+ fs . writeFileSync ( path . join ( this . outDir , 'models.js' ) , modelsBody ) ;
132137
133138 const authDecl = getAuthDecl ( getDataModelAndTypeDefs ( this . model ) ) ;
134139 const authTypes = authDecl ? generateAuthType ( this . model , authDecl ) : '' ;
@@ -338,6 +343,7 @@ export type Enhanced<Client> =
338343 overrideClientGenerationPath : prismaClientOutDir ,
339344 mode : 'logical' ,
340345 customAttributesAsComments : true ,
346+ isEsm : this . options . isEsm ,
341347 } ) ;
342348
343349 // reverse direction of shortNameMap and store for future lookup
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ export type PluginOptions = {
4242 * @private
4343 */
4444 shortNameMap ?: Map < string , string > ;
45+ /**
46+ * Is the plugin generating into an ESM project?
47+ */
48+ esm ?: boolean ;
4549} & PluginDeclaredOptions ;
4650
4751/**
You can’t perform that action at this time.
0 commit comments