@prisma/cli 8.0.0-rc.1 → 8.0.0-rc.10-dev.80

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 (110) hide show
  1. package/README.md +25 -29
  2. package/dist/cli.js +14551 -16
  3. package/dist/{v8/sender.js → sender.js} +1 -1
  4. package/package.json +17 -18
  5. package/dist/adapters/git.js +0 -54
  6. package/dist/adapters/local-state.js +0 -155
  7. package/dist/auth/client.js +0 -30
  8. package/dist/auth/errors.js +0 -50
  9. package/dist/auth/guard.js +0 -39
  10. package/dist/auth/login.js +0 -471
  11. package/dist/auth/operations.js +0 -208
  12. package/dist/auth/recipient.js +0 -42
  13. package/dist/auth/token-storage.js +0 -439
  14. package/dist/auth/workspaces.js +0 -171
  15. package/dist/cli-command.js +0 -14
  16. package/dist/cli-name.js +0 -12
  17. package/dist/cli2.js +0 -136
  18. package/dist/command-arguments.js +0 -12
  19. package/dist/commands/agent/index.js +0 -60
  20. package/dist/commands/app/index.js +0 -350
  21. package/dist/commands/auth/index.js +0 -95
  22. package/dist/commands/branch/index.js +0 -27
  23. package/dist/commands/bucket/index.js +0 -123
  24. package/dist/commands/build/index.js +0 -29
  25. package/dist/commands/database/index.js +0 -249
  26. package/dist/commands/env.js +0 -99
  27. package/dist/commands/feedback/index.js +0 -20
  28. package/dist/commands/git/index.js +0 -36
  29. package/dist/commands/init/index.js +0 -33
  30. package/dist/commands/project/index.js +0 -118
  31. package/dist/commands/version/index.js +0 -18
  32. package/dist/controllers/agent-setup.js +0 -52
  33. package/dist/controllers/agent.js +0 -228
  34. package/dist/controllers/app-env-api.js +0 -55
  35. package/dist/controllers/app-env-file.js +0 -181
  36. package/dist/controllers/app-env.js +0 -502
  37. package/dist/controllers/app.js +0 -2508
  38. package/dist/controllers/auth.js +0 -124
  39. package/dist/controllers/branch.js +0 -92
  40. package/dist/controllers/bucket.js +0 -184
  41. package/dist/controllers/build.js +0 -88
  42. package/dist/controllers/database.js +0 -463
  43. package/dist/controllers/feedback.js +0 -90
  44. package/dist/controllers/init.js +0 -814
  45. package/dist/controllers/project.js +0 -892
  46. package/dist/controllers/select-prompt-port.js +0 -13
  47. package/dist/controllers/version.js +0 -12
  48. package/dist/errors.js +0 -102
  49. package/dist/lib/agent/cli-command.js +0 -20
  50. package/dist/lib/agent/constants.js +0 -12
  51. package/dist/lib/agent/package-manager.js +0 -99
  52. package/dist/lib/agent/setup-status.js +0 -83
  53. package/dist/lib/app/app-provider.js +0 -617
  54. package/dist/lib/app/branch-database-api.js +0 -102
  55. package/dist/lib/app/branch-database-deploy.js +0 -353
  56. package/dist/lib/app/branch-database.js +0 -234
  57. package/dist/lib/app/build-settings.js +0 -98
  58. package/dist/lib/app/build.js +0 -82
  59. package/dist/lib/app/bun-project.js +0 -45
  60. package/dist/lib/app/compute-config.js +0 -145
  61. package/dist/lib/app/deploy-output.js +0 -24
  62. package/dist/lib/app/deploy-plan.js +0 -59
  63. package/dist/lib/app/deploy-progress.js +0 -100
  64. package/dist/lib/app/domain-guidance.js +0 -14
  65. package/dist/lib/app/env-config.js +0 -67
  66. package/dist/lib/app/env-file.js +0 -82
  67. package/dist/lib/app/env-vars.js +0 -50
  68. package/dist/lib/app/local-dev.js +0 -109
  69. package/dist/lib/app/production-deploy-gate.js +0 -162
  70. package/dist/lib/app/read-branch.js +0 -30
  71. package/dist/lib/bucket/provider.js +0 -139
  72. package/dist/lib/database/provider.js +0 -385
  73. package/dist/lib/diagnostics.js +0 -16
  74. package/dist/lib/feedback.js +0 -15
  75. package/dist/lib/fs/home-path.js +0 -24
  76. package/dist/lib/git/local-branch.js +0 -53
  77. package/dist/lib/git/local-status.js +0 -57
  78. package/dist/lib/project/interactive-setup.js +0 -57
  79. package/dist/lib/project/local-pin.js +0 -200
  80. package/dist/lib/project/provider.js +0 -93
  81. package/dist/lib/project/resolution.js +0 -389
  82. package/dist/lib/project/setup.js +0 -138
  83. package/dist/lib/version.js +0 -56
  84. package/dist/lib/workspace-id.js +0 -18
  85. package/dist/output/patterns.js +0 -90
  86. package/dist/presenters/agent.js +0 -74
  87. package/dist/presenters/app-env.js +0 -265
  88. package/dist/presenters/app.js +0 -672
  89. package/dist/presenters/auth.js +0 -184
  90. package/dist/presenters/branch.js +0 -46
  91. package/dist/presenters/bucket.js +0 -174
  92. package/dist/presenters/database.js +0 -462
  93. package/dist/presenters/feedback.js +0 -26
  94. package/dist/presenters/init.js +0 -30
  95. package/dist/presenters/project.js +0 -268
  96. package/dist/presenters/verbose-context.js +0 -64
  97. package/dist/presenters/version.js +0 -29
  98. package/dist/shell/cli-command.js +0 -2
  99. package/dist/shell/command-meta.js +0 -923
  100. package/dist/shell/command-runner.js +0 -119
  101. package/dist/shell/diagnostics-output.js +0 -57
  102. package/dist/shell/global-flags.js +0 -37
  103. package/dist/shell/help.js +0 -90
  104. package/dist/shell/output.js +0 -144
  105. package/dist/shell/prompt.js +0 -48
  106. package/dist/shell/runtime.js +0 -38
  107. package/dist/shell/ui.js +0 -116
  108. package/dist/state-dir.js +0 -12
  109. package/dist/update-check.js +0 -248
  110. package/dist/v8/cli.js +0 -14699
@@ -1,248 +0,0 @@
1
- import { CLI_DOCS_URL } from "./cli-name.js";
2
- import { getCliName, getCliVersion } from "./lib/version.js";
3
- import path from "node:path";
4
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
5
- import os from "node:os";
6
- import { randomUUID } from "node:crypto";
7
- import { spawn } from "node:child_process";
8
- //#region src/update-check.ts
9
- const UPDATE_CHECK_FILE_NAME = "update-check.json";
10
- const FALLBACK_INSTALL_DOCS_URL = CLI_DOCS_URL;
11
- const NOTIFICATION_INTERVAL_MS = 1440 * 60 * 1e3;
12
- const REGISTRY_URL = "https://registry.npmjs.org/@prisma%2fcli";
13
- const REGISTRY_TIMEOUT_MS = 3e3;
14
- var UpdateCheckStore = class {
15
- filePath;
16
- constructor(cacheDir) {
17
- this.filePath = path.join(cacheDir, UPDATE_CHECK_FILE_NAME);
18
- }
19
- async read() {
20
- try {
21
- return JSON.parse(await readFile(this.filePath, "utf8"));
22
- } catch (error) {
23
- if (isUnreadableCacheError(error)) return null;
24
- throw error;
25
- }
26
- }
27
- async write(state) {
28
- const dir = path.dirname(this.filePath);
29
- const tempPath = path.join(dir, `${UPDATE_CHECK_FILE_NAME}.${process.pid}.${randomUUID()}.tmp`);
30
- await mkdir(dir, { recursive: true });
31
- await writeFile(tempPath, `${JSON.stringify(state, null, 2)}\n`, "utf8");
32
- await rename(tempPath, this.filePath);
33
- }
34
- };
35
- async function maybeWriteCachedUpdateNotification(runtime) {
36
- if (!canRunUpdateCheck(runtime)) return;
37
- try {
38
- const cacheDir = resolveUpdateCheckCacheDir(runtime);
39
- const store = new UpdateCheckStore(cacheDir);
40
- const state = await store.read();
41
- const latestVersion = state?.latestVersion;
42
- if (latestVersion && isInstalledVersionStale(getCliVersion(), latestVersion) && shouldNotify(state)) {
43
- runtime.stderr.write(renderUpdateNotification(latestVersion, selectUpdateInstruction(runtime.env)));
44
- await store.write({
45
- ...state,
46
- packageName: "@prisma/cli",
47
- installedVersion: getCliVersion(),
48
- notifiedAt: (/* @__PURE__ */ new Date()).toISOString()
49
- });
50
- }
51
- await scheduleRemoteDiscovery(runtime, store, state, cacheDir);
52
- } catch {
53
- return;
54
- }
55
- }
56
- async function runUpdateDiscovery(options) {
57
- try {
58
- const latestVersion = await fetchLatestVersion(options.registryUrl ?? REGISTRY_URL, options.fetchImpl ?? fetch);
59
- if (!latestVersion) return;
60
- const store = new UpdateCheckStore(options.cacheDir);
61
- const previousState = await store.read();
62
- await store.write({
63
- ...previousState,
64
- packageName: "@prisma/cli",
65
- installedVersion: options.installedVersion,
66
- latestVersion,
67
- checkedAt: (options.now ?? /* @__PURE__ */ new Date()).toISOString()
68
- });
69
- } catch {
70
- return;
71
- }
72
- }
73
- function isUnreadableCacheError(error) {
74
- const code = error.code;
75
- return code === "ENOENT" || code === "EACCES" || code === "EPERM" || error instanceof SyntaxError;
76
- }
77
- async function runUpdateDiscoveryWorker(env = process.env) {
78
- const cacheDir = env.PRISMA_CLI_UPDATE_CHECK_DIR;
79
- const installedVersion = env.PRISMA_CLI_UPDATE_CHECK_INSTALLED_VERSION;
80
- if (!cacheDir || !installedVersion) return;
81
- await runUpdateDiscovery({
82
- cacheDir,
83
- installedVersion,
84
- registryUrl: env.PRISMA_CLI_UPDATE_CHECK_REGISTRY_URL
85
- });
86
- }
87
- function canRunUpdateCheck(runtime) {
88
- if (runtime.env.NO_UPDATE_NOTIFIER !== void 0) return false;
89
- if (isTestRuntime(runtime.env) && runtime.env.PRISMA_CLI_TEST_ENABLE_UPDATE_CHECK !== "1") return false;
90
- if (runtime.env.CI || runtime.env.GITHUB_ACTIONS) return false;
91
- if (!runtime.stderr.isTTY) return false;
92
- if (runtime.argv.includes("--json") || runtime.argv.includes("--quiet") || runtime.argv.includes("-q")) return false;
93
- if (runtime.argv.includes("--version")) return false;
94
- return true;
95
- }
96
- function shouldNotify(state) {
97
- return !state.notifiedAt || isAtLeastIntervalAgo(state.notifiedAt);
98
- }
99
- async function scheduleRemoteDiscovery(runtime, store, state, cacheDir) {
100
- if (state?.checkedAt && !isAtLeastIntervalAgo(state.checkedAt)) return;
101
- const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
102
- await store.write({
103
- ...state,
104
- packageName: "@prisma/cli",
105
- installedVersion: getCliVersion(),
106
- checkedAt
107
- });
108
- if (isTestRuntime(runtime.env)) return;
109
- const entrypoint = process.argv[1];
110
- if (!entrypoint) return;
111
- spawn(process.execPath, [entrypoint], {
112
- detached: true,
113
- stdio: "ignore",
114
- env: {
115
- ...process.env,
116
- PRISMA_CLI_RUN_UPDATE_CHECK_WORKER: "1",
117
- PRISMA_CLI_UPDATE_CHECK_DIR: cacheDir,
118
- PRISMA_CLI_UPDATE_CHECK_INSTALLED_VERSION: getCliVersion(),
119
- PRISMA_CLI_UPDATE_CHECK_REGISTRY_URL: runtime.env.PRISMA_CLI_UPDATE_CHECK_REGISTRY_URL ?? REGISTRY_URL
120
- }
121
- }).unref();
122
- }
123
- function selectUpdateInstruction(env, processArgv = process.argv) {
124
- const entrypoint = (processArgv[1] ?? "").replace(/\\/g, "/").toLowerCase();
125
- const userAgent = env.npm_config_user_agent?.toLowerCase() ?? "";
126
- if (isEphemeralInvocation(entrypoint, env.npm_lifecycle_event?.toLowerCase() ?? "")) return docsInstruction();
127
- if (entrypoint.includes("/node_modules/.bin/")) {
128
- if (userAgent.startsWith("pnpm")) return commandInstruction("pnpm add -D @prisma/cli@latest");
129
- if (userAgent.startsWith("bun")) return commandInstruction("bun add -d @prisma/cli@latest");
130
- if (userAgent.startsWith("npm")) return commandInstruction("npm install --save-dev @prisma/cli@latest");
131
- }
132
- if (env.npm_config_global === "true" || isLikelyGlobalNpmEntrypoint(entrypoint)) return commandInstruction("npm install --global @prisma/cli@latest");
133
- return docsInstruction();
134
- }
135
- function renderUpdateNotification(latestVersion, instruction) {
136
- return [
137
- `Update available: ${getCliName()} ${getCliVersion()} -> ${latestVersion}`,
138
- renderUpdateInstruction(instruction),
139
- ""
140
- ].join("\n");
141
- }
142
- function renderUpdateInstruction(instruction) {
143
- if (instruction.type === "command") return `Run ${instruction.value} to update.`;
144
- return `See ${instruction.value} for update instructions.`;
145
- }
146
- function isEphemeralInvocation(entrypoint, lifecycle) {
147
- return lifecycle === "npx" || lifecycle === "pnpx" || entrypoint.includes("/_npx/") || entrypoint.includes("/.bun/");
148
- }
149
- function isLikelyGlobalNpmEntrypoint(entrypoint) {
150
- return /\/npm\/prisma-cli(\.cmd|\.exe)?$/.test(entrypoint) || /\/npm-global\/bin\/prisma-cli$/.test(entrypoint);
151
- }
152
- function commandInstruction(value) {
153
- return {
154
- type: "command",
155
- value
156
- };
157
- }
158
- function docsInstruction() {
159
- return {
160
- type: "docs",
161
- value: FALLBACK_INSTALL_DOCS_URL
162
- };
163
- }
164
- function resolveUpdateCheckCacheDir(runtime) {
165
- const configured = runtime.env.PRISMA_CLI_UPDATE_CHECK_DIR;
166
- if (configured?.trim()) return path.resolve(configured);
167
- if (process.platform === "darwin") return path.join(os.homedir(), "Library", "Caches", "prisma-cli");
168
- if (process.platform === "win32") {
169
- const localAppData = runtime.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
170
- return path.join(localAppData, "prisma-cli", "cache");
171
- }
172
- const xdgCacheHome = runtime.env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache");
173
- return path.join(xdgCacheHome, "prisma-cli");
174
- }
175
- function isTestRuntime(env) {
176
- return env.VITEST !== void 0 || env.NODE_ENV === "test";
177
- }
178
- function isAtLeastIntervalAgo(value) {
179
- const timestamp = Date.parse(value);
180
- return Number.isNaN(timestamp) || Date.now() - timestamp >= NOTIFICATION_INTERVAL_MS;
181
- }
182
- function isInstalledVersionStale(installedVersion, latestVersion) {
183
- const installed = parseVersion(installedVersion);
184
- const latest = parseVersion(latestVersion);
185
- if (!installed || !latest) return false;
186
- return compareVersions(installed, latest) < 0;
187
- }
188
- function parseVersion(version) {
189
- const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(version);
190
- if (!match) return null;
191
- return {
192
- major: Number(match[1]),
193
- minor: Number(match[2]),
194
- patch: Number(match[3]),
195
- prerelease: match[4]?.split(".") ?? []
196
- };
197
- }
198
- function compareVersions(left, right) {
199
- for (const key of [
200
- "major",
201
- "minor",
202
- "patch"
203
- ]) {
204
- const diff = left[key] - right[key];
205
- if (diff !== 0) return diff;
206
- }
207
- return comparePrerelease(left.prerelease, right.prerelease);
208
- }
209
- function comparePrerelease(left, right) {
210
- if (left.length === 0 && right.length === 0) return 0;
211
- if (left.length === 0) return 1;
212
- if (right.length === 0) return -1;
213
- const count = Math.max(left.length, right.length);
214
- for (let index = 0; index < count; index += 1) {
215
- const leftPart = left[index];
216
- const rightPart = right[index];
217
- if (leftPart === void 0) return -1;
218
- if (rightPart === void 0) return 1;
219
- const diff = comparePrereleasePart(leftPart, rightPart);
220
- if (diff !== 0) return diff;
221
- }
222
- return 0;
223
- }
224
- function comparePrereleasePart(left, right) {
225
- const leftNumber = /^\d+$/.test(left) ? Number(left) : null;
226
- const rightNumber = /^\d+$/.test(right) ? Number(right) : null;
227
- if (leftNumber !== null && rightNumber !== null) return leftNumber - rightNumber;
228
- if (leftNumber !== null) return -1;
229
- if (rightNumber !== null) return 1;
230
- return left.localeCompare(right);
231
- }
232
- async function fetchLatestVersion(registryUrl, fetchImpl) {
233
- const controller = new AbortController();
234
- const timeout = setTimeout(() => controller.abort(), REGISTRY_TIMEOUT_MS);
235
- try {
236
- const response = await fetchImpl(registryUrl, {
237
- signal: controller.signal,
238
- headers: { accept: "application/json" }
239
- });
240
- if (!response.ok) return null;
241
- const latest = (await response.json())["dist-tags"]?.latest;
242
- return typeof latest === "string" ? latest : null;
243
- } finally {
244
- clearTimeout(timeout);
245
- }
246
- }
247
- //#endregion
248
- export { maybeWriteCachedUpdateNotification, runUpdateDiscoveryWorker };