@prisma/composer 0.39.0-dev.12 → 0.39.0-dev.14
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/{app-config-DriAu5RU-C8hYpR38.d.mts → app-config-Dhypzb6a-C3Kb0XtS.d.mts} +35 -63
- package/dist/app-config-Dhypzb6a-C3Kb0XtS.d.mts.map +1 -0
- package/dist/{app-converge-DkTFs-ih-CAr2feEu.mjs → app-converge-DFWYhyDb-BFaMPem0.mjs} +5 -5
- package/dist/app-converge-DFWYhyDb-BFaMPem0.mjs.map +1 -0
- package/dist/config-D615fYD5.d.mts +1 -0
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +12 -2
- package/dist/config.mjs.map +1 -0
- package/dist/control.d.mts +236 -16
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +5 -5
- package/dist/control.mjs.map +1 -1
- package/dist/{converge-in-process-x89zb2MF-Dvj-J8xo.mjs → converge-in-process-CfeblFN9-B1KvX1Fa.mjs} +4 -4
- package/dist/{converge-in-process-x89zb2MF-Dvj-J8xo.mjs.map → converge-in-process-CfeblFN9-B1KvX1Fa.mjs.map} +1 -1
- package/dist/{converge-in-process-CTomEXaD-BnDylZP8.d.mts → converge-in-process-DZRf9uYm-Ohjvy0s_.d.mts} +6 -6
- package/dist/{converge-in-process-CTomEXaD-BnDylZP8.d.mts.map → converge-in-process-DZRf9uYm-Ohjvy0s_.d.mts.map} +1 -1
- package/dist/{deploy-DHgEJDpg.d.mts → deploy-CncPyRbo.d.mts} +4 -4
- package/dist/{deploy-DHgEJDpg.d.mts.map → deploy-CncPyRbo.d.mts.map} +1 -1
- package/dist/{deploy-CSU0kr4j.mjs → deploy-DPX4IXzF.mjs} +15 -43
- package/dist/deploy-DPX4IXzF.mjs.map +1 -0
- package/dist/deploy.d.mts +4 -4
- package/dist/deploy.mjs +3 -3
- package/dist/{dev-converge-messages-DML4rTz7-C_EAB5M_.mjs → dev-converge-messages-CElmPylA-BenEozC3.mjs} +7 -7
- package/dist/dev-converge-messages-CElmPylA-BenEozC3.mjs.map +1 -0
- package/dist/dev-converge-worker.mjs +3 -3
- package/dist/dev-converge-worker.mjs.map +1 -1
- package/dist/{dev-current-C7rT6Yxw-yJ1ORrSC.mjs → dev-current-DFRg3-my-qixpmg6C.mjs} +8 -19
- package/dist/dev-current-DFRg3-my-qixpmg6C.mjs.map +1 -0
- package/dist/{dist-Cf_mZHaH.mjs → dist-Bw5O9TDx.mjs} +2 -2
- package/dist/{dist-Cf_mZHaH.mjs.map → dist-Bw5O9TDx.mjs.map} +1 -1
- package/dist/execute-deploy-destroy-CC5eDvWh-bRklcWAk.mjs +476 -0
- package/dist/execute-deploy-destroy-CC5eDvWh-bRklcWAk.mjs.map +1 -0
- package/dist/{execute-dev-BtSLDMkv-DAXRcK9h.mjs → execute-dev-_8rBPdcp-BrGpYVIu.mjs} +11 -15
- package/dist/execute-dev-_8rBPdcp-BrGpYVIu.mjs.map +1 -0
- package/dist/{execute-dev-current-LEdiAZSw-CwM41ylY.mjs → execute-dev-current-DbcTJmtG-DEZK2Oqn.mjs} +4 -4
- package/dist/{execute-dev-current-LEdiAZSw-CwM41ylY.mjs.map → execute-dev-current-DbcTJmtG-DEZK2Oqn.mjs.map} +1 -1
- package/dist/{execute-log-CzzB35KD-BBHeeC1M.mjs → execute-log-CcNIxcQt-jpflVo9o.mjs} +4 -4
- package/dist/{execute-log-CzzB35KD-BBHeeC1M.mjs.map → execute-log-CcNIxcQt-jpflVo9o.mjs.map} +1 -1
- package/dist/{graph-D2WMLL43-CeiC5wdy.mjs → graph-BYo1OEqk-D5AtX8q4.mjs} +5 -5
- package/dist/graph-BYo1OEqk-D5AtX8q4.mjs.map +1 -0
- package/dist/{graph-CUYXjK8S-BzL-mhjq.d.mts → graph-CRFQxH8r-CI1p78T8.d.mts} +3 -3
- package/dist/graph-CRFQxH8r-CI1p78T8.d.mts.map +1 -0
- package/dist/{graph-types-D4PrtP-l-B0uuchTl.d.mts → graph-types-BeNeqIt4-LGyYX_Sm.d.mts} +9 -10
- package/dist/{graph-types-D4PrtP-l-B0uuchTl.d.mts.map → graph-types-BeNeqIt4-LGyYX_Sm.d.mts.map} +1 -1
- package/dist/http.d.mts +2 -2
- package/dist/http.mjs +2 -2
- package/dist/{index-D8chHe55.d.mts → index-DOJMK47O.d.mts} +3 -3
- package/dist/{index-D8chHe55.d.mts.map → index-DOJMK47O.d.mts.map} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/internal-converge.d.mts +4 -4
- package/dist/internal-converge.mjs +2 -2
- package/dist/{load-entry-CEoVBdMj-CHOz7jKf.mjs → load-entry-CEoVBdMj-L1mXTtEO.mjs} +5 -5
- package/dist/load-entry-CEoVBdMj-L1mXTtEO.mjs.map +1 -0
- package/dist/{local-target-7KRsLMDO.d.mts → local-target-DZFvgvVK.d.mts} +2 -2
- package/dist/{local-target-7KRsLMDO.d.mts.map → local-target-DZFvgvVK.d.mts.map} +1 -1
- package/dist/local-target.d.mts +2 -2
- package/dist/{nextjs-DLyeRR7M-CzUbvPaJ.d.mts → nextjs-DLyeRR7M-C2z32CtL.d.mts} +3 -3
- package/dist/{nextjs-DLyeRR7M-CzUbvPaJ.d.mts.map → nextjs-DLyeRR7M-C2z32CtL.d.mts.map} +1 -1
- package/dist/nextjs-control.d.mts +4 -4
- package/dist/nextjs.d.mts +1 -1
- package/dist/node-control.d.mts +3 -3
- package/dist/node.d.mts +2 -2
- package/dist/{run-report-CmBz2-xc-Cc8rV1CX.mjs → run-report-HI2JqCSO-BWPG--nb.mjs} +5 -7
- package/dist/run-report-HI2JqCSO-BWPG--nb.mjs.map +1 -0
- package/dist/service-rpc.d.mts +2 -2
- package/dist/service-rpc.mjs +2 -2
- package/dist/steps-Det-FSAL-DRvo57Lf.mjs +174 -0
- package/dist/steps-Det-FSAL-DRvo57Lf.mjs.map +1 -0
- package/dist/testing.d.mts +1 -1
- package/dist/{validate-environment-DCZiNSlR-C7lv0cH1.mjs → validate-environment-BevPErw8-BDbXIt8U.mjs} +331 -9
- package/dist/validate-environment-BevPErw8-BDbXIt8U.mjs.map +1 -0
- package/package.json +11 -14
- package/skills/prisma-composer-core-concepts/SKILL.md +6 -23
- package/dist/app-config-DriAu5RU-C8hYpR38.d.mts.map +0 -1
- package/dist/app-configuration-file-D0rB5g65-CdMrjkCc.mjs +0 -186
- package/dist/app-configuration-file-D0rB5g65-CdMrjkCc.mjs.map +0 -1
- package/dist/app-converge-DkTFs-ih-CAr2feEu.mjs.map +0 -1
- package/dist/config-Bpi8QVLB.d.mts +0 -1
- package/dist/deploy-CSU0kr4j.mjs.map +0 -1
- package/dist/deployment-summary-6LgQDUuu-Cu_6UNhc.d.mts +0 -33
- package/dist/deployment-summary-6LgQDUuu-Cu_6UNhc.d.mts.map +0 -1
- package/dist/deployment-summary-CVJZn2v0-Dz-gX1rp.mjs +0 -153
- package/dist/deployment-summary-CVJZn2v0-Dz-gX1rp.mjs.map +0 -1
- package/dist/dev-converge-messages-DML4rTz7-C_EAB5M_.mjs.map +0 -1
- package/dist/dev-current-C7rT6Yxw-yJ1ORrSC.mjs.map +0 -1
- package/dist/execute-deploy-destroy-C-aK5jh--D-AjLWc2.mjs +0 -855
- package/dist/execute-deploy-destroy-C-aK5jh--D-AjLWc2.mjs.map +0 -1
- package/dist/execute-dev-BtSLDMkv-DAXRcK9h.mjs.map +0 -1
- package/dist/graph-CUYXjK8S-BzL-mhjq.d.mts.map +0 -1
- package/dist/graph-D2WMLL43-CeiC5wdy.mjs.map +0 -1
- package/dist/internal-app-configuration-file.d.mts +0 -16
- package/dist/internal-app-configuration-file.d.mts.map +0 -1
- package/dist/internal-app-configuration-file.mjs +0 -2
- package/dist/load-entry-CEoVBdMj-CHOz7jKf.mjs.map +0 -1
- package/dist/preflight-transport-2d6iIchu-B-v7Di6I.mjs +0 -90
- package/dist/preflight-transport-2d6iIchu-B-v7Di6I.mjs.map +0 -1
- package/dist/redaction-DY6eDC12-W-FzW7_r.mjs +0 -339
- package/dist/redaction-DY6eDC12-W-FzW7_r.mjs.map +0 -1
- package/dist/redaction-Dn7BRdaP-BcLSPhLV.d.mts +0 -232
- package/dist/redaction-Dn7BRdaP-BcLSPhLV.d.mts.map +0 -1
- package/dist/report.d.mts +0 -19
- package/dist/report.d.mts.map +0 -1
- package/dist/report.mjs +0 -97
- package/dist/report.mjs.map +0 -1
- package/dist/run-report-CmBz2-xc-Cc8rV1CX.mjs.map +0 -1
- package/dist/steps-BZXNqW6U-C_ME2VLd.mjs +0 -112
- package/dist/steps-BZXNqW6U-C_ME2VLd.mjs.map +0 -1
- package/dist/validate-environment-DCZiNSlR-C7lv0cH1.mjs.map +0 -1
- package/src/exports/internal-app-configuration-file.ts +0 -1
- package/src/exports/report.ts +0 -1
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
import { y as nodeAddresses } from "./graph-D2WMLL43-CeiC5wdy.mjs";
|
|
2
|
-
import { t as InternalError } from "./internal-error-Dfur7Zqt-D96dWHZK.mjs";
|
|
3
|
-
import { t as CliStructuredError } from "./errors-DI3TBXE-.mjs";
|
|
4
|
-
import { o as preflightEnvVarName, t as containerEnv } from "./preflight-transport-2d6iIchu-B-v7Di6I.mjs";
|
|
5
|
-
import { a as refuseSecretsInRootInput, n as prepareSecondProcess, o as removeLeftoverAppConfigurationFiles, t as deployAppConfigurationFile } from "./app-configuration-file-D0rB5g65-CdMrjkCc.mjs";
|
|
6
|
-
import "./deploy-CSU0kr4j.mjs";
|
|
7
|
-
import { c as requireContainerForEnvironment, d as ok, f as okVoid, l as toStructured, t as convergeReasonsText, u as notOk } from "./dev-current-C7rT6Yxw-yJ1ORrSC.mjs";
|
|
8
|
-
import { a as writeRunReport, i as toRunReport, r as resolveRunReportPath, t as RUN_REPORT_FILE_ENV } from "./run-report-CmBz2-xc-Cc8rV1CX.mjs";
|
|
9
|
-
import { c as noComposerExportMessage } from "./load-entry-CEoVBdMj-CHOz7jKf.mjs";
|
|
10
|
-
import { t as loadAppConvergeEntry } from "./app-converge-DkTFs-ih-CAr2feEu.mjs";
|
|
11
|
-
import { c as redactThrown, l as redactUnsetPlatformVariable, n as StreamRedactor, o as redactError, r as credentialLookingValues, s as redactSummary, t as SecretRedaction } from "./redaction-DY6eDC12-W-FzW7_r.mjs";
|
|
12
|
-
import { a as readEngineFailureCause, i as engineFailureFilePath, n as capFailureCause, o as toDeploymentSummary, s as withComposerAdvice, t as DEPLOYMENT_RESULT_FILE_ENV } from "./deployment-summary-CVJZn2v0-Dz-gX1rp.mjs";
|
|
13
|
-
import { i as validateEnvironmentName, r as runPipeline } from "./validate-environment-DCZiNSlR-C7lv0cH1.mjs";
|
|
14
|
-
import { n as reportConvergeEvent, r as stepTracker, t as interactionMessages } from "./steps-BZXNqW6U-C_ME2VLd.mjs";
|
|
15
|
-
import { createRequire } from "node:module";
|
|
16
|
-
import * as path$1 from "node:path";
|
|
17
|
-
import * as fs$1 from "node:fs";
|
|
18
|
-
import { randomUUID } from "node:crypto";
|
|
19
|
-
import spawn from "cross-spawn";
|
|
20
|
-
//#region ../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-C-aK5jh-.mjs
|
|
21
|
-
/** Pipeline step 6: writes a regenerated-every-run, independently runnable stack module at `.prisma-composer/alchemy.run.ts`. */
|
|
22
|
-
const GENERATED_DIR = ".prisma-composer";
|
|
23
|
-
const GENERATED_FILE = "alchemy.run.ts";
|
|
24
|
-
/** A relative import specifier from `.prisma-composer/alchemy.run.ts` to `target` (posix separators). */
|
|
25
|
-
function relativeImportSpecifier(generatedDir, target) {
|
|
26
|
-
const rel = path$1.relative(generatedDir, target).split(path$1.sep).join("/");
|
|
27
|
-
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
28
|
-
}
|
|
29
|
-
function quote(value) {
|
|
30
|
-
return JSON.stringify(value);
|
|
31
|
-
}
|
|
32
|
-
function renderBundle(bundle) {
|
|
33
|
-
return `{ dir: ${quote(bundle.dir)}, entry: ${quote(bundle.entry)} }`;
|
|
34
|
-
}
|
|
35
|
-
function renderOptions(input) {
|
|
36
|
-
const lines = [];
|
|
37
|
-
lines.push(` name: ${quote(input.name)},`);
|
|
38
|
-
lines.push(` environment: ${quote(input.environment)},`);
|
|
39
|
-
lines.push(" appConfigurationRead: file.appConfigurationRead,");
|
|
40
|
-
lines.push(" firstProcessNodeAddresses: file.nodeAddresses,");
|
|
41
|
-
lines.push(" bundles: {");
|
|
42
|
-
for (const [id, bundle] of Object.entries(input.assembled.bundles)) lines.push(` ${quote(id)}: ${renderBundle(bundle)},`);
|
|
43
|
-
lines.push(" },");
|
|
44
|
-
lines.push(" report: report.deploymentReport,");
|
|
45
|
-
return lines.join("\n");
|
|
46
|
-
}
|
|
47
|
-
/** Renders the stack module's source (tests assert on it without touching disk) — uses `//` headers, not a block comment, since a cwd path with a star-slash could close one early. */
|
|
48
|
-
function renderStackFile(input) {
|
|
49
|
-
const generatedDir = path$1.join(input.cwd, GENERATED_DIR);
|
|
50
|
-
const appImport = relativeImportSpecifier(generatedDir, input.entryPath);
|
|
51
|
-
const configImport = relativeImportSpecifier(generatedDir, input.configFile);
|
|
52
|
-
return `// Generated by Composer's deploy and destroy operations — overwritten on every
|
|
53
|
-
// run; do not edit by hand. Runnable from ${quote(input.cwd)} WITH the env the
|
|
54
|
-
// CLI passes its child (the PRISMA_COMPOSER_CONTAINER_*/_PREFLIGHT_* vars and the app configuration file —
|
|
55
|
-
// without them lower() refuses because no container is resolved), by the
|
|
56
|
-
// command Composer starts, which a failed run prints:
|
|
57
|
-
//
|
|
58
|
-
// <node> <bin of the alchemy @prisma/composer depends on> deploy ${GENERATED_DIR}/${GENERATED_FILE} --yes --stage <stage>
|
|
59
|
-
//
|
|
60
|
-
// bisects a CLI bug from an Alchemy bug (deploy-cli.md § Implementation decisions).
|
|
61
|
-
// It runs no config adapter: it reads what the first process's Load read from the app configuration file named in PRISMA_COMPOSER_APP_CONFIGURATION_FILE.
|
|
62
|
-
import { lower } from '@prisma/composer/deploy';
|
|
63
|
-
import * as report from '@prisma/composer/report';
|
|
64
|
-
import { readAppConfigurationFile } from '@prisma/composer/internal/app-configuration-file';
|
|
65
|
-
import prismaConfig from ${quote(configImport)};
|
|
66
|
-
import app from ${quote(appImport)};
|
|
67
|
-
|
|
68
|
-
const config = prismaConfig.composer;
|
|
69
|
-
if (config === undefined) {
|
|
70
|
-
throw new Error(${quote(noComposerExportMessage(input.configFile))});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// The app's own @prisma/composer may predate the failure recorder.
|
|
74
|
-
report.captureEngineFailure?.();
|
|
75
|
-
|
|
76
|
-
const file = readAppConfigurationFile(process.env);
|
|
77
|
-
|
|
78
|
-
export default lower(app, config, {
|
|
79
|
-
${renderOptions(input)}
|
|
80
|
-
});
|
|
81
|
-
`;
|
|
82
|
-
}
|
|
83
|
-
/** Writes the stack file, returning its absolute path. */
|
|
84
|
-
function writeStackFile(input) {
|
|
85
|
-
const generatedDir = path$1.join(input.cwd, GENERATED_DIR);
|
|
86
|
-
fs$1.mkdirSync(generatedDir, { recursive: true });
|
|
87
|
-
const filePath = path$1.join(generatedDir, GENERATED_FILE);
|
|
88
|
-
fs$1.writeFileSync(filePath, renderStackFile(input));
|
|
89
|
-
return filePath;
|
|
90
|
-
}
|
|
91
|
-
const GENERATED_STACK_RELATIVE_PATH = path$1.join(GENERATED_DIR, GENERATED_FILE);
|
|
92
|
-
/**
|
|
93
|
-
* Which Alchemy CLI runs a generated stack file: the `alchemy` that
|
|
94
|
-
* `@prisma/composer` depends on, found from the app the way the stack file's
|
|
95
|
-
* own `@prisma/composer/...` imports are. The CLI and the stack code then
|
|
96
|
-
* come from one install, so the child loads one copy of `alchemy`.
|
|
97
|
-
*
|
|
98
|
-
* Node's resolver finds `@prisma/composer` from the app. It cannot find
|
|
99
|
-
* `alchemy` from there: alchemy exports neither its `package.json` nor its
|
|
100
|
-
* bin, and has no `require` condition. Bun has no `module.findPackageJSON`.
|
|
101
|
-
* So the last step is Node's own lookup written out: each `node_modules`
|
|
102
|
-
* above `@prisma/composer`'s real location, nearest first.
|
|
103
|
-
*/
|
|
104
|
-
const FIX = "Check that the app depends on @prisma/composer and that `alchemy`, which @prisma/composer depends on, is installed in a node_modules directory. Layouts without one, such as Yarn Plug'n'Play, are not supported.";
|
|
105
|
-
function binMissing(message) {
|
|
106
|
-
return new CliStructuredError("DEPLOY.ALCHEMY_BIN_MISSING", message, { fix: FIX });
|
|
107
|
-
}
|
|
108
|
-
function composerPackageDir(appDir) {
|
|
109
|
-
try {
|
|
110
|
-
const manifest = createRequire(path$1.join(appDir, "package.json")).resolve("@prisma/composer/package.json");
|
|
111
|
-
return path$1.dirname(fs$1.realpathSync(manifest));
|
|
112
|
-
} catch {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function alchemyPackageDirAbove(dir) {
|
|
117
|
-
for (let current = dir;; current = path$1.dirname(current)) {
|
|
118
|
-
const candidate = path$1.join(current, "node_modules", "alchemy");
|
|
119
|
-
if (fs$1.existsSync(path$1.join(candidate, "package.json"))) return candidate;
|
|
120
|
-
if (path$1.dirname(current) === current) return void 0;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function readPackageJson(packageDir) {
|
|
124
|
-
try {
|
|
125
|
-
return JSON.parse(fs$1.readFileSync(path$1.join(packageDir, "package.json"), "utf8"));
|
|
126
|
-
} catch {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function binOf(packageDir) {
|
|
131
|
-
const manifest = readPackageJson(packageDir);
|
|
132
|
-
if (typeof manifest !== "object" || manifest === null || !("bin" in manifest)) return void 0;
|
|
133
|
-
const bin = manifest.bin;
|
|
134
|
-
const relative = typeof bin === "string" ? bin : typeof bin === "object" && bin !== null && "alchemy" in bin ? bin.alchemy : void 0;
|
|
135
|
-
if (typeof relative !== "string") return void 0;
|
|
136
|
-
const entry = path$1.join(packageDir, relative);
|
|
137
|
-
return fs$1.existsSync(entry) ? entry : void 0;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* The JavaScript file `alchemy`'s `bin` names, for the app in `appDir`.
|
|
141
|
-
* Raises DEPLOY.ALCHEMY_BIN_MISSING when the app does not resolve
|
|
142
|
-
* `@prisma/composer` or no usable `alchemy` is installed beside it.
|
|
143
|
-
*/
|
|
144
|
-
function resolveAlchemyBin(appDir) {
|
|
145
|
-
const composerDir = composerPackageDir(appDir);
|
|
146
|
-
if (composerDir === void 0) throw binMissing(`Could not resolve @prisma/composer from "${appDir}".`);
|
|
147
|
-
const alchemyDir = alchemyPackageDirAbove(composerDir);
|
|
148
|
-
const entry = alchemyDir === void 0 ? void 0 : binOf(alchemyDir);
|
|
149
|
-
if (entry === void 0) throw binMissing(`Could not resolve the bin of the \`alchemy\` package @prisma/composer depends on, from "${composerDir}".`);
|
|
150
|
-
return entry;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Pipeline step 9 (deploy-cli.md § The pipeline; design-notes.md's "Driving
|
|
154
|
-
* Alchemy" call): run the generated stack file and, for programmatic hosts, pipe its
|
|
155
|
-
* output through redaction.
|
|
156
|
-
*
|
|
157
|
-
* Runs the bin of the `alchemy` the app's `@prisma/composer` depends on
|
|
158
|
-
* (`resolveAlchemyBin`), started with Node (`nodeExecutable`). Never a
|
|
159
|
-
* `node_modules/.bin` link, which pnpm creates only for an app's direct
|
|
160
|
-
* dependencies.
|
|
161
|
-
*
|
|
162
|
-
* Only `destroy` still runs Alchemy in a child; `deploy` and `dev` converge
|
|
163
|
-
* in-process (ADR-0066). This module composes the invocation; `spawnAlchemy`
|
|
164
|
-
* starts it, piping the child's output through the stream redactor
|
|
165
|
-
* (ADR-0062), and tests substitute their own runner.
|
|
166
|
-
*/
|
|
167
|
-
function currentRuntime() {
|
|
168
|
-
return {
|
|
169
|
-
bun: process.versions.bun !== void 0,
|
|
170
|
-
execPath: process.execPath,
|
|
171
|
-
env: process.env,
|
|
172
|
-
platform: process.platform,
|
|
173
|
-
exists: fs$1.existsSync
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
function envValue(env, name) {
|
|
177
|
-
return Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
178
|
-
}
|
|
179
|
-
/** The file names `node` may have in a PATH directory: PATHEXT's extensions on Windows. */
|
|
180
|
-
function nodeFileNames(runtime) {
|
|
181
|
-
if (runtime.platform !== "win32") return ["node"];
|
|
182
|
-
return (envValue(runtime.env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((extension) => extension.length > 0).map((extension) => `node${extension}`);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* The Node that starts Alchemy's launcher: this process's own runtime under
|
|
186
|
-
* Node, and the first `node` on PATH under Bun. Alchemy's launcher may still
|
|
187
|
-
* move itself to Bun when the package-manager environment says Bun invoked
|
|
188
|
-
* it (`bunx`, `bun run`), so the runtime Alchemy ends up on follows how
|
|
189
|
-
* `prisma` was invoked.
|
|
190
|
-
*/
|
|
191
|
-
function nodeExecutable(runtime = currentRuntime()) {
|
|
192
|
-
if (!runtime.bun) return runtime.execPath;
|
|
193
|
-
const paths = runtime.platform === "win32" ? path$1.win32 : path$1.posix;
|
|
194
|
-
const names = nodeFileNames(runtime);
|
|
195
|
-
for (const rawDir of (envValue(runtime.env, "PATH") ?? "").split(paths.delimiter)) {
|
|
196
|
-
const dir = rawDir.replace(/^"(.*)"$/, "$1");
|
|
197
|
-
if (dir.length === 0) continue;
|
|
198
|
-
for (const name of names) {
|
|
199
|
-
const candidate = paths.join(dir, name);
|
|
200
|
-
if (runtime.exists(candidate)) return candidate;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
throw new CliStructuredError("DEPLOY.NODE_MISSING", "Composer starts Alchemy with Node, and no `node` was found on PATH.", { fix: "Install Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer, and put it on PATH, or run `prisma` under Node." });
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Resolves the invocation against this machine — the step every adapter takes
|
|
207
|
-
* and no caller should. Runs alchemy's JavaScript entry with Node, so no shell
|
|
208
|
-
* shim is involved on any platform. Raises DEPLOY.ALCHEMY_BIN_MISSING when
|
|
209
|
-
* Composer's alchemy cannot be resolved, and DEPLOY.NODE_MISSING when no Node
|
|
210
|
-
* can run it.
|
|
211
|
-
*/
|
|
212
|
-
function alchemyCommandLine(invocation, alchemyBin = resolveAlchemyBin(invocation.cwd), node = nodeExecutable()) {
|
|
213
|
-
return {
|
|
214
|
-
command: node,
|
|
215
|
-
args: [
|
|
216
|
-
alchemyBin,
|
|
217
|
-
invocation.action,
|
|
218
|
-
invocation.stackFileRelativePath,
|
|
219
|
-
"--yes",
|
|
220
|
-
"--stage",
|
|
221
|
-
invocation.stage
|
|
222
|
-
],
|
|
223
|
-
cwd: invocation.cwd,
|
|
224
|
-
env: invocation.env
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
/** What becomes `alchemy deploy|destroy <stack file> --yes --stage <stage>`. */
|
|
228
|
-
function alchemyInvocation(input) {
|
|
229
|
-
return {
|
|
230
|
-
action: input.command,
|
|
231
|
-
stackFileRelativePath: input.stackFileRelativePath,
|
|
232
|
-
cwd: input.cwd,
|
|
233
|
-
stage: input.stage,
|
|
234
|
-
env: {
|
|
235
|
-
...input.containerEnv,
|
|
236
|
-
...input.preflightEnv,
|
|
237
|
-
...input.env
|
|
238
|
-
},
|
|
239
|
-
redactedValues: input.redactedValues
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* The default runner for hosts with no engine: stdin inherited and output piped through redaction, the caller's
|
|
244
|
-
* own process group, and the child's status returned verbatim. It does not
|
|
245
|
-
* collapse a signal into an exit code — that collapse is what made a
|
|
246
|
-
* Ctrl-C'd deploy report itself as a failure.
|
|
247
|
-
*/
|
|
248
|
-
const spawnAlchemy = async (invocation) => {
|
|
249
|
-
const commandLine = alchemyCommandLine(invocation);
|
|
250
|
-
return {
|
|
251
|
-
...await spawnCommandLine(commandLine, invocation.redactedValues),
|
|
252
|
-
commandLine
|
|
253
|
-
};
|
|
254
|
-
};
|
|
255
|
-
/**
|
|
256
|
-
* One argument as the platform's shell reads it literally: single quotes for
|
|
257
|
-
* POSIX shells, double quotes for cmd.exe. cmd.exe expands `%VAR%` inside
|
|
258
|
-
* double quotes, and strips or expands `!` when delayed expansion is on; no
|
|
259
|
-
* quoting prevents either, so an argument containing them is not fully
|
|
260
|
-
* literal there.
|
|
261
|
-
*/
|
|
262
|
-
function shellArg(arg, platform) {
|
|
263
|
-
if (platform === "win32") return /^[\w@+=:,./\\~-]+$/.test(arg) ? arg : `"${arg.replaceAll("\"", "\"\"")}"`;
|
|
264
|
-
return /^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* The command a user runs from the invocation's directory to repeat a
|
|
268
|
-
* converge: the command line the adapter started, or, from an adapter that
|
|
269
|
-
* does not report one, `alchemy` with the same arguments.
|
|
270
|
-
*/
|
|
271
|
-
function reproduceCommand(invocation, outcome, platform = process.platform) {
|
|
272
|
-
return (outcome?.commandLine === void 0 ? [
|
|
273
|
-
"alchemy",
|
|
274
|
-
invocation.action,
|
|
275
|
-
invocation.stackFileRelativePath,
|
|
276
|
-
"--yes",
|
|
277
|
-
"--stage",
|
|
278
|
-
invocation.stage
|
|
279
|
-
] : [outcome.commandLine.command, ...outcome.commandLine.args]).map((arg) => shellArg(arg, platform)).join(" ");
|
|
280
|
-
}
|
|
281
|
-
/** Starts a resolved command line with stdin inherited and its output piped through redaction, and returns how it ended. */
|
|
282
|
-
function spawnCommandLine(line, redactedValues, outputs = process) {
|
|
283
|
-
return new Promise((resolve, reject) => {
|
|
284
|
-
const child = spawn(line.command, [...line.args], {
|
|
285
|
-
cwd: line.cwd,
|
|
286
|
-
stdio: [
|
|
287
|
-
"inherit",
|
|
288
|
-
"pipe",
|
|
289
|
-
"pipe"
|
|
290
|
-
],
|
|
291
|
-
env: {
|
|
292
|
-
...process.env,
|
|
293
|
-
...line.env
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
const stdout = new StreamRedactor(redactedValues);
|
|
297
|
-
const stderr = new StreamRedactor(redactedValues);
|
|
298
|
-
const write = (stream, text) => {
|
|
299
|
-
if (text.length > 0) stream.write(text);
|
|
300
|
-
};
|
|
301
|
-
child.stdout?.setEncoding("utf8").on("data", (chunk) => write(outputs.stdout, stdout.push(chunk)));
|
|
302
|
-
child.stderr?.setEncoding("utf8").on("data", (chunk) => write(outputs.stderr, stderr.push(chunk)));
|
|
303
|
-
child.on("error", reject);
|
|
304
|
-
child.on("close", (exitCode, signal) => {
|
|
305
|
-
write(outputs.stdout, stdout.end());
|
|
306
|
-
write(outputs.stderr, stderr.end());
|
|
307
|
-
resolve({
|
|
308
|
-
exitCode,
|
|
309
|
-
signal
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* The deploy/destroy executor — main.ts's pipeline orchestration with argv,
|
|
316
|
-
* console, and exit codes removed: typed inputs in, structured results out.
|
|
317
|
-
* Reached only by lazy import from deploy.ts/destroy.ts — this module's
|
|
318
|
-
* static graph transitively loads alchemy's provider tree, so the control
|
|
319
|
-
* entry must never import it statically.
|
|
320
|
-
*/
|
|
321
|
-
const ALCHEMY_STATE_DIR = ".alchemy";
|
|
322
|
-
/** Destroy guardrail (moved from main.ts): true when `<cwd>/.alchemy` is missing or empty — likely wrong directory or nothing deployed yet. */
|
|
323
|
-
function hasNoLocalDeployState(cwd) {
|
|
324
|
-
const stateDir = path$1.join(cwd, ALCHEMY_STATE_DIR);
|
|
325
|
-
return !(fs$1.existsSync(stateDir) && fs$1.readdirSync(stateDir).length > 0);
|
|
326
|
-
}
|
|
327
|
-
/** Times each deploy step for the host's `onEvent`. A step still open when the run fails is closed as failed, innermost first. */
|
|
328
|
-
function deploySteps(onEvent) {
|
|
329
|
-
return stepTracker((step) => step.name === "assemble-service" ? `${step.name}:${step.address}` : step.name === "apply-resource" ? `${step.name}:${step.resourceId}` : step.name, onEvent);
|
|
330
|
-
}
|
|
331
|
-
async function executeDeploy(input, deps, cwd) {
|
|
332
|
-
const outcome = await runStackPipeline("deploy", {
|
|
333
|
-
entry: input.entry,
|
|
334
|
-
config: input.config,
|
|
335
|
-
name: input.name,
|
|
336
|
-
environment: input.environment ?? "production",
|
|
337
|
-
cwd,
|
|
338
|
-
onEvent: void 0,
|
|
339
|
-
deps,
|
|
340
|
-
reportId: input.reportId,
|
|
341
|
-
reportPath: resolveRunReportPath(input.reportPath, process.env[RUN_REPORT_FILE_ENV], cwd),
|
|
342
|
-
steps: deploySteps(input.onEvent),
|
|
343
|
-
signal: input.signal,
|
|
344
|
-
redaction: deps.redaction ?? new SecretRedaction(process.env)
|
|
345
|
-
});
|
|
346
|
-
if (!outcome.ok) return outcome;
|
|
347
|
-
return ok({ summary: outcome.value });
|
|
348
|
-
}
|
|
349
|
-
async function executeDestroy(input, deps, cwd) {
|
|
350
|
-
const outcome = await runStackPipeline("destroy", {
|
|
351
|
-
entry: input.entry,
|
|
352
|
-
config: input.config,
|
|
353
|
-
name: input.name,
|
|
354
|
-
environment: input.environment,
|
|
355
|
-
cwd,
|
|
356
|
-
onEvent: input.onEvent,
|
|
357
|
-
deps,
|
|
358
|
-
reportId: void 0,
|
|
359
|
-
reportPath: void 0,
|
|
360
|
-
steps: deploySteps(void 0),
|
|
361
|
-
signal: void 0,
|
|
362
|
-
redaction: new SecretRedaction(process.env)
|
|
363
|
-
});
|
|
364
|
-
if (!outcome.ok) return outcome;
|
|
365
|
-
return okVoid();
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Opens a session per extension that declares a reporter. A `begin` that
|
|
369
|
-
* throws costs that extension its reporting and nothing else — the deploy
|
|
370
|
-
* has not started, and refusing to run it because an observer failed would
|
|
371
|
-
* invert the relationship.
|
|
372
|
-
*/
|
|
373
|
-
async function beginReporters(extensions, context, redaction) {
|
|
374
|
-
return (await Promise.all(extensions.map(async (extension) => {
|
|
375
|
-
if (extension.reporter === void 0) return void 0;
|
|
376
|
-
try {
|
|
377
|
-
const reporter = await extension.reporter.begin(context);
|
|
378
|
-
return reporter === void 0 ? void 0 : {
|
|
379
|
-
extensionId: extension.id,
|
|
380
|
-
reporter
|
|
381
|
-
};
|
|
382
|
-
} catch (error) {
|
|
383
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
384
|
-
console.warn(`\nCould not start deploy reporting for ${extension.id}: ${redaction.redact(detail)}`);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
}))).filter((entry) => entry !== void 0);
|
|
388
|
-
}
|
|
389
|
-
/** Hands each session its own extension's resolved container, so it can attach the run to what that container names. */
|
|
390
|
-
async function attachReporters(reporters, containers, redaction) {
|
|
391
|
-
await Promise.all(reporters.map(async ({ extensionId, reporter }) => {
|
|
392
|
-
try {
|
|
393
|
-
await reporter.attach({ container: containers.get(extensionId) });
|
|
394
|
-
} catch (error) {
|
|
395
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
396
|
-
console.warn(`\nCould not attach this deploy to its project for ${extensionId}: ${redaction.redact(detail)}`);
|
|
397
|
-
}
|
|
398
|
-
}));
|
|
399
|
-
}
|
|
400
|
-
/** Every session's contribution to the apply's environment, so reporting that happens inside the apply can find the run. */
|
|
401
|
-
function reporterEnv(reporters, redaction) {
|
|
402
|
-
const env = {};
|
|
403
|
-
for (const { extensionId, reporter } of reporters) try {
|
|
404
|
-
Object.assign(env, reporter.childEnv());
|
|
405
|
-
} catch (error) {
|
|
406
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
407
|
-
console.warn(`\nCould not pass deploy reporting into the apply for ${extensionId}: ${redaction.redact(detail)}`);
|
|
408
|
-
}
|
|
409
|
-
return env;
|
|
410
|
-
}
|
|
411
|
-
/** `failingStep` is capped at 500 by the platform and `errorMessage` at 5000; truncating here keeps a long message from costing the whole report. */
|
|
412
|
-
function truncate(value, limit) {
|
|
413
|
-
return value.length <= limit ? value : `${value.slice(0, limit - 1)}…`;
|
|
414
|
-
}
|
|
415
|
-
/** An interrupted converge — reported as `cancelled`, never as `failed`. */
|
|
416
|
-
function wasInterrupted(failure) {
|
|
417
|
-
return failure.code === "DEPLOY.INTERRUPTED" || typeof failure.meta?.["signal"] === "string";
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Ends every reporting session, whatever the run did. Sessions never reject
|
|
421
|
-
* by contract, but a buggy one must not turn a converged deploy into a
|
|
422
|
-
* failure — so this swallows anyway, and reports each session independently
|
|
423
|
-
* so one bad implementation cannot silence another.
|
|
424
|
-
*/
|
|
425
|
-
async function finishReporters(reporters, outcome, redaction) {
|
|
426
|
-
const entities = outcome.summary?.nodes.flatMap((node) => node.entities) ?? [];
|
|
427
|
-
await Promise.all(reporters.map(async ({ reporter }) => {
|
|
428
|
-
try {
|
|
429
|
-
await reporter.finish({
|
|
430
|
-
ok: outcome.ok,
|
|
431
|
-
cancelled: outcome.cancelled,
|
|
432
|
-
failingStep: outcome.code === void 0 ? void 0 : truncate(outcome.code, 500),
|
|
433
|
-
errorMessage: outcome.message === void 0 ? void 0 : truncate(outcome.message, 5e3),
|
|
434
|
-
entities
|
|
435
|
-
});
|
|
436
|
-
} catch (error) {
|
|
437
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
438
|
-
console.warn(`\nCould not report this deploy's outcome: ${redaction.redact(detail)}`);
|
|
439
|
-
}
|
|
440
|
-
}));
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Owns the reporting sessions around the pipeline: the inner run opens them
|
|
444
|
-
* once it knows which extensions are configured, and this closes them on
|
|
445
|
-
* every exit path — a returned failure, a success, or a thrown defect — as
|
|
446
|
-
* the `record` step, which also writes the run report.
|
|
447
|
-
* Nothing here can change what the pipeline returns.
|
|
448
|
-
*/
|
|
449
|
-
async function runStackPipeline(action, opts) {
|
|
450
|
-
const reporters = [];
|
|
451
|
-
let outcome;
|
|
452
|
-
try {
|
|
453
|
-
outcome = await runStackPipelineInner(action, opts, reporters);
|
|
454
|
-
} catch (error) {
|
|
455
|
-
opts.steps.closeOpen("failed");
|
|
456
|
-
opts.steps.start({ name: "record" });
|
|
457
|
-
const thrown = redactThrown(error, opts.redaction);
|
|
458
|
-
await finishReporters(reporters, {
|
|
459
|
-
ok: false,
|
|
460
|
-
cancelled: false,
|
|
461
|
-
code: "DEPLOY.UNEXPECTED",
|
|
462
|
-
message: thrown.message
|
|
463
|
-
}, opts.redaction);
|
|
464
|
-
opts.steps.finish({ name: "record" });
|
|
465
|
-
throw thrown;
|
|
466
|
-
}
|
|
467
|
-
if (!outcome.ok) outcome = notOk(redactError(outcome.failure, opts.redaction));
|
|
468
|
-
if (!outcome.ok) opts.steps.closeOpen("failed");
|
|
469
|
-
opts.steps.start({ name: "record" });
|
|
470
|
-
await finishReporters(reporters, outcome.ok ? {
|
|
471
|
-
ok: true,
|
|
472
|
-
cancelled: false,
|
|
473
|
-
summary: outcome.value
|
|
474
|
-
} : {
|
|
475
|
-
ok: false,
|
|
476
|
-
cancelled: wasInterrupted(outcome.failure),
|
|
477
|
-
code: outcome.failure.code,
|
|
478
|
-
message: outcome.failure.message
|
|
479
|
-
}, opts.redaction);
|
|
480
|
-
if (opts.reportPath === void 0 || writeRunReport(opts.reportPath, toRunReport({
|
|
481
|
-
summary: outcome.ok ? outcome.value : void 0,
|
|
482
|
-
environment: opts.environment,
|
|
483
|
-
failure: outcome.ok ? void 0 : {
|
|
484
|
-
code: outcome.failure.code,
|
|
485
|
-
message: outcome.failure.message
|
|
486
|
-
}
|
|
487
|
-
}))) opts.steps.finish({ name: "record" });
|
|
488
|
-
else opts.steps.fail({ name: "record" });
|
|
489
|
-
return outcome;
|
|
490
|
-
}
|
|
491
|
-
/** The pipeline both actions share: validate, resolve containers, then for
|
|
492
|
-
* deploy preflight and the in-process converge, and for destroy the stack
|
|
493
|
-
* file, the alchemy child and the teardown/removal suffix. The value is only
|
|
494
|
-
* ever a summary for deploy. */
|
|
495
|
-
async function runStackPipelineInner(action, opts, reporters) {
|
|
496
|
-
const { entry, config: composerConfig, name, environment, cwd, onEvent, deps, steps } = opts;
|
|
497
|
-
steps.start({ name: "prepare" });
|
|
498
|
-
removeLeftoverAppConfigurationFiles(cwd);
|
|
499
|
-
try {
|
|
500
|
-
validateEnvironmentName(environment);
|
|
501
|
-
} catch (error) {
|
|
502
|
-
if (CliStructuredError.is(error)) return notOk(error);
|
|
503
|
-
throw error;
|
|
504
|
-
}
|
|
505
|
-
let appConvergeEntry;
|
|
506
|
-
if (action === "deploy") {
|
|
507
|
-
const loaded = await prepareAppConvergeEntry(deps, path$1.dirname(path$1.resolve(cwd, composerConfig.file)));
|
|
508
|
-
if (!loaded.ok) return loaded;
|
|
509
|
-
appConvergeEntry = loaded.value;
|
|
510
|
-
}
|
|
511
|
-
const platformCredentials = deps.credentials;
|
|
512
|
-
if (action === "destroy" && hasNoLocalDeployState(cwd)) onEvent?.({
|
|
513
|
-
kind: "no-local-deploy-state",
|
|
514
|
-
cwd
|
|
515
|
-
});
|
|
516
|
-
let pipeline;
|
|
517
|
-
let containers;
|
|
518
|
-
let alchemyStage;
|
|
519
|
-
const preflightPayloads = /* @__PURE__ */ new Map();
|
|
520
|
-
const unset = [];
|
|
521
|
-
const preflightTransportEnv = {};
|
|
522
|
-
try {
|
|
523
|
-
pipeline = await runPipeline(entry, name, environment, cwd, composerConfig, {
|
|
524
|
-
runAssembler: deps.runAssembler,
|
|
525
|
-
readSecrets: action === "deploy",
|
|
526
|
-
redaction: opts.redaction,
|
|
527
|
-
onEvent: (event) => {
|
|
528
|
-
switch (event.kind) {
|
|
529
|
-
case "loaded":
|
|
530
|
-
steps.finish({ name: "prepare" });
|
|
531
|
-
steps.start({ name: "assemble" });
|
|
532
|
-
return;
|
|
533
|
-
case "service-started":
|
|
534
|
-
steps.start({
|
|
535
|
-
name: "assemble-service",
|
|
536
|
-
address: event.address
|
|
537
|
-
});
|
|
538
|
-
return;
|
|
539
|
-
case "service-assembled":
|
|
540
|
-
steps.finish({
|
|
541
|
-
name: "assemble-service",
|
|
542
|
-
address: event.address
|
|
543
|
-
}, event.data);
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}, action === "destroy" ? (error) => new CliStructuredError("DEPLOY.BUILD_REQUIRED", error.message, {
|
|
548
|
-
why: "destroy evaluates the same stack program as deploy, which packages the built artifacts — so the app must be built first.",
|
|
549
|
-
fix: "Run the build, then retry the destroy.",
|
|
550
|
-
cause: error
|
|
551
|
-
}) : void 0);
|
|
552
|
-
steps.finish({ name: "assemble" });
|
|
553
|
-
const { graph, name: resolvedName } = pipeline;
|
|
554
|
-
const config = pipeline.configSource.value;
|
|
555
|
-
if (action === "deploy") refuseSecretsInRootInput(graph.appConfigurationRead, opts.redaction.knownSecrets, "A deploy sends every plain value Load read to the platform as plain configuration, and never sends a secret that way.");
|
|
556
|
-
steps.start({ name: "connect" });
|
|
557
|
-
if (action === "deploy") reporters.push(...await beginReporters(config.extensions, {
|
|
558
|
-
appName: resolvedName,
|
|
559
|
-
graph,
|
|
560
|
-
environment,
|
|
561
|
-
cwd,
|
|
562
|
-
reportId: opts.reportId,
|
|
563
|
-
credentials: platformCredentials
|
|
564
|
-
}, opts.redaction));
|
|
565
|
-
containers = /* @__PURE__ */ new Map();
|
|
566
|
-
for (const extension of config.extensions) {
|
|
567
|
-
if (extension.container === void 0) continue;
|
|
568
|
-
try {
|
|
569
|
-
if (action === "deploy") {
|
|
570
|
-
const instance = await extension.container.ensure({
|
|
571
|
-
appName: resolvedName,
|
|
572
|
-
environment
|
|
573
|
-
}, platformCredentials);
|
|
574
|
-
requireContainerForEnvironment(action, extension.id, extension.container, instance, environment);
|
|
575
|
-
containers.set(extension.id, instance);
|
|
576
|
-
} else {
|
|
577
|
-
const instance = await extension.container.locate({
|
|
578
|
-
appName: resolvedName,
|
|
579
|
-
environment
|
|
580
|
-
}, platformCredentials);
|
|
581
|
-
if (instance === void 0) throw new CliStructuredError("DEPLOY.TARGET_NOT_FOUND", `Nothing deployed for ${resolvedName} in the environment ${environment}.`, { fix: "Deploy it first." });
|
|
582
|
-
requireContainerForEnvironment(action, extension.id, extension.container, instance, environment);
|
|
583
|
-
containers.set(extension.id, instance);
|
|
584
|
-
}
|
|
585
|
-
} catch (error) {
|
|
586
|
-
throw toStructured("DEPLOY.CONTAINER_FAILED", error);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
await attachReporters(reporters, containers, opts.redaction);
|
|
590
|
-
alchemyStage = containers.get(config.state.extension)?.alchemyStage ?? environment;
|
|
591
|
-
steps.finish({ name: "connect" });
|
|
592
|
-
if (action === "deploy") {
|
|
593
|
-
steps.start({ name: "preflight" });
|
|
594
|
-
let checked = 0;
|
|
595
|
-
const report = (reported) => {
|
|
596
|
-
checked += reported.checked;
|
|
597
|
-
unset.push(...reported.unset.map((variable) => redactUnsetPlatformVariable(variable, opts.redaction)));
|
|
598
|
-
};
|
|
599
|
-
for (const extension of config.extensions) {
|
|
600
|
-
if (extension.preflight === void 0) continue;
|
|
601
|
-
try {
|
|
602
|
-
const payload = await extension.preflight({
|
|
603
|
-
graph,
|
|
604
|
-
container: containers.get(extension.id),
|
|
605
|
-
environment,
|
|
606
|
-
configuration: pipeline.configuration,
|
|
607
|
-
secrets: pipeline.secrets,
|
|
608
|
-
credentials: platformCredentials,
|
|
609
|
-
report
|
|
610
|
-
});
|
|
611
|
-
if (payload !== void 0) preflightPayloads.set(extension.id, payload);
|
|
612
|
-
} catch (error) {
|
|
613
|
-
throw toStructured("DEPLOY.PREFLIGHT_FAILED", error);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
steps.finish({ name: "preflight" }, {
|
|
617
|
-
checked,
|
|
618
|
-
unset: unset.length
|
|
619
|
-
});
|
|
620
|
-
if (unset.length > 0) steps.emit({
|
|
621
|
-
kind: "preflight-findings",
|
|
622
|
-
findings: { unset }
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
if (action === "destroy") for (const extension of config.extensions) preflightTransportEnv[preflightEnvVarName(extension.id)] = "";
|
|
626
|
-
} catch (error) {
|
|
627
|
-
if (CliStructuredError.is(error)) return notOk(error);
|
|
628
|
-
throw error;
|
|
629
|
-
}
|
|
630
|
-
if (appConvergeEntry !== void 0) return convergeDeploy(opts, pipeline, appConvergeEntry, {
|
|
631
|
-
containers,
|
|
632
|
-
stage: alchemyStage,
|
|
633
|
-
preflightPayloads,
|
|
634
|
-
findings: { unset },
|
|
635
|
-
env: reporterEnv(reporters, opts.redaction)
|
|
636
|
-
});
|
|
637
|
-
let stackPath;
|
|
638
|
-
const resultFilePath = path$1.join(cwd, ".prisma-composer", `deployment-result-${String(process.pid)}-${randomUUID()}.json`);
|
|
639
|
-
let handover;
|
|
640
|
-
try {
|
|
641
|
-
try {
|
|
642
|
-
handover = prepareSecondProcess({
|
|
643
|
-
file: deployAppConfigurationFile(cwd, randomUUID()),
|
|
644
|
-
appConfigurationRead: pipeline.graph.appConfigurationRead,
|
|
645
|
-
plainVariableText: {},
|
|
646
|
-
nodeAddresses: nodeAddresses(pipeline.graph),
|
|
647
|
-
knownSecrets: opts.redaction.knownSecrets
|
|
648
|
-
});
|
|
649
|
-
stackPath = writeStackFile({
|
|
650
|
-
entryPath: pipeline.entryModule.path,
|
|
651
|
-
cwd,
|
|
652
|
-
configFile: pipeline.configSource.file,
|
|
653
|
-
name: pipeline.name,
|
|
654
|
-
environment,
|
|
655
|
-
assembled: pipeline.assembled
|
|
656
|
-
});
|
|
657
|
-
handover.writeFile();
|
|
658
|
-
} catch (error) {
|
|
659
|
-
return notOk(toStructured("DEPLOY.STACK_WRITE_FAILED", error));
|
|
660
|
-
}
|
|
661
|
-
const invocation = alchemyInvocation({
|
|
662
|
-
command: action,
|
|
663
|
-
stackFileRelativePath: GENERATED_STACK_RELATIVE_PATH,
|
|
664
|
-
cwd,
|
|
665
|
-
stage: alchemyStage,
|
|
666
|
-
containerEnv: containerEnv(containers),
|
|
667
|
-
preflightEnv: preflightTransportEnv,
|
|
668
|
-
env: {
|
|
669
|
-
...reporterEnv(reporters, opts.redaction),
|
|
670
|
-
...handover.env,
|
|
671
|
-
[DEPLOYMENT_RESULT_FILE_ENV]: resultFilePath
|
|
672
|
-
},
|
|
673
|
-
redactedValues: opts.redaction.allValues()
|
|
674
|
-
});
|
|
675
|
-
steps.start({ name: "apply" });
|
|
676
|
-
let outcome;
|
|
677
|
-
try {
|
|
678
|
-
outcome = await (deps.alchemy ?? spawnAlchemy)(invocation);
|
|
679
|
-
} catch (error) {
|
|
680
|
-
if (CliStructuredError.is(error)) return notOk(error);
|
|
681
|
-
return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", error instanceof Error ? error.message : String(error), {
|
|
682
|
-
cause: error,
|
|
683
|
-
meta: { diagnostics: {
|
|
684
|
-
exitCode: void 0,
|
|
685
|
-
stackFilePath: stackPath,
|
|
686
|
-
reproduceCommand: reproduceCommand(invocation),
|
|
687
|
-
cwd
|
|
688
|
-
} }
|
|
689
|
-
}));
|
|
690
|
-
}
|
|
691
|
-
const reproduce = reproduceCommand(invocation, outcome);
|
|
692
|
-
if (outcome.signal !== null) return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", `alchemy ${action} was interrupted by ${outcome.signal}.`, { meta: {
|
|
693
|
-
signal: outcome.signal,
|
|
694
|
-
diagnostics: {
|
|
695
|
-
exitCode: void 0,
|
|
696
|
-
signal: outcome.signal,
|
|
697
|
-
stackFilePath: stackPath,
|
|
698
|
-
reproduceCommand: reproduce,
|
|
699
|
-
cwd
|
|
700
|
-
}
|
|
701
|
-
} }));
|
|
702
|
-
const status = outcome.exitCode ?? 1;
|
|
703
|
-
if (status !== 0) {
|
|
704
|
-
const engineCause = readEngineFailureCause(resultFilePath, (text) => opts.redaction.redact(text));
|
|
705
|
-
const withCause = (sentence) => engineCause === void 0 ? sentence : `${sentence}\n${engineCause}`;
|
|
706
|
-
return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", withCause(`alchemy ${action} exited with status ${status}.`), { meta: {
|
|
707
|
-
exitCode: status,
|
|
708
|
-
...engineCause !== void 0 ? { engineCause } : {},
|
|
709
|
-
diagnostics: {
|
|
710
|
-
exitCode: status,
|
|
711
|
-
stackFilePath: stackPath,
|
|
712
|
-
reproduceCommand: reproduce,
|
|
713
|
-
cwd
|
|
714
|
-
}
|
|
715
|
-
} }));
|
|
716
|
-
}
|
|
717
|
-
steps.finish({ name: "apply" });
|
|
718
|
-
try {
|
|
719
|
-
if (action === "destroy") {
|
|
720
|
-
for (const extension of pipeline.configSource.value.extensions) {
|
|
721
|
-
if (extension.teardown === void 0) continue;
|
|
722
|
-
try {
|
|
723
|
-
await extension.teardown({
|
|
724
|
-
container: containers.get(extension.id),
|
|
725
|
-
environment
|
|
726
|
-
});
|
|
727
|
-
} catch (error) {
|
|
728
|
-
throw toStructured("DEPLOY.TEARDOWN_FAILED", error);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
for (const extension of pipeline.configSource.value.extensions) {
|
|
732
|
-
if (extension.container === void 0) continue;
|
|
733
|
-
const instance = containers.get(extension.id);
|
|
734
|
-
if (instance === void 0) continue;
|
|
735
|
-
try {
|
|
736
|
-
await extension.container.remove(instance, platformCredentials);
|
|
737
|
-
} catch (error) {
|
|
738
|
-
throw toStructured("DEPLOY.CONTAINER_REMOVE_FAILED", error);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
} catch (error) {
|
|
743
|
-
if (CliStructuredError.is(error)) return notOk(error);
|
|
744
|
-
throw error;
|
|
745
|
-
}
|
|
746
|
-
return ok(void 0);
|
|
747
|
-
} finally {
|
|
748
|
-
try {
|
|
749
|
-
fs$1.rmSync(resultFilePath, { force: true });
|
|
750
|
-
fs$1.rmSync(engineFailureFilePath(resultFilePath), { force: true });
|
|
751
|
-
} catch {}
|
|
752
|
-
handover?.removeFile();
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
/** Loaded before anything is created, so a missing or incompatible install fails first. */
|
|
756
|
-
async function prepareAppConvergeEntry(deps, appDir) {
|
|
757
|
-
try {
|
|
758
|
-
return ok(deps.appConvergeEntry ?? await loadAppConvergeEntry(appDir));
|
|
759
|
-
} catch (error) {
|
|
760
|
-
if (CliStructuredError.is(error)) return notOk(error);
|
|
761
|
-
throw error;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
/** The structured failure a converge that did not apply settles as. */
|
|
765
|
-
function convergeFailure(outcome, redact) {
|
|
766
|
-
switch (outcome.kind) {
|
|
767
|
-
case "interrupted": return new CliStructuredError("DEPLOY.INTERRUPTED", "The deploy was interrupted.", {
|
|
768
|
-
why: "It stopped while Alchemy planned or applied it. Resources it had already changed stay as they are.",
|
|
769
|
-
fix: "Deploy again to finish."
|
|
770
|
-
});
|
|
771
|
-
case "refused": return outcome.reason === "already-running" ? new CliStructuredError("DEPLOY.CONVERGE_RUNNING", "Another deploy is already running in this process.", {
|
|
772
|
-
why: "A deploy sets the process's environment and working directory while Alchemy runs, so two cannot overlap.",
|
|
773
|
-
fix: "Wait for the other deploy to finish, or run this one in its own process."
|
|
774
|
-
}) : new CliStructuredError("DEPLOY.WORKER_THREAD", "Deploy cannot run in a worker thread when its cwd is not the process working directory.", {
|
|
775
|
-
why: "Alchemy reads `.env` and keeps `.alchemy` in the working directory, and a worker thread cannot change it.",
|
|
776
|
-
fix: "Call deploy from the main thread, or with the process's working directory as its cwd."
|
|
777
|
-
});
|
|
778
|
-
case "failed": {
|
|
779
|
-
const cause = capFailureCause(redact(withComposerAdvice(convergeReasonsText(outcome.reasons))));
|
|
780
|
-
return new CliStructuredError("DEPLOY.ENGINE_FAILED", `Alchemy could not deploy the app.\n${cause}`, { meta: {
|
|
781
|
-
engineCause: cause,
|
|
782
|
-
reasons: outcome.reasons.map(({ tag, message }) => ({
|
|
783
|
-
tag,
|
|
784
|
-
message: redact(message)
|
|
785
|
-
}))
|
|
786
|
-
} });
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
return new CliStructuredError("DEPLOY.ENGINE_FAILED", "The converge ended with an outcome this Composer does not know.");
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Deploy's converge: lowers the app with the containers and preflight
|
|
793
|
-
* payloads this run resolved, then plans and applies it in this process.
|
|
794
|
-
* The report hook runs inside the apply, here, so the summary comes back as
|
|
795
|
-
* a value.
|
|
796
|
-
*/
|
|
797
|
-
async function convergeDeploy(opts, pipeline, entry, resolved) {
|
|
798
|
-
const { cwd, environment, steps } = opts;
|
|
799
|
-
const config = pipeline.configSource.value;
|
|
800
|
-
const env = resolved.env;
|
|
801
|
-
opts.redaction.addCredentialLookingValues(credentialLookingValues(env));
|
|
802
|
-
const redact = (text) => opts.redaction.redact(text);
|
|
803
|
-
let summary;
|
|
804
|
-
const root = pipeline.graph.root.node;
|
|
805
|
-
if (root.kind !== "module") throw new InternalError("runPipeline admitted a root that is not a module");
|
|
806
|
-
steps.start({ name: "apply" });
|
|
807
|
-
let stack;
|
|
808
|
-
try {
|
|
809
|
-
stack = entry.lower(root, config, {
|
|
810
|
-
name: pipeline.name,
|
|
811
|
-
environment,
|
|
812
|
-
appConfigurationRead: pipeline.graph.appConfigurationRead,
|
|
813
|
-
firstProcessNodeAddresses: nodeAddresses(pipeline.graph),
|
|
814
|
-
bundles: pipeline.assembled.bundles,
|
|
815
|
-
containers: resolved.containers,
|
|
816
|
-
preflightPayloads: resolved.preflightPayloads,
|
|
817
|
-
findings: resolved.findings,
|
|
818
|
-
credentials: opts.deps.credentials,
|
|
819
|
-
report: (result) => {
|
|
820
|
-
summary = toDeploymentSummary(result);
|
|
821
|
-
}
|
|
822
|
-
});
|
|
823
|
-
} catch (error) {
|
|
824
|
-
if (CliStructuredError.is(error)) return notOk(error);
|
|
825
|
-
return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", redact(error instanceof Error ? error.message : String(error))));
|
|
826
|
-
}
|
|
827
|
-
const output = interactionMessages(steps, opts.redaction);
|
|
828
|
-
let outcome;
|
|
829
|
-
try {
|
|
830
|
-
outcome = await entry.converge({
|
|
831
|
-
operation: "deploy",
|
|
832
|
-
stack,
|
|
833
|
-
stage: resolved.stage,
|
|
834
|
-
cwd,
|
|
835
|
-
env,
|
|
836
|
-
signal: opts.signal,
|
|
837
|
-
onEvent: (event) => reportConvergeEvent(steps, event, redact, (resource) => ({
|
|
838
|
-
name: "apply-resource",
|
|
839
|
-
...resource
|
|
840
|
-
})),
|
|
841
|
-
output: (text) => output.push(text)
|
|
842
|
-
});
|
|
843
|
-
} catch (error) {
|
|
844
|
-
return notOk(new CliStructuredError("DEPLOY.ENGINE_FAILED", redact(`Alchemy could not deploy the app.\n${error instanceof Error ? error.message : String(error)}`)));
|
|
845
|
-
} finally {
|
|
846
|
-
output.end();
|
|
847
|
-
}
|
|
848
|
-
if (outcome.kind !== "applied") return notOk(convergeFailure(outcome, redact));
|
|
849
|
-
steps.finish({ name: "apply" });
|
|
850
|
-
return ok(redactSummary(summary, opts.redaction));
|
|
851
|
-
}
|
|
852
|
-
//#endregion
|
|
853
|
-
export { executeDeploy, executeDestroy };
|
|
854
|
-
|
|
855
|
-
//# sourceMappingURL=execute-deploy-destroy-C-aK5jh--D-AjLWc2.mjs.map
|