Skip to content

Commit c7e7406

Browse files
authored
fix: generated zod schemas fail to compile when outputting to a custom dir (#1611)
1 parent 17fe8c3 commit c7e7406

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export class EnhancerGenerator {
9595

9696
const enhanceTs = this.project.createSourceFile(
9797
path.join(this.outDir, 'enhance.ts'),
98-
`import { type EnhancementContext, type EnhancementOptions, type ZodSchemas, type AuthUser } from '@zenstackhq/runtime';
98+
`/* eslint-disable */
99+
import { type EnhancementContext, type EnhancementOptions, type ZodSchemas, type AuthUser } from '@zenstackhq/runtime';
99100
import { createEnhancement } from '@zenstackhq/runtime/enhancements';
100101
import modelMeta from './model-meta';
101102
import policy from './policy';

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ const run: PluginFunction = async (model, options, _dmmf, globalOptions) => {
2424
let prismaClientPath: string | undefined;
2525
if (dmmf) {
2626
// a logical client is generated
27-
if (typeof options.output === 'string') {
27+
if (options.output || globalOptions?.output) {
28+
// handle custom output path
29+
2830
// get the absolute path of the prisma client types
29-
const prismaClientPathAbs = path.resolve(options.output, 'models');
31+
const prismaClientPathAbs = path.resolve(outDir, 'models');
3032

3133
// resolve it relative to the schema path
3234
prismaClientPath = path.relative(path.dirname(options.schemaPath), prismaClientPathAbs);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
describe('issue 1610', () => {
3+
it('regular prisma client', async () => {
4+
await loadSchema(
5+
`
6+
model User {
7+
id Int @id
8+
posts Post[]
9+
}
10+
11+
model Post {
12+
id Int @id
13+
author User @relation(fields: [authorId], references: [id])
14+
authorId Int
15+
}
16+
`,
17+
{ fullZod: true, output: './lib/zen' }
18+
);
19+
});
20+
21+
it('logical prisma client', async () => {
22+
await loadSchema(
23+
`
24+
model User {
25+
id Int @id
26+
posts Post[]
27+
}
28+
29+
model Post {
30+
id Int @id
31+
author User @relation(fields: [authorId], references: [id])
32+
authorId Int @default(auth().id)
33+
}
34+
`,
35+
{ fullZod: true, output: './lib/zen' }
36+
);
37+
});
38+
39+
it('no custom output', async () => {
40+
await loadSchema(
41+
`
42+
model User {
43+
id Int @id
44+
posts Post[]
45+
}
46+
47+
model Post {
48+
id Int @id
49+
author User @relation(fields: [authorId], references: [id])
50+
authorId Int @default(auth().id)
51+
}
52+
`,
53+
{ fullZod: true, preserveTsFiles: true }
54+
);
55+
});
56+
});

0 commit comments

Comments
 (0)