Skip to content

Conversation

hongkongkiwi
Copy link

@hongkongkiwi hongkongkiwi commented Sep 25, 2025

Summary

  • Fixed package.json resolution bug that could select wrong package in pnpm workspaces
  • Added fallback to read version directly from node_modules when primary detection fails
  • Added support for workspace: protocol and helpful error messages for catalog: references

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:

  1. Package.json resolution finding parent workspace package.json instead of @prisma/client's
  2. No support for pnpm catalog: or workspace: version specifiers

Fixes #2556

Solution

  1. Fixed root cause: Added verification that resolved package.json belongs to the correct package
  2. Added robust fallback: Read directly from node_modules/@prisma/client/package.json when primary detection fails
  3. Better error messages: Detect catalog: references and provide clear guidance
  4. Zero new dependencies: Solution uses only existing dependencies

Test Plan

  • Verify Prisma extension works with regular npm/yarn projects
  • Test with pnpm workspace using workspace: protocol
  • Test with pnpm catalog references (should get helpful error)
  • Verify fallback to node_modules reading works when externals detection fails

🤖 Generated with Claude Code

- 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]>
Copy link

changeset-bot bot commented Sep 25, 2025

⚠️ No Changeset found

Latest commit: 0e4e7d5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

The 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)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description presents a clear summary, problem statement, solution, and test plan but does not follow the repository’s required template headings nor include a “Closes #” line, checklist items, changelog, or screenshots as specified, resulting in a mismatch with the template structure. Please update the description to use the repository’s template by adding the “Closes #” line, completing the ✅ Checklist section, including a Changelog entry, and providing screenshots or noting their absence under the Screenshots heading to align with the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely describes the primary change of improving Prisma version resolution for pnpm workspaces and follows the conventional commit format, making it clear and directly related to the main fix outlined in the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 package

This 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:^/~ specs

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between e22c321 and 0e4e7d5.

⛔ 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 needed

Import changes look fine for the added logic.


7-7: LGTM on pkg-types usage

Using resolvePackageJSON/readPackageJSON fits the new resolution flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Prisma extension intermittently selects wrong version with pnpm workspaces and catalogs
1 participant