From 320222c7315cf46fdf1116584db2f5015e8b7e85 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:54:27 +0800 Subject: [PATCH 1/2] fix(cli): install proper prisma version during init --- packages/schema/src/cli/actions/init.ts | 19 +++++++++++++++++-- packages/schema/src/package.json | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) create mode 120000 packages/schema/src/package.json 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 From e404c54d79ca04392d155cf512f0c3f1b715cb19 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:11:00 +0800 Subject: [PATCH 2/2] fix test --- tests/integration/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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"] }