11import colors from 'colors' ;
22import fs from 'fs' ;
33import path from 'path' ;
4+ import pkgJson from '../../package.json' ;
45import { PackageManagers , ensurePackage , installPackage } from '../../utils/pkg-utils' ;
56import { getVersion } from '../../utils/version-utils' ;
67import { CliError } from '../cli-error' ;
@@ -50,8 +51,10 @@ export async function init(projectPath: string, options: Options) {
5051 }
5152 }
5253
53- ensurePackage ( 'prisma' , true , options . packageManager , 'latest' , projectPath ) ;
54- ensurePackage ( '@prisma/client' , false , options . packageManager , 'latest' , projectPath ) ;
54+ const latestSupportedPrismaVersion = getLatestSupportedPrismaVersion ( ) ;
55+
56+ ensurePackage ( 'prisma' , true , options . packageManager , latestSupportedPrismaVersion , projectPath ) ;
57+ ensurePackage ( '@prisma/client' , false , options . packageManager , latestSupportedPrismaVersion , projectPath ) ;
5558
5659 const tag = options . tag ?? getVersion ( ) ;
5760 installPackage ( 'zenstack' , true , options . packageManager , tag , projectPath ) ;
@@ -75,3 +78,15 @@ Moving forward please edit this file and run "zenstack generate" to regenerate P
7578 await checkNewVersion ( ) ;
7679 }
7780}
81+
82+ function getLatestSupportedPrismaVersion ( ) {
83+ const versionSpec = pkgJson . peerDependencies . prisma ;
84+ let maxVersion : string | undefined ;
85+ const hyphen = versionSpec . indexOf ( '-' ) ;
86+ if ( hyphen > 0 ) {
87+ maxVersion = versionSpec . substring ( hyphen + 1 ) . trim ( ) ;
88+ } else {
89+ maxVersion = versionSpec ;
90+ }
91+ return maxVersion ?? 'latest' ;
92+ }
0 commit comments