@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.
- package/README.md +5 -16
- package/dist/adapters/git.js +8 -3
- package/dist/adapters/local-state.js +26 -7
- package/dist/adapters/mock-api.js +81 -2
- package/dist/adapters/token-storage.js +344 -25
- package/dist/cli.js +18 -3
- package/dist/cli2.js +12 -4
- package/dist/commands/agent/index.js +60 -0
- package/dist/commands/app/index.js +90 -61
- package/dist/commands/auth/index.js +55 -2
- package/dist/commands/branch/index.js +2 -27
- package/dist/commands/build/index.js +29 -0
- package/dist/commands/database/index.js +159 -0
- package/dist/commands/env.js +8 -4
- package/dist/commands/git/index.js +1 -1
- package/dist/commands/project/index.js +1 -1
- package/dist/controllers/agent.js +228 -0
- package/dist/controllers/app-env-api.js +54 -0
- package/dist/controllers/app-env-file.js +181 -0
- package/dist/controllers/app-env.js +286 -131
- package/dist/controllers/app.js +849 -309
- package/dist/controllers/auth.js +255 -11
- package/dist/controllers/branch.js +78 -48
- package/dist/controllers/build.js +88 -0
- package/dist/controllers/database.js +318 -0
- package/dist/controllers/project.js +156 -87
- package/dist/controllers/select-prompt-port.js +1 -0
- package/dist/lib/agent/cli-command.js +17 -0
- package/dist/lib/agent/constants.js +12 -0
- package/dist/lib/agent/package-manager.js +99 -0
- package/dist/lib/agent/setup-status.js +83 -0
- package/dist/lib/app/app-interaction.js +5 -0
- package/dist/lib/app/{preview-provider.js → app-provider.js} +220 -104
- package/dist/lib/app/branch-database-api.js +102 -0
- package/dist/lib/app/branch-database-deploy.js +326 -0
- package/dist/lib/app/branch-database.js +216 -0
- package/dist/lib/app/build-settings.js +93 -0
- package/dist/lib/app/build.js +82 -0
- package/dist/lib/app/bun-project.js +15 -9
- package/dist/lib/app/compute-config.js +145 -0
- package/dist/lib/app/deploy-plan.js +59 -0
- package/dist/lib/app/{preview-progress.js → deploy-progress.js} +12 -12
- package/dist/lib/app/env-config.js +1 -1
- package/dist/lib/app/env-file.js +82 -0
- package/dist/lib/app/env-vars.js +28 -2
- package/dist/lib/app/local-dev.js +8 -49
- package/dist/lib/app/production-deploy-gate.js +162 -0
- package/dist/lib/app/read-branch.js +30 -0
- package/dist/lib/auth/auth-ops.js +38 -23
- package/dist/lib/auth/guard.js +6 -2
- package/dist/lib/auth/login.js +117 -15
- package/dist/lib/database/provider.js +167 -0
- package/dist/lib/diagnostics.js +15 -0
- package/dist/lib/fs/home-path.js +24 -0
- package/dist/lib/git/local-branch.js +53 -0
- package/dist/lib/git/local-status.js +57 -0
- package/dist/lib/project/interactive-setup.js +2 -1
- package/dist/lib/project/local-pin.js +183 -34
- package/dist/lib/project/resolution.js +206 -50
- package/dist/lib/project/setup.js +64 -18
- package/dist/output/patterns.js +1 -1
- package/dist/presenters/agent.js +74 -0
- package/dist/presenters/app-env.js +149 -14
- package/dist/presenters/app.js +187 -26
- package/dist/presenters/auth.js +99 -2
- package/dist/presenters/branch.js +37 -102
- package/dist/presenters/database.js +274 -0
- package/dist/presenters/project.js +44 -26
- package/dist/presenters/verbose-context.js +64 -0
- package/dist/shell/cli-command.js +12 -0
- package/dist/shell/command-arguments.js +7 -1
- package/dist/shell/command-meta.js +243 -15
- package/dist/shell/command-runner.js +60 -21
- package/dist/shell/diagnostics-output.js +57 -0
- package/dist/shell/errors.js +61 -1
- package/dist/shell/help.js +31 -20
- package/dist/shell/output.js +10 -1
- package/dist/shell/prompt.js +7 -3
- package/dist/shell/runtime.js +10 -6
- package/dist/shell/ui.js +42 -3
- package/dist/shell/update-check.js +247 -0
- package/dist/use-cases/auth.js +68 -1
- package/dist/use-cases/branch.js +20 -68
- package/dist/use-cases/create-cli-gateways.js +2 -17
- package/package.json +27 -10
- package/dist/lib/app/preview-build.js +0 -284
- package/dist/lib/app/preview-interaction.js +0 -5
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { resolveBuildSettings, resolveConfiguredBuildSettings } from "@prisma/compute-sdk";
|
|
4
|
+
//#region src/lib/app/build-settings.ts
|
|
5
|
+
/** Legacy build-settings file: no longer read or written, only detected for migration. */
|
|
6
|
+
const PRISMA_APP_CONFIG_FILENAME = "prisma.app.json";
|
|
7
|
+
/**
|
|
8
|
+
* Detects a leftover `prisma.app.json`. The file is no longer used: one that
|
|
9
|
+
* matches the effective settings is reported for deletion, one with custom
|
|
10
|
+
* values must be migrated to the compute config so builds never silently
|
|
11
|
+
* change.
|
|
12
|
+
*/
|
|
13
|
+
async function detectLegacyBuildSettings(options) {
|
|
14
|
+
const configPath = path.join(options.appPath, PRISMA_APP_CONFIG_FILENAME);
|
|
15
|
+
let content;
|
|
16
|
+
try {
|
|
17
|
+
options.signal?.throwIfAborted();
|
|
18
|
+
content = await readFile(configPath, {
|
|
19
|
+
encoding: "utf8",
|
|
20
|
+
signal: options.signal
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (options.signal?.aborted) throw error;
|
|
24
|
+
return { kind: "absent" };
|
|
25
|
+
}
|
|
26
|
+
let legacy;
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(content);
|
|
29
|
+
const buildCommand = parsed.buildCommand === null || typeof parsed.buildCommand === "string" ? typeof parsed.buildCommand === "string" ? parsed.buildCommand.trim() || null : null : void 0;
|
|
30
|
+
const outputDirectory = typeof parsed.outputDirectory === "string" ? normalizeRelativePath(parsed.outputDirectory) : void 0;
|
|
31
|
+
if (buildCommand === void 0 || !outputDirectory) return {
|
|
32
|
+
kind: "invalid",
|
|
33
|
+
configPath
|
|
34
|
+
};
|
|
35
|
+
legacy = {
|
|
36
|
+
buildCommand,
|
|
37
|
+
outputDirectory
|
|
38
|
+
};
|
|
39
|
+
} catch {
|
|
40
|
+
return {
|
|
41
|
+
kind: "invalid",
|
|
42
|
+
configPath
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return legacy.buildCommand === options.effective.buildCommand && legacy.outputDirectory === options.effective.outputDirectory ? {
|
|
46
|
+
kind: "matching",
|
|
47
|
+
configPath
|
|
48
|
+
} : {
|
|
49
|
+
kind: "custom",
|
|
50
|
+
configPath,
|
|
51
|
+
...legacy
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Resolves build settings purely from framework inference; nothing is read or written. */
|
|
55
|
+
async function resolveInferredAppBuildSettings(options) {
|
|
56
|
+
return {
|
|
57
|
+
status: "inferred",
|
|
58
|
+
configPath: null,
|
|
59
|
+
relativeConfigPath: null,
|
|
60
|
+
settings: await resolveBuildSettings(options)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves build settings when the compute config owns them: configured
|
|
65
|
+
* fields win, omitted fields fall back to framework defaults.
|
|
66
|
+
*/
|
|
67
|
+
async function resolveConfiguredAppBuildSettings(options) {
|
|
68
|
+
const configFilename = path.basename(options.configPath);
|
|
69
|
+
const settings = await resolveConfiguredBuildSettings({
|
|
70
|
+
appPath: options.appPath,
|
|
71
|
+
buildType: options.buildType,
|
|
72
|
+
configured: options.configured,
|
|
73
|
+
source: `set by ${configFilename}`,
|
|
74
|
+
signal: options.signal
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
status: "config",
|
|
78
|
+
configPath: options.configPath,
|
|
79
|
+
relativeConfigPath: configFilename,
|
|
80
|
+
settings
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function normalizeRelativePath(value) {
|
|
84
|
+
const raw = value.trim().replace(/\\/g, "/");
|
|
85
|
+
if (raw.length === 0 || raw.split("/").includes("..")) return;
|
|
86
|
+
if (/^[A-Za-z]:/.test(raw)) return;
|
|
87
|
+
const normalized = path.posix.normalize(raw);
|
|
88
|
+
const segments = normalized.split("/");
|
|
89
|
+
if (path.win32.isAbsolute(value) || path.posix.isAbsolute(normalized) || segments.includes("..")) return;
|
|
90
|
+
return normalized === "." ? "." : normalized;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { PRISMA_APP_CONFIG_FILENAME, detectLegacyBuildSettings, resolveConfiguredAppBuildSettings, resolveInferredAppBuildSettings };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import "./build-settings.js";
|
|
2
|
+
import "node:path";
|
|
3
|
+
import "node:fs/promises";
|
|
4
|
+
import { FRAMEWORKS } from "@prisma/compute-sdk/config";
|
|
5
|
+
import { normalizeArtifactSymlinks, resolveBuildStrategy } from "@prisma/compute-sdk";
|
|
6
|
+
//#region src/lib/app/build.ts
|
|
7
|
+
const RESOLVED_APP_BUILD_TYPES = [...frameworkBuildTypesByLastOccurrence()];
|
|
8
|
+
const APP_BUILD_TYPES = ["auto", ...RESOLVED_APP_BUILD_TYPES];
|
|
9
|
+
const APP_BUILD_TYPE_LABELS = APP_BUILD_TYPES.join(", ");
|
|
10
|
+
function frameworkBuildTypesByLastOccurrence() {
|
|
11
|
+
const buildTypes = /* @__PURE__ */ new Set();
|
|
12
|
+
for (const framework of FRAMEWORKS) {
|
|
13
|
+
if (buildTypes.has(framework.buildType)) buildTypes.delete(framework.buildType);
|
|
14
|
+
buildTypes.add(framework.buildType);
|
|
15
|
+
}
|
|
16
|
+
return buildTypes;
|
|
17
|
+
}
|
|
18
|
+
var AppBuildStrategy = class {
|
|
19
|
+
#appPath;
|
|
20
|
+
#entrypoint;
|
|
21
|
+
#buildType;
|
|
22
|
+
#signal;
|
|
23
|
+
#buildSettings;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.#appPath = options.appPath;
|
|
26
|
+
this.#entrypoint = options.entrypoint;
|
|
27
|
+
this.#buildType = options.buildType ?? "auto";
|
|
28
|
+
this.#signal = options.signal;
|
|
29
|
+
this.#buildSettings = options.buildSettings;
|
|
30
|
+
}
|
|
31
|
+
async canBuild(signal = this.#signal) {
|
|
32
|
+
const { strategy } = await resolveAppBuildStrategy({
|
|
33
|
+
appPath: this.#appPath,
|
|
34
|
+
entrypoint: this.#entrypoint,
|
|
35
|
+
buildType: this.#buildType,
|
|
36
|
+
signal,
|
|
37
|
+
buildSettings: this.#buildSettings
|
|
38
|
+
});
|
|
39
|
+
return strategy.canBuild(signal);
|
|
40
|
+
}
|
|
41
|
+
async execute(signal = this.#signal) {
|
|
42
|
+
const { artifact } = await executeAppBuild({
|
|
43
|
+
appPath: this.#appPath,
|
|
44
|
+
entrypoint: this.#entrypoint,
|
|
45
|
+
buildType: this.#buildType,
|
|
46
|
+
signal,
|
|
47
|
+
buildSettings: this.#buildSettings
|
|
48
|
+
});
|
|
49
|
+
return artifact;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
async function executeAppBuild(options) {
|
|
53
|
+
const { strategy, buildType } = await resolveAppBuildStrategy({
|
|
54
|
+
appPath: options.appPath,
|
|
55
|
+
entrypoint: options.entrypoint,
|
|
56
|
+
buildType: options.buildType ?? "auto",
|
|
57
|
+
signal: options.signal,
|
|
58
|
+
buildSettings: options.buildSettings
|
|
59
|
+
});
|
|
60
|
+
const artifact = await strategy.execute(options.signal);
|
|
61
|
+
try {
|
|
62
|
+
await normalizeArtifactSymlinks(artifact.directory, options.appPath, options.signal);
|
|
63
|
+
return {
|
|
64
|
+
artifact,
|
|
65
|
+
buildType
|
|
66
|
+
};
|
|
67
|
+
} catch (error) {
|
|
68
|
+
await artifact.cleanup?.().catch(() => void 0);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function resolveAppBuildStrategy(options) {
|
|
73
|
+
return resolveBuildStrategy({
|
|
74
|
+
appPath: options.appPath,
|
|
75
|
+
buildType: options.buildType,
|
|
76
|
+
entrypoint: options.entrypoint,
|
|
77
|
+
buildSettings: options.buildSettings,
|
|
78
|
+
signal: options.signal
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { APP_BUILD_TYPES, APP_BUILD_TYPE_LABELS, AppBuildStrategy, RESOLVED_APP_BUILD_TYPES, executeAppBuild };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { access, readFile } from "node:fs/promises";
|
|
2
1
|
import path from "node:path";
|
|
2
|
+
import { access, readFile } from "node:fs/promises";
|
|
3
3
|
//#region src/lib/app/bun-project.ts
|
|
4
|
-
async function readBunPackageJson(appPath) {
|
|
4
|
+
async function readBunPackageJson(appPath, signal) {
|
|
5
5
|
const packageJsonPath = path.join(appPath, "package.json");
|
|
6
6
|
let content;
|
|
7
|
+
signal?.throwIfAborted();
|
|
7
8
|
try {
|
|
8
|
-
content = await readFile(packageJsonPath,
|
|
9
|
+
content = await readFile(packageJsonPath, {
|
|
10
|
+
encoding: "utf8",
|
|
11
|
+
signal
|
|
12
|
+
});
|
|
9
13
|
} catch (error) {
|
|
10
14
|
if (error.code === "ENOENT") return null;
|
|
11
15
|
throw new Error(`Failed to read ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -17,20 +21,22 @@ async function readBunPackageJson(appPath) {
|
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
function readBunPackageEntrypoint(packageJson) {
|
|
20
|
-
|
|
21
|
-
if (typeof packageJson?.module === "string") return packageJson.module;
|
|
24
|
+
return typeof packageJson?.main === "string" ? packageJson.main : void 0;
|
|
22
25
|
}
|
|
23
|
-
async function resolveBunEntrypoint(appPath, explicitEntrypoint) {
|
|
24
|
-
const packageJson = await readBunPackageJson(appPath);
|
|
26
|
+
async function resolveBunEntrypoint(appPath, explicitEntrypoint, signal) {
|
|
27
|
+
const packageJson = await readBunPackageJson(appPath, signal);
|
|
25
28
|
const candidate = explicitEntrypoint ?? readBunPackageEntrypoint(packageJson);
|
|
26
|
-
if (!candidate) throw new Error("Entrypoint is required. Pass --entry or define package.json main
|
|
29
|
+
if (!candidate) throw new Error("Entrypoint is required. Pass --entry or define package.json main.");
|
|
27
30
|
if (path.isAbsolute(candidate)) throw new Error("Entrypoint must be a relative path.");
|
|
28
31
|
const normalized = path.normalize(candidate);
|
|
29
32
|
if (normalized.startsWith("..") || path.isAbsolute(normalized) || normalized.includes(`${path.sep}..${path.sep}`)) throw new Error("Entrypoint must not escape the app directory.");
|
|
30
33
|
const entrypointPath = path.join(appPath, normalized);
|
|
34
|
+
signal?.throwIfAborted();
|
|
31
35
|
try {
|
|
32
36
|
await access(entrypointPath);
|
|
33
|
-
|
|
37
|
+
signal?.throwIfAborted();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (signal?.aborted) throw error;
|
|
34
40
|
throw new Error(`Entrypoint file does not exist: ${entrypointPath}`);
|
|
35
41
|
}
|
|
36
42
|
return normalized.split(path.sep).join("/");
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { CliError } from "../../shell/errors.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { COMPUTE_CONFIG_FILENAME, COMPUTE_CONFIG_FILENAME as COMPUTE_CONFIG_FILENAME$1, ComputeConfigTargetRequiredError, computeTargetAppDir, frameworkByKey, inferComputeTargetFromCwd, loadComputeConfig, selectComputeDeployTarget } from "@prisma/compute-sdk/config";
|
|
4
|
+
import { matchError } from "better-result";
|
|
5
|
+
//#region src/lib/app/compute-config.ts
|
|
6
|
+
/**
|
|
7
|
+
* Loads the nearest compute config, searching from `cwd` up to the source
|
|
8
|
+
* root (repository or workspace boundary). Thin adapter over the SDK loader
|
|
9
|
+
* keeping the CLI's positional-signal call shape.
|
|
10
|
+
*/
|
|
11
|
+
async function loadComputeConfig$1(cwd, signal) {
|
|
12
|
+
return loadComputeConfig(cwd, { signal });
|
|
13
|
+
}
|
|
14
|
+
/** Local build/run strategy implied by a configured framework. */
|
|
15
|
+
function computeFrameworkToBuildType(framework) {
|
|
16
|
+
return frameworkByKey(framework).buildType;
|
|
17
|
+
}
|
|
18
|
+
function mergeComputeDeployInputs(options) {
|
|
19
|
+
const { cli, target, configFilename } = options;
|
|
20
|
+
const configAnnotation = `set by ${configFilename}`;
|
|
21
|
+
const framework = mergeStringInput(cli.framework, "set by --framework", target?.framework ?? void 0, configAnnotation);
|
|
22
|
+
const entrypoint = mergeStringInput(cli.entrypoint, "set by --entry", target?.entry ?? void 0, configAnnotation);
|
|
23
|
+
const httpPort = mergeStringInput(cli.httpPort, "set by --http-port", target?.httpPort ? String(target.httpPort) : void 0, configAnnotation);
|
|
24
|
+
const region = mergeStringInput(cli.region, "set by --region", target?.region ?? void 0, configAnnotation);
|
|
25
|
+
const cliEnvInputs = cli.envInputs && cli.envInputs.length > 0 ? cli.envInputs : void 0;
|
|
26
|
+
const configEnvInputs = target && target.envInputs.length > 0 ? target.envInputs : void 0;
|
|
27
|
+
const envInputs = cliEnvInputs ?? configEnvInputs;
|
|
28
|
+
const configAppName = readConfigAppName(target, configAnnotation);
|
|
29
|
+
return {
|
|
30
|
+
framework,
|
|
31
|
+
entrypoint,
|
|
32
|
+
httpPort,
|
|
33
|
+
region,
|
|
34
|
+
envInputs,
|
|
35
|
+
envInputsFromConfig: !cliEnvInputs && configEnvInputs !== void 0,
|
|
36
|
+
configAppName,
|
|
37
|
+
appRoot: target?.root ?? void 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function mergeStringInput(cliValue, cliAnnotation, configValue, configAnnotation) {
|
|
41
|
+
if (cliValue !== void 0) return {
|
|
42
|
+
value: cliValue,
|
|
43
|
+
annotation: cliAnnotation
|
|
44
|
+
};
|
|
45
|
+
if (configValue) return {
|
|
46
|
+
value: configValue,
|
|
47
|
+
annotation: configAnnotation
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function readConfigAppName(target, configAnnotation) {
|
|
51
|
+
if (target?.name) return {
|
|
52
|
+
value: target.name,
|
|
53
|
+
annotation: configAnnotation
|
|
54
|
+
};
|
|
55
|
+
if (target?.key) return {
|
|
56
|
+
value: target.key,
|
|
57
|
+
annotation: configAnnotation
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Merges CLI inputs for the local `app build` and `app run` commands with a
|
|
62
|
+
* selected config target. Explicit flags win; `--build-type auto` is the
|
|
63
|
+
* flag default and defers to the configured framework.
|
|
64
|
+
*/
|
|
65
|
+
function mergeComputeLocalInputs(options) {
|
|
66
|
+
const { cli, target } = options;
|
|
67
|
+
const cliBuildType = cli.buildType && cli.buildType !== "auto" ? cli.buildType : void 0;
|
|
68
|
+
const configBuildType = target?.framework ? computeFrameworkToBuildType(target.framework) : void 0;
|
|
69
|
+
return {
|
|
70
|
+
entrypoint: cli.entrypoint ?? target?.entry ?? void 0,
|
|
71
|
+
buildType: cliBuildType ?? configBuildType,
|
|
72
|
+
buildTypeFromConfig: !cliBuildType && configBuildType !== void 0,
|
|
73
|
+
port: cli.port ?? (target?.httpPort ? String(target.httpPort) : void 0),
|
|
74
|
+
appRoot: target?.root ?? void 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function computeConfigErrorToCliError(error, commandName = "deploy") {
|
|
78
|
+
const command = `prisma-cli app ${commandName}`;
|
|
79
|
+
return matchError(error, {
|
|
80
|
+
ComputeConfigAmbiguousError: (ambiguous) => new CliError({
|
|
81
|
+
code: "COMPUTE_CONFIG_INVALID",
|
|
82
|
+
domain: "app",
|
|
83
|
+
summary: "Multiple compute config files found",
|
|
84
|
+
why: ambiguous.message,
|
|
85
|
+
fix: `Keep exactly one compute config file, preferably ${COMPUTE_CONFIG_FILENAME}.`,
|
|
86
|
+
meta: { configPaths: ambiguous.configPaths },
|
|
87
|
+
exitCode: 2,
|
|
88
|
+
nextSteps: [command]
|
|
89
|
+
}),
|
|
90
|
+
ComputeConfigLoadError: (load) => new CliError({
|
|
91
|
+
code: "COMPUTE_CONFIG_INVALID",
|
|
92
|
+
domain: "app",
|
|
93
|
+
summary: `Could not load ${path.basename(load.configPath)}`,
|
|
94
|
+
why: load.message,
|
|
95
|
+
fix: `Fix the error in ${path.basename(load.configPath)} and rerun the command.`,
|
|
96
|
+
where: load.configPath,
|
|
97
|
+
meta: { configPath: load.configPath },
|
|
98
|
+
exitCode: 2,
|
|
99
|
+
nextSteps: [command]
|
|
100
|
+
}),
|
|
101
|
+
ComputeConfigInvalidError: (invalid) => new CliError({
|
|
102
|
+
code: "COMPUTE_CONFIG_INVALID",
|
|
103
|
+
domain: "app",
|
|
104
|
+
summary: `Invalid ${path.basename(invalid.configPath)}`,
|
|
105
|
+
why: invalid.issues.join(" "),
|
|
106
|
+
fix: `Edit ${path.basename(invalid.configPath)} so it default-exports defineComputeConfig({ app }) or defineComputeConfig({ apps }).`,
|
|
107
|
+
where: invalid.configPath,
|
|
108
|
+
meta: {
|
|
109
|
+
configPath: invalid.configPath,
|
|
110
|
+
issues: invalid.issues
|
|
111
|
+
},
|
|
112
|
+
exitCode: 2,
|
|
113
|
+
nextSteps: [command]
|
|
114
|
+
}),
|
|
115
|
+
ComputeConfigTargetRequiredError: (required) => new CliError({
|
|
116
|
+
code: "COMPUTE_CONFIG_TARGET_REQUIRED",
|
|
117
|
+
domain: "app",
|
|
118
|
+
summary: "App target required",
|
|
119
|
+
why: required.message,
|
|
120
|
+
fix: `Pass the app target, for example ${command} <target>.`,
|
|
121
|
+
meta: {
|
|
122
|
+
configPath: required.configPath,
|
|
123
|
+
availableTargets: required.availableTargets
|
|
124
|
+
},
|
|
125
|
+
exitCode: 2,
|
|
126
|
+
nextSteps: required.availableTargets.map((target) => `${command} ${target}`)
|
|
127
|
+
}),
|
|
128
|
+
ComputeConfigTargetUnknownError: (unknown) => new CliError({
|
|
129
|
+
code: "COMPUTE_CONFIG_TARGET_UNKNOWN",
|
|
130
|
+
domain: "app",
|
|
131
|
+
summary: `Unknown app target "${unknown.requestedTarget}"`,
|
|
132
|
+
why: unknown.message,
|
|
133
|
+
fix: unknown.availableTargets.length > 0 ? `Pass one of the configured targets: ${unknown.availableTargets.join(", ")}.` : "Remove the target argument; this config defines a single app.",
|
|
134
|
+
meta: {
|
|
135
|
+
configPath: unknown.configPath,
|
|
136
|
+
requestedTarget: unknown.requestedTarget,
|
|
137
|
+
availableTargets: unknown.availableTargets
|
|
138
|
+
},
|
|
139
|
+
exitCode: 2,
|
|
140
|
+
nextSteps: unknown.availableTargets.length > 0 ? unknown.availableTargets.map((target) => `${command} ${target}`) : [command]
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { COMPUTE_CONFIG_FILENAME$1 as COMPUTE_CONFIG_FILENAME, ComputeConfigTargetRequiredError, computeConfigErrorToCliError, computeFrameworkToBuildType, computeTargetAppDir, inferComputeTargetFromCwd, loadComputeConfig$1 as loadComputeConfig, mergeComputeDeployInputs, mergeComputeLocalInputs, selectComputeDeployTarget };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/lib/app/deploy-plan.ts
|
|
2
|
+
/**
|
|
3
|
+
* Decides whether a deploy covers one app or the whole system. A multi-app
|
|
4
|
+
* config with no target named or inferred deploys every target in declaration
|
|
5
|
+
* order; everything else (single-app config, an explicit/inferred target, or
|
|
6
|
+
* no config at all) is a single deploy.
|
|
7
|
+
*/
|
|
8
|
+
function planAppDeploy(options) {
|
|
9
|
+
const { config, requestedTarget, hasCreateProject } = options;
|
|
10
|
+
if (!(config !== null && config.kind === "multi" && !requestedTarget && config.targets.length > 1)) return { mode: "single" };
|
|
11
|
+
const total = config.targets.length;
|
|
12
|
+
return {
|
|
13
|
+
mode: "all",
|
|
14
|
+
targets: config.targets.map((target, index) => ({
|
|
15
|
+
targetKey: target.key,
|
|
16
|
+
index,
|
|
17
|
+
total,
|
|
18
|
+
bindsCreateProject: index === 0 && hasCreateProject
|
|
19
|
+
}))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Names the per-app inputs present in a deploy-all invocation, in the order
|
|
24
|
+
* they should be reported. An empty list means the run is unambiguous; the
|
|
25
|
+
* caller renders the usage error when it is not.
|
|
26
|
+
*/
|
|
27
|
+
function perAppInputsForDeployAll(inputs) {
|
|
28
|
+
return [
|
|
29
|
+
["--app", inputs.appName],
|
|
30
|
+
["--framework", inputs.framework],
|
|
31
|
+
["--entry", inputs.entrypoint],
|
|
32
|
+
["--http-port", inputs.httpPort],
|
|
33
|
+
["--region", inputs.region],
|
|
34
|
+
["--env", inputs.envAssignments?.length ? inputs.envAssignments : void 0],
|
|
35
|
+
[inputs.appIdEnvVar.name, inputs.appIdEnvVar.value]
|
|
36
|
+
].filter(([, value]) => value !== void 0).map(([flag]) => flag);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Describes a deploy-all run that stopped at the first failing target: which
|
|
40
|
+
* targets already went live and which were never attempted, so the caller can
|
|
41
|
+
* surface a converge path. Pure; the caller folds this into the CliError.
|
|
42
|
+
*/
|
|
43
|
+
function describeDeployAllFailure(options) {
|
|
44
|
+
const { targetKeys, failedIndex, completed } = options;
|
|
45
|
+
const failedTarget = targetKeys[failedIndex];
|
|
46
|
+
const notAttempted = targetKeys.slice(failedIndex + 1);
|
|
47
|
+
return {
|
|
48
|
+
failedTarget,
|
|
49
|
+
completed,
|
|
50
|
+
notAttempted,
|
|
51
|
+
contextLines: [
|
|
52
|
+
`Deploying all apps stopped at "${failedTarget}" (${failedIndex + 1}/${targetKeys.length}).`,
|
|
53
|
+
...completed.length > 0 ? [`Already live: ${completed.map((entry) => entry.target).join(", ")}.`] : [],
|
|
54
|
+
...notAttempted.length > 0 ? [`Not attempted: ${notAttempted.join(", ")}.`] : []
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { describeDeployAllFailure, perAppInputsForDeployAll, planAppDeploy };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { renderDeployOutputRows } from "./deploy-output.js";
|
|
2
|
-
//#region src/lib/app/
|
|
3
|
-
function
|
|
2
|
+
//#region src/lib/app/deploy-progress.ts
|
|
3
|
+
function createDeployProgressState() {
|
|
4
4
|
return {
|
|
5
5
|
buildStarted: false,
|
|
6
6
|
buildCompleted: false,
|
|
7
7
|
archiveReady: false,
|
|
8
8
|
uploadCompleted: false,
|
|
9
|
-
|
|
9
|
+
deploymentId: null,
|
|
10
10
|
startRequested: false,
|
|
11
11
|
containerLive: false,
|
|
12
12
|
deploymentUrl: null,
|
|
13
13
|
promotedUrl: null
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function createDeployProgress(output, ui, enabled, state = createDeployProgressState()) {
|
|
17
17
|
const write = (line) => {
|
|
18
18
|
if (!enabled) return;
|
|
19
19
|
output.write(`${line}\n`);
|
|
@@ -39,8 +39,8 @@ function createPreviewDeployProgress(output, ui, enabled, state = createPreviewD
|
|
|
39
39
|
onUploadStart() {
|
|
40
40
|
write("Uploading...");
|
|
41
41
|
},
|
|
42
|
-
|
|
43
|
-
state.
|
|
42
|
+
onDeploymentCreated(deploymentId) {
|
|
43
|
+
state.deploymentId = deploymentId;
|
|
44
44
|
},
|
|
45
45
|
onUploadComplete() {
|
|
46
46
|
state.uploadCompleted = true;
|
|
@@ -63,22 +63,22 @@ function createPreviewDeployProgress(output, ui, enabled, state = createPreviewD
|
|
|
63
63
|
function formatArtifactSize(byteLength) {
|
|
64
64
|
return `${(byteLength / 1024 / 1024).toFixed(1)} MB`;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function createPromoteProgress(output, enabled) {
|
|
67
67
|
if (!enabled) return;
|
|
68
68
|
const write = (line) => {
|
|
69
69
|
output.write(`${line}\n`);
|
|
70
70
|
};
|
|
71
71
|
return {
|
|
72
|
-
|
|
73
|
-
write(`Starting deployment ${
|
|
72
|
+
onDeploymentStarting(deploymentId) {
|
|
73
|
+
write(`Starting deployment ${deploymentId}...`);
|
|
74
74
|
},
|
|
75
|
-
|
|
75
|
+
onDeploymentStartRequested() {
|
|
76
76
|
write("Requesting deployment start...");
|
|
77
77
|
},
|
|
78
78
|
onStatusChange(status) {
|
|
79
79
|
write(`Status: ${status}`);
|
|
80
80
|
},
|
|
81
|
-
|
|
81
|
+
onDeploymentRunning() {
|
|
82
82
|
write("Deployment is running.");
|
|
83
83
|
},
|
|
84
84
|
onPromoteStart() {
|
|
@@ -97,4 +97,4 @@ function createPreviewPromoteProgress(output, enabled) {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
//#endregion
|
|
100
|
-
export {
|
|
100
|
+
export { createDeployProgress, createDeployProgressState, createPromoteProgress };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { usageError } from "../../shell/errors.js";
|
|
2
|
+
import { validateKey } from "./env-config.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { parse } from "dotenv";
|
|
6
|
+
//#region src/lib/app/env-file.ts
|
|
7
|
+
const ASSIGNMENT_KEY_PATTERN = /^\s*(?:export\s+)?([^#=\s]+)\s*=/;
|
|
8
|
+
async function readEnvFileAssignments(cwd, filePath, command) {
|
|
9
|
+
const resolvedPath = path.resolve(cwd, filePath);
|
|
10
|
+
let contents;
|
|
11
|
+
try {
|
|
12
|
+
contents = await readFile(resolvedPath, "utf8");
|
|
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.", [command === "deploy" ? "prisma-cli app deploy --env .env" : `prisma-cli project env ${command} --file .env --role preview`], "app");
|
|
15
|
+
}
|
|
16
|
+
return parseEnvFileContents(contents, filePath, command);
|
|
17
|
+
}
|
|
18
|
+
function parseEnvFileContents(contents, filePath, command) {
|
|
19
|
+
const parsedKeys = extractParsedKeys(contents);
|
|
20
|
+
if (parsedKeys.length === 0) throw usageError(`No environment variables found in "${filePath}"`, "The file does not contain any KEY=VALUE assignments.", "Pass a dotenv file with at least one non-empty variable.", [], "app");
|
|
21
|
+
const seen = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const entry of parsedKeys) {
|
|
23
|
+
validateEnvFileKey(entry.key, entry.line, filePath, command);
|
|
24
|
+
const firstLine = seen.get(entry.key);
|
|
25
|
+
if (firstLine !== void 0) throw usageError(`Duplicate environment variable "${entry.key}" in "${filePath}"`, `Lines ${firstLine} and ${entry.line} both define ${entry.key}.`, "Keep one assignment for each key before importing the file.", [], "app");
|
|
26
|
+
seen.set(entry.key, entry.line);
|
|
27
|
+
}
|
|
28
|
+
const parsedValues = parse(contents);
|
|
29
|
+
return parsedKeys.map(({ key }) => {
|
|
30
|
+
const value = parsedValues[key];
|
|
31
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
32
|
+
const line = seen.get(key);
|
|
33
|
+
throw usageError(`Environment variable "${key}" in "${filePath}" has an empty value`, line === void 0 ? `${key} has an empty value.` : `Line ${line} defines ${key} with an empty value.`, "Pass a non-empty value, or omit the key from the file.", [], "app");
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
key,
|
|
37
|
+
value
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function extractParsedKeys(contents) {
|
|
42
|
+
const keys = [];
|
|
43
|
+
let multilineQuote = null;
|
|
44
|
+
const lines = contents.split(/\n/);
|
|
45
|
+
for (const [index, line] of lines.entries()) {
|
|
46
|
+
const lineNumber = index + 1;
|
|
47
|
+
if (multilineQuote !== null) {
|
|
48
|
+
if (hasClosingQuote(line, multilineQuote, 0)) multilineQuote = null;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const match = ASSIGNMENT_KEY_PATTERN.exec(line);
|
|
52
|
+
if (!match) continue;
|
|
53
|
+
const key = match[1];
|
|
54
|
+
keys.push({
|
|
55
|
+
key,
|
|
56
|
+
line: lineNumber
|
|
57
|
+
});
|
|
58
|
+
const valueStart = line.slice(match[0].length).trimStart();
|
|
59
|
+
const openingQuote = valueStart[0];
|
|
60
|
+
if ((openingQuote === "\"" || openingQuote === "'" || openingQuote === "`") && !hasClosingQuote(valueStart, openingQuote, 1)) multilineQuote = openingQuote;
|
|
61
|
+
}
|
|
62
|
+
return keys;
|
|
63
|
+
}
|
|
64
|
+
function validateEnvFileKey(key, line, filePath, command) {
|
|
65
|
+
try {
|
|
66
|
+
validateKey(key, command === "deploy" ? "add" : command);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const reason = error instanceof Error && error.message.length > 0 ? error.message : "Invalid environment variable key.";
|
|
69
|
+
throw usageError(`Invalid environment variable "${key}" in "${filePath}"`, `Line ${line}: ${reason}`, "Use a valid env-var key and retry the import.", [], "app");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function hasClosingQuote(value, quote, startIndex) {
|
|
73
|
+
for (let index = startIndex; index < value.length; index += 1) if (value[index] === quote && !isEscaped(value, index)) return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function isEscaped(value, index) {
|
|
77
|
+
let backslashes = 0;
|
|
78
|
+
for (let cursor = index - 1; cursor >= 0 && value[cursor] === "\\"; cursor -= 1) backslashes += 1;
|
|
79
|
+
return backslashes % 2 === 1;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { readEnvFileAssignments };
|
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 };
|