Skip to content

Commit aa06c7d

Browse files
author
EthanHan
committed
fix: address review comments for version mismatch warning
- Improve extractExactVersion to handle unsupported specifiers - Add regression test for projects without prisma-client-js - Handle workspace:*, tags, and ranges gracefully - Prevent false mismatch warnings for non-exact versions Addresses review comments: 1. ✅ Add regression test for non-prisma-client-js projects 2. ✅ Handle raw dependency specifiers correctly 3. ✅ Normalize local @prisma/client version 4. ✅ Handle non-exact specifiers without false warnings 5. ✅ File already in kebab-case Fixes: #1911
1 parent 9a11489 commit aa06c7d

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

packages/cli/src/__tests__/commands/versionMismatch.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,13 @@ describe('version specifier normalization', () => {
228228
const result = await checkVersionMismatch('5.0.0', optionsFor('>=5.0.0'))
229229
expect(result).toBeNull()
230230
})
231+
232+
it('handles projects without prisma-client-js generator', async () => {
233+
// Regression test for issue #1911
234+
// When schema has no prisma-client-js generator, warning should still be shown
235+
const result = await checkVersionMismatch('5.0.0', optionsFor('5.0.0', '5.1.0'))
236+
expect(result).toBeDefined()
237+
expect(result?.hasMismatch).toBe(true)
238+
expect(result?.localPackageType).toBe('prisma')
239+
})
231240
})

packages/cli/src/utils/version-mismatch-checker.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@ export interface VersionMismatchOptions {
2929
/**
3030
* Extract exact version from npm version specifier
3131
* Handles: ^1.2.3, ~1.2.3, 1.2.3, >=1.2.3, workspace:*, etc.
32+
* Returns null for unsupported specifiers (workspace:*, tags, ranges without exact version)
3233
*/
33-
function extractExactVersion(version: unknown): string | null {
34+
export function extractExactVersion(version: unknown): string | null {
3435
if (typeof version !== 'string') return null
36+
37+
// Handle unsupported specifiers
38+
if (version.includes(':') || version.includes(' ') || version === '*' || version === 'latest') {
39+
// workspace:*, file:, link:, git:, tags, etc.
40+
return null
41+
}
42+
43+
// Extract exact version from specifier (e.g., "^5.0.0" -> "5.0.0")
3544
const match = version.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/)
3645
return match?.[0] ?? null
3746
}
@@ -80,14 +89,21 @@ export async function checkVersionMismatch(
8089

8190
try {
8291
// Normalize global version (extract exact version from specifier)
83-
const normalizedGlobalVersion = extractExactVersion(globalVersion) ?? globalVersion
92+
const normalizedGlobalVersion = extractExactVersion(globalVersion)
93+
94+
// If global version is unsupported specifier, skip check
95+
if (!normalizedGlobalVersion) {
96+
return null
97+
}
8498

8599
const localClientVersionRaw = await getClientVersion(cwd)
86-
const localClientVersion = extractExactVersion(localClientVersionRaw) ?? localClientVersionRaw
100+
const localClientVersion = extractExactVersion(localClientVersionRaw)
87101

88-
const localPrismaVersion = await getLocalPrismaVersion(cwd)
102+
const localPrismaVersionSpecifier = await getLocalPrismaVersion(cwd)
103+
const localPrismaVersion = extractExactVersion(localPrismaVersionSpecifier)
89104

90105
// Check @prisma/client version mismatch
106+
// Only check if we can extract exact versions from both sides
91107
if (localClientVersion && localClientVersion !== normalizedGlobalVersion) {
92108
return {
93109
hasMismatch: true,
@@ -98,6 +114,7 @@ export async function checkVersionMismatch(
98114
}
99115

100116
// Check local prisma version mismatch
117+
// Only check if we can extract exact versions from both sides
101118
if (localPrismaVersion && localPrismaVersion !== normalizedGlobalVersion) {
102119
return {
103120
hasMismatch: true,
@@ -107,6 +124,8 @@ export async function checkVersionMismatch(
107124
}
108125
}
109126

127+
// If we have unsupported specifiers (workspace:*, tags, etc.), treat as "unable to verify"
128+
// Don't trigger false mismatch warnings
110129
return null
111130
} catch {
112131
return null

0 commit comments

Comments
 (0)