feat(cli): warn on mismatch of global and local versions upon generate command#20951
feat(cli): warn on mismatch of global and local versions upon generate command#20951akhill10 wants to merge 6 commits intoprisma:mainfrom
Conversation
jharrell
left a comment
There was a problem hiding this comment.
@akhill10 thank you for your first PR!
However, I will need to request changes. This PR should do the following:
If a user is running prisma generate, meaning the generate command run from prisma that is globally installed (npm i -g prisma) and the local version of prisma and/or @prisma/client differ from the globally installed version, we should explicitly require the user to confirm they want to proceed.
Please make the following changes:
- check against globally installed
prismanot.prisma/client - check against locally installed
prismaand@prisma/client(checking thepackage.jsonis probably a good first step) - Please ask for explicit confirmation from the user. Y/y/yes/etc. Not any key.
- Please provide tests that fail on main and pass after your implementation
Thank you for your time!
…cal prisma/prisma@client
|
@jharrell Thanks for the feedback. Updated the PR with the requested changes.
https://www.loom.com/share/6c2def1c11164690a314dc456182c466?sid=138bb99a-8e3e-4332-adfe-27e8933872b1
|
|
Hi @jharrell, did you get a chance to look at this? |
|
@akhill10 thank you very much for the loom video and apologies for the delay on my end! For this case, I think you should only test what is needed. That is to say, mock the results of |
|
@jharrell I tried mocking the functions but result is not giving the mocked results in the //imports
import { Generate, getLocalPrismaVersion } from '../../Generate'
import { getInstalledPrismaClientVersion } from '../../utils/getClientVersion'
it('should warn on mismatch of global version and local client version', async () => {
ctx.fixture('example-project')
const versions = { getInstalledPrismaClientVersion, isCurrentBinInstalledGlobally, getLocalPrismaVersion }
jest.spyOn(versions, 'getInstalledPrismaClientVersion').mockReturnValue(Promise.resolve('0.0.1'))
jest.spyOn(versions, 'isCurrentBinInstalledGlobally').mockReturnValue('npm')
jest.spyOn(versions, 'getLocalPrismaVersion').mockReturnValue(Promise.resolve('0.0.2'))
const data = await ctx.cli('generate')
expect(data.stdout).toMatchInlineSnapshot(`warn: Global prisma@0.0.0 and Local @prisma/client@0.0.1 don't match. This might lead to unexpected behavior. Would you like to proceed ? [yes/no]`)
});Its still getting the example-project version value i.e |
|
@akhill10 I'm not sure. Please push your changes to this branch so that I can review. |
|
@jharrell Pushed the test case commit. Please take a look |
|
Hello @jharrell , did you get a chance to review this? am I doing anything wrong in mocking the functions ? |
|
Have you tried using |
|
Yeah, I did but no luck. |
|
Unfortunately, I'm not sure here. We'll need a way to mock these calls before we move forward. |
|
Okay thank you, I try will some alternative approaches. |
|
Hi @akhill10, It looks like there haven't been any updates since @jharrell's last message to you. I'm closing this PR for now as part of our ongoing efforts to reduce the number of open issues and PRs in the repo. If you feel like this is a mistake, feel free to reopen the PR and address the comments :) |
Fixes prisma#1911 When using a globally installed prisma CLI with a different local @prisma/client or prisma version, users will now see a warning message. Implementation: - Added versionMismatchChecker.ts with dependency injection for testability - Modified Generate.ts to check version mismatch before running generate - Added comprehensive test suite (11 tests, all passing) The solution uses dependency injection to make the version checking functions mockable in tests, addressing the issue from the previous attempt in PR prisma#20951 where jest.spyOn could not properly mock the module-level functions.
Fixes #1911
/claim #1911