Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): install proper prisma version during init #1906

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
}
ymc9 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions packages/schema/src/package.json
Loading