@@ -38,6 +38,7 @@ import {
3838import { upperCaseFirst } from 'upper-case-first' ;
3939import { name } from '..' ;
4040import { execPackage } from '../../../utils/exec-utils' ;
41+ import { CorePlugins , getPluginCustomOutputFolder } from '../../plugin-utils' ;
4142import { trackPrismaSchemaError } from '../../prisma' ;
4243import { PrismaSchemaGenerator } from '../../prisma/schema-generator' ;
4344import { isDefaultWithAuth } from '../enhancer-utils' ;
@@ -100,7 +101,11 @@ import { type EnhancementContext, type EnhancementOptions, type ZodSchemas, type
100101import { createEnhancement } from '@zenstackhq/runtime/enhancements';
101102import modelMeta from './model-meta';
102103import policy from './policy';
103- ${ this . options . withZodSchemas ? "import * as zodSchemas from './zod';" : 'const zodSchemas = undefined;' }
104+ ${
105+ this . options . withZodSchemas
106+ ? `import * as zodSchemas from '${ this . getZodImport ( ) } ';`
107+ : 'const zodSchemas = undefined;'
108+ }
104109
105110${
106111 logicalPrismaClientDir
126131 return { dmmf } ;
127132 }
128133
134+ private getZodImport ( ) {
135+ const zodCustomOutput = getPluginCustomOutputFolder ( this . model , CorePlugins . Zod ) ;
136+
137+ if ( ! this . options . output && ! zodCustomOutput ) {
138+ // neither zod or me (enhancer) have custom output, use the default
139+ return './zod' ;
140+ }
141+
142+ if ( ! zodCustomOutput ) {
143+ // I have a custom output, but zod doesn't, import from runtime
144+ return '@zenstackhq/runtime/zod' ;
145+ }
146+
147+ // both zod and me have custom output, resolve to relative path and import
148+ const schemaDir = path . dirname ( this . options . schemaPath ) ;
149+ const zodAbsPath = path . isAbsolute ( zodCustomOutput )
150+ ? zodCustomOutput
151+ : path . resolve ( schemaDir , zodCustomOutput ) ;
152+ return path . relative ( this . outDir , zodAbsPath ) ;
153+ }
154+
129155 private createSimplePrismaImports ( prismaImport : string ) {
130156 return `import { Prisma, type PrismaClient } from '${ prismaImport } ';
131157import type * as _P from '${ prismaImport } ';
0 commit comments