Skip to content

Commit 4ecfc11

Browse files
authored
fix: additional fix for 1667 (#1679)
1 parent 83bdd6d commit 4ecfc11

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/schema/src/plugins/enhancer/enhance/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,18 @@ ${
144144
return '@zenstackhq/runtime/zod';
145145
}
146146

147+
if (!this.options.output) {
148+
// I don't have a custom output, but zod has, CLI will still generate
149+
// a copy into the default output, so we can still import from there
150+
return './zod';
151+
}
152+
147153
// both zod and me have custom output, resolve to relative path and import
148154
const schemaDir = path.dirname(this.options.schemaPath);
149155
const zodAbsPath = path.isAbsolute(zodCustomOutput)
150156
? zodCustomOutput
151157
: path.resolve(schemaDir, zodCustomOutput);
152-
return path.relative(this.outDir, zodAbsPath);
158+
return path.relative(this.outDir, zodAbsPath) || '.';
153159
}
154160

155161
private createSimplePrismaImports(prismaImport: string) {

tests/regression/tests/issue-1667.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,30 @@ describe('issue 1667', () => {
5757
{ addPrelude: false, getPrismaOnly: true, generateNoCompile: true, compile: true }
5858
);
5959
});
60+
61+
it('standard enhance custom zod output', async () => {
62+
await loadSchema(
63+
`
64+
generator client {
65+
provider = "prisma-client-js"
66+
}
67+
68+
datasource db {
69+
provider = "sqlite"
70+
url = "file:./dev.db"
71+
}
72+
73+
plugin zod {
74+
provider = '@core/zod'
75+
output = './myzod'
76+
}
77+
78+
model User {
79+
id Int @id
80+
email String @unique @email
81+
}
82+
`,
83+
{ addPrelude: false, getPrismaOnly: true, compile: true }
84+
);
85+
});
6086
});

0 commit comments

Comments
 (0)