-
-
Notifications
You must be signed in to change notification settings - Fork 834
fix: improve Prisma version resolution for pnpm workspaces #2555
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
base: main
Are you sure you want to change the base?
fix: improve Prisma version resolution for pnpm workspaces #2555
Conversation
- Fix package.json resolution bug that could pick wrong package in pnpm workspaces - Add fallback to read version directly from node_modules/@prisma/client - Support workspace: protocol by extracting explicit versions - Provide helpful error messages for catalog: references - Zero new dependencies added Fixes issue where Prisma extension would select wrong version when using pnpm workspaces without explicit version in trigger.config.ts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
WalkthroughThe changes extend version resolution for @prisma/client in build-time logic by attempting multiple fallbacks: checking externals/options, reading the installed node_modules package.json, and inspecting the project’s package.json (including resolvePackageJSON) for dependencies or devDependencies, with handling for catalog: and workspace: specifiers. It adds debug logs and throws a specific error when workspace: lacks an explicit version. Separately, the externals resolution in the CLI now validates that a discovered package.json’s name matches the originally resolved package name, aborting on mismatch before applying existing filters. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/cli-v3/src/build/externals.ts (1)
218-228
: Good safeguard: verify resolved package.json belongs to the expected packageThis will prevent parent workspace/package.json mismatches. To further reduce false negatives (e.g., hitting a type-marker package.json without a version), prefer resolving with the main/real package.json filter already defined in this file.
Apply this change to the earlier resolve step (outside this range) to skip marker package.json files:
- const packageJsonPath = await resolvePackageJSON(dirname(resolvedPath)); + const packageJsonPath = await resolvePackageJSON(dirname(resolvedPath), { + test: isMainPackageJson, + });packages/build/src/extensions/prisma.ts (1)
106-160
: Robust Prisma version fallback; consider normalizing workspace:^/~ specsThe fallback chain (externals → node_modules → package.json with workspace/catalog handling) is solid. For workspace protocol, also handle caret/tilde-prefixed versions (e.g., workspace:^6.14.0) by stripping the prefix so the dependency added to the layer is pinned.
Apply this diff within the workspace: handling:
- } else if (versionSpec?.startsWith("workspace:")) { - // Handle workspace: protocol - strip prefix and use the version if it's explicit - const stripped = versionSpec.replace("workspace:", "").trim(); - if (stripped && stripped !== "*" && stripped !== "^" && stripped !== "~") { - version = stripped; - context.logger.debug( - `PrismaExtension resolved version from workspace protocol: ${version}` - ); - } else { - errorDetail = `Found workspace reference "${versionSpec}". `; - } - } + } else if (versionSpec?.startsWith("workspace:")) { + // Handle workspace: protocol - strip prefix and normalize ^/~ if present + let stripped = versionSpec.replace("workspace:", "").trim(); + if (stripped.startsWith("^") || stripped.startsWith("~")) { + stripped = stripped.slice(1); + } + if (stripped && stripped !== "*") { + version = stripped; + context.logger.debug( + `PrismaExtension resolved version from workspace protocol: ${version}` + ); + } else { + errorDetail = `Found workspace reference "${versionSpec}". `; + } + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
packages/build/src/extensions/prisma.ts
(2 hunks)packages/cli-v3/src/build/externals.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}
: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations
Files:
packages/build/src/extensions/prisma.ts
packages/cli-v3/src/build/externals.ts
🧠 Learnings (3)
📚 Learning: 2025-07-18T17:49:24.468Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to internal-packages/database/**/*.{ts,tsx} : We use prisma in internal-packages/database for our database interactions using PostgreSQL
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: 2025-08-18T10:07:17.368Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-08-18T10:07:17.368Z
Learning: Applies to trigger.config.ts : Declare build options and extensions (external, jsx, conditions, extensions) via the build block in trigger.config.ts rather than custom scripts
Applied to files:
packages/build/src/extensions/prisma.ts
📚 Learning: 2025-08-18T10:07:17.368Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-08-18T10:07:17.368Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Import Trigger.dev APIs from "trigger.dev/sdk/v3" when writing tasks or related utilities
Applied to files:
packages/build/src/extensions/prisma.ts
🔇 Additional comments (2)
packages/build/src/extensions/prisma.ts (2)
5-5
: No action neededImport changes look fine for the added logic.
7-7
: LGTM on pkg-types usageUsing resolvePackageJSON/readPackageJSON fits the new resolution flow.
Summary
Problem
When using pnpm workspaces without an explicit version in
trigger.config.ts
, the Prisma extension could fail to detect or select the wrong version due to:Fixes #2556
Solution
node_modules/@prisma/client/package.json
when primary detection failsTest Plan
🤖 Generated with Claude Code