Skip to content

fix(generate): place usage instructions directly after generator output#29315

Open
Felipeness wants to merge 4 commits intoprisma:mainfrom
Felipeness:fix/generate-usage-hint-position
Open

fix(generate): place usage instructions directly after generator output#29315
Felipeness wants to merge 4 commits intoprisma:mainfrom
Felipeness:fix/generate-usage-hint-position

Conversation

@Felipeness
Copy link
Contributor

@Felipeness Felipeness commented Mar 7, 2026

Summary

When multiple generators are used, the usage instructions ("Start by importing your Prisma Client...") now appear directly after the corresponding generator's ✔ Generated message instead of at the very end of the output.

Before:

✔ Generated Prisma Client to .\node_modules\@prisma\client in 287ms

✔ Generated Custom Generator to .\prisma\node_modules\@generated\custom in 3.50s

Start by importing your Prisma Client (See: https://pris.ly/d/importing-client)

After:

✔ Generated Prisma Client to .\node_modules\@prisma\client in 287ms

Start by importing your Prisma Client (See: https://pris.ly/d/importing-client)

✔ Generated Custom Generator to .\prisma\node_modules\@generated\custom in 3.50s

Changes

  • packages/cli/src/Generate.ts: Restructured runGenerate to collect per-generator results with provider info, then insert the usage hint after the first prisma-client-js generator (only when no errors occurred). Moved hideHints extraction 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-hints still suppresses usage instructions
  • Watch mode unchanged (no hints)
  • Version mismatch warnings still appended at end
  • Hint suppressed when any generator errors (same as before)
  • Single-generator output is functionally identical

Fixes #1737

Summary by CodeRabbit

  • Improvements

    • Generator outputs are emitted as separate, consistently ordered sections so each generator’s messages are clearer.
    • Import hints are collected per-generator and appended only when the overall run succeeds; hints are suppressed during watch mode or when any generator fails.
    • Error messages are normalized for clearer, consistent reporting.
    • Global warnings and breaking-change notices are consolidated and shown reliably.
  • Tests

    • Updated snapshots to reflect the improved multi-generator output formatting.

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
@CLAassistant
Copy link

CLAassistant commented Mar 7, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

Walkthrough

runGenerate 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

Cohort / File(s) Summary
Generate command
packages/cli/src/Generate.ts
Refactored runGenerate to return/compose messages: string[] and hints: Map<Generator,string>, accept jsClient?: Generator and showHint: boolean, normalize non-Error throws, append the JS-client usage hint inline to the corresponding generator message only when showHint and no generator errored, compute hideHints from --no-hints, discover/persist jsClient once in parse, and suppress hints in watch mode. Simplified final/global warnings handling.
Tests
packages/cli/src/__tests__/commands/Generate.test.ts
Updated test snapshots and expectations to reflect per-generator outputs appearing separately (additional client entries) and adjusted blank-line/spacing in stdout snapshots to match the new per-generator hint placement and multi-generator formatting.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving usage instructions to appear directly after generator output instead of at the end.
Linked Issues check ✅ Passed The PR directly addresses issue #1737 by repositioning usage instructions to appear immediately after the corresponding generator's output, matching all stated objectives.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives: hint collection refactoring, per-generator message handling, and conditional hint display based on generator type.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

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.

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 biome.

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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 77b2d811-9eaa-408e-88f4-75db2d292cc2

📥 Commits

Reviewing files that changed from the base of the PR and between 9fa295d and c1e1f68.

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

@Felipeness
Copy link
Contributor Author

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 7.5.0?) so the check can pass? Thanks!

private runGenerate = simpleDebounce(async ({ generators }: { generators: Generator[] }) => {
const message: string[] = []
private runGenerate = simpleDebounce(
async ({ generators, usageHint }: { generators: Generator[]; usageHint?: string }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 })[]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Contributor

@jacek-prisma jacek-prisma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left 1 important comment

jacek-prisma pushed a commit that referenced this pull request Mar 17, 2026
…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 -->
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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 55d60c41-11b3-4f02-b9cf-a61de71b7d04

📥 Commits

Reviewing files that changed from the base of the PR and between f56c5d9 and 3bb8448.

📒 Files selected for processing (1)
  • packages/cli/src/Generate.ts

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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb8448 and 091743d.

📒 Files selected for processing (1)
  • packages/cli/src/Generate.ts

Comment on lines +93 to +97
}: {
generators: Generator[]
jsClient?: Generator
showHint: boolean
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Contributor

@jacek-prisma jacek-prisma Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

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.

generate: Usage instructions should be directly below ✔ Generated ... of generator

3 participants