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() {
125
125
. addOption ( new Option ( '--without-plugins <plugins...>' , 'exclude specific plugins' ) )
126
126
. addOption ( new Option ( '--no-default-plugins' , 'do not run default plugins' ) )
127
127
. 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' ) )
128
129
. addOption ( noVersionCheckOption )
129
130
. addOption ( noDependencyCheckOption )
130
131
. addOption ( offlineOption )
Original file line number Diff line number Diff line change @@ -128,7 +128,12 @@ export class EnhancerGenerator {
128
128
await modelsDts . save ( ) ;
129
129
130
130
// 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 ) ;
132
137
133
138
const authDecl = getAuthDecl ( getDataModelAndTypeDefs ( this . model ) ) ;
134
139
const authTypes = authDecl ? generateAuthType ( this . model , authDecl ) : '' ;
@@ -338,6 +343,7 @@ export type Enhanced<Client> =
338
343
overrideClientGenerationPath : prismaClientOutDir ,
339
344
mode : 'logical' ,
340
345
customAttributesAsComments : true ,
346
+ isEsm : this . options . isEsm ,
341
347
} ) ;
342
348
343
349
// 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 = {
42
42
* @private
43
43
*/
44
44
shortNameMap ?: Map < string , string > ;
45
+ /**
46
+ * Is the plugin generating into an ESM project?
47
+ */
48
+ esm ?: boolean ;
45
49
} & PluginDeclaredOptions ;
46
50
47
51
/**
You can’t perform that action at this time.
0 commit comments