Skip to content

TML-3053: Export a programmatic init plan/apply API from @prisma-next/cli#1004

Open
AmanVarshney01 wants to merge 1 commit into
mainfrom
aman/tml-3053-programmatic-init
Open

TML-3053: Export a programmatic init plan/apply API from @prisma-next/cli#1004
AmanVarshney01 wants to merge 1 commit into
mainfrom
aman/tml-3053-programmatic-init

Conversation

@AmanVarshney01

@AmanVarshney01 AmanVarshney01 commented Jul 19, 2026

Copy link
Copy Markdown
Member

Linked issue

TML-3053

Summary

Scaffolders (create-prisma@next, prisma/create-prisma#37) can only reach init by spawning the CLI and re-editing the files it wrote, which is nondeterministic at render time and fragile (write-then-merge ordering). This PR splits runInit at the seam it already had — the FR6.2 precondition phase vs the write phase — into buildInitPlan / applyInitPlan in src/commands/init/plan.ts, and exports a prompt-free planInit + applyInitPlan pair as a new @prisma-next/cli/init subpath so consumers can stage the scaffold in memory, merge it with their own templates, and write once.

runInit now consumes the same pair, so CLI behavior is unchanged (same file set, ordering, warnings, structured errors, and exit codes). resolveInitInputs takes autoAcceptPrompts: boolean instead of the full GlobalFlags so prompt-free callers do not synthesise CLI flag state; hasDirectDep / defaultPackageJsonContent moved to plan.ts with the logic that uses them (no compat re-exports, per convention).

Testing performed

  • pnpm --filter @prisma-next/cli test — 1360 tests / 107 files pass, including new test/commands/init/plan.test.ts (14 tests: plan purity, apply fidelity, structured errors 5002/5004/5010/5011/5014, target alias mapping, .env opt-in, re-init deletions, package-manager threading)
  • pnpm --filter @prisma-next/cli typecheck
  • pnpm --filter @prisma-next/cli lint (baseline infos only, no new diagnostics)
  • pnpm --filter @prisma-next/cli builddist/exports/init.mjs / .d.mts emitted for the new subpath

Skill update

n/a — the init CLI surface (flags, prompts, JSON output, exit codes) is unchanged; this adds a package-level programmatic API whose first consumer is create-prisma. The init --json document contract remains exported via @prisma-next/cli/init-output.

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form.

Summary by CodeRabbit

  • New Features

    • Added a programmatic init interface for planning and applying project scaffolding.
    • Added support for previewing planned file changes before writing them.
    • Improved initialization handling for configuration files, package scripts, environment files, and stale generated artifacts.
    • Added a new CLI package export for the initialization tools.
  • Bug Fixes

    • Improved validation and error handling during project initialization.
    • Preserved existing configuration while merging required settings.

@AmanVarshney01
AmanVarshney01 requested a review from a team as a code owner July 19, 2026 22:16
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: d46983b9-ae4b-406e-aa39-b1b3469cb2e9

📥 Commits

Reviewing files that changed from the base of the PR and between df330d9 and 841c1fe.

📒 Files selected for processing (8)
  • packages/1-framework/3-tooling/cli/package.json
  • packages/1-framework/3-tooling/cli/src/commands/init/init.ts
  • packages/1-framework/3-tooling/cli/src/commands/init/inputs.ts
  • packages/1-framework/3-tooling/cli/src/commands/init/plan.ts
  • packages/1-framework/3-tooling/cli/src/exports/init.ts
  • packages/1-framework/3-tooling/cli/test/commands/init/init.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/init/plan.test.ts
  • packages/1-framework/3-tooling/cli/tsdown.config.ts
📝 Walkthrough

Walkthrough

The init command now separates input resolution, scaffold planning, and filesystem application. A new programmatic @prisma-next/cli/init entrypoint exposes the planning API, and build configuration, package exports, and tests are updated accordingly.

Changes

Init planning and application

Layer / File(s) Summary
Input and plan contracts
packages/1-framework/3-tooling/cli/src/commands/init/inputs.ts, packages/1-framework/3-tooling/cli/src/commands/init/plan.ts
resolveInitInputs accepts explicit prompt behavior, while new plan interfaces define planning options, staged files, deletions, warnings, and application results.
Scaffold plan construction
packages/1-framework/3-tooling/cli/src/commands/init/plan.ts
buildInitPlan stages scaffold files, manifest and configuration updates, re-init deletions, warnings, normalized targets, and dependency metadata without writing to disk.
CLI plan application
packages/1-framework/3-tooling/cli/src/commands/init/init.ts, packages/1-framework/3-tooling/cli/src/commands/init/plan.ts
runInit delegates to buildInitPlan and applyInitPlan; application writes planned files, deletes queued paths, reports written files, and derives install and output metadata from the plan.
Public entrypoint and validation
packages/1-framework/3-tooling/cli/src/exports/init.ts, packages/1-framework/3-tooling/cli/package.json, packages/1-framework/3-tooling/cli/tsdown.config.ts, packages/1-framework/3-tooling/cli/test/commands/init/*
The new init API is built and exported through @prisma-next/cli/init; tests cover planning, application, structured errors, merging, deletions, and hooks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: tensordreams

Sequence Diagram(s)

sequenceDiagram
  participant InitCommand
  participant buildInitPlan
  participant applyInitPlan
  participant Filesystem
  InitCommand->>buildInitPlan: resolve inputs and create InitPlan
  buildInitPlan-->>InitCommand: staged files, deletions, warnings
  InitCommand->>applyInitPlan: apply InitPlan
  applyInitPlan->>Filesystem: write planned files
  applyInitPlan->>Filesystem: delete planned paths
  applyInitPlan-->>InitCommand: written and deleted paths
Loading
🚥 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 summarizes the main change: exporting a programmatic init plan/apply API from @prisma-next/cli.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aman/tml-3053-programmatic-init

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@1004

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@1004

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@1004

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@1004

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@1004

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@1004

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@1004

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@1004

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@1004

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@1004

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@1004

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@1004

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@1004

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@1004

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@1004

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@1004

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@1004

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@1004

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@1004

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@1004

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@1004

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@1004

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@1004

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@1004

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@1004

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@1004

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@1004

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@1004

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@1004

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@1004

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@1004

@prisma-next/config-loader

npm i https://pkg.pr.new/@prisma-next/config-loader@1004

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@1004

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@1004

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@1004

prisma-next

npm i https://pkg.pr.new/prisma-next@1004

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@1004

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@1004

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@1004

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@1004

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@1004

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@1004

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@1004

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@1004

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@1004

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@1004

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@1004

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@1004

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@1004

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@1004

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@1004

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@1004

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@1004

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@1004

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@1004

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@1004

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@1004

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@1004

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@1004

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@1004

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@1004

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@1004

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@1004

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@1004

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@1004

commit: 841c1fe

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 158.95 KB (0%)
postgres / emit 132.46 KB (0%)
mongo / no-emit 98.7 KB (0%)
mongo / emit 89.43 KB (0%)
cf-worker / no-emit 185.15 KB (0%)
cf-worker / emit 155.91 KB (0%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/1-framework/3-tooling/cli/src/commands/init/plan.ts (1)

254-254: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer the repo cast helpers over bare as.

JSON.parse(pkgRaw) as Record<string, unknown> (Line 254) and (err as { code: string }).code (Line 373) are bare casts in production code. As per coding guidelines ("No bare as in production code. Use blindCast<T, \"Reason\"> or castAs<T> from @prisma-next/utils/casts"), wrap these with the sanctioned helpers. This is mechanically-moved code, so treat it as cleanup rather than a blocker.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/1-framework/3-tooling/cli/src/commands/init/plan.ts` at line 254,
Replace the bare casts in the init planning flow with the sanctioned cast
helpers from `@prisma-next/utils/casts`: update the JSON.parse assignment near
parsedPackageJson and the error-code access near the existing err handling to
use blindCast or castAs with an appropriate reason. Preserve the current runtime
behavior and types.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/1-framework/3-tooling/cli/src/commands/init/plan.ts`:
- Line 254: Replace the bare casts in the init planning flow with the sanctioned
cast helpers from `@prisma-next/utils/casts`: update the JSON.parse assignment
near parsedPackageJson and the error-code access near the existing err handling
to use blindCast or castAs with an appropriate reason. Preserve the current
runtime behavior and types.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 5197b18e-148d-4fec-a781-34a3b8d2f759

📥 Commits

Reviewing files that changed from the base of the PR and between 310f70b and df330d9.

📒 Files selected for processing (8)
  • packages/1-framework/3-tooling/cli/package.json
  • packages/1-framework/3-tooling/cli/src/commands/init/init.ts
  • packages/1-framework/3-tooling/cli/src/commands/init/inputs.ts
  • packages/1-framework/3-tooling/cli/src/commands/init/plan.ts
  • packages/1-framework/3-tooling/cli/src/exports/init.ts
  • packages/1-framework/3-tooling/cli/test/commands/init/init.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/init/plan.test.ts
  • packages/1-framework/3-tooling/cli/tsdown.config.ts

…/cli

Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
@AmanVarshney01
AmanVarshney01 force-pushed the aman/tml-3053-programmatic-init branch from df330d9 to 841c1fe Compare July 19, 2026 22:34
@AmanVarshney01
AmanVarshney01 requested a review from wmadden July 19, 2026 22:54

@wmadden wmadden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have a programmatic API for CLI commands already, called the ControlClient. Extend that with access to the init operations

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.

2 participants