@prisma/cli 3.0.0-beta.3 → 3.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/commands/app/index.js +4 -2
- package/dist/commands/branch/index.js +2 -27
- package/dist/controllers/app-env.js +152 -21
- package/dist/controllers/app.js +26 -50
- package/dist/controllers/branch.js +73 -47
- package/dist/lib/app/preview-provider.js +26 -6
- package/dist/lib/app/production-deploy-gate.js +160 -0
- package/dist/lib/git/local-branch.js +41 -0
- package/dist/presenters/app-env.js +14 -3
- package/dist/presenters/branch.js +29 -101
- package/dist/shell/command-meta.js +6 -24
- package/dist/shell/ui.js +4 -1
- package/dist/use-cases/branch.js +20 -68
- package/dist/use-cases/create-cli-gateways.js +2 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ Useful next commands:
|
|
|
57
57
|
npx prisma-cli app logs
|
|
58
58
|
npx prisma-cli app open
|
|
59
59
|
npx prisma-cli project env add DATABASE_URL=postgresql://example --role preview
|
|
60
|
+
npx prisma-cli project env list
|
|
60
61
|
npx prisma-cli project env list --role preview
|
|
61
62
|
```
|
|
62
63
|
|
|
@@ -73,7 +74,7 @@ The beta package exposes `prisma-cli` so it can coexist with the existing
|
|
|
73
74
|
| `auth` | Log in, log out, and inspect the active Prisma account. |
|
|
74
75
|
| `project` | List projects, show the resolved project, and manage project environment variables. |
|
|
75
76
|
| `git` | Connect or disconnect a project from a GitHub repository. |
|
|
76
|
-
| `branch` |
|
|
77
|
+
| `branch` | List Prisma branches for the resolved project. |
|
|
77
78
|
| `app` | Build, run, deploy, inspect, open, stream logs, promote, roll back, and remove apps. |
|
|
78
79
|
|
|
79
80
|
Common examples:
|
|
@@ -82,7 +83,7 @@ Common examples:
|
|
|
82
83
|
npx prisma-cli version
|
|
83
84
|
npx prisma-cli auth whoami
|
|
84
85
|
npx prisma-cli project show
|
|
85
|
-
npx prisma-cli branch
|
|
86
|
+
npx prisma-cli branch list
|
|
86
87
|
npx prisma-cli app deploy --branch feat-login --framework nextjs
|
|
87
88
|
npx prisma-cli app promote <deployment-id>
|
|
88
89
|
```
|
|
@@ -64,7 +64,7 @@ function createDeployCommand(runtime) {
|
|
|
64
64
|
"hono",
|
|
65
65
|
"tanstack-start",
|
|
66
66
|
"bun"
|
|
67
|
-
])).addOption(new Option("--entry <path>", "Entrypoint path for Bun deploys")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues));
|
|
67
|
+
])).addOption(new Option("--entry <path>", "Entrypoint path for Bun deploys")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues)).addOption(new Option("--prod", "Confirm intent to deploy to production"));
|
|
68
68
|
addGlobalFlags(command);
|
|
69
69
|
command.action(async (options) => {
|
|
70
70
|
const appName = options.app;
|
|
@@ -75,6 +75,7 @@ function createDeployCommand(runtime) {
|
|
|
75
75
|
const envAssignments = options.env;
|
|
76
76
|
const projectRef = options.project;
|
|
77
77
|
const createProjectName = options.createProject;
|
|
78
|
+
const prod = options.prod;
|
|
78
79
|
await runCommand(runtime, "app.deploy", options, (context) => runAppDeploy(context, appName, {
|
|
79
80
|
projectRef,
|
|
80
81
|
createProjectName,
|
|
@@ -82,7 +83,8 @@ function createDeployCommand(runtime) {
|
|
|
82
83
|
entrypoint: entry,
|
|
83
84
|
framework,
|
|
84
85
|
httpPort,
|
|
85
|
-
envAssignments
|
|
86
|
+
envAssignments,
|
|
87
|
+
prod: prod === true
|
|
86
88
|
}), {
|
|
87
89
|
renderHuman: (context, descriptor, result) => renderAppDeploy(context, descriptor, result),
|
|
88
90
|
renderJson: (result) => serializeAppDeploy(result)
|
|
@@ -2,16 +2,14 @@ import { attachCommandDescriptor } from "../../shell/command-meta.js";
|
|
|
2
2
|
import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
|
|
3
3
|
import { configureRuntimeCommand } from "../../shell/runtime.js";
|
|
4
4
|
import { runCommand } from "../../shell/command-runner.js";
|
|
5
|
-
import { runBranchList
|
|
6
|
-
import { renderBranchList,
|
|
5
|
+
import { runBranchList } from "../../controllers/branch.js";
|
|
6
|
+
import { renderBranchList, serializeBranchList } from "../../presenters/branch.js";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
//#region src/commands/branch/index.ts
|
|
9
9
|
function createBranchCommand(runtime) {
|
|
10
10
|
const branch = attachCommandDescriptor(configureRuntimeCommand(new Command("branch"), runtime), "branch");
|
|
11
11
|
addCompactGlobalFlags(branch);
|
|
12
12
|
branch.addCommand(createBranchListCommand(runtime));
|
|
13
|
-
branch.addCommand(createBranchShowCommand(runtime));
|
|
14
|
-
branch.addCommand(createBranchUseCommand(runtime));
|
|
15
13
|
return branch;
|
|
16
14
|
}
|
|
17
15
|
function createBranchListCommand(runtime) {
|
|
@@ -25,28 +23,5 @@ function createBranchListCommand(runtime) {
|
|
|
25
23
|
});
|
|
26
24
|
return command;
|
|
27
25
|
}
|
|
28
|
-
function createBranchShowCommand(runtime) {
|
|
29
|
-
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("show"), runtime), "branch.show");
|
|
30
|
-
addGlobalFlags(command);
|
|
31
|
-
command.action(async (options) => {
|
|
32
|
-
await runCommand(runtime, "branch.show", options, (context) => runBranchShow(context), {
|
|
33
|
-
renderHuman: (context, descriptor, result) => renderBranchShow(context, descriptor, result),
|
|
34
|
-
renderJson: (result) => serializeBranchShow(result)
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return command;
|
|
38
|
-
}
|
|
39
|
-
function createBranchUseCommand(runtime) {
|
|
40
|
-
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("use"), runtime), "branch.use");
|
|
41
|
-
command.argument("[name]", "Branch name");
|
|
42
|
-
addGlobalFlags(command);
|
|
43
|
-
command.action(async (branchName, options) => {
|
|
44
|
-
await runCommand(runtime, "branch.use", options, (context) => runBranchUse(context, branchName), {
|
|
45
|
-
renderHuman: (context, descriptor, result) => renderBranchUse(context, descriptor, result),
|
|
46
|
-
renderJson: (result) => serializeBranchShow(result)
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
return command;
|
|
50
|
-
}
|
|
51
26
|
//#endregion
|
|
52
27
|
export { createBranchCommand };
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { CliError, authRequiredError, usageError, workspaceRequiredError } from "../shell/errors.js";
|
|
2
2
|
import { requireComputeAuth } from "../lib/auth/guard.js";
|
|
3
3
|
import { resolveProjectTarget } from "../lib/project/resolution.js";
|
|
4
|
+
import { readLocalGitBranch } from "../lib/git/local-branch.js";
|
|
4
5
|
import { requireAuthenticatedAuthState } from "./auth.js";
|
|
5
6
|
import { listRealWorkspaceProjects } from "./project.js";
|
|
6
7
|
import { formatScopeLabel, parseKeyValuePositional, resolveEnvScope } from "../lib/app/env-config.js";
|
|
7
8
|
//#region src/controllers/app-env.ts
|
|
8
|
-
function defaultRoleScope() {
|
|
9
|
-
return {
|
|
10
|
-
kind: "role",
|
|
11
|
-
role: "production"
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
9
|
async function runEnvAdd(context, rawAssignment, flags) {
|
|
15
10
|
const { key, value } = parseKeyValuePositional(rawAssignment, "add", context.runtime.env);
|
|
16
11
|
const scope = resolveEnvScope(flags, {
|
|
@@ -108,25 +103,30 @@ async function runEnvUpdate(context, rawAssignment, flags) {
|
|
|
108
103
|
};
|
|
109
104
|
}
|
|
110
105
|
async function runEnvList(context, flags) {
|
|
111
|
-
const
|
|
106
|
+
const explicit = resolveEnvScope(flags, {
|
|
112
107
|
requireExplicit: false,
|
|
113
108
|
command: "list"
|
|
114
|
-
})
|
|
109
|
+
});
|
|
115
110
|
const { client, projectId } = await requireClientAndProject(context, flags.projectRef, "project env list");
|
|
116
|
-
const resolved = await
|
|
117
|
-
|
|
111
|
+
const resolved = await resolveListScopeToApi(client, projectId, explicit, {
|
|
112
|
+
cwd: context.runtime.cwd,
|
|
118
113
|
signal: context.runtime.signal
|
|
119
114
|
});
|
|
120
|
-
const variables = await listVariables(client, projectId,
|
|
115
|
+
const variables = resolved.kind === "scoped" ? await listVariables(client, projectId, {
|
|
116
|
+
scope: resolved.addScope,
|
|
117
|
+
descriptor: resolved.descriptor,
|
|
118
|
+
apiTarget: resolved.apiTarget
|
|
119
|
+
}, context.runtime.signal) : await listOverviewVariables(client, projectId, context.runtime.signal);
|
|
121
120
|
return {
|
|
122
121
|
command: "project.env.list",
|
|
123
122
|
result: {
|
|
124
123
|
projectId,
|
|
125
124
|
scope: resolved.descriptor,
|
|
125
|
+
target: resolved.target,
|
|
126
126
|
variables: variables.map((row) => toMetadata(row, resolved.descriptor))
|
|
127
127
|
},
|
|
128
128
|
warnings: [],
|
|
129
|
-
nextSteps: variables.length === 0 ? [`prisma-cli project env add KEY=value ${formatScopeFlag(
|
|
129
|
+
nextSteps: variables.length === 0 ? [`prisma-cli project env add KEY=value ${formatScopeFlag(resolved.addScope)}`] : []
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
async function runEnvRemove(context, key, flags) {
|
|
@@ -196,12 +196,12 @@ async function resolveScopeToApi(client, projectId, scope, options) {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
const branch = options.createBranchIfMissing ? await resolveOrCreateBranch(client, projectId, scope.branchName, options.signal) : await resolveExistingBranch(client, projectId, scope.branchName, options.signal);
|
|
199
|
-
if (branch.
|
|
199
|
+
if (branch.role === "production") throw new CliError({
|
|
200
200
|
code: "ENV_BRANCH_SCOPE_IS_PRODUCTION",
|
|
201
201
|
domain: "app",
|
|
202
|
-
summary: `Branch "${scope.branchName}" is the
|
|
202
|
+
summary: `Branch "${scope.branchName}" is the production branch`,
|
|
203
203
|
why: "Production variables are project-level only; branch overrides apply to preview branches.",
|
|
204
|
-
fix: "Use --role production for the
|
|
204
|
+
fix: "Use --role production for the production branch.",
|
|
205
205
|
exitCode: 1,
|
|
206
206
|
nextSteps: ["prisma-cli project env list --role production"]
|
|
207
207
|
});
|
|
@@ -218,6 +218,123 @@ async function resolveScopeToApi(client, projectId, scope, options) {
|
|
|
218
218
|
}
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
|
+
async function resolveListScopeToApi(client, projectId, explicit, options) {
|
|
222
|
+
if (explicit) {
|
|
223
|
+
const resolved = await resolveScopeToApi(client, projectId, explicit, {
|
|
224
|
+
createBranchIfMissing: false,
|
|
225
|
+
signal: options.signal
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
kind: "scoped",
|
|
229
|
+
descriptor: resolved.descriptor,
|
|
230
|
+
target: targetFromExplicitScope(resolved.descriptor),
|
|
231
|
+
apiTarget: resolved.apiTarget,
|
|
232
|
+
addScope: resolved.scope
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const gitBranch = await readLocalGitBranch(options.cwd, options.signal);
|
|
236
|
+
if (gitBranch) {
|
|
237
|
+
const branch = (await listBranchesByName(client, projectId, gitBranch, options.signal))[0];
|
|
238
|
+
if (!branch) return {
|
|
239
|
+
kind: "scoped",
|
|
240
|
+
descriptor: {
|
|
241
|
+
kind: "role",
|
|
242
|
+
role: "preview"
|
|
243
|
+
},
|
|
244
|
+
target: {
|
|
245
|
+
source: "local-git",
|
|
246
|
+
branchName: gitBranch,
|
|
247
|
+
branchExists: false,
|
|
248
|
+
envMap: "preview"
|
|
249
|
+
},
|
|
250
|
+
apiTarget: {
|
|
251
|
+
class: "preview",
|
|
252
|
+
branchId: null
|
|
253
|
+
},
|
|
254
|
+
addScope: {
|
|
255
|
+
kind: "branch",
|
|
256
|
+
branchName: gitBranch
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
if (branch.role === "production") return {
|
|
260
|
+
kind: "scoped",
|
|
261
|
+
descriptor: {
|
|
262
|
+
kind: "role",
|
|
263
|
+
role: "production"
|
|
264
|
+
},
|
|
265
|
+
target: {
|
|
266
|
+
source: "local-git",
|
|
267
|
+
branchName: branch.gitName,
|
|
268
|
+
branchId: branch.id,
|
|
269
|
+
branchRole: branch.role,
|
|
270
|
+
branchExists: true,
|
|
271
|
+
envMap: "production"
|
|
272
|
+
},
|
|
273
|
+
apiTarget: {
|
|
274
|
+
class: "production",
|
|
275
|
+
branchId: null
|
|
276
|
+
},
|
|
277
|
+
addScope: {
|
|
278
|
+
kind: "role",
|
|
279
|
+
role: "production"
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
kind: "scoped",
|
|
284
|
+
descriptor: {
|
|
285
|
+
kind: "branch",
|
|
286
|
+
branchName: branch.gitName,
|
|
287
|
+
branchId: branch.id
|
|
288
|
+
},
|
|
289
|
+
target: {
|
|
290
|
+
source: "local-git",
|
|
291
|
+
branchName: branch.gitName,
|
|
292
|
+
branchId: branch.id,
|
|
293
|
+
branchRole: branch.role,
|
|
294
|
+
branchExists: true,
|
|
295
|
+
envMap: "preview"
|
|
296
|
+
},
|
|
297
|
+
apiTarget: {
|
|
298
|
+
class: "preview",
|
|
299
|
+
branchId: branch.id
|
|
300
|
+
},
|
|
301
|
+
addScope: {
|
|
302
|
+
kind: "branch",
|
|
303
|
+
branchName: branch.gitName
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
kind: "overview",
|
|
309
|
+
descriptor: { kind: "overview" },
|
|
310
|
+
target: {
|
|
311
|
+
source: "overview",
|
|
312
|
+
envMap: "overview"
|
|
313
|
+
},
|
|
314
|
+
addScope: {
|
|
315
|
+
kind: "role",
|
|
316
|
+
role: "preview"
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function targetFromExplicitScope(scope) {
|
|
321
|
+
if (scope.kind === "branch") return {
|
|
322
|
+
source: "explicit",
|
|
323
|
+
branchName: scope.branchName,
|
|
324
|
+
branchId: scope.branchId,
|
|
325
|
+
branchRole: "preview",
|
|
326
|
+
branchExists: true,
|
|
327
|
+
envMap: "preview"
|
|
328
|
+
};
|
|
329
|
+
if (scope.kind === "role") return {
|
|
330
|
+
source: "explicit",
|
|
331
|
+
envMap: scope.role
|
|
332
|
+
};
|
|
333
|
+
return {
|
|
334
|
+
source: "overview",
|
|
335
|
+
envMap: "overview"
|
|
336
|
+
};
|
|
337
|
+
}
|
|
221
338
|
function formatScopeFlag(scope) {
|
|
222
339
|
if (scope.kind === "role") return `--role ${scope.role}`;
|
|
223
340
|
return `--branch ${scope.branchName}`;
|
|
@@ -306,25 +423,38 @@ async function findVariableByNaturalKey(client, projectId, key, resolved, signal
|
|
|
306
423
|
return data.data.filter((row) => rowMatchesExactScope(row, resolved))[0] ?? null;
|
|
307
424
|
}
|
|
308
425
|
async function listVariables(client, projectId, resolved, signal) {
|
|
426
|
+
return materializeEffectiveRows(await collectEnvironmentVariables(client, projectId, signal, {
|
|
427
|
+
className: resolved.apiTarget.class,
|
|
428
|
+
filter: (row) => rowMatchesScope(row, resolved)
|
|
429
|
+
}), resolved);
|
|
430
|
+
}
|
|
431
|
+
async function listOverviewVariables(client, projectId, signal) {
|
|
432
|
+
return (await collectEnvironmentVariables(client, projectId, signal, { filter: (row) => row.branchId === null && (row.class === "production" || row.class === "preview") })).sort((left, right) => {
|
|
433
|
+
const roleOrder = roleSortOrder(left.class) - roleSortOrder(right.class);
|
|
434
|
+
return roleOrder !== 0 ? roleOrder : left.key.localeCompare(right.key);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
async function collectEnvironmentVariables(client, projectId, signal, options) {
|
|
309
438
|
const collected = [];
|
|
310
439
|
let cursor;
|
|
311
440
|
while (true) {
|
|
312
|
-
const query = {
|
|
313
|
-
|
|
314
|
-
class: resolved.apiTarget.class
|
|
315
|
-
};
|
|
441
|
+
const query = { projectId };
|
|
442
|
+
if (options.className !== void 0) query.class = options.className;
|
|
316
443
|
if (cursor !== void 0) query.cursor = cursor;
|
|
317
444
|
const result = await client.GET("/v1/environment-variables", {
|
|
318
445
|
params: { query },
|
|
319
446
|
signal
|
|
320
447
|
});
|
|
321
448
|
if (result.error || !result.data) throw apiCallError(`Failed to list environment variables`, result.response, result.error);
|
|
322
|
-
const page = result.data.data.filter(
|
|
449
|
+
const page = result.data.data.filter(options.filter);
|
|
323
450
|
collected.push(...page);
|
|
324
451
|
if (!result.data.pagination.hasMore || !result.data.pagination.nextCursor) break;
|
|
325
452
|
cursor = result.data.pagination.nextCursor;
|
|
326
453
|
}
|
|
327
|
-
return
|
|
454
|
+
return collected;
|
|
455
|
+
}
|
|
456
|
+
function roleSortOrder(role) {
|
|
457
|
+
return role === "production" ? 0 : 1;
|
|
328
458
|
}
|
|
329
459
|
function rowMatchesScope(row, resolved) {
|
|
330
460
|
if (row.class !== resolved.apiTarget.class) return false;
|
|
@@ -357,6 +487,7 @@ function toMetadata(row, requestedScope) {
|
|
|
357
487
|
}
|
|
358
488
|
function formatDescriptorLabel(scope) {
|
|
359
489
|
if (scope.kind === "role") return scope.role ?? "unknown";
|
|
490
|
+
if (scope.kind === "overview") return "overview";
|
|
360
491
|
return `branch:${scope.branchName ?? scope.branchId ?? "unknown"}`;
|
|
361
492
|
}
|
|
362
493
|
function apiCallError(summary, response, error) {
|
package/dist/controllers/app.js
CHANGED
|
@@ -16,10 +16,12 @@ import { LOCAL_RESOLUTION_PIN_RELATIVE_PATH, readLocalResolutionPin } from "../l
|
|
|
16
16
|
import { buildProjectSetupNextActions, inferTargetName, projectNotFoundError, resolveDurablePlatformMapping, resolveProjectTarget, sortProjects } from "../lib/project/resolution.js";
|
|
17
17
|
import { bindProjectToDirectory, projectCreateFailedError, projectSetupNameRequiredError, resolveProjectForSetup, toProjectSummary } from "../lib/project/setup.js";
|
|
18
18
|
import { promptForProjectSetupChoice } from "../lib/project/interactive-setup.js";
|
|
19
|
+
import { readLocalGitBranch } from "../lib/git/local-branch.js";
|
|
19
20
|
import { PREVIEW_BUILD_TYPES, RESOLVED_PREVIEW_BUILD_TYPES, executePreviewBuild } from "../lib/app/preview-build.js";
|
|
20
21
|
import { PREVIEW_DEFAULT_REGION } from "../lib/app/preview-interaction.js";
|
|
21
22
|
import { createPreviewDeployProgress, createPreviewDeployProgressState, createPreviewPromoteProgress } from "../lib/app/preview-progress.js";
|
|
22
23
|
import { PreviewDomainApiError, createPreviewAppProvider } from "../lib/app/preview-provider.js";
|
|
24
|
+
import { enforceProductionDeployGate } from "../lib/app/production-deploy-gate.js";
|
|
23
25
|
import { formatDomainFailureFix } from "../lib/app/domain-guidance.js";
|
|
24
26
|
import { createSelectPromptPort } from "./select-prompt-port.js";
|
|
25
27
|
import { requireAuthenticatedAuthState } from "./auth.js";
|
|
@@ -158,6 +160,12 @@ async function runAppDeploy(context, appName, options) {
|
|
|
158
160
|
});
|
|
159
161
|
framework = customized.framework;
|
|
160
162
|
runtime = customized.runtime;
|
|
163
|
+
await enforceProductionDeployGate(context, provider, {
|
|
164
|
+
appId: selectedApp.appId,
|
|
165
|
+
appName: selectedApp.displayName,
|
|
166
|
+
branchKind: target.branch.kind,
|
|
167
|
+
prod: options?.prod === true
|
|
168
|
+
});
|
|
161
169
|
const buildType = framework.buildType;
|
|
162
170
|
assertSupportedEntrypoint(buildType, options?.entrypoint, "deploy");
|
|
163
171
|
const entrypoint = await resolveDeployEntrypoint(context.runtime.cwd, framework, options?.entrypoint, context.runtime.signal);
|
|
@@ -1322,7 +1330,7 @@ async function resolveDeployProjectContext(context, client, provider, explicitPr
|
|
|
1322
1330
|
if (!workspace) throw workspaceRequiredError();
|
|
1323
1331
|
const branch = options.branch ?? await resolveDeployBranch(context, void 0);
|
|
1324
1332
|
const projects = await listRealWorkspaceProjects(client, workspace, context.runtime.signal);
|
|
1325
|
-
if (explicitProject) return
|
|
1333
|
+
if (explicitProject) return withRemoteDeployBranch(provider, {
|
|
1326
1334
|
workspace,
|
|
1327
1335
|
project: toProjectSummary(resolveProjectForSetup(explicitProject, projects, workspace)),
|
|
1328
1336
|
resolution: {
|
|
@@ -1331,11 +1339,11 @@ async function resolveDeployProjectContext(context, client, provider, explicitPr
|
|
|
1331
1339
|
targetNameSource: "explicit"
|
|
1332
1340
|
},
|
|
1333
1341
|
localPinAction: "linked"
|
|
1334
|
-
}, branch);
|
|
1342
|
+
}, branch, context.runtime.signal);
|
|
1335
1343
|
if (options.createProjectName) {
|
|
1336
1344
|
const projectName = options.createProjectName.trim();
|
|
1337
1345
|
if (!projectName) throw projectSetupNameRequiredError("app deploy --create-project");
|
|
1338
|
-
return
|
|
1346
|
+
return withRemoteDeployBranch(provider, {
|
|
1339
1347
|
workspace,
|
|
1340
1348
|
project: toProjectSummary(await createProjectForDeploySetup(provider, projectName, workspace, context.runtime.signal)),
|
|
1341
1349
|
resolution: {
|
|
@@ -1344,12 +1352,12 @@ async function resolveDeployProjectContext(context, client, provider, explicitPr
|
|
|
1344
1352
|
targetNameSource: "explicit"
|
|
1345
1353
|
},
|
|
1346
1354
|
localPinAction: "created"
|
|
1347
|
-
}, branch);
|
|
1355
|
+
}, branch, context.runtime.signal);
|
|
1348
1356
|
}
|
|
1349
1357
|
if (options.envProjectId) {
|
|
1350
1358
|
const project = projects.find((candidate) => candidate.id === options.envProjectId);
|
|
1351
1359
|
if (!project) throw projectNotFoundError(options.envProjectId, workspace);
|
|
1352
|
-
return
|
|
1360
|
+
return withRemoteDeployBranch(provider, {
|
|
1353
1361
|
workspace,
|
|
1354
1362
|
project: toProjectSummary(project),
|
|
1355
1363
|
resolution: {
|
|
@@ -1357,14 +1365,14 @@ async function resolveDeployProjectContext(context, client, provider, explicitPr
|
|
|
1357
1365
|
targetName: options.envProjectId,
|
|
1358
1366
|
targetNameSource: "env"
|
|
1359
1367
|
}
|
|
1360
|
-
}, branch);
|
|
1368
|
+
}, branch, context.runtime.signal);
|
|
1361
1369
|
}
|
|
1362
1370
|
const localPin = options.localPin;
|
|
1363
1371
|
if (localPin.kind === "present") {
|
|
1364
1372
|
if (localPin.pin.workspaceId !== workspace.id) throw localResolutionPinStaleError();
|
|
1365
1373
|
const project = projects.find((candidate) => candidate.id === localPin.pin.projectId);
|
|
1366
1374
|
if (!project) throw localResolutionPinStaleError();
|
|
1367
|
-
return
|
|
1375
|
+
return withRemoteDeployBranch(provider, {
|
|
1368
1376
|
workspace,
|
|
1369
1377
|
project: toProjectSummary(project),
|
|
1370
1378
|
resolution: {
|
|
@@ -1372,10 +1380,10 @@ async function resolveDeployProjectContext(context, client, provider, explicitPr
|
|
|
1372
1380
|
targetName: project.name,
|
|
1373
1381
|
targetNameSource: "local-pin"
|
|
1374
1382
|
}
|
|
1375
|
-
}, branch);
|
|
1383
|
+
}, branch, context.runtime.signal);
|
|
1376
1384
|
}
|
|
1377
1385
|
const platformMapping = await resolveDurablePlatformMapping();
|
|
1378
|
-
if (platformMapping && platformMapping.workspace.id === workspace.id) return
|
|
1386
|
+
if (platformMapping && platformMapping.workspace.id === workspace.id) return withRemoteDeployBranch(provider, {
|
|
1379
1387
|
workspace,
|
|
1380
1388
|
project: toProjectSummary(platformMapping),
|
|
1381
1389
|
resolution: {
|
|
@@ -1383,8 +1391,8 @@ async function resolveDeployProjectContext(context, client, provider, explicitPr
|
|
|
1383
1391
|
targetName: platformMapping.name,
|
|
1384
1392
|
targetNameSource: "platform-mapping"
|
|
1385
1393
|
}
|
|
1386
|
-
}, branch);
|
|
1387
|
-
if (canPrompt(context) && !context.flags.yes) return
|
|
1394
|
+
}, branch, context.runtime.signal);
|
|
1395
|
+
if (canPrompt(context) && !context.flags.yes) return withRemoteDeployBranch(provider, await resolveInteractiveDeployProjectSetup(context, provider, workspace, projects), branch, context.runtime.signal);
|
|
1388
1396
|
throw projectSetupRequiredError(projects, await inferTargetName(context.runtime.cwd, context.runtime.signal));
|
|
1389
1397
|
}
|
|
1390
1398
|
async function resolveInteractiveDeployProjectSetup(context, provider, workspace, projects) {
|
|
@@ -1430,12 +1438,16 @@ async function createProjectForDeploySetup(provider, projectName, workspace, sig
|
|
|
1430
1438
|
workspace
|
|
1431
1439
|
};
|
|
1432
1440
|
}
|
|
1433
|
-
function
|
|
1441
|
+
async function withRemoteDeployBranch(provider, target, branch, signal) {
|
|
1442
|
+
const remoteBranch = await provider.resolveBranch(target.project.id, {
|
|
1443
|
+
branchName: branch.name,
|
|
1444
|
+
signal
|
|
1445
|
+
});
|
|
1434
1446
|
return {
|
|
1435
1447
|
...target,
|
|
1436
1448
|
branch: {
|
|
1437
|
-
name:
|
|
1438
|
-
kind:
|
|
1449
|
+
name: remoteBranch.name,
|
|
1450
|
+
kind: remoteBranch.role
|
|
1439
1451
|
}
|
|
1440
1452
|
};
|
|
1441
1453
|
}
|
|
@@ -1470,42 +1482,6 @@ async function resolveDeployBranch(context, explicitBranchName) {
|
|
|
1470
1482
|
annotation: "default"
|
|
1471
1483
|
};
|
|
1472
1484
|
}
|
|
1473
|
-
async function readLocalGitBranch(cwd, signal) {
|
|
1474
|
-
const headPath = await resolveGitHeadPath(path.join(cwd, ".git"), signal);
|
|
1475
|
-
if (!headPath) return null;
|
|
1476
|
-
try {
|
|
1477
|
-
const head = (await readFile(headPath, {
|
|
1478
|
-
encoding: "utf8",
|
|
1479
|
-
signal
|
|
1480
|
-
})).trim();
|
|
1481
|
-
if (head.startsWith("ref: refs/heads/")) return head.slice(16);
|
|
1482
|
-
} catch (error) {
|
|
1483
|
-
if (signal.aborted) throw error;
|
|
1484
|
-
return null;
|
|
1485
|
-
}
|
|
1486
|
-
return null;
|
|
1487
|
-
}
|
|
1488
|
-
async function resolveGitHeadPath(gitPath, signal) {
|
|
1489
|
-
signal.throwIfAborted();
|
|
1490
|
-
try {
|
|
1491
|
-
const raw = await readFile(gitPath, {
|
|
1492
|
-
encoding: "utf8",
|
|
1493
|
-
signal
|
|
1494
|
-
});
|
|
1495
|
-
if (raw.startsWith("gitdir:")) return path.join(path.resolve(path.dirname(gitPath), raw.slice(7).trim()), "HEAD");
|
|
1496
|
-
} catch (error) {
|
|
1497
|
-
if (signal.aborted) throw error;
|
|
1498
|
-
}
|
|
1499
|
-
signal.throwIfAborted();
|
|
1500
|
-
try {
|
|
1501
|
-
await access(path.join(gitPath, "HEAD"));
|
|
1502
|
-
signal.throwIfAborted();
|
|
1503
|
-
return path.join(gitPath, "HEAD");
|
|
1504
|
-
} catch (error) {
|
|
1505
|
-
if (signal.aborted) throw error;
|
|
1506
|
-
return null;
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
1485
|
async function resolveDeployFramework(context, options) {
|
|
1510
1486
|
if (options.requestedFramework) return frameworkFromUserFacingValue(options.requestedFramework, "set by --framework");
|
|
1511
1487
|
if (options.entrypoint) return {
|
|
@@ -1,73 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CliError, authRequiredError, workspaceRequiredError } from "../shell/errors.js";
|
|
2
|
+
import { requireComputeAuth } from "../lib/auth/guard.js";
|
|
3
|
+
import { resolveProjectTarget } from "../lib/project/resolution.js";
|
|
3
4
|
import { createCliUseCaseGateways } from "../use-cases/create-cli-gateways.js";
|
|
4
5
|
import { createSelectPromptPort } from "./select-prompt-port.js";
|
|
6
|
+
import { requireAuthenticatedAuthState } from "./auth.js";
|
|
7
|
+
import { listRealWorkspaceProjects } from "./project.js";
|
|
5
8
|
import { createBranchUseCases } from "../use-cases/branch.js";
|
|
6
9
|
//#region src/controllers/branch.ts
|
|
7
|
-
const PREVIEW_BRANCH_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8
10
|
function isRealMode(context) {
|
|
9
11
|
return !context.runtime.fixturePath && !context.runtime.env.PRISMA_CLI_MOCK_FIXTURE_PATH;
|
|
10
12
|
}
|
|
11
13
|
async function runBranchList(context) {
|
|
12
|
-
if (isRealMode(context))
|
|
13
|
-
return {
|
|
14
|
+
if (isRealMode(context)) return {
|
|
14
15
|
command: "branch.list",
|
|
15
|
-
result: await
|
|
16
|
+
result: await listRealBranches(context),
|
|
16
17
|
warnings: [],
|
|
17
18
|
nextSteps: []
|
|
18
19
|
};
|
|
19
|
-
}
|
|
20
|
-
async function runBranchShow(context) {
|
|
21
|
-
if (isRealMode(context)) throw branchCommandsUnavailableError();
|
|
22
|
-
const result = await createBranchUseCases(createCliUseCaseGateways(context)).show();
|
|
23
20
|
return {
|
|
24
|
-
command: "branch.
|
|
25
|
-
result,
|
|
21
|
+
command: "branch.list",
|
|
22
|
+
result: await createBranchUseCases(createCliUseCaseGateways(context)).list(),
|
|
26
23
|
warnings: [],
|
|
27
|
-
nextSteps:
|
|
24
|
+
nextSteps: []
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
|
-
async function
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
async function listRealBranches(context) {
|
|
28
|
+
const authState = await requireAuthenticatedAuthState(context);
|
|
29
|
+
const client = await requireComputeAuth(context.runtime.env, context.runtime.signal);
|
|
30
|
+
if (!client) throw authRequiredError(["prisma-cli auth login"]);
|
|
31
|
+
const workspace = authState.workspace;
|
|
32
|
+
if (!workspace) throw workspaceRequiredError();
|
|
33
|
+
const target = await resolveProjectTarget({
|
|
34
|
+
context,
|
|
35
|
+
workspace,
|
|
36
|
+
listProjects: () => listRealWorkspaceProjects(client, workspace, context.runtime.signal),
|
|
37
|
+
prompt: createSelectPromptPort(context),
|
|
38
|
+
remember: true
|
|
39
|
+
});
|
|
40
|
+
const branches = await listBranches(client, target.project.id, context.runtime.signal);
|
|
36
41
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
nextSteps: result.branch.kind === "preview" && !result.branch.remoteState ? ["prisma-cli branch show", "prisma-cli app deploy"] : ["prisma-cli branch show"]
|
|
42
|
+
projectId: target.project.id,
|
|
43
|
+
projectName: target.project.name,
|
|
44
|
+
branches: sortBranches(branches.map(toBranchSummary))
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
choices: result.branches.map((branch) => ({
|
|
50
|
-
label: renderBranchChoiceLabel(branch),
|
|
51
|
-
value: branch.name
|
|
52
|
-
}))
|
|
47
|
+
function sortBranches(branches) {
|
|
48
|
+
return branches.slice().sort((left, right) => {
|
|
49
|
+
const leftRank = branchOrder(left);
|
|
50
|
+
const rightRank = branchOrder(right);
|
|
51
|
+
if (leftRank !== rightRank) return leftRank - rightRank;
|
|
52
|
+
return left.name.localeCompare(right.name);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
if (branch.active) markers.push("active");
|
|
58
|
-
if (!branch.remoteState) markers.push("not created yet");
|
|
59
|
-
return markers.length > 0 ? `${branch.name} (${markers.join(", ")})` : branch.name;
|
|
55
|
+
function branchOrder(branch) {
|
|
56
|
+
return branch.role === "production" ? 0 : 1;
|
|
60
57
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
async function listBranches(client, projectId, signal) {
|
|
59
|
+
const collected = [];
|
|
60
|
+
let cursor;
|
|
61
|
+
while (true) {
|
|
62
|
+
const query = {};
|
|
63
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
64
|
+
const { data, error, response } = await client.GET("/v1/projects/{projectId}/branches", {
|
|
65
|
+
params: {
|
|
66
|
+
path: { projectId },
|
|
67
|
+
query
|
|
68
|
+
},
|
|
69
|
+
signal
|
|
70
|
+
});
|
|
71
|
+
if (error || !data) throw branchApiError("Failed to list branches", response, error);
|
|
72
|
+
collected.push(...data.data);
|
|
73
|
+
if (!data.pagination.hasMore || !data.pagination.nextCursor) break;
|
|
74
|
+
cursor = data.pagination.nextCursor;
|
|
75
|
+
}
|
|
76
|
+
return collected;
|
|
65
77
|
}
|
|
66
|
-
function
|
|
67
|
-
return
|
|
78
|
+
function toBranchSummary(branch) {
|
|
79
|
+
return {
|
|
80
|
+
id: branch.id,
|
|
81
|
+
name: branch.gitName,
|
|
82
|
+
role: branch.role,
|
|
83
|
+
envMap: branch.role
|
|
84
|
+
};
|
|
68
85
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
86
|
+
function branchApiError(summary, response, error) {
|
|
87
|
+
const status = response?.status ?? 0;
|
|
88
|
+
return new CliError({
|
|
89
|
+
code: error?.error?.code ?? "BRANCH_API_ERROR",
|
|
90
|
+
domain: "branch",
|
|
91
|
+
summary,
|
|
92
|
+
why: error?.error?.message ?? `The Management API returned status ${status || "unknown"}.`,
|
|
93
|
+
fix: error?.error?.hint ?? "Re-run with --trace for the underlying API response details.",
|
|
94
|
+
exitCode: 1,
|
|
95
|
+
nextSteps: []
|
|
96
|
+
});
|
|
71
97
|
}
|
|
72
98
|
//#endregion
|
|
73
|
-
export { runBranchList
|
|
99
|
+
export { runBranchList };
|