@prisma/cli 3.0.0-beta.2 → 3.0.0-beta.20

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 +5 -16
  2. package/dist/adapters/git.js +8 -3
  3. package/dist/adapters/local-state.js +26 -7
  4. package/dist/adapters/mock-api.js +81 -2
  5. package/dist/adapters/token-storage.js +344 -25
  6. package/dist/cli.js +18 -3
  7. package/dist/cli2.js +12 -4
  8. package/dist/commands/agent/index.js +60 -0
  9. package/dist/commands/app/index.js +90 -61
  10. package/dist/commands/auth/index.js +55 -2
  11. package/dist/commands/branch/index.js +2 -27
  12. package/dist/commands/build/index.js +29 -0
  13. package/dist/commands/database/index.js +159 -0
  14. package/dist/commands/env.js +8 -4
  15. package/dist/commands/git/index.js +1 -1
  16. package/dist/commands/project/index.js +1 -1
  17. package/dist/controllers/agent.js +228 -0
  18. package/dist/controllers/app-env-api.js +54 -0
  19. package/dist/controllers/app-env-file.js +181 -0
  20. package/dist/controllers/app-env.js +286 -131
  21. package/dist/controllers/app.js +849 -309
  22. package/dist/controllers/auth.js +255 -11
  23. package/dist/controllers/branch.js +78 -48
  24. package/dist/controllers/build.js +88 -0
  25. package/dist/controllers/database.js +318 -0
  26. package/dist/controllers/project.js +156 -87
  27. package/dist/controllers/select-prompt-port.js +1 -0
  28. package/dist/lib/agent/cli-command.js +17 -0
  29. package/dist/lib/agent/constants.js +12 -0
  30. package/dist/lib/agent/package-manager.js +99 -0
  31. package/dist/lib/agent/setup-status.js +83 -0
  32. package/dist/lib/app/app-interaction.js +5 -0
  33. package/dist/lib/app/{preview-provider.js → app-provider.js} +220 -104
  34. package/dist/lib/app/branch-database-api.js +102 -0
  35. package/dist/lib/app/branch-database-deploy.js +326 -0
  36. package/dist/lib/app/branch-database.js +216 -0
  37. package/dist/lib/app/build-settings.js +93 -0
  38. package/dist/lib/app/build.js +82 -0
  39. package/dist/lib/app/bun-project.js +15 -9
  40. package/dist/lib/app/compute-config.js +145 -0
  41. package/dist/lib/app/deploy-plan.js +59 -0
  42. package/dist/lib/app/{preview-progress.js → deploy-progress.js} +12 -12
  43. package/dist/lib/app/env-config.js +1 -1
  44. package/dist/lib/app/env-file.js +82 -0
  45. package/dist/lib/app/env-vars.js +28 -2
  46. package/dist/lib/app/local-dev.js +8 -49
  47. package/dist/lib/app/production-deploy-gate.js +162 -0
  48. package/dist/lib/app/read-branch.js +30 -0
  49. package/dist/lib/auth/auth-ops.js +38 -23
  50. package/dist/lib/auth/guard.js +6 -2
  51. package/dist/lib/auth/login.js +117 -15
  52. package/dist/lib/database/provider.js +167 -0
  53. package/dist/lib/diagnostics.js +15 -0
  54. package/dist/lib/fs/home-path.js +24 -0
  55. package/dist/lib/git/local-branch.js +53 -0
  56. package/dist/lib/git/local-status.js +57 -0
  57. package/dist/lib/project/interactive-setup.js +2 -1
  58. package/dist/lib/project/local-pin.js +183 -34
  59. package/dist/lib/project/resolution.js +206 -50
  60. package/dist/lib/project/setup.js +64 -18
  61. package/dist/output/patterns.js +1 -1
  62. package/dist/presenters/agent.js +74 -0
  63. package/dist/presenters/app-env.js +149 -14
  64. package/dist/presenters/app.js +187 -26
  65. package/dist/presenters/auth.js +99 -2
  66. package/dist/presenters/branch.js +37 -102
  67. package/dist/presenters/database.js +274 -0
  68. package/dist/presenters/project.js +44 -26
  69. package/dist/presenters/verbose-context.js +64 -0
  70. package/dist/shell/cli-command.js +12 -0
  71. package/dist/shell/command-arguments.js +7 -1
  72. package/dist/shell/command-meta.js +243 -15
  73. package/dist/shell/command-runner.js +60 -21
  74. package/dist/shell/diagnostics-output.js +57 -0
  75. package/dist/shell/errors.js +61 -1
  76. package/dist/shell/help.js +31 -20
  77. package/dist/shell/output.js +10 -1
  78. package/dist/shell/prompt.js +7 -3
  79. package/dist/shell/runtime.js +10 -6
  80. package/dist/shell/ui.js +42 -3
  81. package/dist/shell/update-check.js +247 -0
  82. package/dist/use-cases/auth.js +68 -1
  83. package/dist/use-cases/branch.js +20 -68
  84. package/dist/use-cases/create-cli-gateways.js +2 -17
  85. package/package.json +27 -10
  86. package/dist/lib/app/preview-build.js +0 -284
  87. package/dist/lib/app/preview-interaction.js +0 -5
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@prisma/cli",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.20",
4
4
  "description": "Command-line interface for the Prisma Developer Platform.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "prisma-cli": "./dist/cli.js"
8
8
  },
9
+ "exports": {
10
+ "./package.json": "./package.json"
11
+ },
9
12
  "files": [
10
13
  "dist",
11
14
  "README.md",
@@ -15,7 +18,7 @@
15
18
  "access": "public"
16
19
  },
17
20
  "engines": {
18
- "node": ">=20"
21
+ "node": ">=22.12.0"
19
22
  },
20
23
  "keywords": [
21
24
  "prisma",
@@ -34,18 +37,32 @@
34
37
  "url": "https://github.com/prisma/prisma-cli/issues"
35
38
  },
36
39
  "license": "Apache-2.0",
40
+ "scripts": {
41
+ "build": "tsdown",
42
+ "prepack": "pnpm run build",
43
+ "test": "vitest run"
44
+ },
37
45
  "dependencies": {
38
- "@clack/prompts": "^1.2.0",
39
- "@prisma/compute-sdk": "^0.19.0",
40
- "c12": "4.0.0-beta.4",
41
- "@prisma/credentials-store": "^7.7.0",
42
- "@prisma/management-api-sdk": "^1.34.0",
46
+ "@clack/prompts": "^1.5.0",
47
+ "@prisma/compute-sdk": "0.31.0",
48
+ "@prisma/credentials-store": "^7.8.0",
49
+ "@prisma/management-api-sdk": "^1.46.0",
50
+ "better-result": "^2.9.2",
43
51
  "colorette": "^2.0.20",
44
- "commander": "^12.1.0",
45
- "magicast": "^0.3.5",
52
+ "commander": "^14.0.3",
53
+ "dotenv": "^17.4.2",
54
+ "execa": "^9.6.1",
55
+ "magicast": "^0.5.3",
46
56
  "open": "^11.0.0",
47
- "string-width": "^8.2.0",
57
+ "string-width": "^8.2.1",
48
58
  "strip-ansi": "^7.2.0",
49
59
  "wrap-ansi": "^10.0.0"
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^22.19.19",
63
+ "tsdown": "^0.21.10",
64
+ "tsx": "^4.22.4",
65
+ "typescript": "^6.0.3",
66
+ "vitest": "^4.1.8"
50
67
  }
51
68
  }
@@ -1,284 +0,0 @@
1
- import { resolveBunEntrypoint } from "./bun-project.js";
2
- import { chmod, copyFile, cp, lstat, mkdir, readFile, readdir, readlink, rm, stat } from "node:fs/promises";
3
- import path from "node:path";
4
- import { AstroBuild, BunBuild, NextjsBuild, NuxtBuild, TanstackStartBuild } from "@prisma/compute-sdk";
5
- //#region src/lib/app/preview-build.ts
6
- const PREVIEW_BUILD_TYPES = [
7
- "auto",
8
- "bun",
9
- "nextjs",
10
- "nuxt",
11
- "astro",
12
- "tanstack-start"
13
- ];
14
- const RESOLVED_PREVIEW_BUILD_TYPES = PREVIEW_BUILD_TYPES.filter((buildType) => buildType !== "auto");
15
- var PreviewBuildStrategy = class {
16
- #appPath;
17
- #entrypoint;
18
- #buildType;
19
- constructor(options) {
20
- this.#appPath = options.appPath;
21
- this.#entrypoint = options.entrypoint;
22
- this.#buildType = options.buildType ?? "auto";
23
- }
24
- async canBuild() {
25
- const { strategy } = await resolvePreviewBuildStrategy({
26
- appPath: this.#appPath,
27
- entrypoint: this.#entrypoint,
28
- buildType: this.#buildType
29
- });
30
- return strategy.canBuild();
31
- }
32
- async execute() {
33
- const { artifact } = await executePreviewBuild({
34
- appPath: this.#appPath,
35
- entrypoint: this.#entrypoint,
36
- buildType: this.#buildType
37
- });
38
- return artifact;
39
- }
40
- };
41
- async function executePreviewBuild(options) {
42
- const { strategy, buildType } = await resolvePreviewBuildStrategy({
43
- appPath: options.appPath,
44
- entrypoint: options.entrypoint,
45
- buildType: options.buildType ?? "auto"
46
- });
47
- const artifact = await strategy.execute();
48
- try {
49
- if (buildType === "nextjs") await restageNextjsArtifact(artifact, options.appPath);
50
- await normalizeArtifactSymlinks(artifact.directory, options.appPath);
51
- return {
52
- artifact,
53
- buildType
54
- };
55
- } catch (error) {
56
- await artifact.cleanup?.().catch(() => void 0);
57
- throw error;
58
- }
59
- }
60
- async function resolvePreviewBuildStrategy(options) {
61
- if (options.buildType !== "auto") {
62
- const strategy = await createPreviewBuildStrategy({
63
- appPath: options.appPath,
64
- entrypoint: options.entrypoint,
65
- buildType: options.buildType
66
- });
67
- return {
68
- buildType: options.buildType,
69
- strategy
70
- };
71
- }
72
- for (const buildType of RESOLVED_PREVIEW_BUILD_TYPES) {
73
- if (buildType === "bun") continue;
74
- const strategy = await createPreviewBuildStrategy({
75
- appPath: options.appPath,
76
- entrypoint: options.entrypoint,
77
- buildType
78
- });
79
- if (await strategy.canBuild()) return {
80
- buildType,
81
- strategy
82
- };
83
- }
84
- return {
85
- buildType: "bun",
86
- strategy: await createPreviewBuildStrategy({
87
- appPath: options.appPath,
88
- entrypoint: options.entrypoint,
89
- buildType: "bun"
90
- })
91
- };
92
- }
93
- async function createPreviewBuildStrategy(options) {
94
- switch (options.buildType) {
95
- case "nextjs": return new NextjsBuild({ appPath: options.appPath });
96
- case "nuxt": return new NuxtBuild({ appPath: options.appPath });
97
- case "astro": return new AstroBuild({ appPath: options.appPath });
98
- case "tanstack-start": return new TanstackStartBuild({ appPath: options.appPath });
99
- case "bun": {
100
- const entrypoint = await resolveBunEntrypoint(options.appPath, options.entrypoint);
101
- return new BunBuild({
102
- appPath: options.appPath,
103
- entrypoint
104
- });
105
- }
106
- }
107
- }
108
- async function stageNextjsStandaloneArtifact(options) {
109
- const standaloneRoot = path.resolve(options.standaloneDir);
110
- const artifactRoot = path.resolve(options.artifactDir);
111
- const appRoot = path.resolve(options.appPath);
112
- await copyPathMaterializingSymlinks(standaloneRoot, artifactRoot, {
113
- standaloneRoot,
114
- appRoot,
115
- sourceRoot: await resolveSourceRoot(appRoot)
116
- });
117
- await hoistPnpmDependencies(path.join(artifactRoot, "node_modules"));
118
- }
119
- async function restageNextjsArtifact(artifact, appPath) {
120
- const artifactDir = artifact.directory;
121
- const standaloneDir = path.join(appPath, ".next", "standalone");
122
- await rm(artifactDir, {
123
- recursive: true,
124
- force: true
125
- });
126
- await stageNextjsStandaloneArtifact({
127
- standaloneDir,
128
- artifactDir,
129
- appPath
130
- });
131
- const serverSubpath = nextjsServerSubpath(artifact.entrypoint);
132
- const serverDir = serverSubpath ? path.join(artifactDir, serverSubpath) : artifactDir;
133
- const publicDir = path.join(appPath, "public");
134
- if (await directoryExists(publicDir)) await cp(publicDir, path.join(serverDir, "public"), {
135
- recursive: true,
136
- verbatimSymlinks: true
137
- });
138
- const staticDir = path.join(appPath, ".next", "static");
139
- if (await directoryExists(staticDir)) await cp(staticDir, path.join(serverDir, ".next", "static"), {
140
- recursive: true,
141
- verbatimSymlinks: true
142
- });
143
- }
144
- function nextjsServerSubpath(entrypoint) {
145
- const dir = path.posix.dirname(entrypoint);
146
- return dir === "." ? "" : dir;
147
- }
148
- async function hoistPnpmDependencies(nodeModulesDir) {
149
- const pnpmNodeModulesDir = path.join(nodeModulesDir, ".pnpm", "node_modules");
150
- if (!await directoryExists(pnpmNodeModulesDir)) return;
151
- const entries = await readdir(pnpmNodeModulesDir, { withFileTypes: true });
152
- for (const entry of entries) {
153
- const sourcePath = path.join(pnpmNodeModulesDir, entry.name);
154
- if (entry.name.startsWith("@") && entry.isDirectory()) {
155
- const scopedEntries = await readdir(sourcePath, { withFileTypes: true });
156
- for (const scopedEntry of scopedEntries) {
157
- const scopedDestination = path.join(nodeModulesDir, entry.name, scopedEntry.name);
158
- if (await pathExists(scopedDestination)) continue;
159
- await mkdir(path.dirname(scopedDestination), { recursive: true });
160
- await copyPathMaterializingSymlinks(path.join(sourcePath, scopedEntry.name), scopedDestination, {
161
- standaloneRoot: pnpmNodeModulesDir,
162
- appRoot: nodeModulesDir,
163
- sourceRoot: nodeModulesDir
164
- });
165
- }
166
- continue;
167
- }
168
- const destinationPath = path.join(nodeModulesDir, entry.name);
169
- if (await pathExists(destinationPath)) continue;
170
- await copyPathMaterializingSymlinks(sourcePath, destinationPath, {
171
- standaloneRoot: pnpmNodeModulesDir,
172
- appRoot: nodeModulesDir,
173
- sourceRoot: nodeModulesDir
174
- });
175
- }
176
- }
177
- async function normalizeArtifactSymlinks(artifactDir, appPath) {
178
- const normalizedArtifactDir = path.resolve(artifactDir);
179
- const normalizedAppPath = path.resolve(appPath);
180
- await walkDirectory(normalizedArtifactDir);
181
- async function walkDirectory(directory) {
182
- const entries = await readdir(directory, { withFileTypes: true });
183
- for (const entry of entries) {
184
- const fullPath = path.join(directory, entry.name);
185
- if (entry.isDirectory()) {
186
- await walkDirectory(fullPath);
187
- continue;
188
- }
189
- if (!entry.isSymbolicLink()) continue;
190
- const target = await readlink(fullPath);
191
- const resolvedTarget = path.resolve(path.dirname(fullPath), target);
192
- if (isPathWithin(normalizedArtifactDir, resolvedTarget)) continue;
193
- if (!isPathWithin(normalizedAppPath, resolvedTarget)) throw new Error(`Build artifact symlink escapes the app directory: ${resolvedTarget}`);
194
- const targetStat = await stat(resolvedTarget);
195
- await rm(fullPath, {
196
- force: true,
197
- recursive: true
198
- });
199
- await cp(resolvedTarget, fullPath, {
200
- recursive: targetStat.isDirectory(),
201
- dereference: true
202
- });
203
- if (targetStat.isDirectory()) await walkDirectory(fullPath);
204
- }
205
- }
206
- }
207
- function isPathWithin(rootPath, candidatePath) {
208
- const relativePath = path.relative(rootPath, candidatePath);
209
- return relativePath === "" || !relativePath.startsWith(`..${path.sep}`) && relativePath !== ".." && !path.isAbsolute(relativePath);
210
- }
211
- async function copyPathMaterializingSymlinks(sourcePath, destinationPath, options) {
212
- const sourceStat = await lstat(sourcePath);
213
- if (sourceStat.isSymbolicLink()) {
214
- const resolvedTarget = await resolveSymlinkTarget(sourcePath, options);
215
- if (resolvedTarget === null) return;
216
- await copyPathMaterializingSymlinks(resolvedTarget, destinationPath, options);
217
- return;
218
- }
219
- if (sourceStat.isDirectory()) {
220
- await mkdir(destinationPath, { recursive: true });
221
- const entries = await readdir(sourcePath, { withFileTypes: true });
222
- for (const entry of entries) await copyPathMaterializingSymlinks(path.join(sourcePath, entry.name), path.join(destinationPath, entry.name), options);
223
- return;
224
- }
225
- if (sourceStat.isFile()) {
226
- await mkdir(path.dirname(destinationPath), { recursive: true });
227
- await copyFile(sourcePath, destinationPath);
228
- await chmod(destinationPath, sourceStat.mode);
229
- }
230
- }
231
- async function resolveSymlinkTarget(symlinkPath, options) {
232
- const linkTarget = await readlink(symlinkPath);
233
- const resolvedTarget = path.resolve(path.dirname(symlinkPath), linkTarget);
234
- if (await pathExists(resolvedTarget)) {
235
- if (!isPathWithin(options.appRoot, resolvedTarget) && !isPathWithin(options.sourceRoot, resolvedTarget)) throw new Error(`Build artifact symlink escapes the app directory: ${resolvedTarget}`);
236
- return resolvedTarget;
237
- }
238
- if (isPathWithin(options.standaloneRoot, resolvedTarget)) {
239
- const fallbackTarget = path.join(options.appRoot, path.relative(options.standaloneRoot, resolvedTarget));
240
- if (await pathExists(fallbackTarget)) return fallbackTarget;
241
- }
242
- if (isPnpmHoistLink(symlinkPath)) return null;
243
- throw new Error(`Next.js standalone symlink target is missing: ${symlinkPath} -> ${linkTarget} (resolved to ${resolvedTarget})`);
244
- }
245
- function isPnpmHoistLink(symlinkPath) {
246
- const parts = path.dirname(symlinkPath).split(path.sep);
247
- for (let i = 0; i < parts.length - 1; i++) if (parts[i] === ".pnpm" && parts[i + 1] === "node_modules") return true;
248
- return false;
249
- }
250
- async function pathExists(targetPath) {
251
- try {
252
- await stat(targetPath);
253
- return true;
254
- } catch {
255
- return false;
256
- }
257
- }
258
- async function directoryExists(targetPath) {
259
- try {
260
- return (await stat(targetPath)).isDirectory();
261
- } catch {
262
- return false;
263
- }
264
- }
265
- async function resolveSourceRoot(appRoot) {
266
- let current = path.resolve(appRoot);
267
- while (true) {
268
- if (await pathExists(path.join(current, ".git")) || await pathExists(path.join(current, "pnpm-workspace.yaml")) || await pathExists(path.join(current, "bun.lock")) || await pathExists(path.join(current, "bun.lockb")) || await packageJsonDeclaresWorkspaces(current)) return current;
269
- const parent = path.dirname(current);
270
- if (parent === current) return path.resolve(appRoot);
271
- current = parent;
272
- }
273
- }
274
- async function packageJsonDeclaresWorkspaces(directory) {
275
- try {
276
- const content = await readFile(path.join(directory, "package.json"), "utf8");
277
- const parsed = JSON.parse(content);
278
- return Boolean(parsed.workspaces);
279
- } catch {
280
- return false;
281
- }
282
- }
283
- //#endregion
284
- export { PREVIEW_BUILD_TYPES, PreviewBuildStrategy, RESOLVED_PREVIEW_BUILD_TYPES, executePreviewBuild };
@@ -1,5 +0,0 @@
1
- import "../../shell/prompt.js";
2
- //#region src/lib/app/preview-interaction.ts
3
- const PREVIEW_DEFAULT_REGION = "eu-central-1";
4
- //#endregion
5
- export { PREVIEW_DEFAULT_REGION };