@prisma/composer 0.39.0-dev.1 → 0.39.0-dev.11

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.
Files changed (141) hide show
  1. package/dist/{app-config-UeKFBma7-CohaMmWp.d.mts → app-config-DriAu5RU-C8hYpR38.d.mts} +88 -83
  2. package/dist/app-config-DriAu5RU-C8hYpR38.d.mts.map +1 -0
  3. package/dist/{app-configuration-file-CeJvBAti-D3uDlheX.mjs → app-configuration-file-D0rB5g65-CdMrjkCc.mjs} +50 -85
  4. package/dist/app-configuration-file-D0rB5g65-CdMrjkCc.mjs.map +1 -0
  5. package/dist/app-converge-bS1l9jIf-DRGbjw2D.mjs +88 -0
  6. package/dist/app-converge-bS1l9jIf-DRGbjw2D.mjs.map +1 -0
  7. package/dist/arktype.d.mts +7 -5
  8. package/dist/arktype.d.mts.map +1 -1
  9. package/dist/arktype.mjs +7 -5
  10. package/dist/arktype.mjs.map +1 -1
  11. package/dist/config-Bpi8QVLB.d.mts +1 -0
  12. package/dist/config.d.mts +3 -3
  13. package/dist/config.mjs +2 -2
  14. package/dist/control.d.mts +19 -21
  15. package/dist/control.d.mts.map +1 -1
  16. package/dist/control.mjs +4 -4
  17. package/dist/control.mjs.map +1 -1
  18. package/dist/converge-in-process-CTomEXaD-BnDylZP8.d.mts +67 -0
  19. package/dist/converge-in-process-CTomEXaD-BnDylZP8.d.mts.map +1 -0
  20. package/dist/converge-in-process-x89zb2MF-Dvj-J8xo.mjs +258 -0
  21. package/dist/converge-in-process-x89zb2MF-Dvj-J8xo.mjs.map +1 -0
  22. package/dist/{deploy-3EXLVrtG.mjs → deploy-CSU0kr4j.mjs} +130 -38
  23. package/dist/deploy-CSU0kr4j.mjs.map +1 -0
  24. package/dist/deploy-DHgEJDpg.d.mts +32 -0
  25. package/dist/deploy-DHgEJDpg.d.mts.map +1 -0
  26. package/dist/deploy.d.mts +4 -4
  27. package/dist/deploy.mjs +3 -3
  28. package/dist/{deployment-summary-p88NV5m5-SgniM8TX.d.mts → deployment-summary-6LgQDUuu-Cu_6UNhc.d.mts} +7 -4
  29. package/dist/deployment-summary-6LgQDUuu-Cu_6UNhc.d.mts.map +1 -0
  30. package/dist/{deployment-summary-D74WrJX7-DQ3LDUuO.mjs → deployment-summary-CVJZn2v0-Dz-gX1rp.mjs} +16 -44
  31. package/dist/deployment-summary-CVJZn2v0-Dz-gX1rp.mjs.map +1 -0
  32. package/dist/{describe-kind-Cpm_euxo-CkhlGJUL.mjs → describe-kind-Cpm_euxo-DsSPENQa.mjs} +4 -4
  33. package/dist/describe-kind-Cpm_euxo-DsSPENQa.mjs.map +1 -0
  34. package/dist/dev-converge-messages-DML4rTz7-C_EAB5M_.mjs +165 -0
  35. package/dist/dev-converge-messages-DML4rTz7-C_EAB5M_.mjs.map +1 -0
  36. package/dist/dev-converge-worker.d.mts +1 -0
  37. package/dist/dev-converge-worker.mjs +142 -0
  38. package/dist/dev-converge-worker.mjs.map +1 -0
  39. package/dist/{dev-current-wD5YDLjA-CzyFYXni.mjs → dev-current-lAlj53eX-DrtBnAmA.mjs} +11 -7
  40. package/dist/dev-current-lAlj53eX-DrtBnAmA.mjs.map +1 -0
  41. package/dist/{dev-environment-name-6eEr5PW8-BwusWVKi.mjs → dev-environment-name-6eEr5PW8-7ntm9Xhs.mjs} +3 -3
  42. package/dist/{dev-environment-name-6eEr5PW8-BwusWVKi.mjs.map → dev-environment-name-6eEr5PW8-7ntm9Xhs.mjs.map} +1 -1
  43. package/dist/{dist-ynqBR6y8.mjs → dist-Cf_mZHaH.mjs} +4 -26
  44. package/dist/dist-Cf_mZHaH.mjs.map +1 -0
  45. package/dist/{emulator-retry-CV8rl69G-BgUzkxc-.mjs → emulator-retry-CV8rl69G-scQ105wk.mjs} +2 -2
  46. package/dist/{emulator-retry-CV8rl69G-BgUzkxc-.mjs.map → emulator-retry-CV8rl69G-scQ105wk.mjs.map} +1 -1
  47. package/dist/{errors-0e8IVwzi.mjs → errors-DI3TBXE-.mjs} +7 -2
  48. package/dist/{errors-0e8IVwzi.mjs.map → errors-DI3TBXE-.mjs.map} +1 -1
  49. package/dist/{execute-deploy-destroy-DOzo2Psp-DmS5miT4.mjs → execute-deploy-destroy-DN16ETAk-BaopEKsA.mjs} +376 -86
  50. package/dist/execute-deploy-destroy-DN16ETAk-BaopEKsA.mjs.map +1 -0
  51. package/dist/{execute-dev-BIyOI3Ys-BbDOLlV4.mjs → execute-dev-DnVmNpc1-kSyPML7l.mjs} +455 -221
  52. package/dist/execute-dev-DnVmNpc1-kSyPML7l.mjs.map +1 -0
  53. package/dist/{execute-dev-current-CKOzjWuO-BPecs6Lf.mjs → execute-dev-current-CZdmxVQ4-Bij2LeBY.mjs} +7 -7
  54. package/dist/{execute-dev-current-CKOzjWuO-BPecs6Lf.mjs.map → execute-dev-current-CZdmxVQ4-Bij2LeBY.mjs.map} +1 -1
  55. package/dist/{execute-log-BDdHor71-B2p8Zae2.mjs → execute-log-Bl-j6izb-BTAo6tRM.mjs} +8 -8
  56. package/dist/{execute-log-BDdHor71-B2p8Zae2.mjs.map → execute-log-Bl-j6izb-BTAo6tRM.mjs.map} +1 -1
  57. package/dist/{graph-C7mdtisq-RnKiwVsx.d.mts → graph-CUYXjK8S-BzL-mhjq.d.mts} +3 -3
  58. package/dist/graph-CUYXjK8S-BzL-mhjq.d.mts.map +1 -0
  59. package/dist/{graph-BzPLUUsB-D7EnB1F5.mjs → graph-D2WMLL43-CeiC5wdy.mjs} +150 -107
  60. package/dist/graph-D2WMLL43-CeiC5wdy.mjs.map +1 -0
  61. package/dist/{graph-types-s5V7pGj2-BxSqB1ZH.d.mts → graph-types-D4PrtP-l-B0uuchTl.d.mts} +101 -98
  62. package/dist/graph-types-D4PrtP-l-B0uuchTl.d.mts.map +1 -0
  63. package/dist/http.d.mts +2 -2
  64. package/dist/http.mjs +2 -2
  65. package/dist/{index-DyuwxTtd.d.mts → index-D8chHe55.d.mts} +3 -3
  66. package/dist/{index-DyuwxTtd.d.mts.map → index-D8chHe55.d.mts.map} +1 -1
  67. package/dist/index.d.mts +5 -5
  68. package/dist/index.mjs +4 -4
  69. package/dist/internal-app-configuration-file.d.mts +7 -10
  70. package/dist/internal-app-configuration-file.d.mts.map +1 -1
  71. package/dist/internal-app-configuration-file.mjs +2 -2
  72. package/dist/internal-converge-contract.d.mts +16 -0
  73. package/dist/internal-converge-contract.d.mts.map +1 -0
  74. package/dist/internal-converge-contract.mjs +16 -0
  75. package/dist/internal-converge-contract.mjs.map +1 -0
  76. package/dist/internal-converge.d.mts +5 -0
  77. package/dist/internal-converge.mjs +4 -0
  78. package/dist/load-entry-CEoVBdMj-CHOz7jKf.mjs +527 -0
  79. package/dist/load-entry-CEoVBdMj-CHOz7jKf.mjs.map +1 -0
  80. package/dist/local-target-7KRsLMDO.d.mts +31 -0
  81. package/dist/local-target-7KRsLMDO.d.mts.map +1 -0
  82. package/dist/{local-target-Dd8FJEb5.mjs → local-target-DhU1vaxd.mjs} +8 -8
  83. package/dist/{local-target-Dd8FJEb5.mjs.map → local-target-DhU1vaxd.mjs.map} +1 -1
  84. package/dist/local-target.d.mts +3 -31
  85. package/dist/local-target.mjs +1 -1
  86. package/dist/{nextjs-DLyeRR7M-0lw_cBIr.d.mts → nextjs-DLyeRR7M-CzUbvPaJ.d.mts} +3 -3
  87. package/dist/{nextjs-DLyeRR7M-0lw_cBIr.d.mts.map → nextjs-DLyeRR7M-CzUbvPaJ.d.mts.map} +1 -1
  88. package/dist/nextjs-control.d.mts +4 -4
  89. package/dist/nextjs.d.mts +1 -1
  90. package/dist/node-control.d.mts +3 -3
  91. package/dist/node.d.mts +2 -2
  92. package/dist/{pointer-CyQZZugO-D7k3vibs.d.mts → pointer-BX2KJ720-BxcfpaHP.d.mts} +8 -6
  93. package/dist/{pointer-CyQZZugO-D7k3vibs.d.mts.map → pointer-BX2KJ720-BxcfpaHP.d.mts.map} +1 -1
  94. package/dist/{preflight-transport-DmmtoFPH-CnDWufmu.mjs → preflight-transport-2d6iIchu-B-v7Di6I.mjs} +7 -44
  95. package/dist/preflight-transport-2d6iIchu-B-v7Di6I.mjs.map +1 -0
  96. package/dist/{redaction-DXung4ip-bBoNomi3.mjs → redaction-DY6eDC12-W-FzW7_r.mjs} +32 -15
  97. package/dist/redaction-DY6eDC12-W-FzW7_r.mjs.map +1 -0
  98. package/dist/{redaction-Bf8FvTFH-D_HvoMrf.d.mts → redaction-Dn7BRdaP-BcLSPhLV.d.mts} +65 -16
  99. package/dist/redaction-Dn7BRdaP-BcLSPhLV.d.mts.map +1 -0
  100. package/dist/report.d.mts +3 -3
  101. package/dist/report.mjs +2 -2
  102. package/dist/report.mjs.map +1 -1
  103. package/dist/service-rpc.d.mts +2 -2
  104. package/dist/service-rpc.mjs +2 -2
  105. package/dist/steps-BZXNqW6U-C_ME2VLd.mjs +112 -0
  106. package/dist/steps-BZXNqW6U-C_ME2VLd.mjs.map +1 -0
  107. package/dist/testing.d.mts +1 -1
  108. package/dist/validate-environment-DCZiNSlR-C7lv0cH1.mjs +344 -0
  109. package/dist/validate-environment-DCZiNSlR-C7lv0cH1.mjs.map +1 -0
  110. package/dist/zod.d.mts +6 -5
  111. package/dist/zod.d.mts.map +1 -1
  112. package/dist/zod.mjs +6 -5
  113. package/dist/zod.mjs.map +1 -1
  114. package/package.json +15 -13
  115. package/skills/prisma-composer-core-concepts/SKILL.md +47 -66
  116. package/src/exports/dev-converge-worker.ts +2 -0
  117. package/src/exports/internal-converge-contract.ts +1 -0
  118. package/src/exports/internal-converge.ts +1 -0
  119. package/dist/app-config-UeKFBma7-CohaMmWp.d.mts.map +0 -1
  120. package/dist/app-configuration-file-CeJvBAti-D3uDlheX.mjs.map +0 -1
  121. package/dist/config-BeZEgGCg.d.mts +0 -1
  122. package/dist/deploy-3EXLVrtG.mjs.map +0 -1
  123. package/dist/deploy-Xi4_JrtE.d.mts +0 -2
  124. package/dist/deployment-summary-D74WrJX7-DQ3LDUuO.mjs.map +0 -1
  125. package/dist/deployment-summary-p88NV5m5-SgniM8TX.d.mts.map +0 -1
  126. package/dist/describe-kind-Cpm_euxo-CkhlGJUL.mjs.map +0 -1
  127. package/dist/dev-current-wD5YDLjA-CzyFYXni.mjs.map +0 -1
  128. package/dist/dist-ynqBR6y8.mjs.map +0 -1
  129. package/dist/execute-deploy-destroy-DOzo2Psp-DmS5miT4.mjs.map +0 -1
  130. package/dist/execute-dev-BIyOI3Ys-BbDOLlV4.mjs.map +0 -1
  131. package/dist/graph-BzPLUUsB-D7EnB1F5.mjs.map +0 -1
  132. package/dist/graph-C7mdtisq-RnKiwVsx.d.mts.map +0 -1
  133. package/dist/graph-types-s5V7pGj2-BxSqB1ZH.d.mts.map +0 -1
  134. package/dist/local-target.d.mts.map +0 -1
  135. package/dist/preflight-transport-DmmtoFPH-CnDWufmu.mjs.map +0 -1
  136. package/dist/redaction-Bf8FvTFH-D_HvoMrf.d.mts.map +0 -1
  137. package/dist/redaction-DXung4ip-bBoNomi3.mjs.map +0 -1
  138. package/dist/run-alchemy-CRLAyOtt-CBUV28We.mjs +0 -236
  139. package/dist/run-alchemy-CRLAyOtt-CBUV28We.mjs.map +0 -1
  140. package/dist/validate-environment-D1BTCkTs-BQprjyNP.mjs +0 -739
  141. package/dist/validate-environment-D1BTCkTs-BQprjyNP.mjs.map +0 -1
@@ -1,120 +1,43 @@
1
- import { S as secretsKeys, g as nodeAddresses } from "./graph-BzPLUUsB-D7EnB1F5.mjs";
2
- import { t as CliStructuredError } from "./errors-0e8IVwzi.mjs";
3
- import { c as preflightFindingsEnv, n as containerEnv, o as preflightEnv, s as preflightEnvVarName } from "./preflight-transport-DmmtoFPH-CnDWufmu.mjs";
1
+ import { E as secretsKeys, a as ROOT_INPUT_UNREAD_ERROR, y as nodeAddresses } from "./graph-D2WMLL43-CeiC5wdy.mjs";
2
+ import { t as InternalError } from "./internal-error-Dfur7Zqt-D96dWHZK.mjs";
3
+ import { n as quotedList, t as CliStructuredError } from "./errors-DI3TBXE-.mjs";
4
4
  import { i as devEnvironmentDir } from "./app-config-CErnR6NK-D9NgSBH4.mjs";
5
- import { i as prepareSecondProcess, n as devAppConfigurationFile, o as removeLeftoverAppConfigurationFiles } from "./app-configuration-file-CeJvBAti-D3uDlheX.mjs";
6
- import { c as toStructured, l as notOk, s as requireContainerForEnvironment, u as ok } from "./dev-current-wD5YDLjA-CzyFYXni.mjs";
7
- import "./deploy-3EXLVrtG.mjs";
8
- import { r as resolveLocalTargets } from "./local-target-Dd8FJEb5.mjs";
9
- import { a as redactDevEvent, c as redactThrown, o as redactError, t as SecretRedaction } from "./redaction-DXung4ip-bBoNomi3.mjs";
10
- import { a as noComposerExportMessage, i as validateEnvironmentName, r as runPipeline } from "./validate-environment-D1BTCkTs-BQprjyNP.mjs";
11
- import { n as reproduceCommand, r as spawnAlchemy, t as alchemyInvocation } from "./run-alchemy-CRLAyOtt-CBUV28We.mjs";
12
- import { n as requireDevEnvironmentName, t as claimDevEnvironmentName } from "./dev-environment-name-6eEr5PW8-BwusWVKi.mjs";
13
- import { t as withEmulatorRetry } from "./emulator-retry-CV8rl69G-BgUzkxc-.mjs";
5
+ import { a as refuseSecretsInRootInput, i as refuseSecretsInPlainVariables, o as removeLeftoverAppConfigurationFiles } from "./app-configuration-file-D0rB5g65-CdMrjkCc.mjs";
6
+ import "./deploy-CSU0kr4j.mjs";
7
+ import { r as holdingConvergeProcess } from "./converge-in-process-x89zb2MF-Dvj-J8xo.mjs";
8
+ import { r as resolveLocalTargets } from "./local-target-DhU1vaxd.mjs";
9
+ import { c as requireContainerForEnvironment, d as ok, l as toStructured, t as convergeReasonsText, u as notOk } from "./dev-current-lAlj53eX-DrtBnAmA.mjs";
10
+ import { t as loadAppConvergeEntry } from "./app-converge-bS1l9jIf-DRGbjw2D.mjs";
11
+ import { a as valueReadsSnapshot, i as thrownResult, r as isWorkerMessage } from "./dev-converge-messages-DML4rTz7-C_EAB5M_.mjs";
12
+ import { a as redactDevEvent, c as redactThrown, o as redactError, t as SecretRedaction } from "./redaction-DY6eDC12-W-FzW7_r.mjs";
13
+ import { s as withComposerAdvice } from "./deployment-summary-CVJZn2v0-Dz-gX1rp.mjs";
14
+ import { i as validateEnvironmentName, r as runPipeline } from "./validate-environment-DCZiNSlR-C7lv0cH1.mjs";
15
+ import { n as reportConvergeEvent, r as stepTracker, t as interactionMessages } from "./steps-BZXNqW6U-C_ME2VLd.mjs";
16
+ import { n as requireDevEnvironmentName, t as claimDevEnvironmentName } from "./dev-environment-name-6eEr5PW8-7ntm9Xhs.mjs";
17
+ import { t as withEmulatorRetry } from "./emulator-retry-CV8rl69G-scQ105wk.mjs";
14
18
  import * as path$1 from "node:path";
15
19
  import { join, relative, resolve, sep } from "node:path";
16
20
  import * as fs$1 from "node:fs";
17
- import { isDeepStrictEqual } from "node:util";
21
+ import { Worker, isMainThread } from "node:worker_threads";
18
22
  import { fileURLToPath } from "node:url";
23
+ import { isDeepStrictEqual } from "node:util";
24
+ import { Readable } from "node:stream";
19
25
  import * as sysPath from "path";
20
26
  import { stat, unwatchFile, watch, watchFile } from "fs";
21
- import { Readable } from "node:stream";
22
27
  import { lstat, readdir, realpath, stat as stat$1 } from "node:fs/promises";
23
28
  import { type } from "os";
24
29
  import { EventEmitter } from "events";
25
30
  import { createHash } from "node:crypto";
26
31
  import { lstat as lstat$1, open, readdir as readdir$1, realpath as realpath$1, stat as stat$2 } from "fs/promises";
27
- //#region ../../0-framework/3-tooling/cli/dist/generate-dev-stack-BV_n-X9n.mjs
28
- /**
29
- * Local-dev spec § 6 `generate-dev-stack.ts`: like generate-stack.ts but in
30
- * the environment's folder, `.prisma-composer/dev/<environment>/alchemy.run.ts`,
31
- * at the Alchemy stage named by the environment, using
32
- * Composer's `devState()` (Alchemy's file store) and no `report` — dev prints its own front
33
- * door (run-dev.ts), so core's presentation-free lower() gets nothing to
34
- * call back into. The generated module IS the one orchestration point where
35
- * dev provenance is resolved (spec § 3 REVISED): it deserializes the
36
- * containers, top-level-awaits `resolveLocalTargets(config)` (the lazy
37
- * `localTarget` thunks, ADR-0041), and passes
38
- * `providers: localTargetProviders(...)` + `state: devState()` explicitly
39
- * — `lower()` learns nothing about dev.
40
- */
41
- const DEV_GENERATED_FILE = "alchemy.run.ts";
42
- /** The stack file's path relative to the cwd. */
43
- function devStackRelativePath(environment) {
44
- return path$1.join(devEnvironmentDir(environment), DEV_GENERATED_FILE);
45
- }
46
- /** A relative import specifier from the stack file to `target` (posix separators). */
47
- function relativeImportSpecifier(generatedDir, target) {
48
- const rel = path$1.relative(generatedDir, target).split(path$1.sep).join("/");
49
- return rel.startsWith(".") ? rel : `./${rel}`;
50
- }
51
- function quote(value) {
52
- return JSON.stringify(value);
53
- }
54
- function renderBundle(bundle) {
55
- return `{ dir: ${quote(bundle.dir)}, entry: ${quote(bundle.entry)} }`;
56
- }
57
- function renderOptions(input) {
58
- const lines = [];
59
- lines.push(` name: ${quote(input.name)},`);
60
- lines.push(` environment: ${quote(input.environment)},`);
61
- lines.push(" appConfigurationRead: file.appConfigurationRead,");
62
- lines.push(" firstProcessNodeAddresses: file.nodeAddresses,");
63
- lines.push(" bundles: {");
64
- for (const [id, bundle] of Object.entries(input.assembled.bundles)) lines.push(` ${quote(id)}: ${renderBundle(bundle)},`);
65
- lines.push(" },");
66
- const unassembled = Object.keys(input.assembled.devServers);
67
- if (unassembled.length > 0) lines.push(` unassembled: [${unassembled.map(quote).join(", ")}],`);
68
- lines.push(" providers: localTargetProviders(resolved, containers, devDir, file.appConfigurationRead.configurationKeyText, namedSecrets),");
69
- lines.push(" state: devState(),");
70
- return lines.join("\n");
71
- }
72
- /** Renders the dev stack module's source (tests assert on it without touching disk). */
73
- function renderDevStackFile(input) {
74
- const generatedDir = path$1.join(input.cwd, devEnvironmentDir(input.environment));
75
- const appImport = relativeImportSpecifier(generatedDir, input.entryPath);
76
- const imports = [
77
- "import * as path from 'node:path';",
78
- "import { deserializeContainers } from '@prisma/composer/config';",
79
- "import { namedSecretsFromEnvironment, readAppConfigurationFile } from '@prisma/composer/internal/app-configuration-file';",
80
- "import { lower } from '@prisma/composer/deploy';",
81
- "import { devEnvironmentDir, devState, localTargetProviders, resolveLocalTargets } from '@prisma/composer/local-target';",
82
- `import prismaConfig from ${quote(relativeImportSpecifier(generatedDir, input.configFile))};`,
83
- `import app from ${quote(appImport)};`
84
- ].join("\n");
85
- return `// Generated by \`prisma dev\` — overwritten on every run; do not
86
- // edit by hand. Independently runnable from ${quote(input.cwd)} by the
87
- // command Composer starts, which a failed run prints:
88
- //
89
- // <node> <bin of the alchemy @prisma/composer depends on> deploy ${devStackRelativePath(input.environment)} --yes --stage ${input.environment}
90
- //
91
- // bisects a CLI bug from an Alchemy bug (deploy-cli.md § Implementation decisions).
92
- // It runs no config or secrets adapter: it reads what the first process's Load read from the app configuration file named in PRISMA_COMPOSER_APP_CONFIGURATION_FILE, and the named secrets from PRISMA_COMPOSER_NAMED_SECRETS.
93
- ${imports}
94
-
95
- const config = prismaConfig.composer;
96
- if (config === undefined) {
97
- throw new Error(${quote(noComposerExportMessage(input.configFile))});
98
- }
99
-
100
- const containers = deserializeContainers(config.extensions, process.env);
101
- const resolved = await resolveLocalTargets(config);
102
- const devDir = path.join(process.cwd(), devEnvironmentDir(${quote(input.environment)}));
103
- const file = readAppConfigurationFile(process.env);
104
- const namedSecrets = namedSecretsFromEnvironment(process.env);
105
-
106
- export default lower(app, config, {
107
- ${renderOptions(input)}
108
- });
109
- `;
110
- }
111
- /** Writes the dev stack file, returning its absolute path. */
112
- function writeDevStackFile(input) {
113
- const generatedDir = path$1.join(input.cwd, devEnvironmentDir(input.environment));
114
- fs$1.mkdirSync(generatedDir, { recursive: true });
115
- const filePath = path$1.join(generatedDir, DEV_GENERATED_FILE);
116
- fs$1.writeFileSync(filePath, renderDevStackFile(input));
117
- return filePath;
32
+ //#region ../../0-framework/3-tooling/cli/dist/value-reads-change-text-DcRCv7Zy.mjs
33
+ /** Which reads changed, as a clause: `reads of "shop.port" were added and "shop.key" was changed`. */
34
+ function valueReadsChangeText(change) {
35
+ const [first, second, third] = [
36
+ ...change.added.length > 0 ? [`reads of ${quotedList(change.added)} were added`] : [],
37
+ ...change.removed.length > 0 ? [`reads of ${quotedList(change.removed)} were removed`] : [],
38
+ ...change.changed.length > 0 ? [`${quotedList(change.changed)} ${change.changed.length === 1 ? "was" : "were"} changed`] : []
39
+ ];
40
+ return third !== void 0 ? `${first}, ${second}, and ${third}` : second !== void 0 ? `${first} and ${second}` : first ?? "";
118
41
  }
119
42
  //#endregion
120
43
  //#region ../../0-framework/3-tooling/cli/node_modules/readdirp/esm/index.js
@@ -1665,7 +1588,7 @@ var esm_default = {
1665
1588
  FSWatcher
1666
1589
  };
1667
1590
  //#endregion
1668
- //#region ../../0-framework/3-tooling/cli/dist/execute-dev-BIyOI3Ys.mjs
1591
+ //#region ../../0-framework/3-tooling/cli/dist/execute-dev-DnVmNpc1.mjs
1669
1592
  /**
1670
1593
  * Local-dev spec § 6 `watch.ts`: watches each assembled bundle's declared
1671
1594
  * `watch` paths and every authoring module (ADR-0056) — a directory watched
@@ -1741,7 +1664,9 @@ function authoringModuleTargets(entryPath, graph) {
1741
1664
  * watched file; proven by the delete-recreate test failing on Linux CI
1742
1665
  * only). Directory targets are watched recursively as themselves; a
1743
1666
  * nonexistent path is treated as a file target, so it starts reporting the
1744
- * moment something creates it.
1667
+ * moment something creates it. A file whose directory does not exist yet is
1668
+ * watched through its nearest existing ancestor, following only the
1669
+ * directories on the way to it.
1745
1670
  */
1746
1671
  function startWatch(targets, onChange, onError) {
1747
1672
  let timer;
@@ -1755,6 +1680,7 @@ function startWatch(targets, onChange, onError) {
1755
1680
  const fileTargets = /* @__PURE__ */ new Set();
1756
1681
  const directoryRoots = /* @__PURE__ */ new Set();
1757
1682
  const parentRoots = /* @__PURE__ */ new Set();
1683
+ const filesInMissingDirectories = /* @__PURE__ */ new Set();
1758
1684
  for (const target of targets) for (const p of target.paths) {
1759
1685
  const abs = path$1.resolve(p);
1760
1686
  let isDirectory = false;
@@ -1764,7 +1690,8 @@ function startWatch(targets, onChange, onError) {
1764
1690
  if (isDirectory) directoryRoots.add(abs);
1765
1691
  else {
1766
1692
  fileTargets.add(abs);
1767
- parentRoots.add(path$1.dirname(abs));
1693
+ if (fs$1.existsSync(path$1.dirname(abs))) parentRoots.add(path$1.dirname(abs));
1694
+ else filesInMissingDirectories.add(abs);
1768
1695
  }
1769
1696
  }
1770
1697
  const reportError = (error) => {
@@ -1788,6 +1715,21 @@ function startWatch(targets, onChange, onError) {
1788
1715
  parentWatcher.on("error", reportError);
1789
1716
  watchers.push(parentWatcher);
1790
1717
  }
1718
+ if (filesInMissingDirectories.size > 0) {
1719
+ const { roots, onTheWay } = nearestExistingAncestors(filesInMissingDirectories);
1720
+ const ancestorWatcher = esm_default.watch([...roots], {
1721
+ ignoreInitial: true,
1722
+ ignored: (candidate) => {
1723
+ const resolved = path$1.resolve(candidate);
1724
+ return !roots.has(resolved) && !onTheWay.has(resolved);
1725
+ }
1726
+ });
1727
+ ancestorWatcher.on("all", (_event, eventPath) => {
1728
+ if (fileTargets.has(path$1.resolve(eventPath))) trigger();
1729
+ });
1730
+ ancestorWatcher.on("error", reportError);
1731
+ watchers.push(ancestorWatcher);
1732
+ }
1791
1733
  let markReady = () => {};
1792
1734
  const allReady = Promise.all(watchers.map((watcher) => new Promise((resolve) => watcher.on("ready", () => resolve())))).then(() => {});
1793
1735
  return {
@@ -1800,13 +1742,151 @@ function startWatch(targets, onChange, onError) {
1800
1742
  };
1801
1743
  }
1802
1744
  /**
1803
- * The dev executor — run-dev.ts's pipeline (local-dev spec § 6) with console
1804
- * and signal handling removed: events out through `onEvent`, lifetime owned by
1805
- * the returned DevSession. The operation NEVER touches process signal
1806
- * handlers — the host does (see run-dev.ts). Reached only by lazy import
1807
- * from dev.ts — this module's static graph transitively loads alchemy's
1745
+ * For files whose directory does not exist yet: the nearest existing ancestor of each, and every
1746
+ * path from there down to the file, which are all a watch on the ancestor needs to follow.
1747
+ */
1748
+ function nearestExistingAncestors(files) {
1749
+ const roots = /* @__PURE__ */ new Set();
1750
+ const onTheWay = /* @__PURE__ */ new Set();
1751
+ for (const file of files) {
1752
+ onTheWay.add(file);
1753
+ let directory = path$1.dirname(file);
1754
+ while (!fs$1.existsSync(directory)) {
1755
+ onTheWay.add(directory);
1756
+ directory = path$1.dirname(directory);
1757
+ }
1758
+ roots.add(directory);
1759
+ }
1760
+ return {
1761
+ roots,
1762
+ onTheWay
1763
+ };
1764
+ }
1765
+ /**
1766
+ * `prisma dev`'s default converge: one new worker thread per converge, so the
1767
+ * worker imports the app's definition files as they are on disk now. For the
1768
+ * worker's lifetime this thread holds the one-converge flag and the process's
1769
+ * working directory, which a worker cannot change.
1770
+ */
1771
+ /** How long an interrupted converge has to stop on its own before its worker is ended. */
1772
+ const STOP_TIMEOUT_MS = 3e4;
1773
+ /** How long to wait for a worker's output streams to end after it exits. */
1774
+ const STREAM_END_TIMEOUT_MS = 1e3;
1775
+ /** The worker file beside this module: `.ts` from source, `.mjs` from the built package. */
1776
+ const WORKER_URL = new URL(`./dev-converge-worker${path$1.extname(fileURLToPath(import.meta.url))}`, import.meta.url);
1777
+ function failed(tag, message) {
1778
+ return {
1779
+ kind: "outcome",
1780
+ outcome: {
1781
+ kind: "failed",
1782
+ reasons: [{
1783
+ tag,
1784
+ message
1785
+ }]
1786
+ },
1787
+ appFiles: []
1788
+ };
1789
+ }
1790
+ /** The worker's own converge refuses when its working directory is not the job's, which the main thread set: that is a fault in Composer, not in how dev was called. */
1791
+ function workerDirectoryFault(result, cwd) {
1792
+ if (result.kind !== "outcome" || result.outcome.kind !== "refused" || result.outcome.reason !== "worker-thread") return result;
1793
+ return {
1794
+ ...failed("InternalError", `The converge worker thread's working directory was not "${cwd}", which prisma dev set before it started the worker. This is a bug in Composer; please report it.`),
1795
+ appFiles: result.appFiles
1796
+ };
1797
+ }
1798
+ function streamEnded(stream) {
1799
+ if (stream === null) return Promise.resolve();
1800
+ return new Promise((resolve) => {
1801
+ stream.once("end", resolve);
1802
+ stream.once("error", () => resolve());
1803
+ });
1804
+ }
1805
+ function runWorker(job, report, signal, stopTimeoutMs) {
1806
+ return new Promise((resolve) => {
1807
+ const worker = new Worker(WORKER_URL, {
1808
+ workerData: job,
1809
+ stdout: true,
1810
+ stderr: true
1811
+ });
1812
+ const streams = [worker.stdout, worker.stderr];
1813
+ for (const stream of streams) stream?.setEncoding("utf8").on("data", (chunk) => report.output(chunk));
1814
+ const ended = Promise.all(streams.map(streamEnded));
1815
+ let outcome;
1816
+ let stopTimer;
1817
+ const abort = () => {
1818
+ worker.postMessage({ kind: "abort" });
1819
+ stopTimer = setTimeout(() => {
1820
+ outcome ??= failed("ConvergeNotStopped", `The converge did not stop within ${String(stopTimeoutMs / 1e3)}s of being interrupted, so its worker thread was ended. Alchemy's local state may not record everything it changed; run \`prisma dev\` again, or \`prisma dev --fresh\` if that fails.`);
1821
+ worker.terminate();
1822
+ }, stopTimeoutMs);
1823
+ };
1824
+ if (signal?.aborted === true) abort();
1825
+ else signal?.addEventListener("abort", abort, { once: true });
1826
+ worker.on("message", (message) => {
1827
+ if (!isWorkerMessage(message) || outcome !== void 0) return;
1828
+ if (message.kind === "event") report.onEvent(message.event);
1829
+ else if (message.kind === "output") report.output(message.text);
1830
+ else outcome = workerDirectoryFault(message.result, job.cwd);
1831
+ });
1832
+ worker.on("error", (error) => {
1833
+ outcome ??= failed(error instanceof Error ? error.name : "Unknown", `The converge worker thread failed before it reported an outcome: ${error instanceof Error ? error.message : String(error)}`);
1834
+ });
1835
+ worker.on("exit", (code) => {
1836
+ clearTimeout(stopTimer);
1837
+ signal?.removeEventListener("abort", abort);
1838
+ const settled = outcome ?? failed("ConvergeWorkerExited", `The converge worker thread exited with code ${String(code)} before it reported an outcome.`);
1839
+ Promise.race([ended, new Promise((done) => setTimeout(done, STREAM_END_TIMEOUT_MS))]).then(() => resolve(settled));
1840
+ });
1841
+ });
1842
+ }
1843
+ const refused = (reason) => ({
1844
+ kind: "outcome",
1845
+ outcome: {
1846
+ kind: "refused",
1847
+ reason
1848
+ },
1849
+ appFiles: []
1850
+ });
1851
+ /**
1852
+ * A {@link RunDevConverge} that runs each converge in a new worker thread. The job's `cwd` must be
1853
+ * a real path, as `process.cwd()` reports it once changed to. `stopTimeoutMs` bounds how long an
1854
+ * interrupted converge may take to stop.
1855
+ */
1856
+ function runDevConvergeInWorkerWith(options = {}) {
1857
+ const stopTimeoutMs = options.stopTimeoutMs ?? STOP_TIMEOUT_MS;
1858
+ return async (job, report, signal) => {
1859
+ try {
1860
+ if (!isMainThread && process.cwd() !== job.cwd) return refused("worker-thread");
1861
+ const held = await holdingConvergeProcess({}, job.cwd, () => runWorker(job, report, signal, stopTimeoutMs));
1862
+ return held.held ? held.value : refused("already-running");
1863
+ } catch (error) {
1864
+ return thrownResult(error);
1865
+ }
1866
+ };
1867
+ }
1868
+ const runDevConvergeInWorker = runDevConvergeInWorkerWith();
1869
+ /**
1870
+ * The dev executor (local-dev spec § 6): events out through `onEvent`,
1871
+ * lifetime owned by the returned DevSession. Every converge lowers the app
1872
+ * against the local target and runs Alchemy's plan and apply in a new worker
1873
+ * thread, through the app's own install (`loadAppConvergeEntry`, ADR-0066), so
1874
+ * each converge imports the app as it is on disk. The operation
1875
+ * NEVER touches process signal handlers; the host does. Reached only by lazy
1876
+ * import from dev.ts: this module's static graph transitively loads alchemy's
1808
1877
  * provider tree, so the control entry must never import it statically.
1809
1878
  */
1879
+ /** `dir` as the process reports it once it changes to it, so the converge worker's directory matches; `dir` resolved when it does not exist. */
1880
+ function realPath(dir) {
1881
+ try {
1882
+ return fs$1.realpathSync(path$1.resolve(dir));
1883
+ } catch {
1884
+ return path$1.resolve(dir);
1885
+ }
1886
+ }
1887
+ function isDottedCode(code) {
1888
+ return /^[^.]+\.[^.]/.test(code);
1889
+ }
1810
1890
  function failureMessage(error) {
1811
1891
  return error instanceof Error ? error.message : String(error);
1812
1892
  }
@@ -1854,7 +1934,6 @@ function assertDevServersSupported(graph, devServers, config, attachments) {
1854
1934
  if (attachments.get(node.extension)?.serve === void 0) throw devServerUnsupported(address, "its target's local attachment has no `serve`", node.extension);
1855
1935
  }
1856
1936
  }
1857
- /** Runs the full dev pipeline; resolves to a running session or a structured failure. */
1858
1937
  /** The file's content hash; undefined when it cannot be read, which counts as a change. */
1859
1938
  function contentHash(file) {
1860
1939
  try {
@@ -1866,10 +1945,97 @@ function contentHash(file) {
1866
1945
  function sameValues(started, now) {
1867
1946
  return isDeepStrictEqual(started.configuration, now.configuration) && isDeepStrictEqual(started.secrets, now.secrets);
1868
1947
  }
1948
+ function isDevPreflightResult(value) {
1949
+ if (typeof value !== "object" || value === null) return false;
1950
+ if (!("payload" in value) || !("plainVariableText" in value)) return false;
1951
+ const { payload, plainVariableText } = value;
1952
+ return (payload === void 0 || typeof payload === "string") && typeof plainVariableText === "object" && plainVariableText !== null && Object.values(plainVariableText).every((text) => typeof text === "string");
1953
+ }
1954
+ const olderLocalTargetError = (id) => /* @__PURE__ */ new Error(`The extension "${id}" returned a dev preflight result prisma dev cannot read: its local target was built for an older @prisma/composer. Upgrade "${id}" to a version built for the @prisma/composer this app uses.`);
1955
+ /** The app secrets under the graph's secrets keys, each with text, for the local providers. In memory only. */
1956
+ function namedSecrets(current) {
1957
+ const named = {};
1958
+ for (const key of secretsKeys(current.graph)) {
1959
+ const text = current.secrets[key];
1960
+ if (text !== void 0 && text !== "") named[key] = text;
1961
+ }
1962
+ return named;
1963
+ }
1964
+ /** A structured error's text with its why and fix after it, as dev reports a rebuild that failed on one. */
1965
+ function withHelp(error) {
1966
+ return [
1967
+ error.summary,
1968
+ error.why,
1969
+ error.fix
1970
+ ].filter((line) => line !== void 0).join("\n");
1971
+ }
1972
+ /** The structured error a converge worker raised, rebuilt from its envelope; undefined when its code is not a dotted code. */
1973
+ function fromEnvelope(error) {
1974
+ if (!isDottedCode(error.code)) return void 0;
1975
+ return new CliStructuredError(error.code, error.summary, {
1976
+ severity: error.severity,
1977
+ ...error.why === void 0 ? {} : { why: error.why },
1978
+ ...error.fix === void 0 ? {} : { fix: error.fix },
1979
+ ...error.where === void 0 ? {} : { where: error.where },
1980
+ ...error.meta === void 0 ? {} : { meta: error.meta },
1981
+ ...error.docsUrl === void 0 ? {} : { docsUrl: error.docsUrl }
1982
+ });
1983
+ }
1984
+ /** How a rebuild reports a structured error its worker raised before the converge began. */
1985
+ function errorFailure(error, redact, lookupKept) {
1986
+ return {
1987
+ code: "DEV.CONVERGE_FAILED",
1988
+ message: lookupKept ? `${redact(withHelp(error))}\n${LOOKUP_KEPT}` : redact(withHelp(error)),
1989
+ reasons: [{
1990
+ tag: error.code,
1991
+ message: redact(error.summary)
1992
+ }]
1993
+ };
1994
+ }
1995
+ /** The code and text a converge that failed or was refused settles as. */
1996
+ function convergeFailure(outcome, redact) {
1997
+ if (outcome.kind === "refused") return outcome.reason === "already-running" ? {
1998
+ code: "DEV.CONVERGE_RUNNING",
1999
+ message: "Another converge is already running in this process.",
2000
+ reasons: []
2001
+ } : {
2002
+ code: "DEV.WORKER_THREAD",
2003
+ message: "dev's converge cannot run: dev was called from a thread that cannot change the process's working directory to its cwd.",
2004
+ reasons: []
2005
+ };
2006
+ const rootInputUnread = rootInputUnreadReason(outcome);
2007
+ return {
2008
+ code: "DEV.CONVERGE_FAILED",
2009
+ message: outcome.reasons.some(({ tag }) => tag === "GraphChangedError") ? NODES_CHANGED : rootInputUnread !== void 0 ? `${ROOT_INPUT_CHANGED}\n${redact(rootInputUnread.message)}` : redact(withComposerAdvice(convergeReasonsText(outcome.reasons))),
2010
+ reasons: outcome.reasons.map(({ tag, message }) => ({
2011
+ tag,
2012
+ message: redact(message)
2013
+ }))
2014
+ };
2015
+ }
2016
+ function rootInputUnreadReason(outcome) {
2017
+ return outcome.kind === "refused" ? void 0 : outcome.reasons.find(({ tag }) => tag === ROOT_INPUT_UNREAD_ERROR);
2018
+ }
2019
+ const LOOKUP_KEPT = "The directory this import names has an `index.ts` now, but Bun keeps a failed lookup of a directory import for as long as the process runs. Restart `prisma dev` to load it.";
2020
+ const NODES_CHANGED = "The app now has a node added or removed. A running `prisma dev` keeps the nodes it started with, so restart `prisma dev` to apply the change.";
2021
+ const ROOT_INPUT_CHANGED = "The app's root now passes on a field of its input that dev did not read when it started, so the field has no value here. Restart `prisma dev` to apply the change.";
2022
+ const CHANGED_WHILE_STARTING = "An app file was edited after dev loaded it, or a module body builds a different graph each time.";
2023
+ const DEV_PLAIN = "prisma dev hands every plain value to the local services as plain configuration, and never hands a secret that way.";
2024
+ const REFUSAL_HELP = {
2025
+ "DEV.CONVERGE_RUNNING": {
2026
+ why: "A converge sets the process's environment and working directory while Alchemy runs, so two cannot overlap.",
2027
+ fix: "Wait for the other converge to finish, or run dev in its own process."
2028
+ },
2029
+ "DEV.WORKER_THREAD": {
2030
+ why: "Each dev converge runs in a worker thread with the process's working directory set to dev's cwd, because Alchemy reads `.env` and keeps `.alchemy` there. Only the main thread can change the process's working directory.",
2031
+ fix: "Call dev from the main thread, or with the process's working directory as its cwd."
2032
+ }
2033
+ };
2034
+ /** Runs the full dev pipeline; resolves to a running session or a structured failure. */
1869
2035
  async function executeDev(input, deps, cwd) {
1870
- const redaction = new SecretRedaction(process.env);
2036
+ const redaction = deps.redaction ?? new SecretRedaction(process.env);
1871
2037
  try {
1872
- const result = await executeDevInner(input, deps, cwd, redaction);
2038
+ const result = await executeDevInner(input, deps, realPath(cwd), redaction);
1873
2039
  return result.ok ? result : notOk(redactError(result.failure, redaction));
1874
2040
  } catch (error) {
1875
2041
  throw redactThrown(error, redaction);
@@ -1883,8 +2049,10 @@ async function executeDevInner(input, deps, cwd, redaction) {
1883
2049
  removeLeftoverAppConfigurationFiles(cwd);
1884
2050
  let pipeline;
1885
2051
  let resolved;
2052
+ let definitionFiles;
1886
2053
  const containers = /* @__PURE__ */ new Map();
1887
- let preflightTransportEnv = {};
2054
+ const preflightPayloads = /* @__PURE__ */ new Map();
2055
+ const plainVariableText = {};
1888
2056
  const attachmentsById = /* @__PURE__ */ new Map();
1889
2057
  const emit = (event) => {
1890
2058
  try {
@@ -1902,6 +2070,8 @@ async function executeDevInner(input, deps, cwd, redaction) {
1902
2070
  pipeline = await runPipeline(input.entry, input.name, environment, cwd, input.config, pipelineDeps);
1903
2071
  const { graph, name } = pipeline;
1904
2072
  const config = pipeline.configSource.value;
2073
+ definitionFiles = [.../* @__PURE__ */ new Set([...pipeline.entryModule.files, ...authoringModuleTargets(pipeline.entryModule.path, graph).flatMap((target) => target.paths)])];
2074
+ if (deps.runDevConverge === void 0) await loadAppConvergeEntry(path$1.dirname(pipeline.configSource.file));
1905
2075
  resolved = await resolveLocalTargets(config);
1906
2076
  for (const [id, dev] of resolved) {
1907
2077
  let container;
@@ -1928,11 +2098,10 @@ async function executeDevInner(input, deps, cwd, redaction) {
1928
2098
  throw toStructured("DEV.TEARDOWN_FAILED", error);
1929
2099
  }
1930
2100
  }
1931
- const preflightPayloads = /* @__PURE__ */ new Map();
1932
2101
  for (const [id, dev] of resolved) {
1933
2102
  if (dev.preflight === void 0) continue;
1934
2103
  try {
1935
- const payload = await dev.preflight({
2104
+ const found = await dev.preflight({
1936
2105
  graph,
1937
2106
  container: containers.get(id),
1938
2107
  environment,
@@ -1943,18 +2112,13 @@ async function executeDevInner(input, deps, cwd, redaction) {
1943
2112
  message
1944
2113
  })
1945
2114
  });
1946
- if (payload !== void 0) preflightPayloads.set(id, payload);
2115
+ if (!isDevPreflightResult(found)) throw olderLocalTargetError(id);
2116
+ if (found.payload !== void 0) preflightPayloads.set(id, found.payload);
2117
+ Object.assign(plainVariableText, found.plainVariableText);
1947
2118
  } catch (error) {
1948
2119
  throw toStructured("DEV.PREFLIGHT_FAILED", error);
1949
2120
  }
1950
2121
  }
1951
- try {
1952
- preflightTransportEnv = preflightEnv(preflightPayloads);
1953
- } catch (error) {
1954
- throw toStructured("DEV.PREFLIGHT_FAILED", error);
1955
- }
1956
- for (const extension of config.extensions) preflightTransportEnv[preflightEnvVarName(extension.id)] ??= "";
1957
- Object.assign(preflightTransportEnv, preflightFindingsEnv({ unset: [] }));
1958
2122
  for (const [id, dev] of resolved) {
1959
2123
  if (dev.emulators === void 0) continue;
1960
2124
  try {
@@ -1987,68 +2151,66 @@ async function executeDevInner(input, deps, cwd, redaction) {
1987
2151
  if (CliStructuredError.is(error)) return notOk(error);
1988
2152
  throw error;
1989
2153
  }
1990
- const invocationFor = (p) => {
1991
- const handover = prepareSecondProcess({
1992
- file: devAppConfigurationFile(devDir),
1993
- appConfigurationRead: p.graph.appConfigurationRead,
1994
- nodeAddresses: nodeAddresses(p.graph),
1995
- secretsKeys: secretsKeys(p.graph),
1996
- knownSecrets: redaction.knownSecrets,
1997
- appSecrets: p.secrets
1998
- });
1999
- return {
2000
- invocation: alchemyInvocation({
2001
- command: "deploy",
2002
- stackFileRelativePath: devStackRelativePath(environment),
2003
- cwd,
2004
- stage: environment,
2005
- containerEnv: containerEnv(containers),
2006
- preflightEnv: preflightTransportEnv,
2007
- env: handover.env,
2008
- redactedValues: redaction.allValues()
2009
- }),
2010
- handover
2011
- };
2012
- };
2013
- const converge = async (p) => {
2014
- const { invocation, handover } = invocationFor(p);
2015
- let stackPath;
2154
+ const redact = (text) => redaction.redact(text);
2155
+ const runDevConverge = deps.runDevConverge ?? runDevConvergeInWorker;
2156
+ const startReads = valueReadsSnapshot(pipeline.graph);
2157
+ const steps = stepTracker((step) => step.name === "converge" ? step.id : `${step.converge}:${step.resourceId}`, emit);
2158
+ /**
2159
+ * Lowers `current` against the local target and plans and applies it in a
2160
+ * worker thread, as the step `id`. The worker, and every step it opened, end
2161
+ * before this returns.
2162
+ */
2163
+ const converge = async (current, signal, id) => {
2164
+ refuseSecretsInRootInput(current.graph.appConfigurationRead, redaction.knownSecrets, DEV_PLAIN);
2165
+ refuseSecretsInPlainVariables(plainVariableText, redaction.knownSecrets, DEV_PLAIN);
2016
2166
  try {
2017
2167
  claimDevEnvironmentName(devDir, environment);
2018
- stackPath = writeDevStackFile({
2019
- entryPath: p.entryModule.path,
2020
- cwd,
2021
- environment,
2022
- configFile: p.configSource.file,
2023
- name: p.name,
2024
- assembled: p.assembled
2025
- });
2026
- handover.writeFile();
2027
2168
  } catch (error) {
2028
- throw toStructured("DEV.STACK_WRITE_FAILED", error);
2169
+ throw toStructured("DEV.ENVIRONMENT_WRITE_FAILED", error);
2029
2170
  }
2030
- let outcome;
2171
+ if (current.graph.root.node.kind !== "module") throw new InternalError("runPipeline admitted a root that is not a module");
2172
+ steps.start({
2173
+ name: "converge",
2174
+ id
2175
+ });
2176
+ const result = await lowerAndConverge(current, signal, id);
2177
+ steps.closeOpen(result.kind === "outcome" && result.outcome.kind === "applied" ? "ok" : "failed");
2178
+ return result;
2179
+ };
2180
+ const lowerAndConverge = async (current, signal, id) => {
2181
+ const output = interactionMessages(steps, redaction);
2031
2182
  try {
2032
- outcome = await (deps.alchemy ?? spawnAlchemy)(invocation);
2033
- } catch (error) {
2034
- if (CliStructuredError.is(error)) throw error;
2035
- throw new CliStructuredError("DEV.CONVERGE_FAILED", failureMessage(error), {
2036
- cause: error,
2037
- meta: { diagnostics: {
2038
- exitCode: void 0,
2039
- stackFilePath: stackPath,
2040
- reproduceCommand: reproduceCommand(invocation),
2041
- cwd
2042
- } }
2043
- });
2183
+ return await runDevConverge({
2184
+ configFile: current.configSource.file,
2185
+ entry: current.entryModule.path,
2186
+ appDir: path$1.dirname(current.configSource.file),
2187
+ cwd,
2188
+ name: current.name,
2189
+ environment,
2190
+ appConfigurationRead: current.graph.appConfigurationRead,
2191
+ bundles: Object.fromEntries(Object.entries(current.assembled.bundles).map(([address, { dir, entry }]) => [address, {
2192
+ dir,
2193
+ entry
2194
+ }])),
2195
+ unassembled: Object.keys(current.assembled.devServers),
2196
+ containers: Object.fromEntries([...containers].map(([extension, container]) => [extension, container.serialize()])),
2197
+ preflightPayloads: Object.fromEntries(preflightPayloads),
2198
+ devDir,
2199
+ plainVariableText,
2200
+ namedSecrets: namedSecrets(current),
2201
+ nodeAddresses: nodeAddresses(pipeline.graph),
2202
+ valueReads: startReads
2203
+ }, {
2204
+ onEvent: (event) => reportConvergeEvent(steps, event, redact, (resource) => ({
2205
+ name: "apply-resource",
2206
+ converge: id,
2207
+ ...resource
2208
+ })),
2209
+ output: (text) => output.push(text)
2210
+ }, signal);
2044
2211
  } finally {
2045
- handover.removeFile();
2212
+ output.end();
2046
2213
  }
2047
- return {
2048
- outcome,
2049
- stackPath,
2050
- invocation
2051
- };
2052
2214
  };
2053
2215
  const stopStartedServices = async () => {
2054
2216
  for (const attachment of attachmentsById.values()) try {
@@ -2080,27 +2242,49 @@ async function executeDevInner(input, deps, cwd, redaction) {
2080
2242
  if (restarted) onRestarted?.(address, server);
2081
2243
  }
2082
2244
  };
2083
- let first;
2245
+ let firstResult;
2084
2246
  try {
2085
- first = await converge(pipeline);
2247
+ firstResult = await converge(pipeline, input.signal, "dev.converge");
2086
2248
  } catch (error) {
2087
2249
  await stopStartedServices();
2088
2250
  if (CliStructuredError.is(error)) return notOk(error);
2089
2251
  throw error;
2090
2252
  }
2091
- const firstStatus = first.outcome.signal !== null ? null : first.outcome.exitCode ?? 1;
2092
- if (firstStatus !== 0) {
2253
+ if (firstResult.kind === "value-reads-changed") {
2093
2254
  await stopStartedServices();
2094
- return notOk(new CliStructuredError("DEV.CONVERGE_FAILED", first.outcome.signal !== null ? `alchemy deploy was interrupted by ${first.outcome.signal}.` : `alchemy deploy exited with status ${String(firstStatus)}.`, { meta: {
2095
- ...first.outcome.signal !== null ? { signal: first.outcome.signal } : { exitCode: firstStatus },
2096
- diagnostics: {
2097
- exitCode: firstStatus ?? void 0,
2098
- ...first.outcome.signal !== null ? { signal: first.outcome.signal } : {},
2099
- stackFilePath: first.stackPath,
2100
- reproduceCommand: reproduceCommand(first.invocation, first.outcome),
2101
- cwd
2102
- }
2103
- } }));
2255
+ return notOk(new CliStructuredError("DEV.CONVERGE_FAILED", `The platform variables the app reads changed while dev started: ${valueReadsChangeText(firstResult.change)}.`, {
2256
+ why: CHANGED_WHILE_STARTING,
2257
+ fix: "Run dev again."
2258
+ }));
2259
+ }
2260
+ if (firstResult.kind === "error") {
2261
+ await stopStartedServices();
2262
+ return notOk(fromEnvelope(firstResult.error) ?? new CliStructuredError("DEV.CONVERGE_FAILED", `The app could not be converged.\n${redact(withHelp(firstResult.error))}`, { meta: { reasons: [{
2263
+ tag: firstResult.error.code,
2264
+ message: firstResult.error.summary
2265
+ }] } }));
2266
+ }
2267
+ const first = firstResult.outcome;
2268
+ if (first.kind === "interrupted") {
2269
+ await stopStartedServices();
2270
+ return notOk(new CliStructuredError("DEV.INTERRUPTED", "dev was interrupted while it converged.", {
2271
+ why: "It stopped while Alchemy planned or applied the app. Resources it had already changed stay as they are.",
2272
+ fix: "Run dev again to finish."
2273
+ }));
2274
+ }
2275
+ if (first.kind !== "applied") {
2276
+ await stopStartedServices();
2277
+ const rootInputUnread = rootInputUnreadReason(first);
2278
+ if (rootInputUnread !== void 0) return notOk(new CliStructuredError("DEV.CONVERGE_FAILED", `The app could not be converged.\n${redact(rootInputUnread.message)}`, {
2279
+ why: CHANGED_WHILE_STARTING,
2280
+ fix: "Run dev again.",
2281
+ meta: { reasons: [{
2282
+ tag: rootInputUnread.tag,
2283
+ message: redact(rootInputUnread.message)
2284
+ }] }
2285
+ }));
2286
+ const failure = convergeFailure(first, redact);
2287
+ return notOk(failure.code === "DEV.CONVERGE_FAILED" ? new CliStructuredError(failure.code, `The app could not be converged.\n${failure.message}`, { meta: { reasons: failure.reasons } }) : new CliStructuredError(failure.code, failure.message, REFUSAL_HELP[failure.code]));
2104
2288
  }
2105
2289
  const attachments = [...attachmentsById.values()];
2106
2290
  const started = [];
@@ -2110,6 +2294,8 @@ async function executeDevInner(input, deps, cwd, redaction) {
2110
2294
  const stopBeforeExit = () => {
2111
2295
  for (const attachment of attachments) attachment.stopAppBeforeExit?.();
2112
2296
  };
2297
+ const stopController = new AbortController();
2298
+ const convergeSignal = stopController.signal;
2113
2299
  try {
2114
2300
  for (const attachment of attachments) {
2115
2301
  started.push(attachment);
@@ -2156,11 +2342,26 @@ async function executeDevInner(input, deps, cwd, redaction) {
2156
2342
  })();
2157
2343
  }
2158
2344
  const bundleWatch = watchTargetsFrom(pipeline.assembled.bundles);
2159
- const targets = [...bundleWatch.targets, ...authoringModuleTargets(pipeline.entryModule.path, pipeline.graph)];
2345
+ const watchedDefinitions = /* @__PURE__ */ new Set([...definitionFiles, ...firstResult.appFiles]);
2346
+ const definitionTargets = (files) => [...files].map((file) => ({
2347
+ address: pipeline.graph.root.id,
2348
+ paths: [file]
2349
+ }));
2350
+ const targets = [...bundleWatch.targets, ...definitionTargets(watchedDefinitions)];
2160
2351
  for (const address of bundleWatch.unwatchable) emit({
2161
2352
  kind: "unwatchable",
2162
2353
  address
2163
2354
  });
2355
+ let stopping = false;
2356
+ let rebuilds = 0;
2357
+ let converging;
2358
+ const laterWatches = [];
2359
+ const watchNewAppFiles = (files) => {
2360
+ const added = files.filter((file) => !watchedDefinitions.has(file));
2361
+ if (added.length === 0 || stopping) return;
2362
+ for (const file of added) watchedDefinitions.add(file);
2363
+ laterWatches.push(watchFiles(definitionTargets(added), onChange, onWatchError));
2364
+ };
2164
2365
  const watchDeps = {
2165
2366
  runAssembler: deps.runAssembler,
2166
2367
  devServers: true,
@@ -2176,15 +2377,18 @@ async function executeDevInner(input, deps, cwd, redaction) {
2176
2377
  const startedConfig = contentHash(configFile);
2177
2378
  let configChanged = false;
2178
2379
  let valuesChanged = false;
2380
+ let readsChanged = false;
2179
2381
  const paused = () => {
2180
- if (valuesChanged) return true;
2181
- if (!configChanged && contentHash(configFile) === startedConfig) return false;
2182
- configChanged = true;
2183
- emit({
2184
- kind: "config-changed",
2185
- file: configFile
2186
- });
2187
- return true;
2382
+ if (valuesChanged || readsChanged) return true;
2383
+ if (configChanged || contentHash(configFile) !== startedConfig) {
2384
+ configChanged = true;
2385
+ emit({
2386
+ kind: "config-changed",
2387
+ file: configFile
2388
+ });
2389
+ return true;
2390
+ }
2391
+ return false;
2188
2392
  };
2189
2393
  configWatch = watchFiles([{
2190
2394
  address: configFile,
@@ -2193,21 +2397,43 @@ async function executeDevInner(input, deps, cwd, redaction) {
2193
2397
  const rebuild = async () => {
2194
2398
  try {
2195
2399
  const rePipeline = await runPipeline(input.entry, input.name, environment, cwd, input.config, watchDeps);
2400
+ if (stopping) return;
2196
2401
  if (!sameValues(pipeline, rePipeline)) {
2197
2402
  if (!valuesChanged) emit({ kind: "values-changed" });
2198
2403
  valuesChanged = true;
2199
2404
  return;
2200
2405
  }
2201
- const { outcome, stackPath, invocation } = await converge(rePipeline);
2202
- if (outcome.signal !== null || outcome.exitCode !== 0) {
2406
+ rebuilds += 1;
2407
+ converging = converge(rePipeline, convergeSignal, `dev.rebuild.${String(rebuilds)}`);
2408
+ const result = await converging.finally(() => {
2409
+ converging = void 0;
2410
+ });
2411
+ watchNewAppFiles(result.appFiles);
2412
+ if (result.kind === "value-reads-changed") {
2413
+ if (!readsChanged) emit({
2414
+ kind: "value-reads-changed",
2415
+ ...result.change
2416
+ });
2417
+ readsChanged = true;
2418
+ return;
2419
+ }
2420
+ if (result.kind === "error") {
2203
2421
  emit({
2204
2422
  kind: "converge-failed",
2205
- stackFilePath: stackPath,
2206
- reproduceCommand: reproduceCommand(invocation, outcome),
2207
- cwd
2423
+ ...errorFailure(result.error, redact, result.lookupKept === true)
2208
2424
  });
2209
2425
  return;
2210
2426
  }
2427
+ const { outcome } = result;
2428
+ if (outcome.kind === "interrupted") return;
2429
+ if (outcome.kind !== "applied") {
2430
+ emit({
2431
+ kind: "converge-failed",
2432
+ ...convergeFailure(outcome, redact)
2433
+ });
2434
+ return;
2435
+ }
2436
+ if (stopping) return;
2211
2437
  await serveDevServers(rePipeline.graph, rePipeline.assembled.devServers, (address, server) => emit({
2212
2438
  kind: "dev-server-restarted",
2213
2439
  address,
@@ -2224,28 +2450,27 @@ async function executeDevInner(input, deps, cwd, redaction) {
2224
2450
  });
2225
2451
  }
2226
2452
  };
2227
- let rebuilding = false;
2453
+ let rebuilding;
2228
2454
  let changedDuringRebuild = false;
2229
2455
  const rebuildUntilSettled = async () => {
2230
- rebuilding = true;
2231
2456
  do {
2232
2457
  changedDuringRebuild = false;
2233
2458
  await rebuild();
2234
- } while (changedDuringRebuild && !paused());
2235
- rebuilding = false;
2459
+ } while (changedDuringRebuild && !stopping && !paused());
2460
+ rebuilding = void 0;
2236
2461
  };
2237
- watch = watchFiles(targets, () => {
2238
- if (paused()) return;
2239
- if (rebuilding) {
2462
+ function onChange() {
2463
+ if (stopping || paused()) return;
2464
+ if (rebuilding !== void 0) {
2240
2465
  changedDuringRebuild = true;
2241
2466
  return;
2242
2467
  }
2243
- rebuildUntilSettled();
2244
- }, onWatchError);
2468
+ rebuilding = rebuildUntilSettled();
2469
+ }
2470
+ watch = watchFiles(targets, onChange, onWatchError);
2245
2471
  const startedWatch = watch;
2246
2472
  const startedConfigWatch = configWatch;
2247
2473
  await Promise.all([watch.ready, configWatch.ready]);
2248
- let stopping = false;
2249
2474
  let resolveClosed = () => void 0;
2250
2475
  const closed = new Promise((resolve) => {
2251
2476
  resolveClosed = resolve;
@@ -2254,10 +2479,14 @@ async function executeDevInner(input, deps, cwd, redaction) {
2254
2479
  if (!stopping) {
2255
2480
  stopping = true;
2256
2481
  emit({ kind: "stopping" });
2482
+ stopController.abort();
2257
2483
  following.abort();
2258
2484
  startedWatch.stop();
2259
2485
  startedConfigWatch.stop();
2486
+ for (const later of laterWatches) later.stop();
2487
+ input.signal?.removeEventListener("abort", stopOnAbort);
2260
2488
  (async () => {
2489
+ await converging?.catch(() => void 0);
2261
2490
  for (const attachment of attachments) try {
2262
2491
  await attachment.stopApp();
2263
2492
  } catch (error) {
@@ -2273,6 +2502,11 @@ async function executeDevInner(input, deps, cwd, redaction) {
2273
2502
  }
2274
2503
  return closed;
2275
2504
  };
2505
+ function stopOnAbort() {
2506
+ stop();
2507
+ }
2508
+ if (input.signal?.aborted === true) stop();
2509
+ else input.signal?.addEventListener("abort", stopOnAbort, { once: true });
2276
2510
  return ok({
2277
2511
  endpoints,
2278
2512
  stop,
@@ -2291,4 +2525,4 @@ async function executeDevInner(input, deps, cwd, redaction) {
2291
2525
  //#endregion
2292
2526
  export { executeDev };
2293
2527
 
2294
- //# sourceMappingURL=execute-dev-BIyOI3Ys-BbDOLlV4.mjs.map
2528
+ //# sourceMappingURL=execute-dev-DnVmNpc1-kSyPML7l.mjs.map