Skip to content

feat(cli): an app can be written inside prisma.config.ts, and prisma dev restarts itself when that file changes - #491

Draft
wmadden-electric wants to merge 2 commits into
mainfrom
onramp/slice-1-app-in-config
Draft

wmadden-electric wants to merge 2 commits into
mainfrom
onramp/slice-1-app-in-config

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

Draft: waiting for a maintainer to review the design and the code. This is #487 again, unchanged. It merged on a review bot's approval alone and was reverted by #490. Known problem: the design says prisma dev rebuilds when prisma.config.ts changes and asks for a restart only for other config changes; this restarts on every change to the file.

At a glance

// examples/bucket/prisma.config.ts
import { appRoot } from '@prisma/composer';
import { defineConfig as composer } from '@prisma/composer/config';
import { nodeBuild } from '@prisma/composer/node/control';
import { bucket } from '@prisma/composer-prisma-cloud';
import { prismaCloud, prismaState } from '@prisma/composer-prisma-cloud/control';
import { definePrismaConfig } from 'prisma/config';
import blobsService from './src/blobs/service.ts';

export default definePrismaConfig({
  composer: composer({
    app: appRoot('bucket-example', ({ provision }) => {
      const store = provision(bucket({ name: 'files' }));
      provision(blobsService, { deps: { store } });
    }),
    extensions: [prismaCloud(), nodeBuild()],
    state: prismaState(),
  }),
});

The whole app is written in prisma.config.ts. prisma deploy deploys it. Under prisma dev, editing it, for example adding a second bucket(), restarts dev on its own.

Linked issue

Refs TML-4040.

Summary

We want a user's deploy configuration to grow inside one file, prisma.config.ts, as their app grows: first a short list of Services, databases and buckets, later Composer code. Both need the file's composer section to hold the app itself. Until now it could only name another file, in entry, whose default export is the app's root (the outermost module, see "App root" in the glossary). This pull request adds the app field and makes prisma dev handle edits to it.

The section holds the root in app

app takes a root made with appRoot(), as in the example. A section that uses entry behaves as before. Giving both is an error (CONFIG.APP_AND_ENTRY).

Every command reads the root with the runtime's own import

The prisma CLI loads prisma.config.ts through jiti, a transpiler, and hands Composer the result. Composer reads an entry file with the runtime's own import(). If the root were taken from the CLI's jiti-loaded value, the app would run on a second copy of Composer and of the extensions it imports. So deploy, destroy, log and dev import prisma.config.ts natively and take the root from that import. If the two loads disagree on the app's name, the command refuses with CONFIG.APP_MISMATCH.

prisma dev restarts itself when a rebuild cannot apply a change

An edit to a Service's own code, such as src/blobs/service.ts in the example, rebuilds live, as before. Other edits cannot be applied by a rebuild. prisma dev runs in two parts: a main process that starts the Services and their dev servers (the programs that serve each Service locally), and a worker that rebuilds the app on each edit. The main process keeps the config it imported at start, because the runtime caches the import, and extension options such as prismaCloud({ region }) are held inside functions where they cannot be compared. Before this change dev paused on any edit to prisma.config.ts and told the user to restart it.

Now dev restarts itself in a new process when:

  • prisma.config.ts changes, as in the example's second bucket;
  • a file only the config imports changes, for a section that uses entry;
  • the extensions, the state store or a Service's build settings change;
  • the values the config or secrets adapters return change (these are the functions that supply the app's configuration values and its secrets), or the set of platform variables the app reads changes;
  • a Service, database or bucket is added or removed in a file the root imports;
  • a file changes while dev is starting (DEV.CHANGED_WHILE_STARTING; after 3 restarts in a row it waits for an edit).

A restart stops the Services and dev servers. It keeps the local emulators of Prisma Cloud, their data and their ports, and it ignores --fresh, so it never deletes data. If the new process fails to start, dev watches the app's folders and tries again on the next edit. The restart message names what changed.

Docs and example

The decisions that said the root lives in an entry file, and that dev pauses on a config edit, are amended: ADR-0003, ADR-0017, ADR-0044, ADR-0049 and ADR-0067. The glossary's "App root" entry, the local-dev and deploy guides, and the prisma-composer-core-concepts skill are updated. examples/bucket now uses the form shown above, so CI's real-deploy job covers it.

Testing performed

  • Unit tests for each area changed, run one file at a time: section validation, root loading, the pipeline, recording of imported files, the dev worker, the dev command and its restart (dev-restart.test.ts), and the config cases of operations.test.ts. Typecheck and Biome pass.
  • New integration test test/integration/test/local-dev-restart.integration.ts: one edit to the config restarts dev once, the new root runs, the old processes are gone, and Ctrl-C frees every port. It runs in CI.
  • Manual, against real Prisma Cloud: deployed examples/bucket from this branch, and its own check that writes a file to the bucket and reads it back passed. Added a second bucket in prisma.config.ts and redeployed: only the new bucket and its key were created, and the existing bucket and Service kept their IDs. Destroyed everything.

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.
  • The PR title is a conventional commit.
  • Tests are updated.

Notes for the reviewer

Known limits, each recorded in ADR-0049:

  • An edit to a root written in prisma.config.ts restarts dev rather than rebuilding it. An edit to a Service file the config imports still rebuilds live.
  • The restart re-runs process.execPath with process.argv. That is right for the CLI run as a Node or Bun script, and wrong for a compiled binary or a program that runs the CLI's command runner directly. The runner gives a command no way to learn its own arguments; fixing it needs a change in prisma-cli.
  • With --json, the restarted process's events go to stderr, because the CLI's command runner sends a spawned process's stdout there. The restart warning carries data: { restarting: { eventsOn: 'stderr' } }; events of the old session stopping can still follow it on stdout, and everything from the restarted process goes to stderr.
  • With the app in the config, a change to an extension's options made in another file the config imports is not detected, because one import loads the app's files and the config's files together.
  • An edit that makes the root pass an input field dev did not read at start still asks the user to restart.

Alternatives considered

  • Keep pausing on config edits and asking the user to restart. Every edit to an app written in the config would then be a manual step, which defeats writing it there.
  • Keep the root in its own file and name it from the config. That keeps live rebuilds, but the point of this work is that the app is written in prisma.config.ts.
  • Reload the config in the same process. The runtime's module cache returns the first import, and Bun does not re-evaluate a module imported with a query string.

…in until it has been reviewed

Reverts #489 and #487. Both merged on a review bot's approval alone, without the design or code being reviewed by a maintainer, and the design has open problems (where migrations belong, connection strings in deploy state). Main returns to the tree of 3c5187b. The work comes back as a draft pull request.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
…dev restarts itself when that file changes (#487)

* feat(cli): the composer section can hold the app root as `app`, and prisma dev rebuilds on edits to it

The section takes an optional `app`, an appRoot() node, exclusive with `entry` (CONFIG.APP_AND_ENTRY). deploy, destroy, log and dev read it from a native import of the declaring prisma.config.ts, as they import an entry, never from the value the CLI engine loaded, so one loader reads the app everywhere. The import records the app files it loads, under Node and Bun.

prisma dev no longer pauses on any edit to prisma.config.ts. It watches the file and the app files it imports, and an edit rebuilds. The converge worker compares the section, other than `app` (extension ids, state extension, entry, adapter sources), with what the first converge saw, and returns config-changed without converging when they differ; dev then reports it and pauses as before. This also lets an entry config rebuild after an edit that keeps those fields.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* docs: the composer section can hold the app; amend ADR-0003, ADR-0017, ADR-0049 and ADR-0067

ADR-0003 and ADR-0049 record that the root may be written in the config as `app`, read by a native import of the file, and that dev pauses only when the section changes in more than its app. ADR-0017 notes the firewall still holds: the config may import app code, app code never imports the config. The deploying and running-locally guides and the core-concepts skill describe the field and the new pause rule, including that options captured inside an extension or adapter call are not compared.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* chore(examples): the bucket example holds its app in prisma.config.ts

It has one service and one bucket, so its root moves into the config as `app` and module.ts is deleted. The e2e deploy job now deploys an app written this way.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* fix(cli): prisma dev never runs a half-applied config or build; review fixes for the app in the composer section

An edit to prisma.config.ts pauses rebuilds again, an inline app included.
The worker refuses a rebuild whose build declarations differ from start
(DEV.BUILD_CHANGED). A handed section whose app differs from the file is
CONFIG.APP_MISMATCH. The config import has its own error codes. ADR-0003,
ADR-0044, ADR-0049, ADR-0067, the glossary, guides and skill updated.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* feat(cli): prisma dev restarts itself when prisma.config.ts or the app's build changes

In place of pausing until the user restarts it, the prisma dev command
stops the session and runs the same command again in a child process
through ctx.spawn. A new process loads the config, app, extensions and
build declarations fresh, which the module cache prevents in-process.
A restarted run ignores --fresh. A build change now returns
config-changed, so DEV.BUILD_CHANGED is removed. The dev operation
still pauses. ADR-0049, ADR-0067, ADR-0044, guides and skill updated.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* feat(cli): adding or removing a node restarts prisma dev

The converge worker compares the node set with the one the session
started with and returns config-changed before converging, so the
prisma dev command restarts itself as for other config-level changes.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* fix(cli): prisma dev restarts on changes made while it starts and on config-only files; review fixes

An edit made while dev starts now restarts it instead of failing with an
internal error. With an entry, an edit to a file only prisma.config.ts
imports restarts dev. A failed restart is retried when any file of the app
changes. Restart messages name what changed. The load-entry test no longer
depends on test order.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* fix(cli): prisma dev survives watch errors after a failed restart and marks the restart for --json consumers

After a failed restart, dev watches each app directory outside node_modules,
.git, .prisma-composer and .alchemy, and falls back to prisma.config.ts when
it cannot watch them, instead of crashing. The warning that says dev
restarts carries data telling a --json consumer that further events come on
stderr.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* docs(adr-0049): the restart warning is not the last event on stdout

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* test(integration): bind the web service input in the restart test config; fail at once when the restart fails

The restarted prisma dev refused the edited config with COMPOSE.GRAPH_INVALID,
because the web service declares an input schema and the test did not bind
it. The test then waited out its whole timeout.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

* docs(local-dev): a changed adapter value restarts prisma dev

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

---------

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@prisma-gizmo

prisma-gizmo Bot commented Dec 5, 2026

Copy link
Copy Markdown

⏸️ Gizmo skipped the automatic review of e0a123d because this pull request is a draft. It will review automatically once the PR is marked ready for review.

  • Check this box to request a one-time review of the current commit.

@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pkg-pr-new

pkg-pr-new Bot commented Dec 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@prisma/composer@491
npm i https://pkg.pr.new/@prisma/composer-cli@491
npm i https://pkg.pr.new/@prisma/composer-prisma-cloud@491

commit: e0a123d

Base automatically changed from revert/onramp-slices-1-2 to main December 5, 2026 22:13

This branch has not been deployed

No deployments
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.

1 participant