@prisma/composer-cli 0.6.0-dev.21
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/LICENSE +201 -0
- package/dist/bin.mjs +987 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/container-transport-DKmKg5JQ-CoY4XPma.mjs +30 -0
- package/dist/container-transport-DKmKg5JQ-CoY4XPma.mjs.map +1 -0
- package/dist/execute-deploy-destroy-DfVJUICu-D-kARRtf.mjs +317 -0
- package/dist/execute-deploy-destroy-DfVJUICu-D-kARRtf.mjs.map +1 -0
- package/dist/execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs +316 -0
- package/dist/execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs.map +1 -0
- package/dist/execute-dev-BMTFWfFc-B1whS-Rr.mjs +2011 -0
- package/dist/execute-dev-BMTFWfFc-B1whS-Rr.mjs.map +1 -0
- package/dist/execute-dev-BMTFWfFc-D0niyhe3.mjs +2012 -0
- package/dist/execute-dev-BMTFWfFc-D0niyhe3.mjs.map +1 -0
- package/dist/execute-log-Cay9hlKW-DJMh35AZ.mjs +158 -0
- package/dist/execute-log-Cay9hlKW-DJMh35AZ.mjs.map +1 -0
- package/dist/execute-log-Cay9hlKW-DrMeVOXq.mjs +157 -0
- package/dist/execute-log-Cay9hlKW-DrMeVOXq.mjs.map +1 -0
- package/dist/family-DkH0si4D-CN5QubKS.d.mts +1294 -0
- package/dist/family-DkH0si4D-CN5QubKS.d.mts.map +1 -0
- package/dist/family.d.mts +52 -0
- package/dist/family.d.mts.map +1 -0
- package/dist/family.mjs +923 -0
- package/dist/family.mjs.map +1 -0
- package/dist/local-target-CBZyaBy0.mjs +68 -0
- package/dist/local-target-CBZyaBy0.mjs.map +1 -0
- package/dist/local-target-H0IWu_FM.mjs +68 -0
- package/dist/local-target-H0IWu_FM.mjs.map +1 -0
- package/dist/pipeline-AoW8zq4I-C6Qe0VaZ.mjs +976 -0
- package/dist/pipeline-AoW8zq4I-C6Qe0VaZ.mjs.map +1 -0
- package/dist/pipeline-AoW8zq4I-DYNbf-ad.mjs +977 -0
- package/dist/pipeline-AoW8zq4I-DYNbf-ad.mjs.map +1 -0
- package/dist/result-B4XjxVK6.mjs +384 -0
- package/dist/result-B4XjxVK6.mjs.map +1 -0
- package/dist/result-D4d-xy4I.mjs +230 -0
- package/dist/result-D4d-xy4I.mjs.map +1 -0
- package/dist/run-alchemy-D44OZlyB-DA7s331N.mjs +93 -0
- package/dist/run-alchemy-D44OZlyB-DA7s331N.mjs.map +1 -0
- package/dist/run-alchemy-D44OZlyB-wmf8mHRE.mjs +93 -0
- package/dist/run-alchemy-D44OZlyB-wmf8mHRE.mjs.map +1 -0
- package/dist/shared-BTnATsqm-CDCqKwCF.mjs +158 -0
- package/dist/shared-BTnATsqm-CDCqKwCF.mjs.map +1 -0
- package/dist/testing.d.mts +53 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +151 -0
- package/dist/testing.mjs.map +1 -0
- package/package.json +53 -0
- package/src/exports/family.ts +14 -0
- package/src/exports/testing.ts +6 -0
package/dist/bin.mjs
ADDED
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as executionDiagnostics, l as DOCS_BASE, o as executorLoadFailure, t as notOk$1 } from "./result-B4XjxVK6.mjs";
|
|
3
|
+
import { t as alchemyCommandLine } from "./run-alchemy-D44OZlyB-DA7s331N.mjs";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { EnvironmentCredentialManager, createCli, defineCommand, defineCommandFamily, defineConfigSection, defineSessionCommand, exitWithChildStatus, flag, loadConfig, positional } from "@prisma/cli-engine";
|
|
8
|
+
import { CliStructuredError, notOk, ok } from "@prisma/cli-engine/protocol";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
//#region ../../0-framework/3-tooling/cli/dist/log-DfT2hHqi.mjs
|
|
11
|
+
/** In-package variant threading the injection seam (the CLI's RunDeps, unit
|
|
12
|
+
* tests). Deliberately NOT re-exported through `./control` — the seam mirrors
|
|
13
|
+
* internal types and is not part of the published surface. */
|
|
14
|
+
async function deployWithDeps(input, deps) {
|
|
15
|
+
const cwd = input.cwd ?? process.cwd();
|
|
16
|
+
let executor;
|
|
17
|
+
try {
|
|
18
|
+
executor = await import("./execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs");
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return notOk$1(executorLoadFailure("deploy", error, cwd));
|
|
21
|
+
}
|
|
22
|
+
return executor.executeDeploy(input, deps, cwd);
|
|
23
|
+
}
|
|
24
|
+
/** In-package variant threading the injection seam (the CLI's RunDeps, unit
|
|
25
|
+
* tests). Deliberately NOT re-exported through `./control` — the seam mirrors
|
|
26
|
+
* internal types and is not part of the published surface. */
|
|
27
|
+
async function destroyWithDeps(input, deps) {
|
|
28
|
+
const cwd = input.cwd ?? process.cwd();
|
|
29
|
+
let executor;
|
|
30
|
+
try {
|
|
31
|
+
executor = await import("./execute-deploy-destroy-DfVJUICu-quUQ08T8.mjs");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return notOk$1(executorLoadFailure("destroy", error, cwd));
|
|
34
|
+
}
|
|
35
|
+
return executor.executeDestroy(input, deps, cwd);
|
|
36
|
+
}
|
|
37
|
+
/** In-package variant threading the injection seam (the CLI's RunDeps, unit
|
|
38
|
+
* tests). Deliberately NOT re-exported through `./control` — the seam mirrors
|
|
39
|
+
* internal types and is not part of the published surface. */
|
|
40
|
+
async function devWithDeps(input, deps) {
|
|
41
|
+
const cwd = input.cwd ?? process.cwd();
|
|
42
|
+
let executor;
|
|
43
|
+
try {
|
|
44
|
+
executor = await import("./execute-dev-BMTFWfFc-B1whS-Rr.mjs");
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return notOk$1(executorLoadFailure("dev", error, cwd));
|
|
47
|
+
}
|
|
48
|
+
return executor.executeDev(input, deps, cwd);
|
|
49
|
+
}
|
|
50
|
+
/** In-package variant threading the injection seam (the CLI's LogRunDeps,
|
|
51
|
+
* unit tests). Deliberately NOT re-exported through `./control` — the seam
|
|
52
|
+
* mirrors internal types and is not part of the published surface. */
|
|
53
|
+
async function logWithDeps(input, deps) {
|
|
54
|
+
const cwd = input.cwd ?? process.cwd();
|
|
55
|
+
let executor;
|
|
56
|
+
try {
|
|
57
|
+
executor = await import("./execute-log-Cay9hlKW-DrMeVOXq.mjs");
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return notOk$1(executorLoadFailure("log", error, cwd));
|
|
60
|
+
}
|
|
61
|
+
return executor.executeLog(input, deps, cwd);
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region ../../0-framework/3-tooling/cli/dist/engine-cli-BurDkrQe.mjs
|
|
65
|
+
/**
|
|
66
|
+
* The family boundary's error translation.
|
|
67
|
+
*
|
|
68
|
+
* Composer and the engine each carry a class called `CliStructuredError`, both
|
|
69
|
+
* descended from the same prisma/prisma foundation, and both recognize errors
|
|
70
|
+
* by duck-typing on `name === 'CliStructuredError'`. That means a composer
|
|
71
|
+
* error handed to the engine untranslated is ACCEPTED — it does not fail
|
|
72
|
+
* loudly, it renders. What it loses is its `fix`: composer's foundation
|
|
73
|
+
* carries remediation as one prose string on that field, the engine carries it
|
|
74
|
+
* as a `nextActions` list and has no `fix` at all, so the fix text is dropped
|
|
75
|
+
* silently and the user is told what broke with no word on what to do about
|
|
76
|
+
* it. Nothing about that failure is visible without a test that looks for the
|
|
77
|
+
* fix on the other side, which is why there is one.
|
|
78
|
+
*
|
|
79
|
+
* Everything else on the envelope survives as-is; only remediation changes
|
|
80
|
+
* representation.
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Composer's `fix` is free prose — "add this overrides block and reinstall",
|
|
84
|
+
* "run the build, then retry" — with no machine-readable command inside it.
|
|
85
|
+
* `user-choice` is the engine's own kind for exactly that (it is what the
|
|
86
|
+
* engine uses for its own config and prompt failures), so the text carries
|
|
87
|
+
* over verbatim as one action rather than being parsed into a command the
|
|
88
|
+
* author never wrote.
|
|
89
|
+
*/
|
|
90
|
+
function fixAsNextActions(fix) {
|
|
91
|
+
return fix === void 0 ? [] : [{
|
|
92
|
+
kind: "user-choice",
|
|
93
|
+
label: fix
|
|
94
|
+
}];
|
|
95
|
+
}
|
|
96
|
+
/** Translates a composer failure into the engine's error type. Composer-side detail — `meta`, `where`, `docsUrl` — rides along untouched. */
|
|
97
|
+
function toEngineError(error) {
|
|
98
|
+
return new CliStructuredError(error.code, error.message, {
|
|
99
|
+
severity: error.severity,
|
|
100
|
+
nextActions: fixAsNextActions(error.fix),
|
|
101
|
+
...error.why === void 0 ? {} : { why: error.why },
|
|
102
|
+
...error.where === void 0 ? {} : { where: error.where },
|
|
103
|
+
...error.meta === void 0 ? {} : { meta: error.meta },
|
|
104
|
+
...error.docsUrl === void 0 ? {} : { docsUrl: error.docsUrl },
|
|
105
|
+
cause: error
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** The adapter the operations call, backed by the engine's `ctx.spawn` so the
|
|
109
|
+
* terminal reaches alchemy natively and the engine owns signal policy. */
|
|
110
|
+
function convergeSpawn(ctx) {
|
|
111
|
+
return async (invocation) => {
|
|
112
|
+
const line = alchemyCommandLine(invocation);
|
|
113
|
+
return await ctx.spawn({
|
|
114
|
+
command: line.command,
|
|
115
|
+
args: line.args,
|
|
116
|
+
cwd: line.cwd,
|
|
117
|
+
env: line.env
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** The in-process leg's deps: composer's existing seam, carrying the engine's
|
|
122
|
+
* own client and workspace id rather than anything read from the env. */
|
|
123
|
+
function operationDeps(spec) {
|
|
124
|
+
return {
|
|
125
|
+
alchemy: spec.alchemy,
|
|
126
|
+
configPath: spec.configPath,
|
|
127
|
+
credentials: {
|
|
128
|
+
workspaceId: spec.workspaceId,
|
|
129
|
+
client: spec.client
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The reproduce hint a failed converge carries. Deliberately absent for an
|
|
135
|
+
* aborted one: the user stopped it, so there is nothing to reproduce.
|
|
136
|
+
*/
|
|
137
|
+
function reproduceHint(failure) {
|
|
138
|
+
const diagnostics = executionDiagnostics(failure);
|
|
139
|
+
if (diagnostics === void 0) return [];
|
|
140
|
+
return [{
|
|
141
|
+
kind: "run-command",
|
|
142
|
+
label: `Run the converge directly from ${diagnostics.cwd} to reproduce this`,
|
|
143
|
+
command: diagnostics.reproduceCommand,
|
|
144
|
+
reason: `Generated stack file: ${diagnostics.stackFilePath}`
|
|
145
|
+
}];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* How a FAILED converge settles. `deploy`, `destroy` and `dev` all end this
|
|
149
|
+
* way and must not drift apart, so the decision lives here once rather than
|
|
150
|
+
* inline in each handler.
|
|
151
|
+
*
|
|
152
|
+
* A failure that reached the child exits with the child's status verbatim and
|
|
153
|
+
* carries the reproduce hint; a failure that never reached the child is an
|
|
154
|
+
* ordinary structured error and gets the normal envelope. Nothing here reads
|
|
155
|
+
* `signal` — see settleConverge.
|
|
156
|
+
*/
|
|
157
|
+
function settleConvergeFailure(failure, ctx) {
|
|
158
|
+
const child = ctx.lastChild();
|
|
159
|
+
if (child !== void 0 && child.exitCode !== 0) return ok(exitWithChildStatus({ nextActions: reproduceHint(failure) }));
|
|
160
|
+
return notOk(toEngineError(failure));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* How a converge settles, now that the engine owns the child's status.
|
|
164
|
+
*
|
|
165
|
+
* Nothing here reads `signal`. `exitWithChildStatus` settles from the engine's
|
|
166
|
+
* own record of the child, and a signal-killed one overrules whatever this
|
|
167
|
+
* function asked for: 128 + the signal, no failure envelope, and the reproduce
|
|
168
|
+
* hint dropped, because the user stopped the run and there is nothing to
|
|
169
|
+
* reproduce.
|
|
170
|
+
*
|
|
171
|
+
* What is left is the operation's own verdict. A failure that reached the
|
|
172
|
+
* child exits with the child's status verbatim and carries the reproduce hint;
|
|
173
|
+
* a failure that never reached the child is an ordinary structured error and
|
|
174
|
+
* gets the normal envelope.
|
|
175
|
+
*
|
|
176
|
+
* A SUCCESS presents its result even when the child was signal-killed. No
|
|
177
|
+
* composer operation produces that pair today — each one reports a
|
|
178
|
+
* signal-killed converge as a failure — and an operation that ever did would
|
|
179
|
+
* have a real result worth showing. The run still exits 130, because the
|
|
180
|
+
* engine settles a signal-terminated run from its own record of the signal
|
|
181
|
+
* whatever the handler returns.
|
|
182
|
+
*/
|
|
183
|
+
function settleConverge(result, ctx, present) {
|
|
184
|
+
if (!result.ok) return settleConvergeFailure(result.failure, ctx);
|
|
185
|
+
return ok(present(result.value));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Composer's projection into `prisma.config.ts` — the `composer` section.
|
|
189
|
+
*
|
|
190
|
+
* The section is deliberately tiny. Composer's real configuration lives in
|
|
191
|
+
* `prisma-composer.config.ts`, which holds executable values (Effect layers,
|
|
192
|
+
* provider factories, container lifecycles) and can only be understood by
|
|
193
|
+
* evaluating it inside a running command. A config-section validator loads
|
|
194
|
+
* with the command tree at start-up and must be dependency-light and total,
|
|
195
|
+
* so it is the wrong place to evaluate any of that. What the section carries
|
|
196
|
+
* is therefore only the one fact the engine can usefully know before a
|
|
197
|
+
* command runs: WHERE that file is, when the user wants to say so.
|
|
198
|
+
*
|
|
199
|
+
* Its fields grow only by amending the slice contract.
|
|
200
|
+
*/
|
|
201
|
+
const KNOWN_FIELDS = ["configPath"];
|
|
202
|
+
function diagnostic(spec) {
|
|
203
|
+
return {
|
|
204
|
+
code: spec.code,
|
|
205
|
+
severity: spec.severity,
|
|
206
|
+
summary: spec.summary,
|
|
207
|
+
...spec.why === void 0 ? {} : { why: spec.why },
|
|
208
|
+
nextActions: spec.fix === void 0 ? [] : [{
|
|
209
|
+
kind: "edit-file",
|
|
210
|
+
label: spec.fix
|
|
211
|
+
}]
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function validate(raw) {
|
|
215
|
+
if (raw === void 0) return {
|
|
216
|
+
ok: true,
|
|
217
|
+
value: {},
|
|
218
|
+
diagnostics: []
|
|
219
|
+
};
|
|
220
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return {
|
|
221
|
+
ok: false,
|
|
222
|
+
diagnostics: [diagnostic({
|
|
223
|
+
code: "CONFIG.FIELD_INVALID",
|
|
224
|
+
severity: "error",
|
|
225
|
+
summary: "The `composer` section of prisma.config.ts must be an object.",
|
|
226
|
+
fix: "Write `composer: { configPath: \"./prisma-composer.config.ts\" }`, or remove the section entirely."
|
|
227
|
+
})]
|
|
228
|
+
};
|
|
229
|
+
let record;
|
|
230
|
+
try {
|
|
231
|
+
record = { ...raw };
|
|
232
|
+
} catch {
|
|
233
|
+
return {
|
|
234
|
+
ok: false,
|
|
235
|
+
diagnostics: [diagnostic({
|
|
236
|
+
code: "CONFIG.FIELD_INVALID",
|
|
237
|
+
severity: "error",
|
|
238
|
+
summary: "The `composer` section of prisma.config.ts could not be read.",
|
|
239
|
+
why: "Reading its fields threw, so nothing in it can be trusted.",
|
|
240
|
+
fix: "Write it as a plain object literal, e.g. `composer: { configPath: \"./prisma-composer.config.ts\" }`."
|
|
241
|
+
})]
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const configPath = record["configPath"];
|
|
245
|
+
if (configPath !== void 0 && (typeof configPath !== "string" || configPath.length === 0)) return {
|
|
246
|
+
ok: false,
|
|
247
|
+
diagnostics: [diagnostic({
|
|
248
|
+
code: "CONFIG.FIELD_INVALID",
|
|
249
|
+
severity: "error",
|
|
250
|
+
summary: "`composer.configPath` must be a non-empty string.",
|
|
251
|
+
why: "It names the prisma-composer.config.ts file to load.",
|
|
252
|
+
fix: "Set it to a path, or remove it to search upward from the entry."
|
|
253
|
+
})]
|
|
254
|
+
};
|
|
255
|
+
const unknown = Object.keys(record).filter((key) => !KNOWN_FIELDS.includes(key));
|
|
256
|
+
return {
|
|
257
|
+
ok: true,
|
|
258
|
+
value: configPath === void 0 ? {} : { configPath },
|
|
259
|
+
diagnostics: unknown.map((key) => diagnostic({
|
|
260
|
+
code: "CONFIG.FIELD_UNKNOWN",
|
|
261
|
+
severity: "warn",
|
|
262
|
+
summary: `The \`composer\` section has no field \`${key}\`; it is ignored.`,
|
|
263
|
+
fix: `Remove \`${key}\`, or check it against the version of @prisma/composer you have installed.`
|
|
264
|
+
}))
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const composerSection = defineConfigSection({
|
|
268
|
+
name: "composer",
|
|
269
|
+
validate
|
|
270
|
+
});
|
|
271
|
+
/**
|
|
272
|
+
* The workspace the in-process leg acts in, from the engine's credential
|
|
273
|
+
* read. Handlers never decode a token and never read PRISMA_WORKSPACE_ID:
|
|
274
|
+
* whether the credential came from a stored session or the environment, the
|
|
275
|
+
* engine has already resolved it, and branching on where it came from is a
|
|
276
|
+
* defect by the credential-manager design.
|
|
277
|
+
*
|
|
278
|
+
* Undefined when the active credential names no workspace — an environment
|
|
279
|
+
* token whose claims carry none. The container descriptors raise their own
|
|
280
|
+
* "workspace required" error in that case, which is the error the user needs.
|
|
281
|
+
*/
|
|
282
|
+
async function workspaceIdOf(ctx) {
|
|
283
|
+
return (await ctx.activeCredential())?.workspaceId;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* `deploy <entry>` — a result command that hands the terminal to alchemy.
|
|
287
|
+
*
|
|
288
|
+
* `--production` is gone. It was accepted and then always errored ("only
|
|
289
|
+
* valid with destroy"), so no invocation using it could ever have succeeded;
|
|
290
|
+
* deploy targets production by default when no `--stage` is given.
|
|
291
|
+
*/
|
|
292
|
+
const createDeployCommand = (operations) => defineCommand({
|
|
293
|
+
help: {
|
|
294
|
+
summary: "Deploy the application whose root node is <entry>'s default export.",
|
|
295
|
+
examples: ["{bin} deploy src/service.ts", "{bin} deploy src/service.ts --stage feat-auth"]
|
|
296
|
+
},
|
|
297
|
+
args: {
|
|
298
|
+
positionals: { entry: positional.string({
|
|
299
|
+
brief: "The module whose default export is the application root.",
|
|
300
|
+
placeholder: "entry"
|
|
301
|
+
}) },
|
|
302
|
+
flags: {
|
|
303
|
+
name: flag.string({
|
|
304
|
+
brief: "Override the root node's name — the deploy's application name.",
|
|
305
|
+
placeholder: "name"
|
|
306
|
+
}),
|
|
307
|
+
stage: flag.string({
|
|
308
|
+
brief: "Deploy scope to target; omit for production.",
|
|
309
|
+
placeholder: "stage"
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
needs: {
|
|
314
|
+
config: composerSection,
|
|
315
|
+
credentials: "child"
|
|
316
|
+
},
|
|
317
|
+
maySpawn: true,
|
|
318
|
+
handler: async (args, ctx) => {
|
|
319
|
+
const alchemy = convergeSpawn(ctx);
|
|
320
|
+
return settleConverge(await operations.deploy({
|
|
321
|
+
entry: args.positionals.entry,
|
|
322
|
+
name: args.flags.name,
|
|
323
|
+
stage: args.flags.stage,
|
|
324
|
+
cwd: ctx.cwd
|
|
325
|
+
}, operationDeps({
|
|
326
|
+
alchemy,
|
|
327
|
+
configPath: ctx.config.configPath,
|
|
328
|
+
workspaceId: await workspaceIdOf(ctx),
|
|
329
|
+
client: ctx.api
|
|
330
|
+
})), ctx, ({ summary }) => ctx.present({ data: { summary: summary ?? null } }, {
|
|
331
|
+
human: (ui) => summary === void 0 ? [{
|
|
332
|
+
kind: "summary",
|
|
333
|
+
status: "ok",
|
|
334
|
+
text: "Deployed."
|
|
335
|
+
}] : [{
|
|
336
|
+
kind: "summary",
|
|
337
|
+
status: "ok",
|
|
338
|
+
text: `Deployed ${ui.emphasize(summary.app)}.`
|
|
339
|
+
}, {
|
|
340
|
+
kind: "table",
|
|
341
|
+
columns: ["Address", "Deployed"],
|
|
342
|
+
rows: summary.nodes.map((node) => [node.address, node.entities.map((entity) => `${entity.kind} ${entity.id}`).join(", ")])
|
|
343
|
+
}],
|
|
344
|
+
stdout: () => [],
|
|
345
|
+
json: () => ({ summary: summary ?? null }),
|
|
346
|
+
next: () => []
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
/**
|
|
351
|
+
* `destroy`'s target, from its two mutually exclusive flags. Kept out of the
|
|
352
|
+
* grammar because the engine's flag layer has no "exactly one of these"
|
|
353
|
+
* construct — and because both wrong shapes need their own remedy, which a
|
|
354
|
+
* generic arity error could not give.
|
|
355
|
+
*/
|
|
356
|
+
function targetOf(stage, production) {
|
|
357
|
+
if (stage !== void 0 && production) return notOk(new CliStructuredError("DEPLOY.TARGET_CONFLICT", "Pass either --stage <name> or --production to `destroy`, not both."));
|
|
358
|
+
if (stage === void 0 && !production) return notOk(new CliStructuredError("DEPLOY.TARGET_MISSING", "`destroy` requires an explicit target.", { nextActions: [{
|
|
359
|
+
kind: "user-choice",
|
|
360
|
+
label: "Pass --stage <name> to tear down a branch environment, or --production to tear down the production environment."
|
|
361
|
+
}] }));
|
|
362
|
+
return ok(stage !== void 0 ? {
|
|
363
|
+
kind: "stage",
|
|
364
|
+
stage
|
|
365
|
+
} : { kind: "production" });
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* `destroy <entry>` — deploy's mirror: same derivation, alchemy destroy.
|
|
369
|
+
*
|
|
370
|
+
* No confirmation prompt, matching the CLI this replaces. The front door
|
|
371
|
+
* cannot know what the child will tear down, so a consent step here would be
|
|
372
|
+
* asking the user to approve a list nobody has computed yet; if destroy
|
|
373
|
+
* deserves one it belongs in composer's own operation, not in the grammar.
|
|
374
|
+
*/
|
|
375
|
+
const createDestroyCommand = (operations) => defineCommand({
|
|
376
|
+
help: {
|
|
377
|
+
summary: "Tear down the application whose root node is <entry>'s default export.",
|
|
378
|
+
description: "Same derivation as deploy. Requires an explicit target: --stage <name> for a branch environment, or --production for the production environment.",
|
|
379
|
+
examples: ["{bin} destroy src/service.ts --stage feat-auth", "{bin} destroy src/service.ts --production"]
|
|
380
|
+
},
|
|
381
|
+
args: {
|
|
382
|
+
positionals: { entry: positional.string({
|
|
383
|
+
brief: "The module whose default export is the application root.",
|
|
384
|
+
placeholder: "entry"
|
|
385
|
+
}) },
|
|
386
|
+
flags: {
|
|
387
|
+
name: flag.string({
|
|
388
|
+
brief: "Override the root node's name — the application name to tear down.",
|
|
389
|
+
placeholder: "name"
|
|
390
|
+
}),
|
|
391
|
+
stage: flag.string({
|
|
392
|
+
brief: "Tear down this branch environment.",
|
|
393
|
+
placeholder: "stage"
|
|
394
|
+
}),
|
|
395
|
+
production: flag.boolean({ brief: "Tear down the project-level production environment." })
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
needs: {
|
|
399
|
+
config: composerSection,
|
|
400
|
+
credentials: "child"
|
|
401
|
+
},
|
|
402
|
+
maySpawn: true,
|
|
403
|
+
handler: async (args, ctx) => {
|
|
404
|
+
const target = targetOf(args.flags.stage, args.flags.production);
|
|
405
|
+
if (!target.ok) return target;
|
|
406
|
+
const alchemy = convergeSpawn(ctx);
|
|
407
|
+
return settleConverge(await operations.destroy({
|
|
408
|
+
entry: args.positionals.entry,
|
|
409
|
+
name: args.flags.name,
|
|
410
|
+
target: target.value,
|
|
411
|
+
cwd: ctx.cwd,
|
|
412
|
+
onEvent: (event) => {
|
|
413
|
+
if (event.kind !== "no-local-deploy-state") return;
|
|
414
|
+
ctx.report({
|
|
415
|
+
kind: "message",
|
|
416
|
+
severity: "warn",
|
|
417
|
+
text: `No prior deploy state under ${event.cwd} — if you deployed from a different directory, run destroy from there; otherwise this is a no-op.`
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}, operationDeps({
|
|
421
|
+
alchemy,
|
|
422
|
+
configPath: ctx.config.configPath,
|
|
423
|
+
workspaceId: await workspaceIdOf(ctx),
|
|
424
|
+
client: ctx.api
|
|
425
|
+
})), ctx, () => ctx.present({ data: void 0 }, {
|
|
426
|
+
human: () => [{
|
|
427
|
+
kind: "summary",
|
|
428
|
+
status: "ok",
|
|
429
|
+
text: "Destroyed."
|
|
430
|
+
}],
|
|
431
|
+
stdout: () => [],
|
|
432
|
+
json: () => void 0,
|
|
433
|
+
next: () => []
|
|
434
|
+
}));
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
const STOP_STEP = "Stopping the app's services — emulators and data stay up";
|
|
438
|
+
/** Resolves when the run is asked to stop. */
|
|
439
|
+
function stopRequested(signal) {
|
|
440
|
+
if (signal.aborted) return Promise.resolve();
|
|
441
|
+
return new Promise((resolve) => {
|
|
442
|
+
signal.addEventListener("abort", () => resolve(), { once: true });
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* One converge at a time. `ctx.spawn` refuses a second live child, and the
|
|
447
|
+
* watch loop can well fire a rebuild while the previous converge is still
|
|
448
|
+
* running — so a request that arrives during a live converge joins the single
|
|
449
|
+
* queued follow-up instead of starting its own. That extends the coalescing
|
|
450
|
+
* the watcher already does across a burst of edits to cover the converge
|
|
451
|
+
* itself, and it is sound because every dev converge is the SAME invocation:
|
|
452
|
+
* one stack file at one fixed path, rewritten in place before each request.
|
|
453
|
+
*/
|
|
454
|
+
function coalescedConverge(run) {
|
|
455
|
+
let live;
|
|
456
|
+
let queued;
|
|
457
|
+
const start = (invocation) => {
|
|
458
|
+
const outcome = run(invocation);
|
|
459
|
+
const settled = outcome.then(() => void 0, () => void 0);
|
|
460
|
+
live = settled;
|
|
461
|
+
settled.then(() => {
|
|
462
|
+
if (live === settled) live = void 0;
|
|
463
|
+
});
|
|
464
|
+
return outcome;
|
|
465
|
+
};
|
|
466
|
+
return (invocation) => {
|
|
467
|
+
const running = live;
|
|
468
|
+
if (running === void 0) return start(invocation);
|
|
469
|
+
queued ??= running.then(() => {
|
|
470
|
+
queued = void 0;
|
|
471
|
+
return start(invocation);
|
|
472
|
+
});
|
|
473
|
+
return queued;
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
/** The front door, ordered by address depth (fewest dots first) then lexicographically. */
|
|
477
|
+
function frontDoorOrder(endpoints) {
|
|
478
|
+
return [...endpoints].sort((a, b) => {
|
|
479
|
+
const depth = a.address.split(".").length - b.address.split(".").length;
|
|
480
|
+
if (depth !== 0) return depth;
|
|
481
|
+
return a.address < b.address ? -1 : a.address > b.address ? 1 : 0;
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* The operation's events as engine events. The legacy `[dev]` console prefix
|
|
486
|
+
* is gone: these are commentary the engine renders and frames.
|
|
487
|
+
*/
|
|
488
|
+
function reportDevEvent(report, lastChild) {
|
|
489
|
+
let stopFailed = false;
|
|
490
|
+
return (event) => {
|
|
491
|
+
switch (event.kind) {
|
|
492
|
+
case "ready":
|
|
493
|
+
report({
|
|
494
|
+
kind: "status",
|
|
495
|
+
subject: "dev",
|
|
496
|
+
status: "ready"
|
|
497
|
+
});
|
|
498
|
+
for (const endpoint of frontDoorOrder(event.endpoints)) report({
|
|
499
|
+
kind: "endpoint",
|
|
500
|
+
name: endpoint.address,
|
|
501
|
+
url: endpoint.url
|
|
502
|
+
});
|
|
503
|
+
return;
|
|
504
|
+
case "unwatchable":
|
|
505
|
+
report({
|
|
506
|
+
kind: "message",
|
|
507
|
+
severity: "warn",
|
|
508
|
+
text: `${event.address} has no watchable inputs.`
|
|
509
|
+
});
|
|
510
|
+
return;
|
|
511
|
+
case "rebuild-failed":
|
|
512
|
+
report({
|
|
513
|
+
kind: "message",
|
|
514
|
+
severity: "warn",
|
|
515
|
+
text: `Rebuild failed: ${event.message}`
|
|
516
|
+
});
|
|
517
|
+
return;
|
|
518
|
+
case "watch-error":
|
|
519
|
+
report({
|
|
520
|
+
kind: "message",
|
|
521
|
+
severity: "warn",
|
|
522
|
+
text: `Watch error: ${event.message}`
|
|
523
|
+
});
|
|
524
|
+
return;
|
|
525
|
+
case "converge-failed": {
|
|
526
|
+
const child = lastChild();
|
|
527
|
+
if (child !== void 0 && child.signal !== null) return;
|
|
528
|
+
report({
|
|
529
|
+
kind: "message",
|
|
530
|
+
severity: "warn",
|
|
531
|
+
text: `Converge failed — the running app is untouched; still watching.
|
|
532
|
+
Generated stack file: ${event.stackFilePath}\nRun \`${event.reproduceCommand}\` from ${event.cwd} to reproduce this directly.`
|
|
533
|
+
});
|
|
534
|
+
report({
|
|
535
|
+
kind: "remediation",
|
|
536
|
+
action: {
|
|
537
|
+
kind: "run-command",
|
|
538
|
+
label: `Run the converge directly from ${event.cwd} to reproduce this`,
|
|
539
|
+
command: event.reproduceCommand,
|
|
540
|
+
reason: `Generated stack file: ${event.stackFilePath}`
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
case "stopping":
|
|
546
|
+
report({
|
|
547
|
+
kind: "step-started",
|
|
548
|
+
step: STOP_STEP,
|
|
549
|
+
id: "dev-stop"
|
|
550
|
+
});
|
|
551
|
+
return;
|
|
552
|
+
case "stop-error":
|
|
553
|
+
stopFailed = true;
|
|
554
|
+
report({
|
|
555
|
+
kind: "message",
|
|
556
|
+
severity: "warn",
|
|
557
|
+
text: `A service refused to stop: ${event.message}`
|
|
558
|
+
});
|
|
559
|
+
return;
|
|
560
|
+
case "stopped":
|
|
561
|
+
report({
|
|
562
|
+
kind: "step-finished",
|
|
563
|
+
step: STOP_STEP,
|
|
564
|
+
id: "dev-stop",
|
|
565
|
+
outcome: stopFailed ? "warning" : "ok"
|
|
566
|
+
});
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
const createDevCommand = (operations) => defineSessionCommand({
|
|
572
|
+
help: {
|
|
573
|
+
summary: "Bring up the application whose root node is <entry>'s default export, entirely on this machine.",
|
|
574
|
+
description: "Runs credential-free and watches the app for changes, reconverging on every edit. Logs are a separate command; run `log <entry>` to tail them.",
|
|
575
|
+
examples: ["{bin} dev src/service.ts", "{bin} dev src/service.ts --fresh"]
|
|
576
|
+
},
|
|
577
|
+
args: {
|
|
578
|
+
positionals: { entry: positional.string({
|
|
579
|
+
brief: "The module whose default export is the application root.",
|
|
580
|
+
placeholder: "entry"
|
|
581
|
+
}) },
|
|
582
|
+
flags: {
|
|
583
|
+
name: flag.string({
|
|
584
|
+
brief: "Override the root node's name — the dev instance's application name.",
|
|
585
|
+
placeholder: "name"
|
|
586
|
+
}),
|
|
587
|
+
fresh: flag.boolean({ brief: "Destroy the dev stack and wipe the dev state directory before starting." })
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
needs: { config: composerSection },
|
|
591
|
+
maySpawn: true,
|
|
592
|
+
handler: async (args, ctx) => {
|
|
593
|
+
const alchemy = convergeSpawn(ctx);
|
|
594
|
+
const result = await operations.dev({
|
|
595
|
+
entry: args.positionals.entry,
|
|
596
|
+
name: args.flags.name,
|
|
597
|
+
fresh: args.flags.fresh,
|
|
598
|
+
cwd: ctx.cwd,
|
|
599
|
+
onEvent: reportDevEvent(ctx.report, ctx.lastChild)
|
|
600
|
+
}, {
|
|
601
|
+
alchemy: coalescedConverge(alchemy),
|
|
602
|
+
configPath: ctx.config.configPath
|
|
603
|
+
});
|
|
604
|
+
if (!result.ok) return settleConvergeFailure(result.failure, ctx);
|
|
605
|
+
await stopRequested(ctx.signal);
|
|
606
|
+
await result.value.stop();
|
|
607
|
+
return ok(void 0);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
/**
|
|
611
|
+
* `log <entry> [address]` — a session command that tails the merged logs of
|
|
612
|
+
* the app running locally on this machine.
|
|
613
|
+
*
|
|
614
|
+
* It reads the LOCAL dev-emulator daemon, not the platform's logs surface, so
|
|
615
|
+
* it is credential-free. It hands the terminal to nothing, which is why it
|
|
616
|
+
* does not declare `maySpawn` and keeps json support: the log lines ARE its
|
|
617
|
+
* json surface.
|
|
618
|
+
*
|
|
619
|
+
* Windows is refused inside the operation itself (LOG.PLATFORM_UNSUPPORTED),
|
|
620
|
+
* which is why nothing here reads the platform.
|
|
621
|
+
*/
|
|
622
|
+
/** An empty screen reads as broken, so show a little recent history before going live. */
|
|
623
|
+
const DEFAULT_TAIL = 20;
|
|
624
|
+
const createLogCommand = (operations) => defineSessionCommand({
|
|
625
|
+
help: {
|
|
626
|
+
summary: "Tail the merged logs of the locally-running application whose root node is <entry>'s default export.",
|
|
627
|
+
examples: ["{bin} log src/service.ts", "{bin} log src/service.ts catalog.service"]
|
|
628
|
+
},
|
|
629
|
+
args: {
|
|
630
|
+
positionals: {
|
|
631
|
+
entry: positional.string({
|
|
632
|
+
brief: "The module whose default export is the application root.",
|
|
633
|
+
placeholder: "entry"
|
|
634
|
+
}),
|
|
635
|
+
address: positional.optionalString({
|
|
636
|
+
brief: "Only this service's lines, by its dotted address (catalog.service); every service when absent.",
|
|
637
|
+
placeholder: "address"
|
|
638
|
+
})
|
|
639
|
+
},
|
|
640
|
+
flags: {
|
|
641
|
+
name: flag.string({
|
|
642
|
+
brief: "Override the root node's name — the dev instance's application name.",
|
|
643
|
+
placeholder: "name"
|
|
644
|
+
}),
|
|
645
|
+
tail: flag.number({
|
|
646
|
+
brief: `How many trailing history lines to show before live output (default ${String(DEFAULT_TAIL)}).`,
|
|
647
|
+
placeholder: "lines",
|
|
648
|
+
default: DEFAULT_TAIL
|
|
649
|
+
})
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
needs: { config: composerSection },
|
|
653
|
+
handler: async (args, ctx) => {
|
|
654
|
+
const reportLogEvent = (event) => {
|
|
655
|
+
ctx.report({
|
|
656
|
+
kind: "message",
|
|
657
|
+
severity: "warn",
|
|
658
|
+
text: event.kind === "stream-failed" ? `Stream failed: ${event.message}` : `Falling behind — dropped the ${String(event.count)} oldest lines.`
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
const result = await operations.log({
|
|
662
|
+
entry: args.positionals.entry,
|
|
663
|
+
name: args.flags.name,
|
|
664
|
+
address: args.positionals.address,
|
|
665
|
+
tail: args.flags.tail ?? DEFAULT_TAIL,
|
|
666
|
+
cwd: ctx.cwd,
|
|
667
|
+
signal: ctx.signal,
|
|
668
|
+
onEvent: reportLogEvent
|
|
669
|
+
}, { configPath: ctx.config.configPath });
|
|
670
|
+
if (!result.ok) return notOk(toEngineError(result.failure));
|
|
671
|
+
const attached = result.value;
|
|
672
|
+
if (attached.services.length === 0) {
|
|
673
|
+
ctx.report({
|
|
674
|
+
kind: "message",
|
|
675
|
+
severity: "warn",
|
|
676
|
+
text: `No running services for "${attached.appName}" — start it first with \`dev ${args.positionals.entry}\`.`
|
|
677
|
+
});
|
|
678
|
+
return ok(void 0);
|
|
679
|
+
}
|
|
680
|
+
for await (const { service, line } of attached.lines) ctx.report({
|
|
681
|
+
kind: "output",
|
|
682
|
+
source: service,
|
|
683
|
+
channel: "data",
|
|
684
|
+
line: `[${service}] ${line}`
|
|
685
|
+
});
|
|
686
|
+
return ok(void 0);
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
/**
|
|
690
|
+
* Composer's `CommandFamily` — the unit the engine mounts, whether the process
|
|
691
|
+
* is composer's own CLI or the `prisma` bin.
|
|
692
|
+
*
|
|
693
|
+
* This module and everything it reaches statically must stay free of alchemy
|
|
694
|
+
* and of effect VALUE imports: the `prisma` bin imports the family directly,
|
|
695
|
+
* so anything in this static graph loads on `prisma --version`. The mechanism
|
|
696
|
+
* that holds it is the existing lazy boundary inside the operation modules —
|
|
697
|
+
* `operations/deploy.ts`, `destroy.ts`, `dev.ts` and `log.ts` each `await
|
|
698
|
+
* import()` their executor, and it is the executors that reach the provider
|
|
699
|
+
* tree. Importing the operations here is therefore free; importing an
|
|
700
|
+
* executor, or flattening one of those dynamic imports, is not.
|
|
701
|
+
* scripts/check-family-static-graph.mjs enforces this against BUILT output,
|
|
702
|
+
* where type-only imports have already been erased.
|
|
703
|
+
*
|
|
704
|
+
* The four commands close over the operations they are given, so a host can
|
|
705
|
+
* mount this family against the test double and exercise real grammar, real
|
|
706
|
+
* arg validation and real handlers with no alchemy behind them.
|
|
707
|
+
*/
|
|
708
|
+
const realOperations = {
|
|
709
|
+
deploy: deployWithDeps,
|
|
710
|
+
destroy: destroyWithDeps,
|
|
711
|
+
dev: devWithDeps,
|
|
712
|
+
log: logWithDeps
|
|
713
|
+
};
|
|
714
|
+
function createComposerFamily(options = {}) {
|
|
715
|
+
const operations = options.operations ?? realOperations;
|
|
716
|
+
return defineCommandFamily({
|
|
717
|
+
configSection: composerSection,
|
|
718
|
+
commands: {
|
|
719
|
+
deploy: createDeployCommand(operations),
|
|
720
|
+
destroy: createDestroyCommand(operations),
|
|
721
|
+
dev: createDevCommand(operations),
|
|
722
|
+
log: createLogCommand(operations)
|
|
723
|
+
},
|
|
724
|
+
docsBaseUrl: DOCS_BASE
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Everything environmental the engine needs, assembled from a host process.
|
|
729
|
+
*
|
|
730
|
+
* The engine takes no globals: streams, cwd, env, TTY-ness, exit and signal
|
|
731
|
+
* subscription all arrive through `Runtime`, which is what lets a test drive a
|
|
732
|
+
* whole run without touching `process`. Composing one is the substantive part
|
|
733
|
+
* of hosting the engine — `createCli` and `Cli.run` are two calls.
|
|
734
|
+
*
|
|
735
|
+
* Credentials come from the engine's own environment-only manager, which
|
|
736
|
+
* composes a session from PRISMA_SERVICE_TOKEN / PRISMA_WORKSPACE_ID and
|
|
737
|
+
* refuses every mutation. That is the whole of composer's standalone auth
|
|
738
|
+
* story: this CLI has no login flow and mounts no auth commands, so there is
|
|
739
|
+
* nothing to store — the two variables ARE the credential.
|
|
740
|
+
*/
|
|
741
|
+
/** Where the management API lives. Matches the lowering client's default origin; the env var is the escape hatch for staging. */
|
|
742
|
+
const DEFAULT_MANAGEMENT_API_BASE_URL = "https://api.prisma.io";
|
|
743
|
+
const DEFAULT_AUTH_BASE_URL = "https://auth.prisma.io";
|
|
744
|
+
/**
|
|
745
|
+
* Starts the converge child: inherited stdio, this process's own group, no
|
|
746
|
+
* `detached` and no new console — which is what lets the terminal deliver
|
|
747
|
+
* Ctrl-C to the child natively instead of the CLI forwarding it. The engine
|
|
748
|
+
* never imports node:child_process; this adapter is the whole of the host's
|
|
749
|
+
* side of that seam.
|
|
750
|
+
*/
|
|
751
|
+
const spawnChild = (request) => {
|
|
752
|
+
const child = spawn(request.command, [...request.args], {
|
|
753
|
+
cwd: request.cwd,
|
|
754
|
+
stdio: "inherit",
|
|
755
|
+
env: request.env
|
|
756
|
+
});
|
|
757
|
+
return {
|
|
758
|
+
ended: new Promise((resolve, reject) => {
|
|
759
|
+
child.on("error", reject);
|
|
760
|
+
child.on("close", (exitCode, signal) => {
|
|
761
|
+
resolve({
|
|
762
|
+
exitCode,
|
|
763
|
+
signal
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
}),
|
|
767
|
+
kill: (signal) => {
|
|
768
|
+
child.kill(signal);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* The SDK's client construction config. The engine requires all four fields
|
|
774
|
+
* whenever a credential manager is wired, but this host reaches none of the
|
|
775
|
+
* login paths: an environment credential carries no refresh token, so nothing
|
|
776
|
+
* ever refreshes and `clientId`/`redirectUri` are never read. They are
|
|
777
|
+
* env-overridable rather than hard-coded so a staging run can point the whole
|
|
778
|
+
* client somewhere else in one place.
|
|
779
|
+
*/
|
|
780
|
+
function clientConfig(env, apiBaseUrl) {
|
|
781
|
+
return {
|
|
782
|
+
clientId: env["PRISMA_CLIENT_ID"] ?? "prisma-composer-cli",
|
|
783
|
+
redirectUri: env["PRISMA_REDIRECT_URI"] ?? "http://127.0.0.1/callback",
|
|
784
|
+
apiBaseUrl,
|
|
785
|
+
authBaseUrl: env["PRISMA_AUTH_URL"] ?? DEFAULT_AUTH_BASE_URL
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* What this process runs on, for `ctx.host`. Bun and Deno both announce
|
|
790
|
+
* themselves in `versions`; nothing else does, so an absent marker means Node.
|
|
791
|
+
*/
|
|
792
|
+
function describeHost(host) {
|
|
793
|
+
const name = ["bun", "deno"].find((candidate) => host.versions[candidate] !== void 0) ?? "node";
|
|
794
|
+
return {
|
|
795
|
+
runtime: {
|
|
796
|
+
name,
|
|
797
|
+
version: host.versions[name] ?? host.version
|
|
798
|
+
},
|
|
799
|
+
platform: host.platform,
|
|
800
|
+
arch: host.arch
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Which package manager invoked us, read from the `npm_config_user_agent`
|
|
805
|
+
* every major manager sets (`pnpm/10.27.0 npm/? node/v24.16.0 darwin arm64`).
|
|
806
|
+
* `undefined` when the CLI was run directly rather than through a manager — a
|
|
807
|
+
* normal case, not a failure, so nothing is inferred from the filesystem, and
|
|
808
|
+
* the engine falls back to its own detection from the project at cwd.
|
|
809
|
+
*/
|
|
810
|
+
function detectPackageManager(env) {
|
|
811
|
+
const agent = env["npm_config_user_agent"];
|
|
812
|
+
if (agent === void 0) return void 0;
|
|
813
|
+
const name = agent.split("/")[0];
|
|
814
|
+
switch (name) {
|
|
815
|
+
case "npm":
|
|
816
|
+
case "pnpm":
|
|
817
|
+
case "yarn":
|
|
818
|
+
case "bun":
|
|
819
|
+
case "deno": return name;
|
|
820
|
+
default: return;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* The config loader arrives as a function rather than an already-loaded config
|
|
825
|
+
* because the engine reads `prisma.config.ts` on demand — only when the command
|
|
826
|
+
* it is about to run declares a config section, and with whatever file
|
|
827
|
+
* `--config` named. A host that loaded the file up front would read it for runs
|
|
828
|
+
* that never needed it, and would have nowhere to put `--config`.
|
|
829
|
+
*
|
|
830
|
+
* Nothing here answers "is this CI": the engine detects it from `env` itself,
|
|
831
|
+
* and `isCIOverride` exists only for hosts where that detection cannot be
|
|
832
|
+
* right — composer is not one.
|
|
833
|
+
*/
|
|
834
|
+
function createRuntime(host, loadConfig) {
|
|
835
|
+
const env = host.env;
|
|
836
|
+
const apiBaseUrl = env["PRISMA_MANAGEMENT_API_URL"] ?? DEFAULT_MANAGEMENT_API_BASE_URL;
|
|
837
|
+
const packageManager = detectPackageManager(env);
|
|
838
|
+
return {
|
|
839
|
+
stdout: host.stdout,
|
|
840
|
+
stderr: host.stderr,
|
|
841
|
+
stdin: host.stdin,
|
|
842
|
+
cwd: host.cwd(),
|
|
843
|
+
env,
|
|
844
|
+
isTty: {
|
|
845
|
+
stdin: host.stdin.isTTY === true,
|
|
846
|
+
stdout: host.stdout.isTTY === true,
|
|
847
|
+
stderr: host.stderr.isTTY === true
|
|
848
|
+
},
|
|
849
|
+
exit: (code) => host.exit(code),
|
|
850
|
+
onSignal: (cb) => {
|
|
851
|
+
const onSigint = () => {
|
|
852
|
+
cb("SIGINT");
|
|
853
|
+
};
|
|
854
|
+
const onSigterm = () => {
|
|
855
|
+
cb("SIGTERM");
|
|
856
|
+
};
|
|
857
|
+
host.on("SIGINT", onSigint);
|
|
858
|
+
host.on("SIGTERM", onSigterm);
|
|
859
|
+
return () => {
|
|
860
|
+
host.off("SIGINT", onSigint);
|
|
861
|
+
host.off("SIGTERM", onSigterm);
|
|
862
|
+
};
|
|
863
|
+
},
|
|
864
|
+
loadConfig,
|
|
865
|
+
credentialManager: new EnvironmentCredentialManager({ env }),
|
|
866
|
+
managementApiClientConfig: clientConfig(env, apiBaseUrl),
|
|
867
|
+
spawn: spawnChild,
|
|
868
|
+
managementApi: { baseUrl: apiBaseUrl },
|
|
869
|
+
...packageManager !== void 0 && { packageManager },
|
|
870
|
+
host: describeHost(host)
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Composer's own CLI, rebuilt as a thin composition of the family it
|
|
875
|
+
* publishes: `createCli` over `createComposerFamily()`, `Cli.run` with a
|
|
876
|
+
* Runtime. Grammar, help, arg validation, output framing, exit codes and
|
|
877
|
+
* signal ownership all belong to the engine now — this module contributes the
|
|
878
|
+
* family and the environment, and nothing else.
|
|
879
|
+
*
|
|
880
|
+
* Running composer's commands through the same path an external host uses is
|
|
881
|
+
* the point: it is what proves the family works standalone before the `prisma`
|
|
882
|
+
* bin mounts it.
|
|
883
|
+
*
|
|
884
|
+
* This IS composer's CLI. The clipanion shell it replaced, and the bespoke
|
|
885
|
+
* runner that shelled out to alchemy, are gone; `bin.ts` is a call into here.
|
|
886
|
+
*/
|
|
887
|
+
const BINARY_NAME = "prisma-composer";
|
|
888
|
+
/**
|
|
889
|
+
* Composer's commands mount at the top level of its own CLI (`prisma-composer
|
|
890
|
+
* deploy`); under the `prisma` bin the same family mounts one level down
|
|
891
|
+
* (`prisma composer deploy`). The family is identical either way — only the
|
|
892
|
+
* mount paths differ, which is exactly the split `createCli` draws between
|
|
893
|
+
* `commandFamilies` and `commands`.
|
|
894
|
+
*/
|
|
895
|
+
function mountedTree(family) {
|
|
896
|
+
return { ...family.commands };
|
|
897
|
+
}
|
|
898
|
+
function createComposerCli(spec) {
|
|
899
|
+
const family = createComposerFamily({ operations: spec.operations });
|
|
900
|
+
return createCli({
|
|
901
|
+
name: BINARY_NAME,
|
|
902
|
+
version: spec.version,
|
|
903
|
+
commandFamilies: [family],
|
|
904
|
+
groups: {},
|
|
905
|
+
commands: mountedTree(family)
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Composes the Runtime and runs one invocation. Returns the exit code rather
|
|
910
|
+
* than exiting, so the caller owns the process — a bin assigns it to
|
|
911
|
+
* `process.exitCode` and lets the streams drain, as composer's CLI has always
|
|
912
|
+
* done.
|
|
913
|
+
*
|
|
914
|
+
* `prisma.config.ts` is not read here. The loader goes in as a function, and the
|
|
915
|
+
* engine calls it only when the command it is about to run declares a config
|
|
916
|
+
* section, passing it the file `--config` named; the loader resolves that
|
|
917
|
+
* against the host's cwd.
|
|
918
|
+
*/
|
|
919
|
+
function runComposerCli(argv, host, spec, hooks) {
|
|
920
|
+
const runtime = createRuntime(host, (configPath) => loadConfig(host.cwd(), configPath));
|
|
921
|
+
return createComposerCli(spec).run(argv, runtime, hooks);
|
|
922
|
+
}
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region ../../0-framework/3-tooling/cli/dist/cli-Bkm0Wwfk.mjs
|
|
925
|
+
/**
|
|
926
|
+
* The `prisma-composer` entrypoint: adapt this process into the engine's
|
|
927
|
+
* `HostProcess`, run one invocation of composer's own CLI, and hand back an
|
|
928
|
+
* exit code. Grammar, help, argument validation, output framing, exit codes
|
|
929
|
+
* and signal policy all belong to the engine — this module contributes the
|
|
930
|
+
* process and the version, and nothing else.
|
|
931
|
+
*
|
|
932
|
+
* Node's `process` already satisfies `HostProcess` structurally, so there is
|
|
933
|
+
* no adapter object here; that is the whole point of the engine taking a host
|
|
934
|
+
* surface rather than reading globals.
|
|
935
|
+
*/
|
|
936
|
+
/** Printed for a throw that escapes the engine entirely — by the shared base-type rules that is a bug, not a user failure. */
|
|
937
|
+
const REPORT_HINT = "This is a bug in prisma-composer, not in your app — please report it: https://github.com/prisma/composer/issues";
|
|
938
|
+
const UNKNOWN_VERSION = "unknown";
|
|
939
|
+
/**
|
|
940
|
+
* The version the CLI reports, read from the manifest of the package this
|
|
941
|
+
* module was BUNDLED INTO — `@prisma/composer` for the published bin, since
|
|
942
|
+
* that is the package whose executable the user installed. Walking up from the
|
|
943
|
+
* module's own location is what makes that true in both layouts: the published
|
|
944
|
+
* `dist/bin.mjs` finds `@prisma/composer`'s manifest, and a direct run of
|
|
945
|
+
* `src/bin.ts` finds this package's.
|
|
946
|
+
*/
|
|
947
|
+
function shippedVersion(fromDir = path.dirname(fileURLToPath(import.meta.url))) {
|
|
948
|
+
let dir = fromDir;
|
|
949
|
+
while (true) {
|
|
950
|
+
const manifest = path.join(dir, "package.json");
|
|
951
|
+
if (fs.existsSync(manifest)) try {
|
|
952
|
+
const version = JSON.parse(fs.readFileSync(manifest, "utf-8")).version;
|
|
953
|
+
return typeof version === "string" ? version : UNKNOWN_VERSION;
|
|
954
|
+
} catch {
|
|
955
|
+
return UNKNOWN_VERSION;
|
|
956
|
+
}
|
|
957
|
+
const parent = path.dirname(dir);
|
|
958
|
+
if (parent === dir) return UNKNOWN_VERSION;
|
|
959
|
+
dir = parent;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Runs `prisma-composer` end to end and returns the process exit code. The
|
|
964
|
+
* caller assigns it to `process.exitCode` rather than exiting, so the streams
|
|
965
|
+
* drain — the engine returns a code for exactly this reason.
|
|
966
|
+
*
|
|
967
|
+
* The catch is not error handling for commands: the engine renders every
|
|
968
|
+
* command failure itself. It catches a throw that escaped the engine — a
|
|
969
|
+
* construction fault, a broken config load — which by ADR-0044 is a bug in
|
|
970
|
+
* this CLI and exits 1 with a report hint.
|
|
971
|
+
*/
|
|
972
|
+
async function cli(argv = process.argv.slice(2)) {
|
|
973
|
+
try {
|
|
974
|
+
return await runComposerCli(argv, process, { version: shippedVersion() });
|
|
975
|
+
} catch (error) {
|
|
976
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
977
|
+
console.error(REPORT_HINT);
|
|
978
|
+
return 1;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
//#endregion
|
|
982
|
+
//#region ../../0-framework/3-tooling/cli/dist/bin.mjs
|
|
983
|
+
process.exitCode = await cli();
|
|
984
|
+
//#endregion
|
|
985
|
+
export {};
|
|
986
|
+
|
|
987
|
+
//# sourceMappingURL=bin.mjs.map
|