Skip to content

Commit

Permalink
Merge pull request #860 from gperdomor/feature/prisma-5
Browse files Browse the repository at this point in the history
feat(nx-prisma): initial support for prisma 5
  • Loading branch information
gperdomor authored Aug 16, 2023
2 parents 7cc04c5 + 146e924 commit 599c484
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/nx-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"peerDependencies": {
"@nx/devkit": "^16.0.0",
"@nx/workspace": "^16.0.0",
"prisma": "^4.5.0",
"prisma": "^4.5.0 || ^5.0.0",
"ts-node": "*",
"tslib": "^2.5.3"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-prisma/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function (tree: Tree, options: InitGeneratorSchema): Promis
}
}

addPrismaConfig(tree, options, project, prismaInstalledVersion ?? '4');
addPrismaConfig(tree, options, project);

updateProjectConfiguration(tree, options.project, {
...project,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { generateFiles, joinPathFragments, ProjectConfiguration, stripIndents, Tree } from '@nx/devkit';
import { InitGeneratorSchema } from '../schema';

export function addPrismaConfig(
tree: Tree,
options: InitGeneratorSchema,
project: ProjectConfiguration,
prismaVersion: '3' | '4'
): void {
export function addPrismaConfig(tree: Tree, options: InitGeneratorSchema, project: ProjectConfiguration): void {
if (tree.exists(joinPathFragments(project.root, 'prisma', 'schema.prisma'))) {
throw new Error(
stripIndents`The "schema.prisma" file already exists in the project "${options.project}". Are you sure this is the right project to set up Prisma?
If you are sure, you can remove the existing file and re-run the generator.`
);
}

// const filesDir = prismaVersion === '4' ? 'files/v4' : 'files/v3';
const filesDir = 'files/v4';

generateFiles(tree, joinPathFragments(__dirname, '..', filesDir), joinPathFragments(project.root, 'prisma'), {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readJson, Tree } from '@nx/devkit';
import { checkAndCleanWithSemver } from '@nx/workspace/src/utilities/version-utils';
import { lt } from 'semver';

export function detectPrismaInstalledVersion(tree: Tree): '3' | '4' | undefined {
export function detectPrismaInstalledVersion(tree: Tree): '4' | '5' | undefined {
const { dependencies, devDependencies } = readJson(tree, 'package.json');
const prismaVersion = dependencies?.['@prisma/client'] ?? devDependencies?.['@prisma/client'];

Expand All @@ -15,5 +15,5 @@ export function detectPrismaInstalledVersion(tree: Tree): '3' | '4' | undefined
throw new Error(`The prisma version "${prismaVersion}" is not supported. Please upgrade to v4.0.0 or higher.`);
}

return lt(version, '4.0.0') ? '3' : '4';
return lt(version, '5.0.0') ? '4' : '5';
}
2 changes: 1 addition & 1 deletion packages/nx-prisma/src/generators/init/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const prismaVersion = '^4.5.0';
export const prismaVersion = '^5.1.1';

0 comments on commit 599c484

Please sign in to comment.