@prisma/composer-cli 0.39.0-dev.7 → 0.39.0-dev.9
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-converge-C6Zrg2xM-DX-tW6C3.mjs +88 -0
- package/dist/app-converge-C6Zrg2xM-DX-tW6C3.mjs.map +1 -0
- package/dist/composer-config-QKdY85G--CEXrb2Uc.mjs +254 -0
- package/dist/composer-config-QKdY85G--CEXrb2Uc.mjs.map +1 -0
- package/dist/{validate-environment-XwVDifWN-BdYUHyVF.mjs → deploy-Br1yvLe3.mjs} +204 -1010
- package/dist/deploy-Br1yvLe3.mjs.map +1 -0
- package/dist/dev-converge-messages-DML4rTz7-B6uxtpZG.mjs +256 -0
- package/dist/dev-converge-messages-DML4rTz7-B6uxtpZG.mjs.map +1 -0
- package/dist/dev-converge-worker.d.mts +1 -0
- package/dist/dev-converge-worker.mjs +143 -0
- package/dist/dev-converge-worker.mjs.map +1 -0
- package/dist/{dev-current-gQnmjB4V-DrQ4Zzbl.mjs → dev-current-EqQbrtj5-DieSnSVx.mjs} +12 -18
- package/dist/dev-current-EqQbrtj5-DieSnSVx.mjs.map +1 -0
- package/dist/dev-environment-name-6eEr5PW8-CCY7WNWz.mjs +43 -0
- package/dist/dev-environment-name-6eEr5PW8-CCY7WNWz.mjs.map +1 -0
- package/dist/{dist-CRSv_9L8.mjs → dist-C0OGaDnj.mjs} +4 -3
- package/dist/{dist-CRSv_9L8.mjs.map → dist-C0OGaDnj.mjs.map} +1 -1
- package/dist/errors-CVYwN2km.mjs +93 -0
- package/dist/errors-CVYwN2km.mjs.map +1 -0
- package/dist/{execute-deploy-destroy-DKbsBkqK-D8pniqZg.mjs → execute-deploy-destroy-DKEmb8WI-DcgNdw4b.mjs} +245 -244
- package/dist/execute-deploy-destroy-DKEmb8WI-DcgNdw4b.mjs.map +1 -0
- package/dist/{execute-dev-DVCWURmI-D91UZq1o.mjs → execute-dev-C42niIFY-Dh_7dJ5W.mjs} +422 -166
- package/dist/execute-dev-C42niIFY-Dh_7dJ5W.mjs.map +1 -0
- package/dist/{execute-dev-current-Dt_9srY2-D8mAcSv4.mjs → execute-dev-current-AVT4zQ8F--qMLJobM.mjs} +9 -6
- package/dist/{execute-dev-current-Dt_9srY2-D8mAcSv4.mjs.map → execute-dev-current-AVT4zQ8F--qMLJobM.mjs.map} +1 -1
- package/dist/{family-D52hWFMF-FfSJ5SN2.d.mts → family-DfwviKFj-CS1L-EvS.d.mts} +171 -69
- package/dist/family-DfwviKFj-CS1L-EvS.d.mts.map +1 -0
- package/dist/family.d.mts +1 -1
- package/dist/family.mjs +87 -137
- package/dist/family.mjs.map +1 -1
- package/dist/internal-error-Dfur7Zqt-B8J8e7ac.mjs +58 -0
- package/dist/internal-error-Dfur7Zqt-B8J8e7ac.mjs.map +1 -0
- package/dist/{list-deployed-CIaiiV_l.mjs → list-deployed-C1cwFHrb.mjs} +5 -4
- package/dist/{list-deployed-CIaiiV_l.mjs.map → list-deployed-C1cwFHrb.mjs.map} +1 -1
- package/dist/local-target-CZzICh5R.mjs +34 -0
- package/dist/local-target-CZzICh5R.mjs.map +1 -0
- package/dist/preflight-transport-2d6iIchu-ArIJUY1L.mjs +56 -0
- package/dist/preflight-transport-2d6iIchu-ArIJUY1L.mjs.map +1 -0
- package/dist/{redaction-CjMYXtGp-CYefSG9A.mjs → redaction-DY6eDC12-BrK1aSN5.mjs} +17 -256
- package/dist/redaction-DY6eDC12-BrK1aSN5.mjs.map +1 -0
- package/dist/result-CttmabB6.mjs +91 -0
- package/dist/result-CttmabB6.mjs.map +1 -0
- package/dist/rolldown-runtime-C7HZzL1F.mjs +26 -0
- package/dist/steps-BZXNqW6U-BM2Aa8Bp.mjs +287 -0
- package/dist/steps-BZXNqW6U-BM2Aa8Bp.mjs.map +1 -0
- package/dist/testing.d.mts +2 -42
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +2 -5
- package/dist/testing.mjs.map +1 -1
- package/dist/validate-environment-DCZiNSlR-idVge-kq.mjs +983 -0
- package/dist/validate-environment-DCZiNSlR-idVge-kq.mjs.map +1 -0
- package/dist/value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs +15 -0
- package/dist/value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs.map +1 -0
- package/package.json +7 -7
- package/src/exports/dev-converge-worker.ts +2 -0
- package/src/exports/testing.ts +1 -4
- package/dist/app-configuration-file-Bbfq5PR3-CYdGtitc.mjs +0 -137
- package/dist/app-configuration-file-Bbfq5PR3-CYdGtitc.mjs.map +0 -1
- package/dist/dev-current-gQnmjB4V-DrQ4Zzbl.mjs.map +0 -1
- package/dist/dev-environment-name-6eEr5PW8-kDiScOL8.mjs +0 -71
- package/dist/dev-environment-name-6eEr5PW8-kDiScOL8.mjs.map +0 -1
- package/dist/execute-deploy-destroy-DKbsBkqK-D8pniqZg.mjs.map +0 -1
- package/dist/execute-dev-DVCWURmI-D91UZq1o.mjs.map +0 -1
- package/dist/family-D52hWFMF-FfSJ5SN2.d.mts.map +0 -1
- package/dist/generate-dev-stack-BEpqJ3AH-B7o7JyER.mjs +0 -100
- package/dist/generate-dev-stack-BEpqJ3AH-B7o7JyER.mjs.map +0 -1
- package/dist/redaction-CjMYXtGp-CYefSG9A.mjs.map +0 -1
- package/dist/result-DlBttLS8.mjs +0 -234
- package/dist/result-DlBttLS8.mjs.map +0 -1
- package/dist/run-alchemy-BlYyc4Oh-BnFv0AaY.mjs +0 -302
- package/dist/run-alchemy-BlYyc4Oh-BnFv0AaY.mjs.map +0 -1
- package/dist/validate-environment-XwVDifWN-BdYUHyVF.mjs.map +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { n as blindCast } from "./internal-error-Dfur7Zqt-B8J8e7ac.mjs";
|
|
2
|
+
//#region ../../0-framework/0-foundation/foundation/dist/errors.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Returns an object with the key/value if value is defined, otherwise an empty object.
|
|
5
|
+
*
|
|
6
|
+
* Use with spread to conditionally include optional properties while satisfying
|
|
7
|
+
* exactOptionalPropertyTypes. This is explicit about which properties are optional
|
|
8
|
+
* and won't inadvertently strip other undefined values.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Instead of:
|
|
13
|
+
* const obj = {
|
|
14
|
+
* required: 'value',
|
|
15
|
+
* ...(optional ? { optional } : {}),
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* // Use:
|
|
19
|
+
* const obj = {
|
|
20
|
+
* required: 'value',
|
|
21
|
+
* ...ifDefined('optional', optional),
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function ifDefined(key, value) {
|
|
26
|
+
return value !== void 0 ? blindCast({ [key]: value }) : {};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Structured CLI error that contains all information needed for error envelopes.
|
|
30
|
+
* Call sites throw these errors with full context.
|
|
31
|
+
*
|
|
32
|
+
* A `CliStructuredError` is a `StructuredError` (see
|
|
33
|
+
* `./structured-error.ts`): `code` is a dotted
|
|
34
|
+
* `NAMESPACE.SUBCODE` string, and the namespace prefix is the error's
|
|
35
|
+
* category — there is no separate `domain` field. See ADR 239 in
|
|
36
|
+
* prisma/prisma and composer's ADR-0044 for the namespace taxonomy.
|
|
37
|
+
*/
|
|
38
|
+
var CliStructuredError = class extends Error {
|
|
39
|
+
code;
|
|
40
|
+
severity;
|
|
41
|
+
constructor(code, summary, options) {
|
|
42
|
+
super(summary, options?.cause !== void 0 ? { cause: options.cause } : void 0);
|
|
43
|
+
this.name = "CliStructuredError";
|
|
44
|
+
this.code = code;
|
|
45
|
+
this.severity = options?.severity ?? "error";
|
|
46
|
+
const fix = options?.fix === options?.why ? void 0 : options?.fix;
|
|
47
|
+
const where = options?.where ? {
|
|
48
|
+
...ifDefined("path", options.where.path),
|
|
49
|
+
...ifDefined("line", options.where.line)
|
|
50
|
+
} : void 0;
|
|
51
|
+
Object.assign(this, {
|
|
52
|
+
...ifDefined("why", options?.why),
|
|
53
|
+
...ifDefined("fix", fix),
|
|
54
|
+
...ifDefined("where", where),
|
|
55
|
+
...ifDefined("meta", options?.meta),
|
|
56
|
+
...ifDefined("docsUrl", options?.docsUrl)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts this error to a CLI error envelope for output formatting.
|
|
61
|
+
*/
|
|
62
|
+
toEnvelope() {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
code: this.code,
|
|
66
|
+
severity: this.severity,
|
|
67
|
+
summary: this.message,
|
|
68
|
+
...ifDefined("why", this.why),
|
|
69
|
+
...ifDefined("fix", this.fix),
|
|
70
|
+
...ifDefined("where", this.where),
|
|
71
|
+
...ifDefined("meta", this.meta),
|
|
72
|
+
...ifDefined("docsUrl", this.docsUrl)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Type guard to check if an error is a CliStructuredError.
|
|
77
|
+
* Uses duck-typing to work across module boundaries where instanceof may fail.
|
|
78
|
+
*/
|
|
79
|
+
static is(error) {
|
|
80
|
+
if (!(error instanceof Error)) return false;
|
|
81
|
+
const candidate = blindCast(error);
|
|
82
|
+
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && typeof candidate.toEnvelope === "function";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function quotedList(names) {
|
|
86
|
+
const quoted = names.map((name) => `"${name}"`);
|
|
87
|
+
const last = quoted.pop() ?? "";
|
|
88
|
+
return quoted.length === 0 ? last : `${quoted.join(", ")} and ${last}`;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { quotedList as n, CliStructuredError as t };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=errors-CVYwN2km.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CVYwN2km.mjs","names":[],"sources":["../../../0-framework/0-foundation/foundation/dist/errors.mjs"],"sourcesContent":["import { t as blindCast } from \"./casts-DpaahrlC.mjs\";\nimport { t as describeKind } from \"./describe-kind-Cpm_euxo.mjs\";\nimport { n as assertNever, r as isInternalError, t as InternalError } from \"./internal-error-Dfur7Zqt.mjs\";\n//#region src/defined.ts\n/**\n* Returns an object with the key/value if value is defined, otherwise an empty object.\n*\n* Use with spread to conditionally include optional properties while satisfying\n* exactOptionalPropertyTypes. This is explicit about which properties are optional\n* and won't inadvertently strip other undefined values.\n*\n* @example\n* ```typescript\n* // Instead of:\n* const obj = {\n* required: 'value',\n* ...(optional ? { optional } : {}),\n* };\n*\n* // Use:\n* const obj = {\n* required: 'value',\n* ...ifDefined('optional', optional),\n* };\n* ```\n*/\nfunction ifDefined(key, value) {\n\treturn value !== void 0 ? blindCast({ [key]: value }) : {};\n}\n//#endregion\n//#region src/cli-structured-error.ts\n/**\n* Structured CLI error that contains all information needed for error envelopes.\n* Call sites throw these errors with full context.\n*\n* A `CliStructuredError` is a `StructuredError` (see\n* `./structured-error.ts`): `code` is a dotted\n* `NAMESPACE.SUBCODE` string, and the namespace prefix is the error's\n* category — there is no separate `domain` field. See ADR 239 in\n* prisma/prisma and composer's ADR-0044 for the namespace taxonomy.\n*/\nvar CliStructuredError = class extends Error {\n\tcode;\n\tseverity;\n\tconstructor(code, summary, options) {\n\t\tsuper(summary, options?.cause !== void 0 ? { cause: options.cause } : void 0);\n\t\tthis.name = \"CliStructuredError\";\n\t\tthis.code = code;\n\t\tthis.severity = options?.severity ?? \"error\";\n\t\tconst fix = options?.fix === options?.why ? void 0 : options?.fix;\n\t\tconst where = options?.where ? {\n\t\t\t...ifDefined(\"path\", options.where.path),\n\t\t\t...ifDefined(\"line\", options.where.line)\n\t\t} : void 0;\n\t\tObject.assign(this, {\n\t\t\t...ifDefined(\"why\", options?.why),\n\t\t\t...ifDefined(\"fix\", fix),\n\t\t\t...ifDefined(\"where\", where),\n\t\t\t...ifDefined(\"meta\", options?.meta),\n\t\t\t...ifDefined(\"docsUrl\", options?.docsUrl)\n\t\t});\n\t}\n\t/**\n\t* Converts this error to a CLI error envelope for output formatting.\n\t*/\n\ttoEnvelope() {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tcode: this.code,\n\t\t\tseverity: this.severity,\n\t\t\tsummary: this.message,\n\t\t\t...ifDefined(\"why\", this.why),\n\t\t\t...ifDefined(\"fix\", this.fix),\n\t\t\t...ifDefined(\"where\", this.where),\n\t\t\t...ifDefined(\"meta\", this.meta),\n\t\t\t...ifDefined(\"docsUrl\", this.docsUrl)\n\t\t};\n\t}\n\t/**\n\t* Type guard to check if an error is a CliStructuredError.\n\t* Uses duck-typing to work across module boundaries where instanceof may fail.\n\t*/\n\tstatic is(error) {\n\t\tif (!(error instanceof Error)) return false;\n\t\tconst candidate = blindCast(error);\n\t\treturn candidate.name === \"CliStructuredError\" && typeof candidate.code === \"string\" && typeof candidate.toEnvelope === \"function\";\n\t}\n};\n//#endregion\n//#region src/quoted-list.ts\nfunction quotedList(names) {\n\tconst quoted = names.map((name) => `\"${name}\"`);\n\tconst last = quoted.pop() ?? \"\";\n\treturn quoted.length === 0 ? last : `${quoted.join(\", \")} and ${last}`;\n}\n//#endregion\n//#region src/structured-error.ts\nconst STRUCTURED_CODE_RE = /^[A-Z][A-Z0-9]*\\.[A-Z][A-Z0-9_]*$/;\nfunction isStructuredError(e) {\n\treturn typeof e === \"object\" && e !== null && \"code\" in e && typeof e.code === \"string\" && STRUCTURED_CODE_RE.test(e.code) && \"message\" in e && typeof e.message === \"string\";\n}\nfunction structuredError(code, message, options) {\n\tconst error = options?.cause !== void 0 ? new Error(message, { cause: options.cause }) : new Error(message);\n\tObject.defineProperty(error, \"name\", {\n\t\tvalue: \"StructuredError\",\n\t\tconfigurable: true\n\t});\n\treturn Object.assign(error, {\n\t\tcode,\n\t\t...ifDefined(\"why\", options?.why),\n\t\t...ifDefined(\"fix\", options?.fix),\n\t\t...ifDefined(\"where\", options?.where),\n\t\t...ifDefined(\"severity\", options?.severity),\n\t\t...ifDefined(\"meta\", options?.meta),\n\t\t...ifDefined(\"docsUrl\", options?.docsUrl)\n\t});\n}\nconst DOCS_BASE = `https://docs.prisma.io/docs/orm/next/reference/error-reference`;\nfunction docsUrlFor(code) {\n\treturn `${DOCS_BASE}#${code}`;\n}\n//#endregion\nexport { CliStructuredError, DOCS_BASE, InternalError, assertNever, describeKind, docsUrlFor, isInternalError, isStructuredError, quotedList, structuredError };\n\n//# sourceMappingURL=errors.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAS,UAAU,KAAK,OAAO;CAC9B,OAAO,UAAU,KAAK,IAAI,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;AAC1D;;;;;;;;;;;AAaA,IAAI,qBAAqB,cAAc,MAAM;CAC5C;CACA;CACA,YAAY,MAAM,SAAS,SAAS;EACnC,MAAM,SAAS,SAAS,UAAU,KAAK,IAAI,EAAE,OAAO,QAAQ,MAAM,IAAI,KAAK,CAAC;EAC5E,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,WAAW,SAAS,YAAY;EACrC,MAAM,MAAM,SAAS,QAAQ,SAAS,MAAM,KAAK,IAAI,SAAS;EAC9D,MAAM,QAAQ,SAAS,QAAQ;GAC9B,GAAG,UAAU,QAAQ,QAAQ,MAAM,IAAI;GACvC,GAAG,UAAU,QAAQ,QAAQ,MAAM,IAAI;EACxC,IAAI,KAAK;EACT,OAAO,OAAO,MAAM;GACnB,GAAG,UAAU,OAAO,SAAS,GAAG;GAChC,GAAG,UAAU,OAAO,GAAG;GACvB,GAAG,UAAU,SAAS,KAAK;GAC3B,GAAG,UAAU,QAAQ,SAAS,IAAI;GAClC,GAAG,UAAU,WAAW,SAAS,OAAO;EACzC,CAAC;CACF;;;;CAIA,aAAa;EACZ,OAAO;GACN,IAAI;GACJ,MAAM,KAAK;GACX,UAAU,KAAK;GACf,SAAS,KAAK;GACd,GAAG,UAAU,OAAO,KAAK,GAAG;GAC5B,GAAG,UAAU,OAAO,KAAK,GAAG;GAC5B,GAAG,UAAU,SAAS,KAAK,KAAK;GAChC,GAAG,UAAU,QAAQ,KAAK,IAAI;GAC9B,GAAG,UAAU,WAAW,KAAK,OAAO;EACrC;CACD;;;;;CAKA,OAAO,GAAG,OAAO;EAChB,IAAI,EAAE,iBAAiB,QAAQ,OAAO;EACtC,MAAM,YAAY,UAAU,KAAK;EACjC,OAAO,UAAU,SAAS,wBAAwB,OAAO,UAAU,SAAS,YAAY,OAAO,UAAU,eAAe;CACzH;AACD;AAGA,SAAS,WAAW,OAAO;CAC1B,MAAM,SAAS,MAAM,KAAK,SAAS,IAAI,KAAK,EAAE;CAC9C,MAAM,OAAO,OAAO,IAAI,KAAK;CAC7B,OAAO,OAAO,WAAW,IAAI,OAAO,GAAG,OAAO,KAAK,IAAI,EAAE,OAAO;AACjE"}
|
|
@@ -1,70 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { c as
|
|
6
|
-
import {
|
|
1
|
+
import { i as noComposerExportMessage } from "./composer-config-QKdY85G--CEXrb2Uc.mjs";
|
|
2
|
+
import { t as InternalError } from "./internal-error-Dfur7Zqt-B8J8e7ac.mjs";
|
|
3
|
+
import { f as nodeAddresses } from "./deploy-Br1yvLe3.mjs";
|
|
4
|
+
import { t as CliStructuredError } from "./errors-CVYwN2km.mjs";
|
|
5
|
+
import { a as redactError, c as redactUnsetPlatformVariable, n as StreamRedactor, o as redactSummary, r as credentialLookingValues, s as redactThrown, t as SecretRedaction } from "./redaction-DY6eDC12-BrK1aSN5.mjs";
|
|
6
|
+
import { r as preflightEnvVarName, t as containerEnv } from "./preflight-transport-2d6iIchu-ArIJUY1L.mjs";
|
|
7
|
+
import { n as ok, r as okVoid, t as notOk } from "./result-CttmabB6.mjs";
|
|
8
|
+
import { c as toStructured, n as convergeReasonsText, s as requireContainerForEnvironment } from "./dev-current-EqQbrtj5-DieSnSVx.mjs";
|
|
9
|
+
import { t as loadAppConvergeEntry } from "./app-converge-C6Zrg2xM-DX-tW6C3.mjs";
|
|
10
|
+
import { i as validateEnvironmentName, r as runPipeline } from "./validate-environment-DCZiNSlR-idVge-kq.mjs";
|
|
11
|
+
import { a as prepareSecondProcess, c as removeLeftoverAppConfigurationFiles, d as engineFailureFilePath, f as readEngineFailureCause, i as deployAppConfigurationFile, l as DEPLOYMENT_RESULT_FILE_ENV, m as withComposerAdvice, n as reportConvergeEvent, p as toDeploymentSummary, r as stepTracker, s as refuseSecretsInRootInput, t as interactionMessages, u as capFailureCause } from "./steps-BZXNqW6U-BM2Aa8Bp.mjs";
|
|
7
12
|
import { createRequire } from "node:module";
|
|
8
13
|
import * as fs from "node:fs";
|
|
9
14
|
import * as path from "node:path";
|
|
10
|
-
import "node:util";
|
|
11
|
-
import { pathToFileURL } from "node:url";
|
|
12
15
|
import { randomUUID } from "node:crypto";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The deploy result as data, and what a stack file run as a child hands back
|
|
16
|
-
* to the CLI: the summary file the report hook writes, and the failure cause
|
|
17
|
-
* the child records when it exits non-zero. `DeploymentResult` holds live
|
|
18
|
-
* graph nodes (ADR-0033), so the summary keeps only what can be serialized.
|
|
19
|
-
* Both files are best-effort: a write failure never fails the child.
|
|
20
|
-
*/
|
|
21
|
-
/** Env var the deploy operation sets on the alchemy child: when present,
|
|
22
|
-
* the report hook also writes the JSON DeploymentSummary there. */
|
|
23
|
-
const DEPLOYMENT_RESULT_FILE_ENV = "PRISMA_COMPOSER_DEPLOYMENT_RESULT_FILE";
|
|
24
|
-
/** Pure projection: keeps app, each node's address/entities and the findings, drops the in-process `node`. */
|
|
25
|
-
function toDeploymentSummary(result) {
|
|
26
|
-
return {
|
|
27
|
-
app: result.app,
|
|
28
|
-
nodes: result.nodes.map((node) => ({
|
|
29
|
-
address: node.address,
|
|
30
|
-
entities: node.entities
|
|
31
|
-
})),
|
|
32
|
-
findings: result.findings
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/** The child's failure cause rides beside the result file, so the one env var names both and the parent's cleanup removes both. */
|
|
36
|
-
function engineFailureFilePath(resultFilePath) {
|
|
37
|
-
return `${resultFilePath}.failure.txt`;
|
|
38
|
-
}
|
|
39
|
-
/** Fits the platform's 5000-character build `errorMessage` with room for the exit-status prefix. */
|
|
40
|
-
const ENGINE_FAILURE_CAUSE_LIMIT = 1e3;
|
|
41
|
-
/** Alchemy's advice to rerun its own CLI with `--adopt` or to import a resource with adoption, which a Composer user has no way to do. */
|
|
42
|
-
const ALCHEMY_ADOPT_ADVICE = [
|
|
43
|
-
[/Re-run with `--adopt` \(or wrap the effect in `adopt\(true\)`\) to take it over\./g, "Something other than this app holds it. Remove that resource, then deploy again."],
|
|
44
|
-
[/Re-run with `--adopt` \(or wrap the effect in `adopt\(true\)`\) to replace it anyway\./g, "Remove that resource, then deploy again."],
|
|
45
|
-
[/\(re-deploy with --adopt to take ownership, then destroy\)/g, "(remove it by hand)"],
|
|
46
|
-
[/Import it with explicit adoption (?:instead of silently taking it over|or choose a different [\w ]+ name)\./g, "Something other than this app holds it. Remove that resource, then deploy again."],
|
|
47
|
-
[/; rerun with adoption enabled if it is the intended [\w ]+\./g, ". Remove that resource, then deploy again."]
|
|
48
|
-
];
|
|
49
|
-
/** Replaces Alchemy CLI advice in engine output with steps that work from Composer. */
|
|
50
|
-
function withComposerAdvice(text) {
|
|
51
|
-
return ALCHEMY_ADOPT_ADVICE.reduce((current, [advice, replacement]) => current.replace(advice, replacement), text);
|
|
52
|
-
}
|
|
53
|
-
/** Parent half: the cause the child recorded, passed through `redact`, or undefined when it recorded none. The child redacts only what its own environment names as a credential; the parent also knows the known secrets. */
|
|
54
|
-
function readEngineFailureCause(resultFilePath, redact) {
|
|
55
|
-
let cause;
|
|
56
|
-
try {
|
|
57
|
-
cause = fs.readFileSync(engineFailureFilePath(resultFilePath), "utf8");
|
|
58
|
-
} catch {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
return cause.length > 0 ? redact(cause) : void 0;
|
|
62
|
-
}
|
|
63
|
-
/** A failure cause capped to fit the platform build's error message. */
|
|
64
|
-
function capFailureCause(cause) {
|
|
65
|
-
return cause.length <= ENGINE_FAILURE_CAUSE_LIMIT ? cause : `${cause.slice(0, ENGINE_FAILURE_CAUSE_LIMIT - 1)}…`;
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
16
|
+
import spawn from "cross-spawn";
|
|
68
17
|
//#region ../../0-framework/3-tooling/cli/dist/run-report-CmBz2-xc.mjs
|
|
69
18
|
/** Names the file to write the run report to, when `--report` is not passed. */
|
|
70
19
|
const RUN_REPORT_FILE_ENV = "PRISMA_COMPOSER_REPORT_FILE";
|
|
@@ -106,75 +55,7 @@ function writeRunReport(filePath, report) {
|
|
|
106
55
|
}
|
|
107
56
|
}
|
|
108
57
|
//#endregion
|
|
109
|
-
//#region ../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-
|
|
110
|
-
var version = "0.39.0-dev.7";
|
|
111
|
-
const ENTRY = "@prisma/composer/internal/converge";
|
|
112
|
-
const CONTRACT_ENTRY = "@prisma/composer/internal/converge-contract";
|
|
113
|
-
/** The Composer version this host runs; every Composer package carries the same one. */
|
|
114
|
-
const HOST_COMPOSER_VERSION = version;
|
|
115
|
-
function unresolvable(appDir, detail, cause) {
|
|
116
|
-
return new CliStructuredError("DEPS.CONVERGE_UNRESOLVABLE", `Could not load the converge from the app's @prisma/composer in "${appDir}": ${detail}`, {
|
|
117
|
-
why: "`prisma deploy` runs the lowering and Alchemy from the app's own install of @prisma/composer, so the app, its extensions and Alchemy share one copy of alchemy.",
|
|
118
|
-
fix: "Install @prisma/composer in the app, at the same version as the Composer the `prisma` CLI runs.",
|
|
119
|
-
...cause === void 0 ? {} : { cause }
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function installedVersion(require) {
|
|
123
|
-
try {
|
|
124
|
-
const parsed = JSON.parse(fs.readFileSync(require.resolve("@prisma/composer/package.json"), "utf8"));
|
|
125
|
-
return typeof parsed === "object" && parsed !== null && "version" in parsed && typeof parsed.version === "string" ? parsed.version : void 0;
|
|
126
|
-
} catch {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async function importFile(appDir, file) {
|
|
131
|
-
try {
|
|
132
|
-
return await import(pathToFileURL(file).href);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
throw unresolvable(appDir, `${file} failed to load: ${error instanceof Error ? error.message : String(error)}`, error);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function contractMismatch(host, app) {
|
|
138
|
-
const appVersion = app.version ?? "an unknown version";
|
|
139
|
-
const update = app.contract < host.contract ? `Upgrade the app's @prisma/composer to a release that speaks converge contract ${host.contract}, such as ${host.version}.` : `Upgrade the \`prisma\` CLI to one that runs a Composer speaking converge contract ${app.contract}, such as ${appVersion}.`;
|
|
140
|
-
return new CliStructuredError("DEPS.CONVERGE_CONTRACT_MISMATCH", `The app's @prisma/composer ${appVersion} speaks converge contract ${app.contract}, and the \`prisma\` CLI's Composer ${host.version} speaks contract ${host.contract}.`, {
|
|
141
|
-
why: "Deploy calls the app's @prisma/composer from the CLI's Composer, and the two read each other's data only when they speak the same converge contract.",
|
|
142
|
-
fix: update
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* The app's `lower` and converge, from the install `appDir` resolves. Reads the app's
|
|
147
|
-
* converge contract before loading anything else. Raises
|
|
148
|
-
* DEPS.CONVERGE_UNRESOLVABLE when the install is missing or predates the
|
|
149
|
-
* in-process converge, and DEPS.CONVERGE_CONTRACT_MISMATCH when it speaks
|
|
150
|
-
* another contract than `host`.
|
|
151
|
-
*/
|
|
152
|
-
async function loadAppConvergeEntry(appDir, host = {
|
|
153
|
-
contract: 2,
|
|
154
|
-
version: HOST_COMPOSER_VERSION
|
|
155
|
-
}) {
|
|
156
|
-
const require = createRequire(path.join(appDir, "package.json"));
|
|
157
|
-
let contractFile;
|
|
158
|
-
let file;
|
|
159
|
-
try {
|
|
160
|
-
contractFile = require.resolve(CONTRACT_ENTRY);
|
|
161
|
-
file = require.resolve(ENTRY);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
throw unresolvable(appDir, `${CONTRACT_ENTRY} or ${ENTRY} does not resolve.`, error);
|
|
164
|
-
}
|
|
165
|
-
const { CONVERGE_CONTRACT: appContract } = await importFile(appDir, contractFile);
|
|
166
|
-
if (typeof appContract !== "number") throw unresolvable(appDir, `${contractFile} exports no CONVERGE_CONTRACT.`);
|
|
167
|
-
if (appContract !== host.contract) throw contractMismatch(host, {
|
|
168
|
-
contract: appContract,
|
|
169
|
-
version: installedVersion(require)
|
|
170
|
-
});
|
|
171
|
-
const { lower: appLower, convergeInProcess } = await importFile(appDir, file);
|
|
172
|
-
if (typeof appLower !== "function" || typeof convergeInProcess !== "function") throw unresolvable(appDir, `${file} exports no lower and convergeInProcess.`);
|
|
173
|
-
return blindCast({
|
|
174
|
-
lower: appLower,
|
|
175
|
-
converge: convergeInProcess
|
|
176
|
-
});
|
|
177
|
-
}
|
|
58
|
+
//#region ../../0-framework/3-tooling/cli/dist/execute-deploy-destroy-DKEmb8WI.mjs
|
|
178
59
|
/** Pipeline step 6: writes a regenerated-every-run, independently runnable stack module at `.prisma-composer/alchemy.run.ts`. */
|
|
179
60
|
const GENERATED_DIR = ".prisma-composer";
|
|
180
61
|
const GENERATED_FILE = "alchemy.run.ts";
|
|
@@ -247,6 +128,228 @@ function writeStackFile(input) {
|
|
|
247
128
|
}
|
|
248
129
|
const GENERATED_STACK_RELATIVE_PATH = path.join(GENERATED_DIR, GENERATED_FILE);
|
|
249
130
|
/**
|
|
131
|
+
* Which Alchemy CLI runs a generated stack file: the `alchemy` that
|
|
132
|
+
* `@prisma/composer` depends on, found from the app the way the stack file's
|
|
133
|
+
* own `@prisma/composer/...` imports are. The CLI and the stack code then
|
|
134
|
+
* come from one install, so the child loads one copy of `alchemy`.
|
|
135
|
+
*
|
|
136
|
+
* Node's resolver finds `@prisma/composer` from the app. It cannot find
|
|
137
|
+
* `alchemy` from there: alchemy exports neither its `package.json` nor its
|
|
138
|
+
* bin, and has no `require` condition. Bun has no `module.findPackageJSON`.
|
|
139
|
+
* So the last step is Node's own lookup written out: each `node_modules`
|
|
140
|
+
* above `@prisma/composer`'s real location, nearest first.
|
|
141
|
+
*/
|
|
142
|
+
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.";
|
|
143
|
+
function binMissing(message) {
|
|
144
|
+
return new CliStructuredError("DEPLOY.ALCHEMY_BIN_MISSING", message, { fix: FIX });
|
|
145
|
+
}
|
|
146
|
+
function composerPackageDir(appDir) {
|
|
147
|
+
try {
|
|
148
|
+
const manifest = createRequire(path.join(appDir, "package.json")).resolve("@prisma/composer/package.json");
|
|
149
|
+
return path.dirname(fs.realpathSync(manifest));
|
|
150
|
+
} catch {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function alchemyPackageDirAbove(dir) {
|
|
155
|
+
for (let current = dir;; current = path.dirname(current)) {
|
|
156
|
+
const candidate = path.join(current, "node_modules", "alchemy");
|
|
157
|
+
if (fs.existsSync(path.join(candidate, "package.json"))) return candidate;
|
|
158
|
+
if (path.dirname(current) === current) return void 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function readPackageJson(packageDir) {
|
|
162
|
+
try {
|
|
163
|
+
return JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8"));
|
|
164
|
+
} catch {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function binOf(packageDir) {
|
|
169
|
+
const manifest = readPackageJson(packageDir);
|
|
170
|
+
if (typeof manifest !== "object" || manifest === null || !("bin" in manifest)) return void 0;
|
|
171
|
+
const bin = manifest.bin;
|
|
172
|
+
const relative = typeof bin === "string" ? bin : typeof bin === "object" && bin !== null && "alchemy" in bin ? bin.alchemy : void 0;
|
|
173
|
+
if (typeof relative !== "string") return void 0;
|
|
174
|
+
const entry = path.join(packageDir, relative);
|
|
175
|
+
return fs.existsSync(entry) ? entry : void 0;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The JavaScript file `alchemy`'s `bin` names, for the app in `appDir`.
|
|
179
|
+
* Raises DEPLOY.ALCHEMY_BIN_MISSING when the app does not resolve
|
|
180
|
+
* `@prisma/composer` or no usable `alchemy` is installed beside it.
|
|
181
|
+
*/
|
|
182
|
+
function resolveAlchemyBin(appDir) {
|
|
183
|
+
const composerDir = composerPackageDir(appDir);
|
|
184
|
+
if (composerDir === void 0) throw binMissing(`Could not resolve @prisma/composer from "${appDir}".`);
|
|
185
|
+
const alchemyDir = alchemyPackageDirAbove(composerDir);
|
|
186
|
+
const entry = alchemyDir === void 0 ? void 0 : binOf(alchemyDir);
|
|
187
|
+
if (entry === void 0) throw binMissing(`Could not resolve the bin of the \`alchemy\` package @prisma/composer depends on, from "${composerDir}".`);
|
|
188
|
+
return entry;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Pipeline step 9 (deploy-cli.md § The pipeline; design-notes.md's "Driving
|
|
192
|
+
* Alchemy" call): run the generated stack file and, for programmatic hosts, pipe its
|
|
193
|
+
* output through redaction.
|
|
194
|
+
*
|
|
195
|
+
* Runs the bin of the `alchemy` the app's `@prisma/composer` depends on
|
|
196
|
+
* (`resolveAlchemyBin`), started with Node (`nodeExecutable`). Never a
|
|
197
|
+
* `node_modules/.bin` link, which pnpm creates only for an app's direct
|
|
198
|
+
* dependencies.
|
|
199
|
+
*
|
|
200
|
+
* Only `destroy` still runs Alchemy in a child; `deploy` and `dev` converge
|
|
201
|
+
* in-process (ADR-0066). This module composes the invocation; `spawnAlchemy`
|
|
202
|
+
* starts it, piping the child's output through the stream redactor
|
|
203
|
+
* (ADR-0062), and tests substitute their own runner.
|
|
204
|
+
*/
|
|
205
|
+
function currentRuntime() {
|
|
206
|
+
return {
|
|
207
|
+
bun: process.versions.bun !== void 0,
|
|
208
|
+
execPath: process.execPath,
|
|
209
|
+
env: process.env,
|
|
210
|
+
platform: process.platform,
|
|
211
|
+
exists: fs.existsSync
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function envValue(env, name) {
|
|
215
|
+
return Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
216
|
+
}
|
|
217
|
+
/** The file names `node` may have in a PATH directory: PATHEXT's extensions on Windows. */
|
|
218
|
+
function nodeFileNames(runtime) {
|
|
219
|
+
if (runtime.platform !== "win32") return ["node"];
|
|
220
|
+
return (envValue(runtime.env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((extension) => extension.length > 0).map((extension) => `node${extension}`);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The Node that starts Alchemy's launcher: this process's own runtime under
|
|
224
|
+
* Node, and the first `node` on PATH under Bun. Alchemy's launcher may still
|
|
225
|
+
* move itself to Bun when the package-manager environment says Bun invoked
|
|
226
|
+
* it (`bunx`, `bun run`), so the runtime Alchemy ends up on follows how
|
|
227
|
+
* `prisma` was invoked.
|
|
228
|
+
*/
|
|
229
|
+
function nodeExecutable(runtime = currentRuntime()) {
|
|
230
|
+
if (!runtime.bun) return runtime.execPath;
|
|
231
|
+
const paths = runtime.platform === "win32" ? path.win32 : path.posix;
|
|
232
|
+
const names = nodeFileNames(runtime);
|
|
233
|
+
for (const rawDir of (envValue(runtime.env, "PATH") ?? "").split(paths.delimiter)) {
|
|
234
|
+
const dir = rawDir.replace(/^"(.*)"$/, "$1");
|
|
235
|
+
if (dir.length === 0) continue;
|
|
236
|
+
for (const name of names) {
|
|
237
|
+
const candidate = paths.join(dir, name);
|
|
238
|
+
if (runtime.exists(candidate)) return candidate;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
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." });
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Resolves the invocation against this machine — the step every adapter takes
|
|
245
|
+
* and no caller should. Runs alchemy's JavaScript entry with Node, so no shell
|
|
246
|
+
* shim is involved on any platform. Raises DEPLOY.ALCHEMY_BIN_MISSING when
|
|
247
|
+
* Composer's alchemy cannot be resolved, and DEPLOY.NODE_MISSING when no Node
|
|
248
|
+
* can run it.
|
|
249
|
+
*/
|
|
250
|
+
function alchemyCommandLine(invocation, alchemyBin = resolveAlchemyBin(invocation.cwd), node = nodeExecutable()) {
|
|
251
|
+
return {
|
|
252
|
+
command: node,
|
|
253
|
+
args: [
|
|
254
|
+
alchemyBin,
|
|
255
|
+
invocation.action,
|
|
256
|
+
invocation.stackFileRelativePath,
|
|
257
|
+
"--yes",
|
|
258
|
+
"--stage",
|
|
259
|
+
invocation.stage
|
|
260
|
+
],
|
|
261
|
+
cwd: invocation.cwd,
|
|
262
|
+
env: invocation.env
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/** What becomes `alchemy deploy|destroy <stack file> --yes --stage <stage>`. */
|
|
266
|
+
function alchemyInvocation(input) {
|
|
267
|
+
return {
|
|
268
|
+
action: input.command,
|
|
269
|
+
stackFileRelativePath: input.stackFileRelativePath,
|
|
270
|
+
cwd: input.cwd,
|
|
271
|
+
stage: input.stage,
|
|
272
|
+
env: {
|
|
273
|
+
...input.containerEnv,
|
|
274
|
+
...input.preflightEnv,
|
|
275
|
+
...input.env
|
|
276
|
+
},
|
|
277
|
+
redactedValues: input.redactedValues
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The default runner for hosts with no engine: stdin inherited and output piped through redaction, the caller's
|
|
282
|
+
* own process group, and the child's status returned verbatim. It does not
|
|
283
|
+
* collapse a signal into an exit code — that collapse is what made a
|
|
284
|
+
* Ctrl-C'd deploy report itself as a failure.
|
|
285
|
+
*/
|
|
286
|
+
const spawnAlchemy = async (invocation) => {
|
|
287
|
+
const commandLine = alchemyCommandLine(invocation);
|
|
288
|
+
return {
|
|
289
|
+
...await spawnCommandLine(commandLine, invocation.redactedValues),
|
|
290
|
+
commandLine
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* One argument as the platform's shell reads it literally: single quotes for
|
|
295
|
+
* POSIX shells, double quotes for cmd.exe. cmd.exe expands `%VAR%` inside
|
|
296
|
+
* double quotes, and strips or expands `!` when delayed expansion is on; no
|
|
297
|
+
* quoting prevents either, so an argument containing them is not fully
|
|
298
|
+
* literal there.
|
|
299
|
+
*/
|
|
300
|
+
function shellArg(arg, platform) {
|
|
301
|
+
if (platform === "win32") return /^[\w@+=:,./\\~-]+$/.test(arg) ? arg : `"${arg.replaceAll("\"", "\"\"")}"`;
|
|
302
|
+
return /^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The command a user runs from the invocation's directory to repeat a
|
|
306
|
+
* converge: the command line the adapter started, or, from an adapter that
|
|
307
|
+
* does not report one, `alchemy` with the same arguments.
|
|
308
|
+
*/
|
|
309
|
+
function reproduceCommand(invocation, outcome, platform = process.platform) {
|
|
310
|
+
return (outcome?.commandLine === void 0 ? [
|
|
311
|
+
"alchemy",
|
|
312
|
+
invocation.action,
|
|
313
|
+
invocation.stackFileRelativePath,
|
|
314
|
+
"--yes",
|
|
315
|
+
"--stage",
|
|
316
|
+
invocation.stage
|
|
317
|
+
] : [outcome.commandLine.command, ...outcome.commandLine.args]).map((arg) => shellArg(arg, platform)).join(" ");
|
|
318
|
+
}
|
|
319
|
+
/** Starts a resolved command line with stdin inherited and its output piped through redaction, and returns how it ended. */
|
|
320
|
+
function spawnCommandLine(line, redactedValues, outputs = process) {
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
const child = spawn(line.command, [...line.args], {
|
|
323
|
+
cwd: line.cwd,
|
|
324
|
+
stdio: [
|
|
325
|
+
"inherit",
|
|
326
|
+
"pipe",
|
|
327
|
+
"pipe"
|
|
328
|
+
],
|
|
329
|
+
env: {
|
|
330
|
+
...process.env,
|
|
331
|
+
...line.env
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
const stdout = new StreamRedactor(redactedValues);
|
|
335
|
+
const stderr = new StreamRedactor(redactedValues);
|
|
336
|
+
const write = (stream, text) => {
|
|
337
|
+
if (text.length > 0) stream.write(text);
|
|
338
|
+
};
|
|
339
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => write(outputs.stdout, stdout.push(chunk)));
|
|
340
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => write(outputs.stderr, stderr.push(chunk)));
|
|
341
|
+
child.on("error", reject);
|
|
342
|
+
child.on("close", (exitCode, signal) => {
|
|
343
|
+
write(outputs.stdout, stdout.end());
|
|
344
|
+
write(outputs.stderr, stderr.end());
|
|
345
|
+
resolve({
|
|
346
|
+
exitCode,
|
|
347
|
+
signal
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
250
353
|
* The deploy/destroy executor — main.ts's pipeline orchestration with argv,
|
|
251
354
|
* console, and exit codes removed: typed inputs in, structured results out.
|
|
252
355
|
* Reached only by lazy import from deploy.ts/destroy.ts — this module's
|
|
@@ -259,64 +362,9 @@ function hasNoLocalDeployState(cwd) {
|
|
|
259
362
|
const stateDir = path.join(cwd, ALCHEMY_STATE_DIR);
|
|
260
363
|
return !(fs.existsSync(stateDir) && fs.readdirSync(stateDir).length > 0);
|
|
261
364
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Times each deploy step for the host's `onEvent`. A step still open when the
|
|
264
|
-
* run fails is closed as failed, innermost first. A host `onEvent` that throws
|
|
265
|
-
* is the host's bug and cannot fail the deploy.
|
|
266
|
-
*/
|
|
365
|
+
/** Times each deploy step for the host's `onEvent`. A step still open when the run fails is closed as failed, innermost first. */
|
|
267
366
|
function deploySteps(onEvent) {
|
|
268
|
-
|
|
269
|
-
const keyOf = (step) => step.name === "assemble-service" ? `${step.name}:${step.address}` : step.name === "apply-resource" ? `${step.name}:${step.resourceId}` : step.name;
|
|
270
|
-
const emit = (event) => {
|
|
271
|
-
try {
|
|
272
|
-
onEvent?.(event);
|
|
273
|
-
} catch {}
|
|
274
|
-
};
|
|
275
|
-
const finish = (step, outcome, data) => {
|
|
276
|
-
const entry = open.get(keyOf(step));
|
|
277
|
-
if (entry === void 0) return;
|
|
278
|
-
open.delete(keyOf(step));
|
|
279
|
-
const durationMs = Math.round(performance.now() - entry.startedAt);
|
|
280
|
-
emit({
|
|
281
|
-
kind: "step-finished",
|
|
282
|
-
step,
|
|
283
|
-
outcome,
|
|
284
|
-
durationMs,
|
|
285
|
-
data
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
return {
|
|
289
|
-
start(step) {
|
|
290
|
-
open.set(keyOf(step), {
|
|
291
|
-
step,
|
|
292
|
-
startedAt: performance.now()
|
|
293
|
-
});
|
|
294
|
-
emit({
|
|
295
|
-
kind: "step-started",
|
|
296
|
-
step
|
|
297
|
-
});
|
|
298
|
-
},
|
|
299
|
-
finish(step, data) {
|
|
300
|
-
finish(step, "ok", data);
|
|
301
|
-
},
|
|
302
|
-
fail(step) {
|
|
303
|
-
finish(step, "failed");
|
|
304
|
-
},
|
|
305
|
-
failOpen() {
|
|
306
|
-
for (const { step } of [...open.values()].reverse()) finish(step, "failed");
|
|
307
|
-
},
|
|
308
|
-
isOpen(step) {
|
|
309
|
-
return open.has(keyOf(step));
|
|
310
|
-
},
|
|
311
|
-
message(severity, text) {
|
|
312
|
-
emit({
|
|
313
|
-
kind: "message",
|
|
314
|
-
severity,
|
|
315
|
-
text
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
emit
|
|
319
|
-
};
|
|
367
|
+
return stepTracker((step) => step.name === "assemble-service" ? `${step.name}:${step.address}` : step.name === "apply-resource" ? `${step.name}:${step.resourceId}` : step.name, onEvent);
|
|
320
368
|
}
|
|
321
369
|
async function executeDeploy(input, deps, cwd) {
|
|
322
370
|
const outcome = await runStackPipeline("deploy", {
|
|
@@ -442,7 +490,7 @@ async function runStackPipeline(action, opts) {
|
|
|
442
490
|
try {
|
|
443
491
|
outcome = await runStackPipelineInner(action, opts, reporters);
|
|
444
492
|
} catch (error) {
|
|
445
|
-
opts.steps.
|
|
493
|
+
opts.steps.closeOpen("failed");
|
|
446
494
|
opts.steps.start({ name: "record" });
|
|
447
495
|
const thrown = redactThrown(error, opts.redaction);
|
|
448
496
|
await finishReporters(reporters, {
|
|
@@ -455,7 +503,7 @@ async function runStackPipeline(action, opts) {
|
|
|
455
503
|
throw thrown;
|
|
456
504
|
}
|
|
457
505
|
if (!outcome.ok) outcome = notOk(redactError(outcome.failure, opts.redaction));
|
|
458
|
-
if (!outcome.ok) opts.steps.
|
|
506
|
+
if (!outcome.ok) opts.steps.closeOpen("failed");
|
|
459
507
|
opts.steps.start({ name: "record" });
|
|
460
508
|
await finishReporters(reporters, outcome.ok ? {
|
|
461
509
|
ok: true,
|
|
@@ -634,7 +682,6 @@ async function runStackPipelineInner(action, opts, reporters) {
|
|
|
634
682
|
appConfigurationRead: pipeline.graph.appConfigurationRead,
|
|
635
683
|
plainVariableText: {},
|
|
636
684
|
nodeAddresses: nodeAddresses(pipeline.graph),
|
|
637
|
-
secretsKeys: secretsKeys(pipeline.graph),
|
|
638
685
|
knownSecrets: opts.redaction.knownSecrets
|
|
639
686
|
});
|
|
640
687
|
stackPath = writeStackFile({
|
|
@@ -752,37 +799,6 @@ async function prepareAppConvergeEntry(deps, appDir) {
|
|
|
752
799
|
throw error;
|
|
753
800
|
}
|
|
754
801
|
}
|
|
755
|
-
/** One Alchemy progress event as the deploy's step events: each resource is a step inside `apply`. */
|
|
756
|
-
function reportConvergeEvent(steps, event, redact) {
|
|
757
|
-
if (event.kind === "log") {
|
|
758
|
-
steps.message(event.severity, redact(withComposerAdvice(event.text)));
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
const step = {
|
|
762
|
-
name: "apply-resource",
|
|
763
|
-
resourceId: event.fqn,
|
|
764
|
-
resourceType: event.resourceType,
|
|
765
|
-
status: event.status
|
|
766
|
-
};
|
|
767
|
-
switch (event.phase) {
|
|
768
|
-
case "running":
|
|
769
|
-
if (!steps.isOpen(step)) steps.start(step);
|
|
770
|
-
return;
|
|
771
|
-
case "done":
|
|
772
|
-
if (!steps.isOpen(step)) steps.start(step);
|
|
773
|
-
steps.finish(step);
|
|
774
|
-
return;
|
|
775
|
-
case "failed":
|
|
776
|
-
if (!steps.isOpen(step)) steps.start(step);
|
|
777
|
-
steps.fail(step);
|
|
778
|
-
if (event.message !== void 0) steps.message("warn", redact(`${event.fqn}: ${withComposerAdvice(event.message)}`));
|
|
779
|
-
return;
|
|
780
|
-
case "pending": return;
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
function reasonsText(reasons) {
|
|
784
|
-
return reasons.map(({ tag, message }) => tag === "Error" || tag === "Unknown" || message.startsWith(tag) ? message : `${tag}: ${message}`).join("\n");
|
|
785
|
-
}
|
|
786
802
|
/** The structured failure a converge that did not apply settles as. */
|
|
787
803
|
function convergeFailure(outcome, redact) {
|
|
788
804
|
switch (outcome.kind) {
|
|
@@ -798,7 +814,7 @@ function convergeFailure(outcome, redact) {
|
|
|
798
814
|
fix: "Call deploy from the main thread, or with the process's working directory as its cwd."
|
|
799
815
|
});
|
|
800
816
|
case "failed": {
|
|
801
|
-
const cause = capFailureCause(redact(withComposerAdvice(
|
|
817
|
+
const cause = capFailureCause(redact(withComposerAdvice(convergeReasonsText(outcome.reasons))));
|
|
802
818
|
return new CliStructuredError("DEPLOY.ENGINE_FAILED", `Alchemy could not deploy the app.\n${cause}`, { meta: {
|
|
803
819
|
engineCause: cause,
|
|
804
820
|
reasons: outcome.reasons.map(({ tag, message }) => ({
|
|
@@ -811,24 +827,6 @@ function convergeFailure(outcome, redact) {
|
|
|
811
827
|
return new CliStructuredError("DEPLOY.ENGINE_FAILED", "The converge ended with an outcome this Composer does not know.");
|
|
812
828
|
}
|
|
813
829
|
/**
|
|
814
|
-
* Alchemy's terminal text as `info` messages, one per complete line, redacted. A secret split
|
|
815
|
-
* across writes or lines is still found, because the text passes through a `StreamRedactor`
|
|
816
|
-
* before it is cut into lines. `end` sends the last line that has no line break.
|
|
817
|
-
*/
|
|
818
|
-
function interactionMessages(steps, redaction) {
|
|
819
|
-
const stream = new StreamRedactor(redaction.allValues());
|
|
820
|
-
let partial = "";
|
|
821
|
-
const send = (text, last) => {
|
|
822
|
-
const lines = (partial + text).split("\n");
|
|
823
|
-
partial = last ? "" : lines.pop() ?? "";
|
|
824
|
-
for (const line of lines) if (line.trim() !== "") steps.message("info", redaction.redact(line));
|
|
825
|
-
};
|
|
826
|
-
return {
|
|
827
|
-
push: (text) => send(stream.push(text), false),
|
|
828
|
-
end: () => send(stream.end(), true)
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
830
|
* Deploy's converge: lowers the app with the containers and preflight
|
|
833
831
|
* payloads this run resolved, then plans and applies it in this process.
|
|
834
832
|
* The report hook runs inside the apply, here, so the summary comes back as
|
|
@@ -874,7 +872,10 @@ async function convergeDeploy(opts, pipeline, entry, resolved) {
|
|
|
874
872
|
cwd,
|
|
875
873
|
env,
|
|
876
874
|
signal: opts.signal,
|
|
877
|
-
onEvent: (event) => reportConvergeEvent(steps, event, redact)
|
|
875
|
+
onEvent: (event) => reportConvergeEvent(steps, event, redact, (resource) => ({
|
|
876
|
+
name: "apply-resource",
|
|
877
|
+
...resource
|
|
878
|
+
})),
|
|
878
879
|
output: (text) => output.push(text)
|
|
879
880
|
});
|
|
880
881
|
} catch (error) {
|
|
@@ -889,4 +890,4 @@ async function convergeDeploy(opts, pipeline, entry, resolved) {
|
|
|
889
890
|
//#endregion
|
|
890
891
|
export { executeDeploy, executeDestroy };
|
|
891
892
|
|
|
892
|
-
//# sourceMappingURL=execute-deploy-destroy-
|
|
893
|
+
//# sourceMappingURL=execute-deploy-destroy-DKEmb8WI-DcgNdw4b.mjs.map
|