Skip to content

Commit 4c8b86f

Browse files
authored
fix(cli): install proper prisma version during init (#1906)
1 parent d123047 commit 4c8b86f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

packages/schema/src/cli/actions/init.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import colors from 'colors';
22
import fs from 'fs';
33
import path from 'path';
4+
import pkgJson from '../../package.json';
45
import { PackageManagers, ensurePackage, installPackage } from '../../utils/pkg-utils';
56
import { getVersion } from '../../utils/version-utils';
67
import { 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+
}

packages/schema/src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../package.json

tests/integration/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"forceConsistentCasingInFileNames": true,
77
"strict": true,
88
"skipLibCheck": true,
9-
"experimentalDecorators": true
9+
"experimentalDecorators": true,
10+
"resolveJsonModule": true
1011
},
1112
"include": ["**/*.ts", "**/*.d.ts"]
1213
}

0 commit comments

Comments
 (0)