@@ -40,6 +40,8 @@ export type PluginRunnerOptions = {
40
40
schema : Model ;
41
41
schemaPath : string ;
42
42
output ?: string ;
43
+ withPlugins ?: string [ ] ;
44
+ withoutPlugins ?: string [ ] ;
43
45
defaultPlugins : boolean ;
44
46
compile : boolean ;
45
47
} ;
@@ -137,7 +139,17 @@ export class PluginRunner {
137
139
const project = createProject ( ) ;
138
140
for ( const { name, description, run, options : pluginOptions } of corePlugins ) {
139
141
const options = { ...pluginOptions , prismaClientPath } ;
140
- const r = await this . runPlugin ( name , description , run , runnerOptions , options , dmmf , shortNameMap , project ) ;
142
+ const r = await this . runPlugin (
143
+ name ,
144
+ description ,
145
+ run ,
146
+ runnerOptions ,
147
+ options ,
148
+ dmmf ,
149
+ shortNameMap ,
150
+ project ,
151
+ true
152
+ ) ;
141
153
warnings . push ( ...( r ?. warnings ?? [ ] ) ) ; // the null-check is for backward compatibility
142
154
143
155
if ( r . dmmf ) {
@@ -162,7 +174,17 @@ export class PluginRunner {
162
174
// run user plugins
163
175
for ( const { name, description, run, options : pluginOptions } of userPlugins ) {
164
176
const options = { ...pluginOptions , prismaClientPath } ;
165
- const r = await this . runPlugin ( name , description , run , runnerOptions , options , dmmf , shortNameMap , project ) ;
177
+ const r = await this . runPlugin (
178
+ name ,
179
+ description ,
180
+ run ,
181
+ runnerOptions ,
182
+ options ,
183
+ dmmf ,
184
+ shortNameMap ,
185
+ project ,
186
+ false
187
+ ) ;
166
188
warnings . push ( ...( r ?. warnings ?? [ ] ) ) ; // the null-check is for backward compatibility
167
189
}
168
190
@@ -180,8 +202,7 @@ export class PluginRunner {
180
202
if ( existingPrisma ) {
181
203
corePlugins . push ( existingPrisma ) ;
182
204
plugins . splice ( plugins . indexOf ( existingPrisma ) , 1 ) ;
183
- } else if ( options . defaultPlugins || plugins . some ( ( p ) => p . provider !== CorePlugins . Prisma ) ) {
184
- // "@core/prisma" is enabled as default or if any other plugin is configured
205
+ } else if ( options . defaultPlugins ) {
185
206
corePlugins . push ( this . makeCorePlugin ( CorePlugins . Prisma , options . schemaPath , { } ) ) ;
186
207
}
187
208
@@ -215,7 +236,8 @@ export class PluginRunner {
215
236
216
237
if (
217
238
! corePlugins . some ( ( p ) => p . provider === CorePlugins . Zod ) &&
218
- ( options . defaultPlugins || corePlugins . some ( ( p ) => p . provider === CorePlugins . Enhancer ) ) &&
239
+ options . defaultPlugins &&
240
+ corePlugins . some ( ( p ) => p . provider === CorePlugins . Enhancer ) &&
219
241
hasValidation
220
242
) {
221
243
// ensure "@core/zod" is enabled if "@core/enhancer" is enabled and there're validation rules
@@ -319,10 +341,17 @@ export class PluginRunner {
319
341
options : PluginDeclaredOptions ,
320
342
dmmf : DMMF . Document | undefined ,
321
343
shortNameMap : Map < string , string > | undefined ,
322
- project : Project
344
+ project : Project ,
345
+ isCorePlugin : boolean
323
346
) {
347
+ if ( ! isCorePlugin && ! this . isPluginEnabled ( name , runnerOptions ) ) {
348
+ ora ( `Plugin "${ name } " is skipped` ) . start ( ) . warn ( ) ;
349
+ return { warnings : [ ] } ;
350
+ }
351
+
324
352
const title = description ?? `Running plugin ${ colors . cyan ( name ) } ` ;
325
353
const spinner = ora ( title ) . start ( ) ;
354
+
326
355
try {
327
356
const r = await telemetry . trackSpan < PluginResult | void > (
328
357
'cli:plugin:start' ,
@@ -358,6 +387,18 @@ export class PluginRunner {
358
387
}
359
388
}
360
389
390
+ private isPluginEnabled ( name : string , runnerOptions : PluginRunnerOptions ) {
391
+ if ( runnerOptions . withPlugins && ! runnerOptions . withPlugins . includes ( name ) ) {
392
+ return false ;
393
+ }
394
+
395
+ if ( runnerOptions . withoutPlugins && runnerOptions . withoutPlugins . includes ( name ) ) {
396
+ return false ;
397
+ }
398
+
399
+ return true ;
400
+ }
401
+
361
402
private getPluginModulePath ( provider : string , schemaPath : string ) {
362
403
if ( process . env . ZENSTACK_TEST === '1' && provider . startsWith ( '@zenstackhq/' ) ) {
363
404
// test code runs with its own sandbox of node_modules, make sure we don't
0 commit comments