Skip to content

Commit 9458ee3

Browse files
feat: typed prisma.compute.ts compute config
Adds a typed, committed deploy configuration for Prisma Compute and makes the whole app command surface config-aware. Config: - prisma.compute.ts (.mts/.js/.mjs/.cjs) with defineComputeConfig from the new @prisma/cli/config export; single `app` or multi-target `apps` with name, root, framework, entry, httpPort, env, and build per app - compile-time safety (literal unions, app/apps exclusivity, typo suggestions) plus runtime validation reporting every issue at once - loaded via jiti with an alias so configs resolve @prisma/cli/config even when the package is not installed locally Resolution: - upward discovery from cwd to the source root (.git/workspace markers); nearest config wins and discovery never escapes the repository - the config directory is the project directory: local pin, state cache, and the --db schema scan anchor there; config-relative paths (root, env.file) resolve from the config file - target inference: commands run inside a target's root select it - app selection precedence: --app > PRISMA_APP_ID > config target > remembered selection > inference Command surface: - app deploy/build/run and every management command (show, open, logs, list-deploys, promote, rollback, remove, domain *) accept an [app] target argument - bare app deploy with a multi-app config deploys every target in declaration order, fail-fast with already-live/not-attempted reporting; per-app flags are rejected in deploy-all - run/build share deploy's framework detection (one detection, three commands), driven by a framework capability registry that replaces scattered framework literals Build settings: - the config build block owns build settings; otherwise they are inferred with sources shown; prisma.app.json is no longer read or written - leftover matching files warn, customized files fail with BUILD_SETTINGS_MIGRATION_REQUIRED including the exact build block - workspace builds: package-manager detection walks up to the workspace root, ancestor node_modules/.bin dirs join the build PATH, and Next.js standalone staging flattens bun's isolated store alongside pnpm's Database (--db flag flow, no config surface in this PR): - provision-only: deploy creates the branch database and wires DATABASE_URL/DIRECT_URL but never runs schema, migration, or generate commands; it suggests the detected command and a one-time connection URL via database connection create instead Packaging: - exports map with ./config (+ d.ts), jiti dependency, publish-prep now carries exports into the published manifest Spec updated across command-spec, resource-model, output- and error-conventions. 462 tests.
1 parent ee7c648 commit 9458ee3

37 files changed

Lines changed: 3298 additions & 1103 deletions

docs/product/command-spec.md

Lines changed: 113 additions & 35 deletions
Large diffs are not rendered by default.

docs/product/error-conventions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ Recommended meanings:
223223
- `LOCAL_STATE_WRITE_FAILED`: the CLI could not save local Project binding state such as `.prisma/local.json` or the matching `.gitignore` entry; callers should fix directory permissions or filesystem state before retrying
224224
- `LOCAL_STATE_STALE`: local Project pin no longer matches platform data and continuing would be ambiguous
225225
- `BRANCH_NOT_DEPLOYABLE`: command tried to deploy to a non-deployable branch context
226-
- `APP_CONFIG_INVALID`: `prisma.app.json` is missing required build settings, has invalid JSON, or points outside the app root
226+
- `COMPUTE_CONFIG_INVALID`: `prisma.compute.ts` failed to load or validate
227+
- `BUILD_SETTINGS_MIGRATION_REQUIRED`: a legacy `prisma.app.json` contains custom build settings that must move into the `build` block of `prisma.compute.ts`
227228
- `FRAMEWORK_NOT_DETECTED`: app deploy could not detect a supported Beta framework and no explicit framework/build type was provided
228229
- `DEPLOYMENT_NOT_FOUND`: requested deployment id does not exist
229230
- `NO_DEPLOYMENTS`: command resolved a branch or app but found no deployments

docs/product/output-conventions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Examples:
338338
- `app deploy` should state the resolved target that matters in the current slice
339339
- first local `app deploy` binding should make the Project choice explicit before work begins
340340
- subsequent `app deploy` calls should use a compact target header such as `Deploying ./j1 to j1 / main / j1`
341-
- config-backed `app deploy` builds should show whether they created or used `prisma.app.json` before build starts: `Build Command` with its source when inferred, and `Output Directory` as a literal path such as `.next/standalone` rather than an opaque framework default label
341+
- config-backed `app deploy` builds should show the resolved build settings before build starts: `Build Command` and `Output Directory` with their sources (`prisma.compute.ts` or inference), `Output Directory` as a literal path such as `.next/standalone` rather than an opaque framework default label
342342
- `app logs` should state the deployment it resolved
343343
- `app list-deploys` should state which app or branch is being listed
344344

docs/product/resource-model.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Rules:
3838
- `project` is not the same thing as `app`
3939
- Public Beta does not read or write committed config files such as `prisma.config.ts` or `.prisma/settings.json` for project resolution
4040
- `.prisma/local.json` is a gitignored local pin/cache for Workspace and Project IDs; it is not a declarative repo config file
41-
- `prisma.app.json` is a committed app build-settings file only; it must not contain Workspace, Project, Branch, App, env, or secret resolution state
41+
- `prisma.compute.ts` is a committed deploy-defaults file; it must not contain Workspace, Project, Branch, env-secret, or credential resolution state
4242
- Project setup is explicit: users choose an existing Project or explicitly create a new one before remote work starts
4343
- `app deploy` may orchestrate Project setup, but it must not silently choose or create Project scope
4444
- everything under a project happens in a branch
@@ -104,7 +104,7 @@ Rules:
104104
- the runtime app service is scoped by branch in the platform model
105105
- the app may be selected or created as part of app deployment workflows
106106
- app selection is local CLI state when needed for the beta package
107-
- app build settings may live in `prisma.app.json` beside `package.json`; v1 fields are `buildCommand` and `outputDirectory`
107+
- app build settings live in the `build` block of `prisma.compute.ts` (`command`, `outputDirectory`); `prisma.app.json` is legacy and no longer read
108108

109109
### Deployment
110110

packages/cli/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
"bin": {
77
"prisma-cli": "./dist/cli.js"
88
},
9+
"exports": {
10+
"./config": {
11+
"types": "./dist/config.d.ts",
12+
"default": "./dist/config.js"
13+
},
14+
"./package.json": "./package.json"
15+
},
916
"files": [
1017
"dist",
1118
"README.md",
@@ -49,6 +56,7 @@
4956
"colorette": "^2.0.20",
5057
"commander": "^14.0.3",
5158
"dotenv": "^17.4.2",
59+
"jiti": "^2.7.0",
5260
"magicast": "^0.5.3",
5361
"open": "^11.0.0",
5462
"string-width": "^8.2.1",

packages/cli/src/commands/app/index.ts

Lines changed: 59 additions & 34 deletions
Large diffs are not rendered by default.

packages/cli/src/config.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Public typed config surface for `prisma.compute.ts`.
3+
*
4+
* This module is published as `@prisma/cli/config` and must stay free of
5+
* runtime dependencies so user config files can import it cheaply.
6+
*/
7+
8+
export const COMPUTE_FRAMEWORKS = ["nextjs", "hono", "tanstack-start", "bun"] as const;
9+
10+
export type ComputeFramework = (typeof COMPUTE_FRAMEWORKS)[number];
11+
12+
export interface ComputeEnvConfig {
13+
/** Dotenv file path(s) resolved relative to the config file directory. */
14+
file?: string | string[];
15+
/** Inline environment variable assignments. Values are deployed as-is. */
16+
vars?: Record<string, string>;
17+
}
18+
19+
export interface ComputeBuildConfig {
20+
/** Build command run in the app root. `null` skips the build step. */
21+
command?: string | null;
22+
/** Framework output path relative to the app root, e.g. ".next/standalone". */
23+
outputDirectory?: string;
24+
}
25+
26+
27+
export interface ComputeAppConfig {
28+
/** Deployed app name. Defaults to the `apps` key, then package/directory inference. */
29+
name?: string;
30+
/** App directory relative to the config file. Defaults to the config file directory. */
31+
root?: string;
32+
/** Framework to deploy. Defaults to detection from the app directory. */
33+
framework?: ComputeFramework;
34+
/** Entrypoint path for Bun (and Hono) deploys, relative to the app root. */
35+
entry?: string;
36+
/** HTTP port the deployed app listens on. Defaults to the framework default. */
37+
httpPort?: number;
38+
/** Environment variables for the deploy. A string is shorthand for `{ file }`. */
39+
env?: string | ComputeEnvConfig;
40+
/** Build settings. When present, these own the app's build configuration. */
41+
build?: ComputeBuildConfig;
42+
}
43+
44+
/**
45+
* `prisma.compute.ts` accepts exactly one of:
46+
*
47+
* - `app` — a repository that deploys a single app
48+
* - `apps` — a monorepo or multi-app repository, keyed by deploy target
49+
*/
50+
export type ComputeConfig =
51+
| { app: ComputeAppConfig; apps?: never }
52+
| { apps: Record<string, ComputeAppConfig>; app?: never };
53+
54+
/**
55+
* Identity helper that gives `prisma.compute.ts` full type checking:
56+
*
57+
* ```ts
58+
* import { defineComputeConfig } from "@prisma/cli/config";
59+
*
60+
* export default defineComputeConfig({
61+
* app: { framework: "hono", httpPort: 8080 },
62+
* });
63+
* ```
64+
*/
65+
export function defineComputeConfig(config: ComputeConfig): ComputeConfig {
66+
return config;
67+
}

0 commit comments

Comments
 (0)