Repository navigation
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
Draft
wmadden-electric wants to merge 2 commits into
wmadden-electric wants to merge 2 commits into
Conversation
…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>
|
⏸️ 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.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At a glance
The whole app is written in
prisma.config.ts.prisma deploydeploys it. Underprisma dev, editing it, for example adding a secondbucket(), 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'scomposersection to hold the app itself. Until now it could only name another file, inentry, whose default export is the app's root (the outermost module, see "App root" in the glossary). This pull request adds theappfield and makesprisma devhandle edits to it.The section holds the root in
appapptakes a root made withappRoot(), as in the example. A section that usesentrybehaves 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.tsthrough jiti, a transpiler, and hands Composer the result. Composer reads anentryfile with the runtime's ownimport(). 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. Sodeploy,destroy,loganddevimportprisma.config.tsnatively and take the root from that import. If the two loads disagree on the app's name, the command refuses withCONFIG.APP_MISMATCH.prisma devrestarts itself when a rebuild cannot apply a changeAn edit to a Service's own code, such as
src/blobs/service.tsin the example, rebuilds live, as before. Other edits cannot be applied by a rebuild.prisma devruns 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 asprismaCloud({ region })are held inside functions where they cannot be compared. Before this change dev paused on any edit toprisma.config.tsand told the user to restart it.Now dev restarts itself in a new process when:
prisma.config.tschanges, as in the example's second bucket;entry;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
entryfile, 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 theprisma-composer-core-conceptsskill are updated.examples/bucketnow uses the form shown above, so CI's real-deploy job covers it.Testing performed
dev-restart.test.ts), and the config cases ofoperations.test.ts. Typecheck and Biome pass.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.examples/bucketfrom this branch, and its own check that writes a file to the bucket and reads it back passed. Added a second bucket inprisma.config.tsand redeployed: only the new bucket and its key were created, and the existing bucket and Service kept their IDs. Destroyed everything.Checklist
git commit -s) per the DCO.Notes for the reviewer
Known limits, each recorded in ADR-0049:
prisma.config.tsrestarts dev rather than rebuilding it. An edit to a Service file the config imports still rebuilds live.process.execPathwithprocess.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.--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 carriesdata: { restarting: { eventsOn: 'stderr' } }; events of the old session stopping can still follow it on stdout, and everything from the restarted process goes to stderr.Alternatives considered
prisma.config.ts.