@prisma/cli 3.0.0-dev.99.1 → 8.0.0-rc.2

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.
Files changed (87) hide show
  1. package/README.md +3 -1
  2. package/dist/cli.js +15115 -16
  3. package/dist/deploy-framework-C7bQM00A.js +23 -0
  4. package/dist/payload-B88Qvzxk-CrtTXSOe.js +34 -0
  5. package/dist/sender.js +192 -0
  6. package/package.json +22 -18
  7. package/dist/adapters/git.js +0 -54
  8. package/dist/adapters/local-state.js +0 -144
  9. package/dist/adapters/mock-api.js +0 -136
  10. package/dist/adapters/token-storage.js +0 -418
  11. package/dist/cli2.js +0 -119
  12. package/dist/commands/app/index.js +0 -345
  13. package/dist/commands/auth/index.js +0 -96
  14. package/dist/commands/branch/index.js +0 -27
  15. package/dist/commands/database/index.js +0 -159
  16. package/dist/commands/env.js +0 -99
  17. package/dist/commands/git/index.js +0 -36
  18. package/dist/commands/project/index.js +0 -69
  19. package/dist/commands/version/index.js +0 -18
  20. package/dist/controllers/app-env-api.js +0 -54
  21. package/dist/controllers/app-env-file.js +0 -181
  22. package/dist/controllers/app-env.js +0 -502
  23. package/dist/controllers/app.js +0 -2443
  24. package/dist/controllers/auth.js +0 -316
  25. package/dist/controllers/branch.js +0 -103
  26. package/dist/controllers/database.js +0 -318
  27. package/dist/controllers/project.js +0 -731
  28. package/dist/controllers/select-prompt-port.js +0 -12
  29. package/dist/controllers/version.js +0 -12
  30. package/dist/lib/app/app-interaction.js +0 -5
  31. package/dist/lib/app/app-provider.js +0 -544
  32. package/dist/lib/app/branch-database-api.js +0 -102
  33. package/dist/lib/app/branch-database-deploy.js +0 -325
  34. package/dist/lib/app/branch-database.js +0 -215
  35. package/dist/lib/app/build-settings.js +0 -93
  36. package/dist/lib/app/build.js +0 -80
  37. package/dist/lib/app/bun-project.js +0 -45
  38. package/dist/lib/app/compute-config.js +0 -147
  39. package/dist/lib/app/deploy-output.js +0 -24
  40. package/dist/lib/app/deploy-plan.js +0 -58
  41. package/dist/lib/app/deploy-progress.js +0 -100
  42. package/dist/lib/app/domain-guidance.js +0 -14
  43. package/dist/lib/app/env-config.js +0 -67
  44. package/dist/lib/app/env-file.js +0 -82
  45. package/dist/lib/app/env-vars.js +0 -50
  46. package/dist/lib/app/local-dev.js +0 -109
  47. package/dist/lib/app/production-deploy-gate.js +0 -161
  48. package/dist/lib/app/read-branch.js +0 -30
  49. package/dist/lib/auth/auth-ops.js +0 -158
  50. package/dist/lib/auth/client.js +0 -22
  51. package/dist/lib/auth/guard.js +0 -38
  52. package/dist/lib/auth/login.js +0 -330
  53. package/dist/lib/database/provider.js +0 -167
  54. package/dist/lib/diagnostics.js +0 -15
  55. package/dist/lib/fs/home-path.js +0 -24
  56. package/dist/lib/git/local-branch.js +0 -53
  57. package/dist/lib/git/local-status.js +0 -57
  58. package/dist/lib/project/interactive-setup.js +0 -56
  59. package/dist/lib/project/local-pin.js +0 -200
  60. package/dist/lib/project/resolution.js +0 -386
  61. package/dist/lib/project/setup.js +0 -135
  62. package/dist/lib/version.js +0 -55
  63. package/dist/output/patterns.js +0 -90
  64. package/dist/presenters/app-env.js +0 -265
  65. package/dist/presenters/app.js +0 -646
  66. package/dist/presenters/auth.js +0 -183
  67. package/dist/presenters/branch.js +0 -46
  68. package/dist/presenters/database.js +0 -274
  69. package/dist/presenters/project.js +0 -174
  70. package/dist/presenters/verbose-context.js +0 -64
  71. package/dist/presenters/version.js +0 -29
  72. package/dist/shell/command-arguments.js +0 -6
  73. package/dist/shell/command-meta.js +0 -622
  74. package/dist/shell/command-runner.js +0 -112
  75. package/dist/shell/diagnostics-output.js +0 -57
  76. package/dist/shell/errors.js +0 -134
  77. package/dist/shell/global-flags.js +0 -37
  78. package/dist/shell/help.js +0 -89
  79. package/dist/shell/output.js +0 -82
  80. package/dist/shell/prompt.js +0 -41
  81. package/dist/shell/runtime.js +0 -55
  82. package/dist/shell/ui.js +0 -116
  83. package/dist/shell/update-check.js +0 -247
  84. package/dist/use-cases/auth.js +0 -145
  85. package/dist/use-cases/branch.js +0 -47
  86. package/dist/use-cases/create-cli-gateways.js +0 -68
  87. package/dist/use-cases/project.js +0 -30
@@ -1,418 +0,0 @@
1
- import { getAuthFilePath } from "../lib/auth/client.js";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import { randomUUID } from "node:crypto";
5
- import { CredentialsStore } from "@prisma/credentials-store";
6
- //#region src/adapters/token-storage.ts
7
- const REFRESH_LOCK_RETRY_MS = 100;
8
- const REFRESH_LOCK_STALE_MS = 3e4;
9
- const REFRESH_LOCK_WAIT_TIMEOUT_MS = 25e3;
10
- const EMPTY_AUTH_CONTEXT = {
11
- activeWorkspaceId: null,
12
- workspaces: {}
13
- };
14
- const UNKNOWN_WORKSPACE_NAME = "Unknown workspace";
15
- function getAuthContextFilePath(authFilePath) {
16
- const extension = path.extname(authFilePath);
17
- if (!extension) return `${authFilePath}.context.json`;
18
- return `${authFilePath.slice(0, -extension.length)}.context${extension}`;
19
- }
20
- function findLatestValidTokens(allCredentials) {
21
- for (let i = allCredentials.length - 1; i >= 0; i -= 1) {
22
- const credential = allCredentials[i];
23
- if (!credential) continue;
24
- if (typeof credential.workspaceId !== "string" || credential.workspaceId.length === 0 || typeof credential.token !== "string" || credential.token.length === 0 || typeof credential.refreshToken !== "string" || credential.refreshToken.length === 0) continue;
25
- return {
26
- workspaceId: credential.workspaceId,
27
- accessToken: credential.token,
28
- refreshToken: credential.refreshToken
29
- };
30
- }
31
- return null;
32
- }
33
- function storedCredentialToTokens(credential) {
34
- if (!credential) return null;
35
- if (typeof credential.workspaceId !== "string" || credential.workspaceId.length === 0 || typeof credential.token !== "string" || credential.token.length === 0 || typeof credential.refreshToken !== "string" || credential.refreshToken.length === 0) return null;
36
- return {
37
- workspaceId: credential.workspaceId,
38
- accessToken: credential.token,
39
- refreshToken: credential.refreshToken
40
- };
41
- }
42
- function findTokensForWorkspace(allCredentials, workspaceId) {
43
- return storedCredentialToTokens(allCredentials.find((credential) => credential?.workspaceId === workspaceId)) ?? null;
44
- }
45
- function tokensEqual(a, b) {
46
- return a?.workspaceId === b?.workspaceId && a?.accessToken === b?.accessToken && a?.refreshToken === b?.refreshToken;
47
- }
48
- function sleep(ms, signal) {
49
- signal?.throwIfAborted();
50
- return new Promise((resolve, reject) => {
51
- const onAbort = () => {
52
- clearTimeout(timeout);
53
- reject(signal?.reason);
54
- };
55
- const timeout = setTimeout(() => {
56
- signal?.removeEventListener("abort", onAbort);
57
- resolve();
58
- }, ms);
59
- signal?.addEventListener("abort", onAbort, { once: true });
60
- });
61
- }
62
- var FileTokenStorage = class {
63
- credentialsStore;
64
- authFilePath;
65
- contextFilePath;
66
- lockFilePath;
67
- constructor(env = process.env, signal, options = {}) {
68
- this.signal = signal;
69
- this.options = options;
70
- const authFilePath = getAuthFilePath(env);
71
- this.authFilePath = authFilePath;
72
- this.contextFilePath = getAuthContextFilePath(authFilePath);
73
- this.credentialsStore = new CredentialsStore(authFilePath);
74
- this.lockFilePath = `${authFilePath}.lock`;
75
- }
76
- async getTokens() {
77
- this.signal?.throwIfAborted();
78
- try {
79
- const credentials = await this.readCredentialsFromDisk();
80
- const context = await this.readAuthContext();
81
- if (context.state.activeWorkspaceId) return findTokensForWorkspace(credentials, context.state.activeWorkspaceId);
82
- const latest = findLatestValidTokens(credentials);
83
- if (!latest) return null;
84
- if (!context.exists) {
85
- await this.setActiveWorkspaceId(latest.workspaceId);
86
- return latest;
87
- }
88
- return null;
89
- } catch (_error) {
90
- if (this.signal?.aborted) throw this.signal.reason;
91
- return null;
92
- }
93
- }
94
- async setTokens(tokens) {
95
- if (this.options.lockSetTokens === false) {
96
- await this.setTokensUnlocked(tokens);
97
- return;
98
- }
99
- await this.withRefreshLock(() => this.setTokensUnlocked(tokens));
100
- }
101
- async setTokensUnlocked(tokens) {
102
- this.signal?.throwIfAborted();
103
- await this.credentialsStore.storeCredentials({
104
- workspaceId: tokens.workspaceId,
105
- token: tokens.accessToken,
106
- refreshToken: tokens.refreshToken
107
- });
108
- this.signal?.throwIfAborted();
109
- await this.rememberWorkspaceUnlocked(tokens.workspaceId, {
110
- id: tokens.workspaceId,
111
- name: tokens.workspaceId
112
- });
113
- await this.maybeActivateWorkspaceId(tokens.workspaceId);
114
- }
115
- async clearTokens() {
116
- await this.withRefreshLock(() => this.clearTokensUnlocked());
117
- }
118
- async clearTokensUnlocked() {
119
- this.signal?.throwIfAborted();
120
- await fs.mkdir(path.dirname(this.authFilePath), { recursive: true });
121
- this.signal?.throwIfAborted();
122
- await fs.writeFile(this.authFilePath, `${JSON.stringify({ tokens: [] }, null, 2)}\n`, {
123
- encoding: "utf8",
124
- signal: this.signal
125
- });
126
- await this.clearAuthContext();
127
- await this.credentialsStore.reloadCredentialsFromDisk();
128
- this.signal?.throwIfAborted();
129
- }
130
- async clearTokensIfCurrent(tokens) {
131
- this.signal?.throwIfAborted();
132
- if (!tokensEqual(await this.getTokens(), tokens)) return;
133
- await this.credentialsStore.deleteCredentials(tokens.workspaceId);
134
- await this.removeRememberedWorkspace(tokens.workspaceId, { preserveActivePointer: true });
135
- this.signal?.throwIfAborted();
136
- }
137
- async listWorkspaces() {
138
- this.signal?.throwIfAborted();
139
- const credentials = await this.readCredentialsFromDisk();
140
- const context = await this.ensureMigratedAuthContext(credentials);
141
- return credentials.map((credential) => storedCredentialToTokens(credential)).filter((tokens) => tokens !== null).map((tokens) => {
142
- const cached = context.state.workspaces[tokens.workspaceId];
143
- const id = typeof cached?.id === "string" && cached.id.trim().length > 0 ? cached.id.trim() : tokens.workspaceId;
144
- const name = typeof cached?.name === "string" && cached.name.trim().length > 0 ? workspaceDisplayName(cached.name.trim(), tokens.workspaceId) : UNKNOWN_WORKSPACE_NAME;
145
- const lastSeenAt = typeof cached?.lastSeenAt === "string" && cached.lastSeenAt.trim().length > 0 ? cached.lastSeenAt.trim() : null;
146
- return {
147
- id,
148
- name,
149
- credentialWorkspaceId: tokens.workspaceId,
150
- active: context.state.activeWorkspaceId === tokens.workspaceId,
151
- lastSeenAt
152
- };
153
- });
154
- }
155
- async listWorkspaceTokens() {
156
- this.signal?.throwIfAborted();
157
- return (await this.readCredentialsFromDisk()).map((credential) => storedCredentialToTokens(credential)).filter((tokens) => tokens !== null);
158
- }
159
- async useWorkspace(workspaceRef) {
160
- return this.withRefreshLock(() => this.useWorkspaceUnlocked(workspaceRef));
161
- }
162
- async useWorkspaceUnlocked(workspaceRef) {
163
- const ref = workspaceRef.trim();
164
- if (!ref) throw new WorkspaceSelectionError("missing");
165
- const workspaces = await this.listWorkspaces();
166
- const context = await this.readAuthContext();
167
- const previous = workspaces.find((workspace) => workspace.credentialWorkspaceId === context.state.activeWorkspaceId) ?? null;
168
- const matches = workspaces.filter((workspace) => workspaceMatchesRef(workspace, ref));
169
- if (matches.length === 0) throw new WorkspaceSelectionError("not-found", ref);
170
- if (matches.length > 1) throw new WorkspaceSelectionError("ambiguous", ref, matches);
171
- const selected = matches[0];
172
- await this.setActiveWorkspaceId(selected.credentialWorkspaceId);
173
- return {
174
- previous,
175
- selected
176
- };
177
- }
178
- async logoutWorkspace(workspaceRef) {
179
- return this.withRefreshLock(() => this.logoutWorkspaceUnlocked(workspaceRef));
180
- }
181
- async logoutWorkspaceUnlocked(workspaceRef) {
182
- const ref = workspaceRef.trim();
183
- if (!ref) throw new WorkspaceSelectionError("missing");
184
- const workspaces = await this.listWorkspaces();
185
- const context = await this.readAuthContext();
186
- const matches = workspaces.filter((workspace) => workspaceMatchesRef(workspace, ref));
187
- if (matches.length === 0) throw new WorkspaceSelectionError("not-found", ref);
188
- if (matches.length > 1) throw new WorkspaceSelectionError("ambiguous", ref, matches);
189
- const workspace = matches[0];
190
- const wasActive = context.state.activeWorkspaceId === workspace.credentialWorkspaceId;
191
- await this.credentialsStore.deleteCredentials(workspace.credentialWorkspaceId);
192
- this.signal?.throwIfAborted();
193
- const remainingWorkspaces = workspaces.filter((candidate) => candidate.credentialWorkspaceId !== workspace.credentialWorkspaceId);
194
- if (remainingWorkspaces.length === 0) {
195
- await this.clearAuthContext();
196
- return {
197
- workspace,
198
- wasActive,
199
- activeWorkspace: null
200
- };
201
- }
202
- delete context.state.workspaces[workspace.credentialWorkspaceId];
203
- if (wasActive) context.state.activeWorkspaceId = null;
204
- await this.writeAuthContext(context.state);
205
- return {
206
- workspace,
207
- wasActive,
208
- activeWorkspace: context.state.activeWorkspaceId === null ? null : remainingWorkspaces.find((candidate) => candidate.credentialWorkspaceId === context.state.activeWorkspaceId) ?? null
209
- };
210
- }
211
- async rememberWorkspace(credentialWorkspaceId, workspace) {
212
- await this.withRefreshLock(() => this.rememberWorkspaceUnlocked(credentialWorkspaceId, workspace));
213
- }
214
- async rememberWorkspaceUnlocked(credentialWorkspaceId, workspace) {
215
- const context = await this.readAuthContext();
216
- context.state.workspaces[credentialWorkspaceId] = {
217
- id: workspace.id,
218
- name: workspace.name,
219
- lastSeenAt: (/* @__PURE__ */ new Date()).toISOString()
220
- };
221
- await this.writeAuthContext(context.state);
222
- }
223
- async withRefreshLock(fn) {
224
- const lockId = await this.acquireRefreshLock();
225
- try {
226
- return await fn();
227
- } finally {
228
- await this.releaseRefreshLock(lockId);
229
- }
230
- }
231
- async acquireRefreshLock() {
232
- const lockId = randomUUID();
233
- const startedAt = Date.now();
234
- const retryMs = this.options.lockRetryMs ?? REFRESH_LOCK_RETRY_MS;
235
- const waitTimeoutMs = this.options.lockWaitTimeoutMs ?? REFRESH_LOCK_WAIT_TIMEOUT_MS;
236
- this.signal?.throwIfAborted();
237
- await fs.mkdir(path.dirname(this.lockFilePath), { recursive: true });
238
- while (true) {
239
- this.signal?.throwIfAborted();
240
- if (await this.tryCreateRefreshLock(lockId)) return lockId;
241
- if (await this.releaseStaleRefreshLock()) continue;
242
- this.throwIfRefreshLockWaitTimedOut(startedAt, waitTimeoutMs);
243
- await sleep(retryMs, this.signal);
244
- }
245
- }
246
- async tryCreateRefreshLock(lockId) {
247
- let lockFileCreated = false;
248
- try {
249
- const handle = await fs.open(this.lockFilePath, "wx");
250
- lockFileCreated = true;
251
- try {
252
- this.signal?.throwIfAborted();
253
- await handle.writeFile(lockId, { encoding: "utf8" });
254
- this.signal?.throwIfAborted();
255
- } finally {
256
- await handle.close();
257
- }
258
- return true;
259
- } catch (error) {
260
- if (lockFileCreated) await fs.unlink(this.lockFilePath).catch(() => void 0);
261
- if (error.code === "EEXIST") return false;
262
- throw error;
263
- }
264
- }
265
- async releaseStaleRefreshLock() {
266
- const staleLockId = await this.getStaleRefreshLockId();
267
- if (!staleLockId) return false;
268
- await this.releaseRefreshLock(staleLockId);
269
- return true;
270
- }
271
- throwIfRefreshLockWaitTimedOut(startedAt, waitTimeoutMs) {
272
- if (Date.now() - startedAt < waitTimeoutMs) return;
273
- throw new RefreshLockTimeoutError(this.lockFilePath, waitTimeoutMs);
274
- }
275
- async getStaleRefreshLockId() {
276
- this.signal?.throwIfAborted();
277
- const lockId = await fs.readFile(this.lockFilePath, {
278
- encoding: "utf8",
279
- signal: this.signal
280
- }).catch((error) => {
281
- if (this.signal?.aborted) throw error;
282
- return null;
283
- });
284
- if (lockId === null) return null;
285
- this.signal?.throwIfAborted();
286
- const stats = await fs.stat(this.lockFilePath).catch(() => null);
287
- this.signal?.throwIfAborted();
288
- if (!stats) return null;
289
- const staleMs = this.options.lockStaleMs ?? REFRESH_LOCK_STALE_MS;
290
- return Date.now() - stats.mtimeMs > staleMs ? lockId : null;
291
- }
292
- async releaseRefreshLock(lockId) {
293
- if (await fs.readFile(this.lockFilePath, { encoding: "utf8" }).catch(() => null) !== lockId) return;
294
- await fs.unlink(this.lockFilePath).catch(() => {});
295
- }
296
- async readCredentialsFromDisk() {
297
- this.signal?.throwIfAborted();
298
- await this.credentialsStore.reloadCredentialsFromDisk();
299
- this.signal?.throwIfAborted();
300
- return await this.credentialsStore.getCredentials();
301
- }
302
- async ensureMigratedAuthContext(credentials) {
303
- const context = await this.readAuthContext();
304
- if (context.state.activeWorkspaceId || context.exists) return context;
305
- const latest = findLatestValidTokens(credentials);
306
- if (!latest) return context;
307
- context.state.activeWorkspaceId = latest.workspaceId;
308
- context.state.workspaces[latest.workspaceId] ??= {
309
- id: latest.workspaceId,
310
- name: latest.workspaceId,
311
- lastSeenAt: (/* @__PURE__ */ new Date()).toISOString()
312
- };
313
- await this.writeAuthContext(context.state);
314
- return {
315
- exists: true,
316
- state: context.state
317
- };
318
- }
319
- async setActiveWorkspaceId(workspaceId) {
320
- const context = await this.readAuthContext();
321
- context.state.activeWorkspaceId = workspaceId;
322
- context.state.workspaces[workspaceId] ??= {
323
- id: workspaceId,
324
- name: workspaceId,
325
- lastSeenAt: (/* @__PURE__ */ new Date()).toISOString()
326
- };
327
- await this.writeAuthContext(context.state);
328
- }
329
- async maybeActivateWorkspaceId(workspaceId) {
330
- const context = await this.readAuthContext();
331
- if (this.options.activateOnSetTokens === false && context.exists && context.state.activeWorkspaceId && context.state.activeWorkspaceId !== workspaceId) return;
332
- context.state.activeWorkspaceId = workspaceId;
333
- context.state.workspaces[workspaceId] ??= {
334
- id: workspaceId,
335
- name: workspaceId,
336
- lastSeenAt: (/* @__PURE__ */ new Date()).toISOString()
337
- };
338
- await this.writeAuthContext(context.state);
339
- }
340
- async removeRememberedWorkspace(workspaceId, options) {
341
- const context = await this.readAuthContext();
342
- delete context.state.workspaces[workspaceId];
343
- if (!options.preserveActivePointer && context.state.activeWorkspaceId === workspaceId) context.state.activeWorkspaceId = null;
344
- await this.writeAuthContext(context.state);
345
- }
346
- async readAuthContext() {
347
- this.signal?.throwIfAborted();
348
- const raw = await fs.readFile(this.contextFilePath, {
349
- encoding: "utf8",
350
- signal: this.signal
351
- }).catch((error) => {
352
- if (this.signal?.aborted) throw error;
353
- if (error.code === "ENOENT") return null;
354
- throw error;
355
- });
356
- if (raw === null) return {
357
- exists: false,
358
- state: structuredClone(EMPTY_AUTH_CONTEXT)
359
- };
360
- try {
361
- const parsed = JSON.parse(raw);
362
- return {
363
- exists: true,
364
- state: {
365
- activeWorkspaceId: typeof parsed.activeWorkspaceId === "string" && parsed.activeWorkspaceId.trim().length > 0 ? parsed.activeWorkspaceId.trim() : null,
366
- workspaces: parsed.workspaces && typeof parsed.workspaces === "object" && !Array.isArray(parsed.workspaces) ? parsed.workspaces : {}
367
- }
368
- };
369
- } catch {
370
- return {
371
- exists: false,
372
- state: structuredClone(EMPTY_AUTH_CONTEXT)
373
- };
374
- }
375
- }
376
- async writeAuthContext(state) {
377
- this.signal?.throwIfAborted();
378
- await fs.mkdir(path.dirname(this.contextFilePath), { recursive: true });
379
- this.signal?.throwIfAborted();
380
- await fs.writeFile(this.contextFilePath, `${JSON.stringify(state, null, 2)}\n`, {
381
- encoding: "utf8",
382
- signal: this.signal
383
- });
384
- this.signal?.throwIfAborted();
385
- }
386
- async clearAuthContext() {
387
- await fs.unlink(this.contextFilePath).catch((error) => {
388
- if (error.code === "ENOENT") return;
389
- throw error;
390
- });
391
- }
392
- };
393
- var WorkspaceSelectionError = class extends Error {
394
- constructor(reason, workspaceRef, matches = []) {
395
- super(reason);
396
- this.reason = reason;
397
- this.workspaceRef = workspaceRef;
398
- this.matches = matches;
399
- this.name = "WorkspaceSelectionError";
400
- }
401
- };
402
- var RefreshLockTimeoutError = class extends Error {
403
- constructor(lockFilePath, waitTimeoutMs) {
404
- super(`Timed out waiting ${waitTimeoutMs}ms for auth refresh lock at ${lockFilePath}`);
405
- this.name = "RefreshLockTimeoutError";
406
- }
407
- };
408
- function workspaceMatchesRef(workspace, ref) {
409
- return workspace.credentialWorkspaceId === ref || workspace.id === ref || stripWorkspacePrefix(workspace.credentialWorkspaceId) === stripWorkspacePrefix(ref) || stripWorkspacePrefix(workspace.id) === stripWorkspacePrefix(ref) || workspace.name.toLowerCase() === ref.toLowerCase();
410
- }
411
- function stripWorkspacePrefix(value) {
412
- return value.startsWith("wksp_") ? value.slice(5) : value;
413
- }
414
- function workspaceDisplayName(name, credentialWorkspaceId) {
415
- return name === credentialWorkspaceId ? UNKNOWN_WORKSPACE_NAME : name;
416
- }
417
- //#endregion
418
- export { FileTokenStorage, WorkspaceSelectionError };
package/dist/cli2.js DELETED
@@ -1,119 +0,0 @@
1
- import { CliError } from "./shell/errors.js";
2
- import "./shell/prompt.js";
3
- import { attachCommandDescriptor } from "./shell/command-meta.js";
4
- import { addCompactGlobalFlags } from "./shell/global-flags.js";
5
- import { createShellUi } from "./shell/ui.js";
6
- import { configureRuntimeCommand, createCommandContext } from "./shell/runtime.js";
7
- import { formatUnexpectedError, writeHumanError, writeJsonError, writeJsonSuccess } from "./shell/output.js";
8
- import { createAppCommand } from "./commands/app/index.js";
9
- import { createAuthCommand } from "./commands/auth/index.js";
10
- import { createBranchCommand } from "./commands/branch/index.js";
11
- import { createDatabaseCommand } from "./commands/database/index.js";
12
- import { createGitCommand } from "./commands/git/index.js";
13
- import { createProjectCommand } from "./commands/project/index.js";
14
- import { getCliName, getCliVersion } from "./lib/version.js";
15
- import { runVersion } from "./controllers/version.js";
16
- import { createVersionCommand } from "./commands/version/index.js";
17
- import { maybeWriteCachedUpdateNotification } from "./shell/update-check.js";
18
- import process from "node:process";
19
- import { Command, CommanderError, Option } from "commander";
20
- //#region src/cli.ts
21
- async function runCli(options = {}) {
22
- const runtime = resolveRuntime(options);
23
- const program = createProgram(runtime);
24
- process.exitCode = 0;
25
- try {
26
- await maybeWriteCachedUpdateNotification(runtime);
27
- if (runtime.argv.includes("--version")) return await handleVersionFlag(runtime);
28
- const bareHelpCommand = resolveBareHelpCommand(program, runtime.argv);
29
- if (bareHelpCommand) {
30
- runtime.stderr.write(bareHelpCommand.helpInformation());
31
- return 0;
32
- }
33
- await program.parseAsync(runtime.argv, { from: "user" });
34
- return process.exitCode ?? 0;
35
- } catch (error) {
36
- if (error instanceof CommanderError) return error.code === "commander.helpDisplayed" ? 0 : 2;
37
- runtime.stderr.write(formatUnexpectedError(error, runtime.argv.includes("--trace")));
38
- return 1;
39
- } finally {
40
- runtime.stdin;
41
- }
42
- }
43
- function createProgram(runtime) {
44
- const program = attachCommandDescriptor(configureRuntimeCommand(new Command(), runtime), "root");
45
- addCompactGlobalFlags(program);
46
- program.addOption(new Option("--version", "Print the CLI version and exit."));
47
- program.name("prisma").showSuggestionAfterError();
48
- program.addCommand(createVersionCommand(runtime));
49
- program.addCommand(createAuthCommand(runtime));
50
- program.addCommand(createProjectCommand(runtime));
51
- program.addCommand(createGitCommand(runtime));
52
- program.addCommand(createBranchCommand(runtime));
53
- program.addCommand(createDatabaseCommand(runtime));
54
- program.addCommand(createAppCommand(runtime));
55
- return program;
56
- }
57
- async function handleVersionFlag(runtime) {
58
- const wantsJson = runtime.argv.includes("--json");
59
- const output = {
60
- stdout: runtime.stdout,
61
- stderr: runtime.stderr
62
- };
63
- try {
64
- if (wantsJson) {
65
- const success = await runVersion(await createCommandContext(runtime, buildVersionFlagFlags(runtime)));
66
- writeJsonSuccess(output, {
67
- command: success.command,
68
- result: { version: success.result.cli.version },
69
- warnings: success.warnings,
70
- nextSteps: success.nextSteps
71
- });
72
- return 0;
73
- }
74
- const versionLine = `${getCliName()} ${getCliVersion()}`;
75
- runtime.stdout.write(`${versionLine}\n`);
76
- return 0;
77
- } catch (error) {
78
- if (error instanceof CliError) {
79
- if (wantsJson) writeJsonError(output, "version", error);
80
- else writeHumanError(output, createShellUi(runtime, buildVersionFlagFlags(runtime)), error, { trace: false });
81
- return error.exitCode;
82
- }
83
- throw error;
84
- }
85
- }
86
- function buildVersionFlagFlags(runtime) {
87
- return {
88
- json: runtime.argv.includes("--json"),
89
- quiet: false,
90
- verbose: false,
91
- trace: false,
92
- yes: false,
93
- interactive: void 0,
94
- color: void 0
95
- };
96
- }
97
- function resolveBareHelpCommand(program, argv) {
98
- if (argv.length === 0) return program;
99
- if (argv.length !== 1) return null;
100
- const candidate = program.commands.find((command) => command.name() === argv[0]) ?? null;
101
- if (!candidate) return null;
102
- if (candidate.commands.length === 0) return null;
103
- return candidate;
104
- }
105
- function resolveRuntime(options) {
106
- return {
107
- argv: options.argv ?? process.argv.slice(2),
108
- cwd: options.cwd ?? process.env.INIT_CWD ?? process.cwd(),
109
- env: options.env ?? process.env,
110
- signal: options.signal ?? new AbortController().signal,
111
- stdin: options.stdin ?? process.stdin,
112
- stdout: options.stdout ?? process.stdout,
113
- stderr: options.stderr ?? process.stderr,
114
- fixturePath: options.fixturePath,
115
- stateDir: options.stateDir
116
- };
117
- }
118
- //#endregion
119
- export { runCli };