@prisma/cli 3.0.0-beta.2 → 3.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/adapters/git.js +8 -3
- package/dist/adapters/local-state.js +11 -3
- package/dist/adapters/mock-api.js +6 -2
- package/dist/adapters/token-storage.js +63 -22
- package/dist/cli.js +17 -2
- package/dist/cli2.js +3 -0
- package/dist/commands/app/index.js +4 -2
- package/dist/commands/branch/index.js +2 -27
- package/dist/controllers/app-env.js +227 -64
- package/dist/controllers/app.js +116 -91
- package/dist/controllers/auth.js +8 -8
- package/dist/controllers/branch.js +73 -47
- package/dist/controllers/project.js +107 -67
- package/dist/lib/app/bun-project.js +12 -5
- package/dist/lib/app/local-dev.js +34 -18
- package/dist/lib/app/preview-build.js +90 -62
- package/dist/lib/app/preview-provider.js +143 -54
- package/dist/lib/app/production-deploy-gate.js +160 -0
- package/dist/lib/auth/auth-ops.js +30 -21
- package/dist/lib/auth/guard.js +3 -2
- package/dist/lib/auth/login.js +109 -14
- package/dist/lib/git/local-branch.js +41 -0
- package/dist/lib/project/interactive-setup.js +1 -1
- package/dist/lib/project/local-pin.js +27 -8
- package/dist/lib/project/resolution.js +14 -8
- package/dist/lib/project/setup.js +2 -2
- package/dist/presenters/app-env.js +14 -3
- package/dist/presenters/branch.js +29 -101
- package/dist/shell/command-meta.js +6 -24
- package/dist/shell/command-runner.js +9 -4
- package/dist/shell/errors.js +12 -1
- package/dist/shell/runtime.js +2 -2
- package/dist/shell/ui.js +4 -1
- package/dist/shell/update-check.js +247 -0
- package/dist/use-cases/branch.js +20 -68
- package/dist/use-cases/create-cli-gateways.js +2 -17
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ Useful next commands:
|
|
|
57
57
|
npx prisma-cli app logs
|
|
58
58
|
npx prisma-cli app open
|
|
59
59
|
npx prisma-cli project env add DATABASE_URL=postgresql://example --role preview
|
|
60
|
+
npx prisma-cli project env list
|
|
60
61
|
npx prisma-cli project env list --role preview
|
|
61
62
|
```
|
|
62
63
|
|
|
@@ -73,7 +74,7 @@ The beta package exposes `prisma-cli` so it can coexist with the existing
|
|
|
73
74
|
| `auth` | Log in, log out, and inspect the active Prisma account. |
|
|
74
75
|
| `project` | List projects, show the resolved project, and manage project environment variables. |
|
|
75
76
|
| `git` | Connect or disconnect a project from a GitHub repository. |
|
|
76
|
-
| `branch` |
|
|
77
|
+
| `branch` | List Prisma branches for the resolved project. |
|
|
77
78
|
| `app` | Build, run, deploy, inspect, open, stream logs, promote, roll back, and remove apps. |
|
|
78
79
|
|
|
79
80
|
Common examples:
|
|
@@ -82,7 +83,7 @@ Common examples:
|
|
|
82
83
|
npx prisma-cli version
|
|
83
84
|
npx prisma-cli auth whoami
|
|
84
85
|
npx prisma-cli project show
|
|
85
|
-
npx prisma-cli branch
|
|
86
|
+
npx prisma-cli branch list
|
|
86
87
|
npx prisma-cli app deploy --branch feat-login --framework nextjs
|
|
87
88
|
npx prisma-cli app promote <deployment-id>
|
|
88
89
|
```
|
|
@@ -113,7 +114,7 @@ the result, and route CLI / Compute feedback to the right Prisma channel.
|
|
|
113
114
|
|
|
114
115
|
## Beta notes
|
|
115
116
|
|
|
116
|
-
- Requires Node.js
|
|
117
|
+
- Requires Node.js 22.12 or newer.
|
|
117
118
|
- This is a beta package and may change quickly.
|
|
118
119
|
- Official beta releases publish as `@prisma/cli`.
|
|
119
120
|
- The package binary is `prisma-cli`, not `prisma`, during beta.
|
package/dist/adapters/git.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
3
|
//#region src/adapters/git.ts
|
|
4
4
|
const execFileAsync = promisify(execFile);
|
|
5
|
-
async function readGitOriginRemote(cwd) {
|
|
5
|
+
async function readGitOriginRemote(cwd, signal) {
|
|
6
6
|
try {
|
|
7
7
|
const { stdout } = await execFileAsync("git", [
|
|
8
8
|
"config",
|
|
@@ -10,14 +10,19 @@ async function readGitOriginRemote(cwd) {
|
|
|
10
10
|
"remote.origin.url"
|
|
11
11
|
], {
|
|
12
12
|
cwd,
|
|
13
|
-
timeout: 5e3
|
|
13
|
+
timeout: 5e3,
|
|
14
|
+
signal
|
|
14
15
|
});
|
|
15
16
|
const remote = stdout.trim();
|
|
16
17
|
return remote.length > 0 ? remote : null;
|
|
17
|
-
} catch {
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (signal?.aborted || isAbortError(error)) throw error;
|
|
18
20
|
return null;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
23
|
+
function isAbortError(error) {
|
|
24
|
+
return error instanceof Error && error.name === "AbortError";
|
|
25
|
+
}
|
|
21
26
|
function parseGitHubRepositoryUrl(value) {
|
|
22
27
|
const input = value.trim();
|
|
23
28
|
const shorthand = input.match(/^git@github\.com:([^/\s]+)\/([^/\s]+?)(?:\.git)?$/);
|
|
@@ -20,12 +20,17 @@ function resolveLocalStateFilePath(stateDir) {
|
|
|
20
20
|
}
|
|
21
21
|
var LocalStateStore = class {
|
|
22
22
|
stateFilePath;
|
|
23
|
-
constructor(stateDir) {
|
|
23
|
+
constructor(stateDir, signal) {
|
|
24
|
+
this.signal = signal;
|
|
24
25
|
this.stateFilePath = resolveLocalStateFilePath(stateDir);
|
|
25
26
|
}
|
|
26
27
|
async read() {
|
|
28
|
+
this.signal?.throwIfAborted();
|
|
27
29
|
try {
|
|
28
|
-
const raw = await readFile(this.stateFilePath,
|
|
30
|
+
const raw = await readFile(this.stateFilePath, {
|
|
31
|
+
encoding: "utf8",
|
|
32
|
+
signal: this.signal
|
|
33
|
+
});
|
|
29
34
|
const parsed = JSON.parse(raw);
|
|
30
35
|
return {
|
|
31
36
|
auth: parsed.auth ?? structuredClone(DEFAULT_STATE.auth),
|
|
@@ -46,8 +51,11 @@ var LocalStateStore = class {
|
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
async write(state) {
|
|
54
|
+
this.signal?.throwIfAborted();
|
|
49
55
|
await mkdir(path.dirname(this.stateFilePath), { recursive: true });
|
|
50
|
-
|
|
56
|
+
this.signal?.throwIfAborted();
|
|
57
|
+
await writeFile(this.stateFilePath, `${JSON.stringify(state, null, 2)}\n`, { encoding: "utf8" });
|
|
58
|
+
this.signal?.throwIfAborted();
|
|
51
59
|
}
|
|
52
60
|
async setAuthSession(session) {
|
|
53
61
|
const state = await this.read();
|
|
@@ -5,8 +5,12 @@ var MockApi = class MockApi {
|
|
|
5
5
|
constructor(data) {
|
|
6
6
|
this.data = data;
|
|
7
7
|
}
|
|
8
|
-
static async load(fixturePath) {
|
|
9
|
-
|
|
8
|
+
static async load(fixturePath, signal) {
|
|
9
|
+
signal?.throwIfAborted();
|
|
10
|
+
const raw = await readFile(fixturePath, {
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
signal
|
|
13
|
+
});
|
|
10
14
|
return new MockApi(JSON.parse(raw));
|
|
11
15
|
}
|
|
12
16
|
listProviders() {
|
|
@@ -20,37 +20,60 @@ function findLatestValidTokens(allCredentials) {
|
|
|
20
20
|
function tokensEqual(a, b) {
|
|
21
21
|
return a?.workspaceId === b?.workspaceId && a?.accessToken === b?.accessToken && a?.refreshToken === b?.refreshToken;
|
|
22
22
|
}
|
|
23
|
-
function sleep(ms) {
|
|
24
|
-
|
|
23
|
+
function sleep(ms, signal) {
|
|
24
|
+
signal?.throwIfAborted();
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const onAbort = () => {
|
|
27
|
+
clearTimeout(timeout);
|
|
28
|
+
reject(signal?.reason);
|
|
29
|
+
};
|
|
30
|
+
const timeout = setTimeout(() => {
|
|
31
|
+
signal?.removeEventListener("abort", onAbort);
|
|
32
|
+
resolve();
|
|
33
|
+
}, ms);
|
|
34
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
35
|
+
});
|
|
25
36
|
}
|
|
26
37
|
var FileTokenStorage = class {
|
|
27
38
|
credentialsStore;
|
|
28
39
|
lockFilePath;
|
|
29
|
-
constructor(env = process.env) {
|
|
40
|
+
constructor(env = process.env, signal) {
|
|
41
|
+
this.signal = signal;
|
|
30
42
|
const authFilePath = getAuthFilePath(env);
|
|
31
43
|
this.credentialsStore = new CredentialsStore(authFilePath);
|
|
32
44
|
this.lockFilePath = `${authFilePath}.lock`;
|
|
33
45
|
}
|
|
34
46
|
async getTokens() {
|
|
47
|
+
this.signal?.throwIfAborted();
|
|
35
48
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const all = await this.credentialsStore.getCredentials();
|
|
50
|
+
this.signal?.throwIfAborted();
|
|
51
|
+
return findLatestValidTokens(all);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (this.signal?.aborted) throw this.signal.reason;
|
|
38
54
|
return null;
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
57
|
async setTokens(tokens) {
|
|
58
|
+
this.signal?.throwIfAborted();
|
|
42
59
|
await this.credentialsStore.storeCredentials({
|
|
43
60
|
workspaceId: tokens.workspaceId,
|
|
44
61
|
token: tokens.accessToken,
|
|
45
62
|
refreshToken: tokens.refreshToken
|
|
46
63
|
});
|
|
64
|
+
this.signal?.throwIfAborted();
|
|
47
65
|
}
|
|
48
66
|
async clearTokens() {
|
|
49
|
-
|
|
67
|
+
this.signal?.throwIfAborted();
|
|
68
|
+
const all = await this.credentialsStore.getCredentials();
|
|
69
|
+
this.signal?.throwIfAborted();
|
|
70
|
+
const tokens = findLatestValidTokens(all);
|
|
50
71
|
if (!tokens) return;
|
|
51
72
|
await this.credentialsStore.deleteCredentials(tokens.workspaceId);
|
|
73
|
+
this.signal?.throwIfAborted();
|
|
52
74
|
}
|
|
53
75
|
async clearTokensIfCurrent(tokens) {
|
|
76
|
+
this.signal?.throwIfAborted();
|
|
54
77
|
if (!tokensEqual(await this.getTokens(), tokens)) return;
|
|
55
78
|
await this.clearTokens();
|
|
56
79
|
}
|
|
@@ -64,34 +87,52 @@ var FileTokenStorage = class {
|
|
|
64
87
|
}
|
|
65
88
|
async acquireRefreshLock() {
|
|
66
89
|
const lockId = randomUUID();
|
|
90
|
+
this.signal?.throwIfAborted();
|
|
67
91
|
await fs.mkdir(path.dirname(this.lockFilePath), { recursive: true });
|
|
68
|
-
while (true)
|
|
69
|
-
|
|
92
|
+
while (true) {
|
|
93
|
+
this.signal?.throwIfAborted();
|
|
94
|
+
let lockFileCreated = false;
|
|
70
95
|
try {
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
const handle = await fs.open(this.lockFilePath, "wx");
|
|
97
|
+
lockFileCreated = true;
|
|
98
|
+
try {
|
|
99
|
+
this.signal?.throwIfAborted();
|
|
100
|
+
await handle.writeFile(lockId, { encoding: "utf8" });
|
|
101
|
+
this.signal?.throwIfAborted();
|
|
102
|
+
} finally {
|
|
103
|
+
await handle.close();
|
|
104
|
+
}
|
|
105
|
+
return lockId;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (lockFileCreated) await fs.unlink(this.lockFilePath).catch(() => void 0);
|
|
108
|
+
if (error.code !== "EEXIST") throw error;
|
|
109
|
+
const staleLockId = await this.getStaleRefreshLockId();
|
|
110
|
+
if (staleLockId) {
|
|
111
|
+
await this.releaseRefreshLock(staleLockId);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
await sleep(100, this.signal);
|
|
82
115
|
}
|
|
83
|
-
await sleep(100);
|
|
84
116
|
}
|
|
85
117
|
}
|
|
86
118
|
async getStaleRefreshLockId() {
|
|
87
|
-
|
|
119
|
+
this.signal?.throwIfAborted();
|
|
120
|
+
const lockId = await fs.readFile(this.lockFilePath, {
|
|
121
|
+
encoding: "utf8",
|
|
122
|
+
signal: this.signal
|
|
123
|
+
}).catch((error) => {
|
|
124
|
+
if (this.signal?.aborted) throw error;
|
|
125
|
+
return null;
|
|
126
|
+
});
|
|
88
127
|
if (lockId === null) return null;
|
|
128
|
+
this.signal?.throwIfAborted();
|
|
89
129
|
const stats = await fs.stat(this.lockFilePath).catch(() => null);
|
|
130
|
+
this.signal?.throwIfAborted();
|
|
90
131
|
if (!stats) return null;
|
|
91
132
|
return Date.now() - stats.mtimeMs > 3e4 ? lockId : null;
|
|
92
133
|
}
|
|
93
134
|
async releaseRefreshLock(lockId) {
|
|
94
|
-
if (await fs.readFile(this.lockFilePath, "utf8").catch(() => null) !== lockId) return;
|
|
135
|
+
if (await fs.readFile(this.lockFilePath, { encoding: "utf8" }).catch(() => null) !== lockId) return;
|
|
95
136
|
await fs.unlink(this.lockFilePath).catch(() => {});
|
|
96
137
|
}
|
|
97
138
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { runUpdateDiscoveryWorker } from "./shell/update-check.js";
|
|
2
3
|
import { runCli } from "./cli2.js";
|
|
3
4
|
import process from "node:process";
|
|
4
5
|
//#region src/bin.ts
|
|
5
|
-
|
|
6
|
-
process.exitCode =
|
|
6
|
+
if (process.env.PRISMA_CLI_RUN_UPDATE_CHECK_WORKER === "1") runUpdateDiscoveryWorker().then(() => {
|
|
7
|
+
process.exitCode = 0;
|
|
7
8
|
});
|
|
9
|
+
else {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const abortCli = () => {
|
|
12
|
+
if (!controller.signal.aborted) controller.abort(new DOMException("Command canceled", "AbortError"));
|
|
13
|
+
};
|
|
14
|
+
process.once("SIGINT", abortCli);
|
|
15
|
+
process.once("SIGTERM", abortCli);
|
|
16
|
+
runCli({ signal: controller.signal }).then((exitCode) => {
|
|
17
|
+
process.exitCode = exitCode;
|
|
18
|
+
}).finally(() => {
|
|
19
|
+
process.off("SIGINT", abortCli);
|
|
20
|
+
process.off("SIGTERM", abortCli);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
8
23
|
//#endregion
|
|
9
24
|
export {};
|
package/dist/cli2.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createProjectCommand } from "./commands/project/index.js";
|
|
|
13
13
|
import { getCliName, getCliVersion } from "./lib/version.js";
|
|
14
14
|
import { runVersion } from "./controllers/version.js";
|
|
15
15
|
import { createVersionCommand } from "./commands/version/index.js";
|
|
16
|
+
import { maybeWriteCachedUpdateNotification } from "./shell/update-check.js";
|
|
16
17
|
import process from "node:process";
|
|
17
18
|
import { Command, CommanderError, Option } from "commander";
|
|
18
19
|
//#region src/cli.ts
|
|
@@ -21,6 +22,7 @@ async function runCli(options = {}) {
|
|
|
21
22
|
const program = createProgram(runtime);
|
|
22
23
|
process.exitCode = 0;
|
|
23
24
|
try {
|
|
25
|
+
await maybeWriteCachedUpdateNotification(runtime);
|
|
24
26
|
if (runtime.argv.includes("--version")) return await handleVersionFlag(runtime);
|
|
25
27
|
const bareHelpCommand = resolveBareHelpCommand(program, runtime.argv);
|
|
26
28
|
if (bareHelpCommand) {
|
|
@@ -104,6 +106,7 @@ function resolveRuntime(options) {
|
|
|
104
106
|
argv: options.argv ?? process.argv.slice(2),
|
|
105
107
|
cwd: options.cwd ?? process.env.INIT_CWD ?? process.cwd(),
|
|
106
108
|
env: options.env ?? process.env,
|
|
109
|
+
signal: options.signal ?? new AbortController().signal,
|
|
107
110
|
stdin: options.stdin ?? process.stdin,
|
|
108
111
|
stdout: options.stdout ?? process.stdout,
|
|
109
112
|
stderr: options.stderr ?? process.stderr,
|
|
@@ -64,7 +64,7 @@ function createDeployCommand(runtime) {
|
|
|
64
64
|
"hono",
|
|
65
65
|
"tanstack-start",
|
|
66
66
|
"bun"
|
|
67
|
-
])).addOption(new Option("--entry <path>", "Entrypoint path for Bun deploys")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues));
|
|
67
|
+
])).addOption(new Option("--entry <path>", "Entrypoint path for Bun deploys")).addOption(new Option("--http-port <port>", "HTTP port override for the deployed app")).addOption(new Option("--env <name=value>", "Environment variable").argParser(collectRepeatableValues)).addOption(new Option("--prod", "Confirm intent to deploy to production"));
|
|
68
68
|
addGlobalFlags(command);
|
|
69
69
|
command.action(async (options) => {
|
|
70
70
|
const appName = options.app;
|
|
@@ -75,6 +75,7 @@ function createDeployCommand(runtime) {
|
|
|
75
75
|
const envAssignments = options.env;
|
|
76
76
|
const projectRef = options.project;
|
|
77
77
|
const createProjectName = options.createProject;
|
|
78
|
+
const prod = options.prod;
|
|
78
79
|
await runCommand(runtime, "app.deploy", options, (context) => runAppDeploy(context, appName, {
|
|
79
80
|
projectRef,
|
|
80
81
|
createProjectName,
|
|
@@ -82,7 +83,8 @@ function createDeployCommand(runtime) {
|
|
|
82
83
|
entrypoint: entry,
|
|
83
84
|
framework,
|
|
84
85
|
httpPort,
|
|
85
|
-
envAssignments
|
|
86
|
+
envAssignments,
|
|
87
|
+
prod: prod === true
|
|
86
88
|
}), {
|
|
87
89
|
renderHuman: (context, descriptor, result) => renderAppDeploy(context, descriptor, result),
|
|
88
90
|
renderJson: (result) => serializeAppDeploy(result)
|
|
@@ -2,16 +2,14 @@ import { attachCommandDescriptor } from "../../shell/command-meta.js";
|
|
|
2
2
|
import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
|
|
3
3
|
import { configureRuntimeCommand } from "../../shell/runtime.js";
|
|
4
4
|
import { runCommand } from "../../shell/command-runner.js";
|
|
5
|
-
import { runBranchList
|
|
6
|
-
import { renderBranchList,
|
|
5
|
+
import { runBranchList } from "../../controllers/branch.js";
|
|
6
|
+
import { renderBranchList, serializeBranchList } from "../../presenters/branch.js";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
//#region src/commands/branch/index.ts
|
|
9
9
|
function createBranchCommand(runtime) {
|
|
10
10
|
const branch = attachCommandDescriptor(configureRuntimeCommand(new Command("branch"), runtime), "branch");
|
|
11
11
|
addCompactGlobalFlags(branch);
|
|
12
12
|
branch.addCommand(createBranchListCommand(runtime));
|
|
13
|
-
branch.addCommand(createBranchShowCommand(runtime));
|
|
14
|
-
branch.addCommand(createBranchUseCommand(runtime));
|
|
15
13
|
return branch;
|
|
16
14
|
}
|
|
17
15
|
function createBranchListCommand(runtime) {
|
|
@@ -25,28 +23,5 @@ function createBranchListCommand(runtime) {
|
|
|
25
23
|
});
|
|
26
24
|
return command;
|
|
27
25
|
}
|
|
28
|
-
function createBranchShowCommand(runtime) {
|
|
29
|
-
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("show"), runtime), "branch.show");
|
|
30
|
-
addGlobalFlags(command);
|
|
31
|
-
command.action(async (options) => {
|
|
32
|
-
await runCommand(runtime, "branch.show", options, (context) => runBranchShow(context), {
|
|
33
|
-
renderHuman: (context, descriptor, result) => renderBranchShow(context, descriptor, result),
|
|
34
|
-
renderJson: (result) => serializeBranchShow(result)
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return command;
|
|
38
|
-
}
|
|
39
|
-
function createBranchUseCommand(runtime) {
|
|
40
|
-
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("use"), runtime), "branch.use");
|
|
41
|
-
command.argument("[name]", "Branch name");
|
|
42
|
-
addGlobalFlags(command);
|
|
43
|
-
command.action(async (branchName, options) => {
|
|
44
|
-
await runCommand(runtime, "branch.use", options, (context) => runBranchUse(context, branchName), {
|
|
45
|
-
renderHuman: (context, descriptor, result) => renderBranchUse(context, descriptor, result),
|
|
46
|
-
renderJson: (result) => serializeBranchShow(result)
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
return command;
|
|
50
|
-
}
|
|
51
26
|
//#endregion
|
|
52
27
|
export { createBranchCommand };
|