diff --git a/packages/schema/src/cli/actions/init.ts b/packages/schema/src/cli/actions/init.ts index 9d798b865..5790997e6 100644 --- a/packages/schema/src/cli/actions/init.ts +++ b/packages/schema/src/cli/actions/init.ts @@ -1,6 +1,7 @@ import colors from 'colors'; import fs from 'fs'; import path from 'path'; +import pkgJson from '../../package.json'; import { PackageManagers, ensurePackage, installPackage } from '../../utils/pkg-utils'; import { getVersion } from '../../utils/version-utils'; import { CliError } from '../cli-error'; @@ -50,8 +51,10 @@ export async function init(projectPath: string, options: Options) { } } - ensurePackage('prisma', true, options.packageManager, 'latest', projectPath); - ensurePackage('@prisma/client', false, options.packageManager, 'latest', projectPath); + const latestSupportedPrismaVersion = getLatestSupportedPrismaVersion(); + + ensurePackage('prisma', true, options.packageManager, latestSupportedPrismaVersion, projectPath); + ensurePackage('@prisma/client', false, options.packageManager, latestSupportedPrismaVersion, projectPath); const tag = options.tag ?? getVersion(); installPackage('zenstack', true, options.packageManager, tag, projectPath); @@ -75,3 +78,15 @@ Moving forward please edit this file and run "zenstack generate" to regenerate P await checkNewVersion(); } } + +function getLatestSupportedPrismaVersion() { + const versionSpec = pkgJson.peerDependencies.prisma; + let maxVersion: string | undefined; + const hyphen = versionSpec.indexOf('-'); + if (hyphen > 0) { + maxVersion = versionSpec.substring(hyphen + 1).trim(); + } else { + maxVersion = versionSpec; + } + return maxVersion ?? 'latest'; +} diff --git a/packages/schema/src/package.json b/packages/schema/src/package.json new file mode 120000 index 000000000..4e26811d4 --- /dev/null +++ b/packages/schema/src/package.json @@ -0,0 +1 @@ +../package.json \ No newline at end of file diff --git a/tests/integration/tsconfig.json b/tests/integration/tsconfig.json index 2771cd805..e11b3381d 100644 --- a/tests/integration/tsconfig.json +++ b/tests/integration/tsconfig.json @@ -6,7 +6,8 @@ "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, - "experimentalDecorators": true + "experimentalDecorators": true, + "resolveJsonModule": true }, "include": ["**/*.ts", "**/*.d.ts"] }