Skip to content

Commit d3a5606

Browse files
authored
fix: prisma plugin not respecting zenstack.output (#298)
* fix: prisma plugin not respecting `zenstack.output` * chore: add test for #295 --------- Co-authored-by: = <=>
1 parent 6c6890e commit d3a5606

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/cli/src/plugins/prisma.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import path from 'node:path';
55
const plugin: CliPlugin = {
66
name: 'Prisma Schema Generator',
77
statusText: 'Generating Prisma schema',
8-
async generate({ model, schemaFile, defaultOutputPath, pluginOptions }) {
8+
async generate({ model, defaultOutputPath, pluginOptions }) {
99
let outFile = path.join(defaultOutputPath, 'schema.prisma');
1010
if (typeof pluginOptions['output'] === 'string') {
11-
outFile = path.resolve(path.dirname(schemaFile), pluginOptions['output']);
11+
outFile = path.resolve(defaultOutputPath, pluginOptions['output']);
1212
if (!fs.existsSync(path.dirname(outFile))) {
1313
fs.mkdirSync(path.dirname(outFile), { recursive: true });
1414
}

packages/cli/test/plugins/prisma-plugin.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,25 @@ model User {
5757
runCli('generate', workDir);
5858
expect(fs.existsSync(path.join(workDir, 'prisma/schema.prisma'))).toBe(true);
5959
});
60+
61+
it('can generate a Prisma schema with custom output relative to zenstack.output', () => {
62+
const workDir = createProject(`
63+
plugin prisma {
64+
provider = '@core/prisma'
65+
output = './schema.prisma'
66+
}
67+
68+
model User {
69+
id String @id @default(cuid())
70+
}
71+
`);
72+
73+
const pkgJson = JSON.parse(fs.readFileSync(path.join(workDir, 'package.json'), 'utf8'));
74+
pkgJson.zenstack = {
75+
output: './relative',
76+
};
77+
fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
78+
runCli('generate', workDir);
79+
expect(fs.existsSync(path.join(workDir, 'relative/schema.prisma'))).toBe(true);
80+
});
6081
});

0 commit comments

Comments
 (0)