Repository navigation
Fix prisma/prisma#7771 - #29585
Fix prisma/prisma#7771#29585baronguyen001 wants to merge 1 commit into
Conversation
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
|
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Knowledge base: Disabled due to Summary by CodeRabbit
WalkthroughThe PR adds a "Prisma CLI Path" field to the ChangesCLI Path Display
🎯 2 (Simple) | ⏱️ ~8 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify 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. Comment |
|
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 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. |
Summary
Adds an installed-path row to
prisma -v/prisma versionso users can see whichprismapackage the running CLI was loaded from.This is the exact debugging information requested in #7771: in the original report,
yarn prisma -vtold the user that engines came fromnode_modules/@prisma/engines, but that directory did not exist in the project - because the executed CLI actually lived in a parent project'snode_modules. Today the-voutput gives no way to tell that the running CLI is outside the local install.Closes #7771
Changes
packages/cli/src/Version.ts(+4)path.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 thepackage.jsonthat defines the running CLI - matching the issue author's suggested solution.['Prisma CLI Path', prismaCliPath]row at the end of therowsarray. Putting it last avoids reflowing any existing snapshot order above it, and it shows up automatically in--jsonoutput as theprisma-cli-pathkey (sinceformatTableslugifies row labels for JSON mode).packages/cli/src/__tests__/commands/Version.test.ts(+3/-1)Adds the new
Prisma CLI Path : sanitized_cli_pathline to the inline snapshot. Padding (6 chars betweenPathand:) matchesformatTable'spadEnd(maxPad)wheremaxPadstays at 20 (Default Engines Hashis still the longest label,Prisma CLI Pathis 15 chars, so 5 spaces of padding plus:).Adds a sanitizer line to
cleanSnapshot:The double-escaped
\\s+(two backslashes in the TS source, one in the resulting regex) mirrors the existingOperating System/Architecturesanitizers two lines above it. A single-escaped\s+inside a string-formRegExpwould be parsed as the literal characterss+, 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
packages/internals/src/utils/formatTable.ts:maxPad = max(label.length), then each row renders as${label.padEnd(maxPad)} : ${value}. WithDefault Engines Hash(20) still the longest label andPrisma CLI Pathbeing 15 characters, the row formats toPrisma CLI Pathplus 5 spaces, then: value- which is exactly what the updated inline snapshot shows.Operating SystemandArchitecturetwo lines above it in the samecleanSnapshotfunction (string-formRegExpwith double-escaped\\s+).pnpm --filter prisma test -- Version.test.tslocally. The fork was a shallow clone withoutnode_modules, and a fullpnpm installon 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 withpnpm jest -ushould produce a one-line diff. Happy to push a follow-up commit with the regenerated snapshot once CI surfaces any drift.path.resolve(__dirname, '..')approach and gotCHANGES_REQUESTEDfrom @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
--jsonoutput gains aprisma-cli-pathkey without any extra plumbing (handled byformatTable's existing slugify).path.resolveeverywhere else in the CLI.