Skip to content

Fix prisma/prisma#7771 - #29585

Closed
baronguyen001 wants to merge 1 commit into
prisma:mainfrom
baronguyen001:bounty/7771-prisma-7771
Closed

baronguyen001 wants to merge 1 commit into
prisma:mainfrom
baronguyen001:bounty/7771-prisma-7771

Conversation

@baronguyen001

@baronguyen001 baronguyen001 commented May 24, 2026 •

Copy link
Copy Markdown

Summary

Adds an installed-path row to prisma -v / prisma version so users can see which prisma package the running CLI was loaded from.

This is the exact debugging information requested in #7771: in the original report, yarn prisma -v told the user that engines came from node_modules/@prisma/engines, but that directory did not exist in the project - because the executed CLI actually lived in a parent project's node_modules. Today the -v output gives no way to tell that the running CLI is outside the local install.

Closes #7771

Changes

packages/cli/src/Version.ts (+4)

  • Imports path.
  • Computes prismaCliPath = path.resolve(__dirname, '..'). This resolves to the package root in both source layout (src/..) and bundled layout (build/..), so it points at the directory containing the package.json that defines the running CLI - matching the issue author's suggested solution.
  • Appends a ['Prisma CLI Path', prismaCliPath] row at the end of the rows array. Putting it last avoids reflowing any existing snapshot order above it, and it shows up automatically in --json output as the prisma-cli-path key (since formatTable slugifies row labels for JSON mode).

packages/cli/src/__tests__/commands/Version.test.ts (+3/-1)

  • Adds the new Prisma CLI Path : sanitized_cli_path line to the inline snapshot. Padding (6 chars between Path and :) matches formatTable's padEnd(maxPad) where maxPad stays at 20 (Default Engines Hash is still the longest label, Prisma CLI Path is 15 chars, so 5 spaces of padding plus :).

  • Adds a sanitizer line to cleanSnapshot:

    str = str.replace(new RegExp('(Prisma CLI Path\\s+:).*', 'g'), '$1 sanitized_cli_path')

    The double-escaped \\s+ (two backslashes in the TS source, one in the resulting regex) mirrors the existing Operating System / Architecture sanitizers two lines above it. A single-escaped \s+ inside a string-form RegExp would be parsed as the literal characters s+, which is the bug that prevented snapshots from stabilising in the prior attempt at this issue (PR feat(cli): add Prisma CLI path to version output #29275).

How tested

  • Verified the snapshot alignment by reading packages/internals/src/utils/formatTable.ts: maxPad = max(label.length), then each row renders as ${label.padEnd(maxPad)} : ${value}. With Default Engines Hash (20) still the longest label and Prisma CLI Path being 15 characters, the row formats to Prisma CLI Path plus 5 spaces, then : value - which is exactly what the updated inline snapshot shows.
  • Verified the sanitizer regex by mirroring the exact form used for Operating System and Architecture two lines above it in the same cleanSnapshot function (string-form RegExp with double-escaped \\s+).
  • Did not run pnpm --filter prisma test -- Version.test.ts locally. The fork was a shallow clone without node_modules, and a full pnpm install on this monorepo would not have finished in the time I had. If the inline snapshot drifts for an unrelated reason (e.g. row order changes elsewhere), regenerating with pnpm jest -u should produce a one-line diff. Happy to push a follow-up commit with the regenerated snapshot once CI surfaces any drift.
  • Cross-checked prior attempts on this issue: PR feat(cli): add Prisma CLI path to version output #29275 (currently the lead, but stale since 2026-02-28) uses the same path.resolve(__dirname, '..') approach and got CHANGES_REQUESTED from @jacek-prisma for snapshot failures - the root cause being the single-escaped \s+ in their sanitizer. This PR uses the correctly escaped \\s+ form.

Notes for reviewers

  • No behavioural change to the rest of the version command - only an additional row.
  • --json output gains a prisma-cli-path key without any extra plumbing (handled by formatTable's existing slugify).
  • The path value is absolute. On Windows it will be backslash-separated, on POSIX forward-slash - same as Node's path.resolve everywhere else in the CLI.

Resolves the path of the installed `prisma` package (which `package.json`
the running CLI was loaded from) and surfaces it as a new `Prisma CLI Path`
row in `prisma -v` / `prisma version` output. Helps debug the
"yarn prisma uses a higher node_modules" case described in prisma#7771 where
the executed CLI lives outside the project's local node_modules.

- Adds `path.resolve(__dirname, '..')` — works in both source (`src/..`)
  and bundled (`build/..`) layouts.
- Row is appended at the end so existing snapshot ordering above it stays
  stable, and shows up automatically in `--json` output as
  `prisma-cli-path`.
- Updates `Version.test.ts` inline snapshot and adds a sanitizer rule
  matching the existing `(Label\s+:).*` pattern (so the test passes
  cross-platform regardless of the actual install directory).

Closes prisma#7771
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 62085b4c-acb6-4921-9736-721a402cebb2

📥 Commits

Reviewing files that changed from the base of the PR and between 42f9102 and a199bf4.

📒 Files selected for processing (2)
  • packages/cli/src/Version.ts
  • packages/cli/src/__tests__/commands/Version.test.ts

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting


Summary by CodeRabbit

  • New Features
    • The prisma version command now displays the resolved Prisma CLI Path in its output, providing additional diagnostic information when running prisma -v or prisma version.

Walkthrough

The PR adds a "Prisma CLI Path" field to the prisma version command output. The implementation computes the CLI root path via path.resolve(__dirname, '..') and includes it in the output table. Tests and snapshot helpers are updated to expect and validate this new field.

Changes

CLI Path Display

Layer / File(s) Summary
CLI path computation and output
packages/cli/src/Version.ts, packages/cli/src/__tests__/commands/Version.test.ts
prismaCliPath is computed from __dirname and added as a row to the version output table. Test snapshots and the cleanSnapshot helper are updated to verify the new field with environment-agnostic path sanitization.

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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.

@baronguyen001
baronguyen001 marked this pull request as ready for review May 24, 2026 08:31
@baronguyen001 baronguyen001 reopened this May 24, 2026
@tensordreams
tensordreams changed the base branch from main to v7 July 21, 2026 12:05
@tensordreams
tensordreams changed the base branch from v7 to main July 21, 2026 15:11
@tensordreams

Copy link
Copy Markdown
Contributor

Hi @baronguyen001 — thanks for this, and apologies for the slow reply.

We're clearing the open PR backlog ahead of moving this codebase to a v7 branch, with the Prisma Next rewrite taking over main.

We are closing this one: the CLI path output has already landed in #29573, and the remaining test coverage and follow-up are being consolidated in #29613. Keeping another implementation open would duplicate that work.

Thanks for the time you put into it.

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.

Output path of current Prisma in -v

3 participants