Skip to content

Commit

Permalink
fix(cli): install proper prisma version during init (#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Dec 5, 2024
1 parent d123047 commit 4c8b86f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
19 changes: 17 additions & 2 deletions packages/schema/src/cli/actions/init.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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';
}
1 change: 1 addition & 0 deletions packages/schema/src/package.json
3 changes: 2 additions & 1 deletion tests/integration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"experimentalDecorators": true
"experimentalDecorators": true,
"resolveJsonModule": true
},
"include": ["**/*.ts", "**/*.d.ts"]
}

0 comments on commit 4c8b86f

Please sign in to comment.