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 <noreply@anthropic.com>
Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: d128d50

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@trigger.dev/build Patch
trigger.dev Patch
@trigger.dev/python Patch
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/zod-worker Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

The build package enhances @prisma/client version resolution by falling back to reading the installed node_modules/@prisma/client package.json and, if needed, inspecting the project package.json (via resolvePackageJSON) for dependencies/devDependencies, handling catalog: and workspace: specifiers and throwing a clear error for unresolved workspace references. It adds debug logs. The CLI externals resolution now validates that a discovered package.json's name matches the originally resolved package name and aborts the extern resolution on mismatch before applying existing filters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description does not follow the repository template, as it omits the required checklist, the “Closes #” header, and the Changelog and Screenshots sections defined in the template. Please update the PR description to use the provided template by adding the “Closes #2556” header, completing the checklist, and including the Testing, Changelog, and Screenshots sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely describes the primary intent of the changeset, namely improving Prisma version resolution for pnpm workspaces, and aligns with the main modifications in the code.
Linked Issues Check ✅ Passed The changes implement all coding requirements from issue #2556 by verifying the correct package.json during resolution, adding a fallback to read the version from node_modules, supporting pnpm workspace specifiers, detecting catalog references with clear errors, and preventing misidentification in externals resolution.
Out of Scope Changes Check ✅ Passed All code modifications focus on enhancing Prisma version detection and external resolution logic as described in the linked issue objectives, with no unrelated or out-of-scope changes introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

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

📒 Files selected for processing (1)
  • .changeset/light-sheep-vanish.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/light-sheep-vanish.md

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

2 participants