@prisma/cli 3.0.0-dev.65.1 → 3.0.0-dev.69.1
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/dist/commands/app/index.js +1 -1
- package/dist/controllers/app-env.js +2 -2
- package/dist/controllers/app.js +3 -3
- package/dist/lib/app/branch-database-deploy.js +3 -3
- package/dist/lib/app/env-file.js +2 -2
- package/dist/lib/app/env-vars.js +28 -2
- package/dist/shell/command-meta.js +1 -0
- package/package.json +2 -2
|
@@ -65,7 +65,7 @@ function createDeployCommand(runtime) {
|
|
|
65
65
|
"hono",
|
|
66
66
|
"tanstack-start",
|
|
67
67
|
"bun"
|
|
68
|
-
])).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("--db", "Create and wire an isolated database for the preview Branch")).addOption(new Option("--no-db", "Skip branch database setup")).addOption(new Option("--prod", "Confirm intent to deploy to production"));
|
|
68
|
+
])).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|file>", "Environment variable assignment or dotenv file").argParser(collectRepeatableValues)).addOption(new Option("--db", "Create and wire an isolated database for the preview Branch")).addOption(new Option("--no-db", "Skip branch database setup")).addOption(new Option("--prod", "Confirm intent to deploy to production"));
|
|
69
69
|
addGlobalFlags(command);
|
|
70
70
|
command.action(async (options) => {
|
|
71
71
|
const appName = options.app;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CliError, authRequiredError, usageError, workspaceRequiredError } from "../shell/errors.js";
|
|
2
2
|
import { requireComputeAuth } from "../lib/auth/guard.js";
|
|
3
|
+
import { formatScopeLabel, parseKeyValuePositional, resolveEnvScope } from "../lib/app/env-config.js";
|
|
4
|
+
import { readEnvFileAssignments } from "../lib/app/env-file.js";
|
|
3
5
|
import { resolveProjectTarget } from "../lib/project/resolution.js";
|
|
4
6
|
import { readLocalGitBranch } from "../lib/git/local-branch.js";
|
|
5
7
|
import { requireAuthenticatedAuthState } from "./auth.js";
|
|
6
8
|
import { listRealWorkspaceProjects } from "./project.js";
|
|
7
|
-
import { formatScopeLabel, parseKeyValuePositional, resolveEnvScope } from "../lib/app/env-config.js";
|
|
8
|
-
import { readEnvFileAssignments } from "../lib/app/env-file.js";
|
|
9
9
|
import { apiCallError, findVariableByNaturalKey, toMetadata } from "./app-env-api.js";
|
|
10
10
|
import { runEnvAddFile, runEnvUpdateFile } from "./app-env-file.js";
|
|
11
11
|
//#region src/controllers/app-env.ts
|
package/dist/controllers/app.js
CHANGED
|
@@ -7,7 +7,7 @@ import { canPrompt } from "../shell/runtime.js";
|
|
|
7
7
|
import { confirmPrompt, selectPrompt, textPrompt } from "../shell/prompt.js";
|
|
8
8
|
import { requireComputeAuth } from "../lib/auth/guard.js";
|
|
9
9
|
import { readAuthState } from "../lib/auth/auth-ops.js";
|
|
10
|
-
import { envVarNames,
|
|
10
|
+
import { envVarNames, parseEnvInputs } from "../lib/app/env-vars.js";
|
|
11
11
|
import { renderDeployOutputRows, renderDeploySettingsPreview } from "../lib/app/deploy-output.js";
|
|
12
12
|
import { readBunPackageEntrypoint, readBunPackageJson } from "../lib/app/bun-project.js";
|
|
13
13
|
import { DEFAULT_LOCAL_DEV_PORT, resolveLocalBuildType, runLocalApp } from "../lib/app/local-dev.js";
|
|
@@ -138,7 +138,7 @@ async function runAppDeploy(context, appName, options) {
|
|
|
138
138
|
});
|
|
139
139
|
let runtime = resolveDeployRuntime(options?.httpPort, framework);
|
|
140
140
|
assertSupportedEntrypoint(framework.buildType, options?.entrypoint, "deploy");
|
|
141
|
-
const envVars = toOptionalEnvVars(
|
|
141
|
+
const envVars = toOptionalEnvVars(await parseEnvInputs(context.runtime.cwd, options?.envAssignments, { commandName: "deploy" }));
|
|
142
142
|
const selectedApp = await resolveDeployAppSelection(context, projectId, await listApps(context, provider, projectId, target.branch.name), {
|
|
143
143
|
explicitAppName: appName,
|
|
144
144
|
explicitAppId: envAppId,
|
|
@@ -173,7 +173,7 @@ async function runAppDeploy(context, appName, options) {
|
|
|
173
173
|
const portMapping = parseDeployPortMapping(String(runtime.port));
|
|
174
174
|
const branchDatabaseSetup = await maybeSetupBranchDatabase(context, provider, projectId, toBranchDatabaseDeployBranch(target.branch), {
|
|
175
175
|
db: options?.db,
|
|
176
|
-
|
|
176
|
+
providedEnvVars: envVars
|
|
177
177
|
});
|
|
178
178
|
const progressState = createPreviewDeployProgressState();
|
|
179
179
|
const deployStartedAt = Date.now();
|
|
@@ -8,8 +8,8 @@ import path from "node:path";
|
|
|
8
8
|
//#region src/lib/app/branch-database-deploy.ts
|
|
9
9
|
async function maybeSetupBranchDatabase(context, provider, projectId, branch, options) {
|
|
10
10
|
if (options.db === false) return emptyBranchDatabaseSetupOutcome();
|
|
11
|
-
if (
|
|
12
|
-
if (options.db === true) throw usageError("Branch database setup cannot be combined with
|
|
11
|
+
if (hasProvidedDatabaseEnvVars(options.providedEnvVars)) {
|
|
12
|
+
if (options.db === true) throw usageError("Branch database setup cannot be combined with provided database env vars", "The deploy command received --db and a DATABASE_URL or DIRECT_URL value from --env.", "Remove the --env database value to let --db create a branch override, or remove --db to deploy with the provided value.", ["prisma-cli app deploy --db", "prisma-cli app deploy --env DATABASE_URL=postgresql://example"], "app");
|
|
13
13
|
return emptyBranchDatabaseSetupOutcome();
|
|
14
14
|
}
|
|
15
15
|
if (branch.kind === "production") {
|
|
@@ -184,7 +184,7 @@ async function inspectBranchDatabaseEnv(provider, projectId, branchId, signal) {
|
|
|
184
184
|
function findEnvVar(rows, options) {
|
|
185
185
|
return rows.find((row) => row.branchId === options.branchId) ?? null;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function hasProvidedDatabaseEnvVars(envVars) {
|
|
188
188
|
return Boolean(envVars && ("DATABASE_URL" in envVars || "DIRECT_URL" in envVars));
|
|
189
189
|
}
|
|
190
190
|
function maybeRenderBranchDatabaseSignal(context, branchName, signal, envState) {
|
package/dist/lib/app/env-file.js
CHANGED
|
@@ -11,7 +11,7 @@ async function readEnvFileAssignments(cwd, filePath, command) {
|
|
|
11
11
|
try {
|
|
12
12
|
contents = await readFile(resolvedPath, "utf8");
|
|
13
13
|
} catch (error) {
|
|
14
|
-
throw usageError(`Failed to read env file "${filePath}"`, error instanceof Error ? error.message : "The file could not be read.", "Pass a readable dotenv file path.", [`prisma-cli project env ${command} --file .env --role preview`], "app");
|
|
14
|
+
throw usageError(`Failed to read env file "${filePath}"`, error instanceof Error ? error.message : "The file could not be read.", "Pass a readable dotenv file path.", [command === "deploy" ? "prisma-cli app deploy --env .env" : `prisma-cli project env ${command} --file .env --role preview`], "app");
|
|
15
15
|
}
|
|
16
16
|
return parseEnvFileContents(contents, filePath, command);
|
|
17
17
|
}
|
|
@@ -63,7 +63,7 @@ function extractParsedKeys(contents) {
|
|
|
63
63
|
}
|
|
64
64
|
function validateEnvFileKey(key, line, filePath, command) {
|
|
65
65
|
try {
|
|
66
|
-
validateKey(key, command);
|
|
66
|
+
validateKey(key, command === "deploy" ? "add" : command);
|
|
67
67
|
} catch (error) {
|
|
68
68
|
const reason = error instanceof Error && error.message.length > 0 ? error.message : "Invalid environment variable key.";
|
|
69
69
|
throw usageError(`Invalid environment variable "${key}" in "${filePath}"`, `Line ${line}: ${reason}`, "Use a valid env-var key and retry the import.", [], "app");
|
package/dist/lib/app/env-vars.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { usageError } from "../../shell/errors.js";
|
|
2
|
+
import { validateKey } from "./env-config.js";
|
|
3
|
+
import { readEnvFileAssignments } from "./env-file.js";
|
|
2
4
|
//#region src/lib/app/env-vars.ts
|
|
3
5
|
function parseEnvAssignments(assignments, options) {
|
|
4
6
|
const values = assignments ?? [];
|
|
@@ -10,15 +12,39 @@ function parseEnvAssignments(assignments, options) {
|
|
|
10
12
|
if (separatorIndex === -1) throw usageError("Environment variable assignment must use NAME=VALUE", "A provided --env flag is missing the = separator.", `Pass repeated --env NAME=VALUE flags, for example prisma-cli app ${options.commandName} --env DATABASE_URL=postgresql://example.`, [`prisma-cli app ${options.commandName} --env DATABASE_URL=postgresql://example`], "app");
|
|
11
13
|
const name = assignment.slice(0, separatorIndex);
|
|
12
14
|
if (name.length === 0) throw usageError("Environment variable name is required", "A provided --env flag has an empty variable name.", `Pass repeated --env NAME=VALUE flags, for example prisma-cli app ${options.commandName} --env DATABASE_URL=postgresql://example.`, [`prisma-cli app ${options.commandName} --env DATABASE_URL=postgresql://example`], "app");
|
|
15
|
+
validateEnvAssignmentName(name, options.commandName);
|
|
13
16
|
if (seen.has(name)) throw usageError(`Environment variable "${name}" was provided more than once`, "Each environment variable name may be set only once per command invocation.", `Remove the duplicate "${name}" assignment and rerun prisma-cli app ${options.commandName}.`, [`prisma-cli app ${options.commandName} --env ${name}=value`], "app");
|
|
17
|
+
const value = assignment.slice(separatorIndex + 1);
|
|
18
|
+
if (value.length === 0) throw usageError(`Environment variable "${name}" has an empty value`, `A provided --env flag defines ${name} with no value.`, "Pass a non-empty value, or omit the key from the deploy command.", [`prisma-cli app ${options.commandName} --env ${name}=value`], "app");
|
|
14
19
|
seen.add(name);
|
|
15
|
-
parsed[name] =
|
|
20
|
+
parsed[name] = value;
|
|
16
21
|
}
|
|
17
22
|
return parsed;
|
|
18
23
|
}
|
|
24
|
+
async function parseEnvInputs(cwd, inputs, options) {
|
|
25
|
+
const values = inputs ?? [];
|
|
26
|
+
const expandedAssignments = [];
|
|
27
|
+
for (const value of values) {
|
|
28
|
+
if (value.includes("=")) {
|
|
29
|
+
expandedAssignments.push(value);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const fileAssignments = await readEnvFileAssignments(cwd, value, options.commandName);
|
|
33
|
+
expandedAssignments.push(...fileAssignments.map((assignment) => `${assignment.key}=${assignment.value}`));
|
|
34
|
+
}
|
|
35
|
+
return parseEnvAssignments(expandedAssignments, options);
|
|
36
|
+
}
|
|
37
|
+
function validateEnvAssignmentName(name, commandName) {
|
|
38
|
+
try {
|
|
39
|
+
validateKey(name, "add");
|
|
40
|
+
} catch (error) {
|
|
41
|
+
const reason = error instanceof Error && error.message.length > 0 ? error.message : "Invalid environment variable name.";
|
|
42
|
+
throw usageError(`Invalid environment variable "${name}"`, reason, "Use a valid env-var name and retry the deploy.", [`prisma-cli app ${commandName} --env DATABASE_URL=postgresql://example`], "app");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
19
45
|
function envVarNames(envVars) {
|
|
20
46
|
if (!envVars) return [];
|
|
21
47
|
return Object.entries(envVars).filter(([, value]) => value !== null).map(([name]) => name).sort((left, right) => left.localeCompare(right));
|
|
22
48
|
}
|
|
23
49
|
//#endregion
|
|
24
|
-
export { envVarNames,
|
|
50
|
+
export { envVarNames, parseEnvInputs };
|
|
@@ -194,6 +194,7 @@ const DESCRIPTORS = [
|
|
|
194
194
|
"prisma-cli app deploy --project proj_123",
|
|
195
195
|
"prisma-cli app deploy --create-project my-app --yes",
|
|
196
196
|
"prisma-cli app deploy --app my-app --env DATABASE_URL=postgresql://example",
|
|
197
|
+
"prisma-cli app deploy --env .env",
|
|
197
198
|
"prisma-cli app deploy --db",
|
|
198
199
|
"prisma-cli app deploy --db --yes",
|
|
199
200
|
"prisma-cli app deploy --app my-app --framework nextjs --http-port 3000",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/cli",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.69.1",
|
|
4
4
|
"description": "Command-line interface for the Prisma Developer Platform.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@clack/prompts": "^1.5.0",
|
|
39
|
-
"@prisma/compute-sdk": "^0.
|
|
39
|
+
"@prisma/compute-sdk": "^0.22.0",
|
|
40
40
|
"@prisma/credentials-store": "^7.8.0",
|
|
41
41
|
"@prisma/management-api-sdk": "^1.37.0",
|
|
42
42
|
"c12": "4.0.0-beta.5",
|