fix(generate): place usage instructions directly after generator output#29315
fix(generate): place usage instructions directly after generator output#29315Felipeness wants to merge 4 commits intoprisma:mainfrom
Conversation
When multiple generators are used, the usage instructions ("Start by
importing your Prisma Client...") now appear directly after the
corresponding generator's success message instead of at the very end
of the output. This makes the output more intuitive when using custom
generators alongside Prisma Client.
Fixes prisma#1737
WalkthroughrunGenerate now collects per-generator result strings into a messages array, records optional per-generator import hints (for the JS client) in a hints map, and appends a JS-client hint inline only when enabled and no generator errored. parse discovers jsClient, honors --no-hints and watch mode, and tests updated for multi-generator output formatting. Changes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 Tip CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.Add a configuration file to your project to customize how CodeRabbit runs |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 77b2d811-9eaa-408e-88f4-75db2d292cc2
📒 Files selected for processing (2)
packages/cli/src/Generate.tspackages/cli/src/__tests__/commands/Generate.test.ts
|
Hi! The "Milestone Check" is currently pending on this PR since no milestone is set, and it looks like only maintainers have permission to assign one. Could someone set the appropriate milestone (perhaps |
packages/cli/src/Generate.ts
Outdated
| private runGenerate = simpleDebounce(async ({ generators }: { generators: Generator[] }) => { | ||
| const message: string[] = [] | ||
| private runGenerate = simpleDebounce( | ||
| async ({ generators, usageHint }: { generators: Generator[]; usageHint?: string }) => { |
There was a problem hiding this comment.
I think it might be cleaner to extend the interface passed in here to allow generators to have hints in order to avoid the generator specific logic here:
generators: (Generator & { usageHint?: string })[]
There was a problem hiding this comment.
Implemented your suggestion — generators now carry an optional usageHint, and runGenerate just checks for it instead of hardcoding provider logic. Thanks for the clean approach!
jacek-prisma
left a comment
There was a problem hiding this comment.
Left 1 important comment
…onstant (#29317) ## Summary Closes #29316 Extracts the hardcoded `'prisma-client-js'` string literal into a shared `PRISMA_CLIENT_JS_PROVIDER` constant defined in `@prisma/internals`, replacing all occurrences across the codebase. ### Changes - **New**: `packages/internals/src/prisma-client-js-provider.ts` — single source of truth for the constant - **Modified** (8 files across 4 packages): - `packages/internals/src/index.ts` — export the constant - `packages/internals/src/cli/getGeneratorSuccessMessage.ts` — use constant - `packages/internals/src/utils/extractPreviewFeatures.ts` — use constant - `packages/cli/src/Generate.ts` — use constant (2 occurrences) - `packages/cli/src/utils/checkpoint.ts` — use constant - `packages/client-generator-js/src/generator.ts` — use constant - `packages/client-generator-js/src/utils/types/dmmfToTypes.ts` — use constant (2 occurrences) - `packages/client/src/utils/getTestClient.ts` — use constant ### Motivation This was identified during the review of #29315 by @coderabbitai. Having a single constant: - Eliminates risk of typos in the provider string - Makes it easy to find all usages via "Find References" - Provides a single place to update if the value ever changes ## Test plan - [x] `pnpm build` passes (43 tasks) - [x] `getGenerators` tests pass (40/40, 33 snapshots) - [x] No behavioral changes — pure mechanical refactor <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Standardized provider identifiers across internal modules using a centralized constant. * No changes to behavior or public APIs; end-user experience remains unchanged. * Improved internal consistency and reliability of provider detection and generator selection logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 55d60c41-11b3-4f02-b9cf-a61de71b7d04
📒 Files selected for processing (1)
packages/cli/src/Generate.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cli/src/Generate.ts`:
- Around line 93-97: Extract the inline object type for the parameter into a
named interface (e.g., GenerateOptions) and replace the inline annotation with
that interface; the interface should declare generators: Generator[], optional
jsClient?: Generator, and showHint: boolean so it can be reused across the file.
Locate the function in Generate.ts that currently types its parameter as {
generators: Generator[]; jsClient?: Generator; showHint: boolean } and update
its signature to use the new interface name, and export the interface if it may
be reused elsewhere.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ccc2c456-628a-4e2d-80c5-0a7700bec2ec
📒 Files selected for processing (1)
packages/cli/src/Generate.ts
| }: { | ||
| generators: Generator[] | ||
| jsClient?: Generator | ||
| showHint: boolean | ||
| }) => { |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider extracting inline type to a named interface.
The parameter type could be extracted for reusability and clarity.
♻️ Suggested refactor
+interface RunGenerateOptions {
+ generators: Generator[]
+ jsClient?: Generator
+ showHint: boolean
+}
+
private runGenerate = simpleDebounce(
- async ({
- generators,
- jsClient,
- showHint,
- }: {
- generators: Generator[]
- jsClient?: Generator
- showHint: boolean
- }) => {
+ async ({ generators, jsClient, showHint }: RunGenerateOptions) => {As per coding guidelines: "Use interface for defining object shapes in TypeScript."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/cli/src/Generate.ts` around lines 93 - 97, Extract the inline object
type for the parameter into a named interface (e.g., GenerateOptions) and
replace the inline annotation with that interface; the interface should declare
generators: Generator[], optional jsClient?: Generator, and showHint: boolean so
it can be reused across the file. Locate the function in Generate.ts that
currently types its parameter as { generators: Generator[]; jsClient?:
Generator; showHint: boolean } and update its signature to use the new interface
name, and export the interface if it may be reused elsewhere.
| private runGenerate = simpleDebounce( | ||
| async ({ | ||
| generators, | ||
| jsClient, |
There was a problem hiding this comment.
I think rather than hardcoding the jsClient here, this should should accept a generic hint parameter that can be passed along with the generator
| showHint: boolean | ||
| }) => { | ||
| const messages: string[] = [] | ||
| const hints: Map<Generator, string> = new Map() |
There was a problem hiding this comment.
There's no need to use a Map here, since this is processed in the same order as the generators array,
It could either be a string[][] or flattened (by just concating the strings) string[] or even string (by joining the strings with newlines)
Summary
When multiple generators are used, the usage instructions ("Start by importing your Prisma Client...") now appear directly after the corresponding generator's
✔ Generatedmessage instead of at the very end of the output.Before:
After:
Changes
packages/cli/src/Generate.ts: RestructuredrunGenerateto collect per-generator results with provider info, then insert the usage hint after the firstprisma-client-jsgenerator (only when no errors occurred). MovedhideHintsextraction earlier. Separated the import guide (per-generator) from global warnings like version mismatches (still appended at end).packages/cli/src/__tests__/commands/Generate.test.ts: Updated inline snapshots to reflect new hint positioning.Behavior preserved
--no-hintsstill suppresses usage instructionsFixes #1737
Summary by CodeRabbit
Improvements
Tests