@prisma/composer-cli 0.39.0-dev.1 → 0.39.0-dev.10

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 (74) hide show
  1. package/dist/app-converge-C_YkTIBF-RmqGOR45.mjs +88 -0
  2. package/dist/app-converge-C_YkTIBF-RmqGOR45.mjs.map +1 -0
  3. package/dist/composer-config-QKdY85G--CEXrb2Uc.mjs +254 -0
  4. package/dist/composer-config-QKdY85G--CEXrb2Uc.mjs.map +1 -0
  5. package/dist/{validate-environment-D1BTCkTs-C5m4rL6t.mjs → deploy-Br1yvLe3.mjs} +335 -1091
  6. package/dist/deploy-Br1yvLe3.mjs.map +1 -0
  7. package/dist/dev-converge-messages-DML4rTz7-B6uxtpZG.mjs +256 -0
  8. package/dist/dev-converge-messages-DML4rTz7-B6uxtpZG.mjs.map +1 -0
  9. package/dist/dev-converge-worker.d.mts +1 -0
  10. package/dist/dev-converge-worker.mjs +143 -0
  11. package/dist/dev-converge-worker.mjs.map +1 -0
  12. package/dist/{dev-current-wD5YDLjA-CFI8XTAK.mjs → dev-current-DANgmcle-RwunETUJ.mjs} +12 -18
  13. package/dist/dev-current-DANgmcle-RwunETUJ.mjs.map +1 -0
  14. package/dist/dev-environment-name-6eEr5PW8-CCY7WNWz.mjs +43 -0
  15. package/dist/dev-environment-name-6eEr5PW8-CCY7WNWz.mjs.map +1 -0
  16. package/dist/{dist-D0rWRHos.mjs → dist-C0OGaDnj.mjs} +4 -3
  17. package/dist/{dist-D0rWRHos.mjs.map → dist-C0OGaDnj.mjs.map} +1 -1
  18. package/dist/errors-CVYwN2km.mjs +93 -0
  19. package/dist/errors-CVYwN2km.mjs.map +1 -0
  20. package/dist/{execute-deploy-destroy-DOzo2Psp-2iWcFbD9.mjs → execute-deploy-destroy-DIR9uvA_-Bk0HBMTz.mjs} +374 -141
  21. package/dist/execute-deploy-destroy-DIR9uvA_-Bk0HBMTz.mjs.map +1 -0
  22. package/dist/{execute-dev-BIyOI3Ys-DGpTd9rP.mjs → execute-dev-Cu9_LsQi-CsyIqphZ.mjs} +444 -128
  23. package/dist/execute-dev-Cu9_LsQi-CsyIqphZ.mjs.map +1 -0
  24. package/dist/{execute-dev-current-CKOzjWuO-DTOVqZzZ.mjs → execute-dev-current-Bs0lE_5--BU3A2hsC.mjs} +9 -6
  25. package/dist/{execute-dev-current-CKOzjWuO-DTOVqZzZ.mjs.map → execute-dev-current-Bs0lE_5--BU3A2hsC.mjs.map} +1 -1
  26. package/dist/{redaction-Bf8FvTFH-XGchRgrK.d.mts → family-DfwviKFj-CS1L-EvS.d.mts} +439 -204
  27. package/dist/family-DfwviKFj-CS1L-EvS.d.mts.map +1 -0
  28. package/dist/family.d.mts +1 -1
  29. package/dist/family.mjs +259 -269
  30. package/dist/family.mjs.map +1 -1
  31. package/dist/internal-error-Dfur7Zqt-B8J8e7ac.mjs +58 -0
  32. package/dist/internal-error-Dfur7Zqt-B8J8e7ac.mjs.map +1 -0
  33. package/dist/{list-deployed-BFJJxt_W.mjs → list-deployed-slo4P7dl.mjs} +6 -5
  34. package/dist/list-deployed-slo4P7dl.mjs.map +1 -0
  35. package/dist/local-target-CZzICh5R.mjs +34 -0
  36. package/dist/local-target-CZzICh5R.mjs.map +1 -0
  37. package/dist/{preflight-transport-DmmtoFPH-CZ0o7QPf.mjs → preflight-transport-2d6iIchu-ArIJUY1L.mjs} +7 -28
  38. package/dist/preflight-transport-2d6iIchu-ArIJUY1L.mjs.map +1 -0
  39. package/dist/{redaction-DXung4ip-Co_fv4Zl.mjs → redaction-DY6eDC12-BrK1aSN5.mjs} +33 -267
  40. package/dist/redaction-DY6eDC12-BrK1aSN5.mjs.map +1 -0
  41. package/dist/result-CttmabB6.mjs +91 -0
  42. package/dist/result-CttmabB6.mjs.map +1 -0
  43. package/dist/rolldown-runtime-C7HZzL1F.mjs +26 -0
  44. package/dist/steps-BZXNqW6U-BM2Aa8Bp.mjs +287 -0
  45. package/dist/steps-BZXNqW6U-BM2Aa8Bp.mjs.map +1 -0
  46. package/dist/testing.d.mts +4 -49
  47. package/dist/testing.d.mts.map +1 -1
  48. package/dist/testing.mjs +2 -75
  49. package/dist/testing.mjs.map +1 -1
  50. package/dist/validate-environment-DCZiNSlR-idVge-kq.mjs +983 -0
  51. package/dist/validate-environment-DCZiNSlR-idVge-kq.mjs.map +1 -0
  52. package/dist/value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs +15 -0
  53. package/dist/value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs.map +1 -0
  54. package/package.json +9 -9
  55. package/src/exports/dev-converge-worker.ts +2 -0
  56. package/src/exports/testing.ts +1 -4
  57. package/dist/app-configuration-file-CeJvBAti-DA4EKwFq.mjs +0 -140
  58. package/dist/app-configuration-file-CeJvBAti-DA4EKwFq.mjs.map +0 -1
  59. package/dist/dev-current-wD5YDLjA-CFI8XTAK.mjs.map +0 -1
  60. package/dist/dev-environment-name-6eEr5PW8-Bs4Dl0vW.mjs +0 -71
  61. package/dist/dev-environment-name-6eEr5PW8-Bs4Dl0vW.mjs.map +0 -1
  62. package/dist/execute-deploy-destroy-DOzo2Psp-2iWcFbD9.mjs.map +0 -1
  63. package/dist/execute-dev-BIyOI3Ys-DGpTd9rP.mjs.map +0 -1
  64. package/dist/generate-dev-stack-BV_n-X9n-DM5faH3-.mjs +0 -100
  65. package/dist/generate-dev-stack-BV_n-X9n-DM5faH3-.mjs.map +0 -1
  66. package/dist/list-deployed-BFJJxt_W.mjs.map +0 -1
  67. package/dist/preflight-transport-DmmtoFPH-CZ0o7QPf.mjs.map +0 -1
  68. package/dist/redaction-Bf8FvTFH-XGchRgrK.d.mts.map +0 -1
  69. package/dist/redaction-DXung4ip-Co_fv4Zl.mjs.map +0 -1
  70. package/dist/result-sR7PBi61.mjs +0 -229
  71. package/dist/result-sR7PBi61.mjs.map +0 -1
  72. package/dist/run-alchemy-CRLAyOtt-CwFLe4Zg.mjs +0 -236
  73. package/dist/run-alchemy-CRLAyOtt-CwFLe4Zg.mjs.map +0 -1
  74. package/dist/validate-environment-D1BTCkTs-C5m4rL6t.mjs.map +0 -1
@@ -1,26 +1,31 @@
1
- import { a as nodeAddresses, i as validateEnvironmentName, o as secretsKeys, r as runPipeline } from "./validate-environment-D1BTCkTs-C5m4rL6t.mjs";
2
- import { a as redactDevEvent, c as redactThrown, n as SecretRedaction, o as redactError } from "./redaction-DXung4ip-Co_fv4Zl.mjs";
3
- import { a as preflightFindingsEnv, i as preflightEnvVarName, r as preflightEnv, t as containerEnv } from "./preflight-transport-DmmtoFPH-CZ0o7QPf.mjs";
1
+ import { t as InternalError } from "./internal-error-Dfur7Zqt-B8J8e7ac.mjs";
2
+ import { f as nodeAddresses, p as secretsKeys, u as ROOT_INPUT_UNREAD_ERROR } from "./deploy-Br1yvLe3.mjs";
3
+ import { t as CliStructuredError } from "./errors-CVYwN2km.mjs";
4
+ import { a as redactError, i as redactDevEvent, s as redactThrown, t as SecretRedaction } from "./redaction-DY6eDC12-BrK1aSN5.mjs";
4
5
  import { r as devEnvironmentDir } from "./app-config-CErnR6NK-DnKH4Kqc.mjs";
5
- import { i as CliStructuredError, n as ok, t as notOk } from "./result-sR7PBi61.mjs";
6
- import { c as toStructured, s as requireContainerForEnvironment } from "./dev-current-wD5YDLjA-CFI8XTAK.mjs";
7
- import { i as spawnAlchemy, n as alchemyInvocation, r as reproduceCommand } from "./run-alchemy-CRLAyOtt-CwFLe4Zg.mjs";
8
- import { i as removeLeftoverAppConfigurationFiles, n as devAppConfigurationFile, r as prepareSecondProcess } from "./app-configuration-file-CeJvBAti-DA4EKwFq.mjs";
9
- import { r as writeDevStackFile, t as devStackRelativePath } from "./generate-dev-stack-BV_n-X9n-DM5faH3-.mjs";
10
- import { n as requireDevEnvironmentName, r as resolveLocalTargets, t as claimDevEnvironmentName } from "./dev-environment-name-6eEr5PW8-Bs4Dl0vW.mjs";
6
+ import { n as ok, t as notOk } from "./result-CttmabB6.mjs";
7
+ import { c as toStructured, n as convergeReasonsText, s as requireContainerForEnvironment } from "./dev-current-DANgmcle-RwunETUJ.mjs";
8
+ import { t as valueReadsChangeText } from "./value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs";
9
+ import { t as loadAppConvergeEntry } from "./app-converge-C_YkTIBF-RmqGOR45.mjs";
10
+ import { a as valueReadsSnapshot, i as thrownResult, o as holdingConvergeProcess, r as isWorkerMessage } from "./dev-converge-messages-DML4rTz7-B6uxtpZG.mjs";
11
+ import { t as resolveLocalTargets } from "./local-target-CZzICh5R.mjs";
12
+ import { i as validateEnvironmentName, r as runPipeline } from "./validate-environment-DCZiNSlR-idVge-kq.mjs";
13
+ import { c as removeLeftoverAppConfigurationFiles, m as withComposerAdvice, n as reportConvergeEvent, o as refuseSecretsInPlainVariables, r as stepTracker, s as refuseSecretsInRootInput, t as interactionMessages } from "./steps-BZXNqW6U-BM2Aa8Bp.mjs";
14
+ import { n as requireDevEnvironmentName, t as claimDevEnvironmentName } from "./dev-environment-name-6eEr5PW8-CCY7WNWz.mjs";
11
15
  import * as fs from "node:fs";
12
16
  import * as path from "node:path";
13
17
  import { join, relative, resolve, sep } from "node:path";
18
+ import { isDeepStrictEqual } from "node:util";
19
+ import { fileURLToPath } from "node:url";
20
+ import { Worker, isMainThread } from "node:worker_threads";
21
+ import { Readable } from "node:stream";
14
22
  import { stat, unwatchFile, watch, watchFile } from "fs";
15
23
  import * as sysPath from "path";
16
24
  import { type } from "os";
17
- import { fileURLToPath } from "node:url";
18
- import { isDeepStrictEqual } from "node:util";
19
25
  import { createHash } from "node:crypto";
20
26
  import { lstat, open, readdir, realpath, stat as stat$1 } from "fs/promises";
21
27
  import { EventEmitter } from "events";
22
28
  import { lstat as lstat$1, readdir as readdir$1, realpath as realpath$1, stat as stat$2 } from "node:fs/promises";
23
- import { Readable } from "node:stream";
24
29
  //#region ../../0-framework/3-tooling/cli/dist/emulator-retry-CV8rl69G.mjs
25
30
  /**
26
31
  * An emulator admin call right after a converge that just PUT dozens of
@@ -1597,7 +1602,7 @@ var esm_default = {
1597
1602
  FSWatcher
1598
1603
  };
1599
1604
  //#endregion
1600
- //#region ../../0-framework/3-tooling/cli/dist/execute-dev-BIyOI3Ys.mjs
1605
+ //#region ../../0-framework/3-tooling/cli/dist/execute-dev-Cu9_LsQi.mjs
1601
1606
  /**
1602
1607
  * Local-dev spec § 6 `watch.ts`: watches each assembled bundle's declared
1603
1608
  * `watch` paths and every authoring module (ADR-0056) — a directory watched
@@ -1673,7 +1678,9 @@ function authoringModuleTargets(entryPath, graph) {
1673
1678
  * watched file; proven by the delete-recreate test failing on Linux CI
1674
1679
  * only). Directory targets are watched recursively as themselves; a
1675
1680
  * nonexistent path is treated as a file target, so it starts reporting the
1676
- * moment something creates it.
1681
+ * moment something creates it. A file whose directory does not exist yet is
1682
+ * watched through its nearest existing ancestor, following only the
1683
+ * directories on the way to it.
1677
1684
  */
1678
1685
  function startWatch(targets, onChange, onError) {
1679
1686
  let timer;
@@ -1687,6 +1694,7 @@ function startWatch(targets, onChange, onError) {
1687
1694
  const fileTargets = /* @__PURE__ */ new Set();
1688
1695
  const directoryRoots = /* @__PURE__ */ new Set();
1689
1696
  const parentRoots = /* @__PURE__ */ new Set();
1697
+ const filesInMissingDirectories = /* @__PURE__ */ new Set();
1690
1698
  for (const target of targets) for (const p of target.paths) {
1691
1699
  const abs = path.resolve(p);
1692
1700
  let isDirectory = false;
@@ -1696,7 +1704,8 @@ function startWatch(targets, onChange, onError) {
1696
1704
  if (isDirectory) directoryRoots.add(abs);
1697
1705
  else {
1698
1706
  fileTargets.add(abs);
1699
- parentRoots.add(path.dirname(abs));
1707
+ if (fs.existsSync(path.dirname(abs))) parentRoots.add(path.dirname(abs));
1708
+ else filesInMissingDirectories.add(abs);
1700
1709
  }
1701
1710
  }
1702
1711
  const reportError = (error) => {
@@ -1720,6 +1729,21 @@ function startWatch(targets, onChange, onError) {
1720
1729
  parentWatcher.on("error", reportError);
1721
1730
  watchers.push(parentWatcher);
1722
1731
  }
1732
+ if (filesInMissingDirectories.size > 0) {
1733
+ const { roots, onTheWay } = nearestExistingAncestors(filesInMissingDirectories);
1734
+ const ancestorWatcher = esm_default.watch([...roots], {
1735
+ ignoreInitial: true,
1736
+ ignored: (candidate) => {
1737
+ const resolved = path.resolve(candidate);
1738
+ return !roots.has(resolved) && !onTheWay.has(resolved);
1739
+ }
1740
+ });
1741
+ ancestorWatcher.on("all", (_event, eventPath) => {
1742
+ if (fileTargets.has(path.resolve(eventPath))) trigger();
1743
+ });
1744
+ ancestorWatcher.on("error", reportError);
1745
+ watchers.push(ancestorWatcher);
1746
+ }
1723
1747
  let markReady = () => {};
1724
1748
  const allReady = Promise.all(watchers.map((watcher) => new Promise((resolve) => watcher.on("ready", () => resolve())))).then(() => {});
1725
1749
  return {
@@ -1732,13 +1756,151 @@ function startWatch(targets, onChange, onError) {
1732
1756
  };
1733
1757
  }
1734
1758
  /**
1735
- * The dev executor — run-dev.ts's pipeline (local-dev spec § 6) with console
1736
- * and signal handling removed: events out through `onEvent`, lifetime owned by
1737
- * the returned DevSession. The operation NEVER touches process signal
1738
- * handlers — the host does (see run-dev.ts). Reached only by lazy import
1739
- * from dev.ts — this module's static graph transitively loads alchemy's
1759
+ * For files whose directory does not exist yet: the nearest existing ancestor of each, and every
1760
+ * path from there down to the file, which are all a watch on the ancestor needs to follow.
1761
+ */
1762
+ function nearestExistingAncestors(files) {
1763
+ const roots = /* @__PURE__ */ new Set();
1764
+ const onTheWay = /* @__PURE__ */ new Set();
1765
+ for (const file of files) {
1766
+ onTheWay.add(file);
1767
+ let directory = path.dirname(file);
1768
+ while (!fs.existsSync(directory)) {
1769
+ onTheWay.add(directory);
1770
+ directory = path.dirname(directory);
1771
+ }
1772
+ roots.add(directory);
1773
+ }
1774
+ return {
1775
+ roots,
1776
+ onTheWay
1777
+ };
1778
+ }
1779
+ /**
1780
+ * `prisma dev`'s default converge: one new worker thread per converge, so the
1781
+ * worker imports the app's definition files as they are on disk now. For the
1782
+ * worker's lifetime this thread holds the one-converge flag and the process's
1783
+ * working directory, which a worker cannot change.
1784
+ */
1785
+ /** How long an interrupted converge has to stop on its own before its worker is ended. */
1786
+ const STOP_TIMEOUT_MS = 3e4;
1787
+ /** How long to wait for a worker's output streams to end after it exits. */
1788
+ const STREAM_END_TIMEOUT_MS = 1e3;
1789
+ /** The worker file beside this module: `.ts` from source, `.mjs` from the built package. */
1790
+ const WORKER_URL = new URL(`./dev-converge-worker${path.extname(fileURLToPath(import.meta.url))}`, import.meta.url);
1791
+ function failed(tag, message) {
1792
+ return {
1793
+ kind: "outcome",
1794
+ outcome: {
1795
+ kind: "failed",
1796
+ reasons: [{
1797
+ tag,
1798
+ message
1799
+ }]
1800
+ },
1801
+ appFiles: []
1802
+ };
1803
+ }
1804
+ /** 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. */
1805
+ function workerDirectoryFault(result, cwd) {
1806
+ if (result.kind !== "outcome" || result.outcome.kind !== "refused" || result.outcome.reason !== "worker-thread") return result;
1807
+ return {
1808
+ ...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.`),
1809
+ appFiles: result.appFiles
1810
+ };
1811
+ }
1812
+ function streamEnded(stream) {
1813
+ if (stream === null) return Promise.resolve();
1814
+ return new Promise((resolve) => {
1815
+ stream.once("end", resolve);
1816
+ stream.once("error", () => resolve());
1817
+ });
1818
+ }
1819
+ function runWorker(job, report, signal, stopTimeoutMs) {
1820
+ return new Promise((resolve) => {
1821
+ const worker = new Worker(WORKER_URL, {
1822
+ workerData: job,
1823
+ stdout: true,
1824
+ stderr: true
1825
+ });
1826
+ const streams = [worker.stdout, worker.stderr];
1827
+ for (const stream of streams) stream?.setEncoding("utf8").on("data", (chunk) => report.output(chunk));
1828
+ const ended = Promise.all(streams.map(streamEnded));
1829
+ let outcome;
1830
+ let stopTimer;
1831
+ const abort = () => {
1832
+ worker.postMessage({ kind: "abort" });
1833
+ stopTimer = setTimeout(() => {
1834
+ 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.`);
1835
+ worker.terminate();
1836
+ }, stopTimeoutMs);
1837
+ };
1838
+ if (signal?.aborted === true) abort();
1839
+ else signal?.addEventListener("abort", abort, { once: true });
1840
+ worker.on("message", (message) => {
1841
+ if (!isWorkerMessage(message) || outcome !== void 0) return;
1842
+ if (message.kind === "event") report.onEvent(message.event);
1843
+ else if (message.kind === "output") report.output(message.text);
1844
+ else outcome = workerDirectoryFault(message.result, job.cwd);
1845
+ });
1846
+ worker.on("error", (error) => {
1847
+ 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)}`);
1848
+ });
1849
+ worker.on("exit", (code) => {
1850
+ clearTimeout(stopTimer);
1851
+ signal?.removeEventListener("abort", abort);
1852
+ const settled = outcome ?? failed("ConvergeWorkerExited", `The converge worker thread exited with code ${String(code)} before it reported an outcome.`);
1853
+ Promise.race([ended, new Promise((done) => setTimeout(done, STREAM_END_TIMEOUT_MS))]).then(() => resolve(settled));
1854
+ });
1855
+ });
1856
+ }
1857
+ const refused = (reason) => ({
1858
+ kind: "outcome",
1859
+ outcome: {
1860
+ kind: "refused",
1861
+ reason
1862
+ },
1863
+ appFiles: []
1864
+ });
1865
+ /**
1866
+ * A {@link RunDevConverge} that runs each converge in a new worker thread. The job's `cwd` must be
1867
+ * a real path, as `process.cwd()` reports it once changed to. `stopTimeoutMs` bounds how long an
1868
+ * interrupted converge may take to stop.
1869
+ */
1870
+ function runDevConvergeInWorkerWith(options = {}) {
1871
+ const stopTimeoutMs = options.stopTimeoutMs ?? STOP_TIMEOUT_MS;
1872
+ return async (job, report, signal) => {
1873
+ try {
1874
+ if (!isMainThread && process.cwd() !== job.cwd) return refused("worker-thread");
1875
+ const held = await holdingConvergeProcess({}, job.cwd, () => runWorker(job, report, signal, stopTimeoutMs));
1876
+ return held.held ? held.value : refused("already-running");
1877
+ } catch (error) {
1878
+ return thrownResult(error);
1879
+ }
1880
+ };
1881
+ }
1882
+ const runDevConvergeInWorker = runDevConvergeInWorkerWith();
1883
+ /**
1884
+ * The dev executor (local-dev spec § 6): events out through `onEvent`,
1885
+ * lifetime owned by the returned DevSession. Every converge lowers the app
1886
+ * against the local target and runs Alchemy's plan and apply in a new worker
1887
+ * thread, through the app's own install (`loadAppConvergeEntry`, ADR-0066), so
1888
+ * each converge imports the app as it is on disk. The operation
1889
+ * NEVER touches process signal handlers; the host does. Reached only by lazy
1890
+ * import from dev.ts: this module's static graph transitively loads alchemy's
1740
1891
  * provider tree, so the control entry must never import it statically.
1741
1892
  */
1893
+ /** `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. */
1894
+ function realPath(dir) {
1895
+ try {
1896
+ return fs.realpathSync(path.resolve(dir));
1897
+ } catch {
1898
+ return path.resolve(dir);
1899
+ }
1900
+ }
1901
+ function isDottedCode(code) {
1902
+ return /^[^.]+\.[^.]/.test(code);
1903
+ }
1742
1904
  function failureMessage(error) {
1743
1905
  return error instanceof Error ? error.message : String(error);
1744
1906
  }
@@ -1786,7 +1948,6 @@ function assertDevServersSupported(graph, devServers, config, attachments) {
1786
1948
  if (attachments.get(node.extension)?.serve === void 0) throw devServerUnsupported(address, "its target's local attachment has no `serve`", node.extension);
1787
1949
  }
1788
1950
  }
1789
- /** Runs the full dev pipeline; resolves to a running session or a structured failure. */
1790
1951
  /** The file's content hash; undefined when it cannot be read, which counts as a change. */
1791
1952
  function contentHash(file) {
1792
1953
  try {
@@ -1798,10 +1959,97 @@ function contentHash(file) {
1798
1959
  function sameValues(started, now) {
1799
1960
  return isDeepStrictEqual(started.configuration, now.configuration) && isDeepStrictEqual(started.secrets, now.secrets);
1800
1961
  }
1962
+ function isDevPreflightResult(value) {
1963
+ if (typeof value !== "object" || value === null) return false;
1964
+ if (!("payload" in value) || !("plainVariableText" in value)) return false;
1965
+ const { payload, plainVariableText } = value;
1966
+ return (payload === void 0 || typeof payload === "string") && typeof plainVariableText === "object" && plainVariableText !== null && Object.values(plainVariableText).every((text) => typeof text === "string");
1967
+ }
1968
+ 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.`);
1969
+ /** The app secrets under the graph's secrets keys, each with text, for the local providers. In memory only. */
1970
+ function namedSecrets(current) {
1971
+ const named = {};
1972
+ for (const key of secretsKeys(current.graph)) {
1973
+ const text = current.secrets[key];
1974
+ if (text !== void 0 && text !== "") named[key] = text;
1975
+ }
1976
+ return named;
1977
+ }
1978
+ /** A structured error's text with its why and fix after it, as dev reports a rebuild that failed on one. */
1979
+ function withHelp(error) {
1980
+ return [
1981
+ error.summary,
1982
+ error.why,
1983
+ error.fix
1984
+ ].filter((line) => line !== void 0).join("\n");
1985
+ }
1986
+ /** The structured error a converge worker raised, rebuilt from its envelope; undefined when its code is not a dotted code. */
1987
+ function fromEnvelope(error) {
1988
+ if (!isDottedCode(error.code)) return void 0;
1989
+ return new CliStructuredError(error.code, error.summary, {
1990
+ severity: error.severity,
1991
+ ...error.why === void 0 ? {} : { why: error.why },
1992
+ ...error.fix === void 0 ? {} : { fix: error.fix },
1993
+ ...error.where === void 0 ? {} : { where: error.where },
1994
+ ...error.meta === void 0 ? {} : { meta: error.meta },
1995
+ ...error.docsUrl === void 0 ? {} : { docsUrl: error.docsUrl }
1996
+ });
1997
+ }
1998
+ /** How a rebuild reports a structured error its worker raised before the converge began. */
1999
+ function errorFailure(error, redact, lookupKept) {
2000
+ return {
2001
+ code: "DEV.CONVERGE_FAILED",
2002
+ message: lookupKept ? `${redact(withHelp(error))}\n${LOOKUP_KEPT}` : redact(withHelp(error)),
2003
+ reasons: [{
2004
+ tag: error.code,
2005
+ message: redact(error.summary)
2006
+ }]
2007
+ };
2008
+ }
2009
+ /** The code and text a converge that failed or was refused settles as. */
2010
+ function convergeFailure(outcome, redact) {
2011
+ if (outcome.kind === "refused") return outcome.reason === "already-running" ? {
2012
+ code: "DEV.CONVERGE_RUNNING",
2013
+ message: "Another converge is already running in this process.",
2014
+ reasons: []
2015
+ } : {
2016
+ code: "DEV.WORKER_THREAD",
2017
+ message: "dev's converge cannot run: dev was called from a thread that cannot change the process's working directory to its cwd.",
2018
+ reasons: []
2019
+ };
2020
+ const rootInputUnread = rootInputUnreadReason(outcome);
2021
+ return {
2022
+ code: "DEV.CONVERGE_FAILED",
2023
+ message: outcome.reasons.some(({ tag }) => tag === "GraphChangedError") ? NODES_CHANGED : rootInputUnread !== void 0 ? `${ROOT_INPUT_CHANGED}\n${redact(rootInputUnread.message)}` : redact(withComposerAdvice(convergeReasonsText(outcome.reasons))),
2024
+ reasons: outcome.reasons.map(({ tag, message }) => ({
2025
+ tag,
2026
+ message: redact(message)
2027
+ }))
2028
+ };
2029
+ }
2030
+ function rootInputUnreadReason(outcome) {
2031
+ return outcome.kind === "refused" ? void 0 : outcome.reasons.find(({ tag }) => tag === ROOT_INPUT_UNREAD_ERROR);
2032
+ }
2033
+ 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.";
2034
+ 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.";
2035
+ 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.";
2036
+ const CHANGED_WHILE_STARTING = "An app file was edited after dev loaded it, or a module body builds a different graph each time.";
2037
+ const DEV_PLAIN = "prisma dev hands every plain value to the local services as plain configuration, and never hands a secret that way.";
2038
+ const REFUSAL_HELP = {
2039
+ "DEV.CONVERGE_RUNNING": {
2040
+ why: "A converge sets the process's environment and working directory while Alchemy runs, so two cannot overlap.",
2041
+ fix: "Wait for the other converge to finish, or run dev in its own process."
2042
+ },
2043
+ "DEV.WORKER_THREAD": {
2044
+ 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.",
2045
+ fix: "Call dev from the main thread, or with the process's working directory as its cwd."
2046
+ }
2047
+ };
2048
+ /** Runs the full dev pipeline; resolves to a running session or a structured failure. */
1801
2049
  async function executeDev(input, deps, cwd) {
1802
- const redaction = new SecretRedaction(process.env);
2050
+ const redaction = deps.redaction ?? new SecretRedaction(process.env);
1803
2051
  try {
1804
- const result = await executeDevInner(input, deps, cwd, redaction);
2052
+ const result = await executeDevInner(input, deps, realPath(cwd), redaction);
1805
2053
  return result.ok ? result : notOk(redactError(result.failure, redaction));
1806
2054
  } catch (error) {
1807
2055
  throw redactThrown(error, redaction);
@@ -1815,8 +2063,10 @@ async function executeDevInner(input, deps, cwd, redaction) {
1815
2063
  removeLeftoverAppConfigurationFiles(cwd);
1816
2064
  let pipeline;
1817
2065
  let resolved;
2066
+ let definitionFiles;
1818
2067
  const containers = /* @__PURE__ */ new Map();
1819
- let preflightTransportEnv = {};
2068
+ const preflightPayloads = /* @__PURE__ */ new Map();
2069
+ const plainVariableText = {};
1820
2070
  const attachmentsById = /* @__PURE__ */ new Map();
1821
2071
  const emit = (event) => {
1822
2072
  try {
@@ -1834,6 +2084,8 @@ async function executeDevInner(input, deps, cwd, redaction) {
1834
2084
  pipeline = await runPipeline(input.entry, input.name, environment, cwd, input.config, pipelineDeps);
1835
2085
  const { graph, name } = pipeline;
1836
2086
  const config = pipeline.configSource.value;
2087
+ definitionFiles = [.../* @__PURE__ */ new Set([...pipeline.entryModule.files, ...authoringModuleTargets(pipeline.entryModule.path, graph).flatMap((target) => target.paths)])];
2088
+ if (deps.runDevConverge === void 0) await loadAppConvergeEntry(path.dirname(pipeline.configSource.file));
1837
2089
  resolved = await resolveLocalTargets(config);
1838
2090
  for (const [id, dev] of resolved) {
1839
2091
  let container;
@@ -1860,11 +2112,10 @@ async function executeDevInner(input, deps, cwd, redaction) {
1860
2112
  throw toStructured("DEV.TEARDOWN_FAILED", error);
1861
2113
  }
1862
2114
  }
1863
- const preflightPayloads = /* @__PURE__ */ new Map();
1864
2115
  for (const [id, dev] of resolved) {
1865
2116
  if (dev.preflight === void 0) continue;
1866
2117
  try {
1867
- const payload = await dev.preflight({
2118
+ const found = await dev.preflight({
1868
2119
  graph,
1869
2120
  container: containers.get(id),
1870
2121
  environment,
@@ -1875,18 +2126,13 @@ async function executeDevInner(input, deps, cwd, redaction) {
1875
2126
  message
1876
2127
  })
1877
2128
  });
1878
- if (payload !== void 0) preflightPayloads.set(id, payload);
2129
+ if (!isDevPreflightResult(found)) throw olderLocalTargetError(id);
2130
+ if (found.payload !== void 0) preflightPayloads.set(id, found.payload);
2131
+ Object.assign(plainVariableText, found.plainVariableText);
1879
2132
  } catch (error) {
1880
2133
  throw toStructured("DEV.PREFLIGHT_FAILED", error);
1881
2134
  }
1882
2135
  }
1883
- try {
1884
- preflightTransportEnv = preflightEnv(preflightPayloads);
1885
- } catch (error) {
1886
- throw toStructured("DEV.PREFLIGHT_FAILED", error);
1887
- }
1888
- for (const extension of config.extensions) preflightTransportEnv[preflightEnvVarName(extension.id)] ??= "";
1889
- Object.assign(preflightTransportEnv, preflightFindingsEnv({ unset: [] }));
1890
2136
  for (const [id, dev] of resolved) {
1891
2137
  if (dev.emulators === void 0) continue;
1892
2138
  try {
@@ -1919,68 +2165,66 @@ async function executeDevInner(input, deps, cwd, redaction) {
1919
2165
  if (CliStructuredError.is(error)) return notOk(error);
1920
2166
  throw error;
1921
2167
  }
1922
- const invocationFor = (p) => {
1923
- const handover = prepareSecondProcess({
1924
- file: devAppConfigurationFile(devDir),
1925
- appConfigurationRead: p.graph.appConfigurationRead,
1926
- nodeAddresses: nodeAddresses(p.graph),
1927
- secretsKeys: secretsKeys(p.graph),
1928
- knownSecrets: redaction.knownSecrets,
1929
- appSecrets: p.secrets
1930
- });
1931
- return {
1932
- invocation: alchemyInvocation({
1933
- command: "deploy",
1934
- stackFileRelativePath: devStackRelativePath(environment),
1935
- cwd,
1936
- stage: environment,
1937
- containerEnv: containerEnv(containers),
1938
- preflightEnv: preflightTransportEnv,
1939
- env: handover.env,
1940
- redactedValues: redaction.allValues()
1941
- }),
1942
- handover
1943
- };
1944
- };
1945
- const converge = async (p) => {
1946
- const { invocation, handover } = invocationFor(p);
1947
- let stackPath;
2168
+ const redact = (text) => redaction.redact(text);
2169
+ const runDevConverge = deps.runDevConverge ?? runDevConvergeInWorker;
2170
+ const startReads = valueReadsSnapshot(pipeline.graph);
2171
+ const steps = stepTracker((step) => step.name === "converge" ? step.id : `${step.converge}:${step.resourceId}`, emit);
2172
+ /**
2173
+ * Lowers `current` against the local target and plans and applies it in a
2174
+ * worker thread, as the step `id`. The worker, and every step it opened, end
2175
+ * before this returns.
2176
+ */
2177
+ const converge = async (current, signal, id) => {
2178
+ refuseSecretsInRootInput(current.graph.appConfigurationRead, redaction.knownSecrets, DEV_PLAIN);
2179
+ refuseSecretsInPlainVariables(plainVariableText, redaction.knownSecrets, DEV_PLAIN);
1948
2180
  try {
1949
2181
  claimDevEnvironmentName(devDir, environment);
1950
- stackPath = writeDevStackFile({
1951
- entryPath: p.entryModule.path,
1952
- cwd,
1953
- environment,
1954
- configFile: p.configSource.file,
1955
- name: p.name,
1956
- assembled: p.assembled
1957
- });
1958
- handover.writeFile();
1959
2182
  } catch (error) {
1960
- throw toStructured("DEV.STACK_WRITE_FAILED", error);
2183
+ throw toStructured("DEV.ENVIRONMENT_WRITE_FAILED", error);
1961
2184
  }
1962
- let outcome;
2185
+ if (current.graph.root.node.kind !== "module") throw new InternalError("runPipeline admitted a root that is not a module");
2186
+ steps.start({
2187
+ name: "converge",
2188
+ id
2189
+ });
2190
+ const result = await lowerAndConverge(current, signal, id);
2191
+ steps.closeOpen(result.kind === "outcome" && result.outcome.kind === "applied" ? "ok" : "failed");
2192
+ return result;
2193
+ };
2194
+ const lowerAndConverge = async (current, signal, id) => {
2195
+ const output = interactionMessages(steps, redaction);
1963
2196
  try {
1964
- outcome = await (deps.alchemy ?? spawnAlchemy)(invocation);
1965
- } catch (error) {
1966
- if (CliStructuredError.is(error)) throw error;
1967
- throw new CliStructuredError("DEV.CONVERGE_FAILED", failureMessage(error), {
1968
- cause: error,
1969
- meta: { diagnostics: {
1970
- exitCode: void 0,
1971
- stackFilePath: stackPath,
1972
- reproduceCommand: reproduceCommand(invocation),
1973
- cwd
1974
- } }
1975
- });
2197
+ return await runDevConverge({
2198
+ configFile: current.configSource.file,
2199
+ entry: current.entryModule.path,
2200
+ appDir: path.dirname(current.configSource.file),
2201
+ cwd,
2202
+ name: current.name,
2203
+ environment,
2204
+ appConfigurationRead: current.graph.appConfigurationRead,
2205
+ bundles: Object.fromEntries(Object.entries(current.assembled.bundles).map(([address, { dir, entry }]) => [address, {
2206
+ dir,
2207
+ entry
2208
+ }])),
2209
+ unassembled: Object.keys(current.assembled.devServers),
2210
+ containers: Object.fromEntries([...containers].map(([extension, container]) => [extension, container.serialize()])),
2211
+ preflightPayloads: Object.fromEntries(preflightPayloads),
2212
+ devDir,
2213
+ plainVariableText,
2214
+ namedSecrets: namedSecrets(current),
2215
+ nodeAddresses: nodeAddresses(pipeline.graph),
2216
+ valueReads: startReads
2217
+ }, {
2218
+ onEvent: (event) => reportConvergeEvent(steps, event, redact, (resource) => ({
2219
+ name: "apply-resource",
2220
+ converge: id,
2221
+ ...resource
2222
+ })),
2223
+ output: (text) => output.push(text)
2224
+ }, signal);
1976
2225
  } finally {
1977
- handover.removeFile();
2226
+ output.end();
1978
2227
  }
1979
- return {
1980
- outcome,
1981
- stackPath,
1982
- invocation
1983
- };
1984
2228
  };
1985
2229
  const stopStartedServices = async () => {
1986
2230
  for (const attachment of attachmentsById.values()) try {
@@ -2012,27 +2256,49 @@ async function executeDevInner(input, deps, cwd, redaction) {
2012
2256
  if (restarted) onRestarted?.(address, server);
2013
2257
  }
2014
2258
  };
2015
- let first;
2259
+ let firstResult;
2016
2260
  try {
2017
- first = await converge(pipeline);
2261
+ firstResult = await converge(pipeline, input.signal, "dev.converge");
2018
2262
  } catch (error) {
2019
2263
  await stopStartedServices();
2020
2264
  if (CliStructuredError.is(error)) return notOk(error);
2021
2265
  throw error;
2022
2266
  }
2023
- const firstStatus = first.outcome.signal !== null ? null : first.outcome.exitCode ?? 1;
2024
- if (firstStatus !== 0) {
2267
+ if (firstResult.kind === "value-reads-changed") {
2025
2268
  await stopStartedServices();
2026
- 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: {
2027
- ...first.outcome.signal !== null ? { signal: first.outcome.signal } : { exitCode: firstStatus },
2028
- diagnostics: {
2029
- exitCode: firstStatus ?? void 0,
2030
- ...first.outcome.signal !== null ? { signal: first.outcome.signal } : {},
2031
- stackFilePath: first.stackPath,
2032
- reproduceCommand: reproduceCommand(first.invocation, first.outcome),
2033
- cwd
2034
- }
2035
- } }));
2269
+ return notOk(new CliStructuredError("DEV.CONVERGE_FAILED", `The platform variables the app reads changed while dev started: ${valueReadsChangeText(firstResult.change)}.`, {
2270
+ why: CHANGED_WHILE_STARTING,
2271
+ fix: "Run dev again."
2272
+ }));
2273
+ }
2274
+ if (firstResult.kind === "error") {
2275
+ await stopStartedServices();
2276
+ return notOk(fromEnvelope(firstResult.error) ?? new CliStructuredError("DEV.CONVERGE_FAILED", `The app could not be converged.\n${redact(withHelp(firstResult.error))}`, { meta: { reasons: [{
2277
+ tag: firstResult.error.code,
2278
+ message: firstResult.error.summary
2279
+ }] } }));
2280
+ }
2281
+ const first = firstResult.outcome;
2282
+ if (first.kind === "interrupted") {
2283
+ await stopStartedServices();
2284
+ return notOk(new CliStructuredError("DEV.INTERRUPTED", "dev was interrupted while it converged.", {
2285
+ why: "It stopped while Alchemy planned or applied the app. Resources it had already changed stay as they are.",
2286
+ fix: "Run dev again to finish."
2287
+ }));
2288
+ }
2289
+ if (first.kind !== "applied") {
2290
+ await stopStartedServices();
2291
+ const rootInputUnread = rootInputUnreadReason(first);
2292
+ if (rootInputUnread !== void 0) return notOk(new CliStructuredError("DEV.CONVERGE_FAILED", `The app could not be converged.\n${redact(rootInputUnread.message)}`, {
2293
+ why: CHANGED_WHILE_STARTING,
2294
+ fix: "Run dev again.",
2295
+ meta: { reasons: [{
2296
+ tag: rootInputUnread.tag,
2297
+ message: redact(rootInputUnread.message)
2298
+ }] }
2299
+ }));
2300
+ const failure = convergeFailure(first, redact);
2301
+ 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]));
2036
2302
  }
2037
2303
  const attachments = [...attachmentsById.values()];
2038
2304
  const started = [];
@@ -2042,6 +2308,8 @@ async function executeDevInner(input, deps, cwd, redaction) {
2042
2308
  const stopBeforeExit = () => {
2043
2309
  for (const attachment of attachments) attachment.stopAppBeforeExit?.();
2044
2310
  };
2311
+ const stopController = new AbortController();
2312
+ const convergeSignal = stopController.signal;
2045
2313
  try {
2046
2314
  for (const attachment of attachments) {
2047
2315
  started.push(attachment);
@@ -2088,11 +2356,26 @@ async function executeDevInner(input, deps, cwd, redaction) {
2088
2356
  })();
2089
2357
  }
2090
2358
  const bundleWatch = watchTargetsFrom(pipeline.assembled.bundles);
2091
- const targets = [...bundleWatch.targets, ...authoringModuleTargets(pipeline.entryModule.path, pipeline.graph)];
2359
+ const watchedDefinitions = /* @__PURE__ */ new Set([...definitionFiles, ...firstResult.appFiles]);
2360
+ const definitionTargets = (files) => [...files].map((file) => ({
2361
+ address: pipeline.graph.root.id,
2362
+ paths: [file]
2363
+ }));
2364
+ const targets = [...bundleWatch.targets, ...definitionTargets(watchedDefinitions)];
2092
2365
  for (const address of bundleWatch.unwatchable) emit({
2093
2366
  kind: "unwatchable",
2094
2367
  address
2095
2368
  });
2369
+ let stopping = false;
2370
+ let rebuilds = 0;
2371
+ let converging;
2372
+ const laterWatches = [];
2373
+ const watchNewAppFiles = (files) => {
2374
+ const added = files.filter((file) => !watchedDefinitions.has(file));
2375
+ if (added.length === 0 || stopping) return;
2376
+ for (const file of added) watchedDefinitions.add(file);
2377
+ laterWatches.push(watchFiles(definitionTargets(added), onChange, onWatchError));
2378
+ };
2096
2379
  const watchDeps = {
2097
2380
  runAssembler: deps.runAssembler,
2098
2381
  devServers: true,
@@ -2108,15 +2391,18 @@ async function executeDevInner(input, deps, cwd, redaction) {
2108
2391
  const startedConfig = contentHash(configFile);
2109
2392
  let configChanged = false;
2110
2393
  let valuesChanged = false;
2394
+ let readsChanged = false;
2111
2395
  const paused = () => {
2112
- if (valuesChanged) return true;
2113
- if (!configChanged && contentHash(configFile) === startedConfig) return false;
2114
- configChanged = true;
2115
- emit({
2116
- kind: "config-changed",
2117
- file: configFile
2118
- });
2119
- return true;
2396
+ if (valuesChanged || readsChanged) return true;
2397
+ if (configChanged || contentHash(configFile) !== startedConfig) {
2398
+ configChanged = true;
2399
+ emit({
2400
+ kind: "config-changed",
2401
+ file: configFile
2402
+ });
2403
+ return true;
2404
+ }
2405
+ return false;
2120
2406
  };
2121
2407
  configWatch = watchFiles([{
2122
2408
  address: configFile,
@@ -2125,21 +2411,43 @@ async function executeDevInner(input, deps, cwd, redaction) {
2125
2411
  const rebuild = async () => {
2126
2412
  try {
2127
2413
  const rePipeline = await runPipeline(input.entry, input.name, environment, cwd, input.config, watchDeps);
2414
+ if (stopping) return;
2128
2415
  if (!sameValues(pipeline, rePipeline)) {
2129
2416
  if (!valuesChanged) emit({ kind: "values-changed" });
2130
2417
  valuesChanged = true;
2131
2418
  return;
2132
2419
  }
2133
- const { outcome, stackPath, invocation } = await converge(rePipeline);
2134
- if (outcome.signal !== null || outcome.exitCode !== 0) {
2420
+ rebuilds += 1;
2421
+ converging = converge(rePipeline, convergeSignal, `dev.rebuild.${String(rebuilds)}`);
2422
+ const result = await converging.finally(() => {
2423
+ converging = void 0;
2424
+ });
2425
+ watchNewAppFiles(result.appFiles);
2426
+ if (result.kind === "value-reads-changed") {
2427
+ if (!readsChanged) emit({
2428
+ kind: "value-reads-changed",
2429
+ ...result.change
2430
+ });
2431
+ readsChanged = true;
2432
+ return;
2433
+ }
2434
+ if (result.kind === "error") {
2135
2435
  emit({
2136
2436
  kind: "converge-failed",
2137
- stackFilePath: stackPath,
2138
- reproduceCommand: reproduceCommand(invocation, outcome),
2139
- cwd
2437
+ ...errorFailure(result.error, redact, result.lookupKept === true)
2140
2438
  });
2141
2439
  return;
2142
2440
  }
2441
+ const { outcome } = result;
2442
+ if (outcome.kind === "interrupted") return;
2443
+ if (outcome.kind !== "applied") {
2444
+ emit({
2445
+ kind: "converge-failed",
2446
+ ...convergeFailure(outcome, redact)
2447
+ });
2448
+ return;
2449
+ }
2450
+ if (stopping) return;
2143
2451
  await serveDevServers(rePipeline.graph, rePipeline.assembled.devServers, (address, server) => emit({
2144
2452
  kind: "dev-server-restarted",
2145
2453
  address,
@@ -2156,28 +2464,27 @@ async function executeDevInner(input, deps, cwd, redaction) {
2156
2464
  });
2157
2465
  }
2158
2466
  };
2159
- let rebuilding = false;
2467
+ let rebuilding;
2160
2468
  let changedDuringRebuild = false;
2161
2469
  const rebuildUntilSettled = async () => {
2162
- rebuilding = true;
2163
2470
  do {
2164
2471
  changedDuringRebuild = false;
2165
2472
  await rebuild();
2166
- } while (changedDuringRebuild && !paused());
2167
- rebuilding = false;
2473
+ } while (changedDuringRebuild && !stopping && !paused());
2474
+ rebuilding = void 0;
2168
2475
  };
2169
- watch = watchFiles(targets, () => {
2170
- if (paused()) return;
2171
- if (rebuilding) {
2476
+ function onChange() {
2477
+ if (stopping || paused()) return;
2478
+ if (rebuilding !== void 0) {
2172
2479
  changedDuringRebuild = true;
2173
2480
  return;
2174
2481
  }
2175
- rebuildUntilSettled();
2176
- }, onWatchError);
2482
+ rebuilding = rebuildUntilSettled();
2483
+ }
2484
+ watch = watchFiles(targets, onChange, onWatchError);
2177
2485
  const startedWatch = watch;
2178
2486
  const startedConfigWatch = configWatch;
2179
2487
  await Promise.all([watch.ready, configWatch.ready]);
2180
- let stopping = false;
2181
2488
  let resolveClosed = () => void 0;
2182
2489
  const closed = new Promise((resolve) => {
2183
2490
  resolveClosed = resolve;
@@ -2186,10 +2493,14 @@ async function executeDevInner(input, deps, cwd, redaction) {
2186
2493
  if (!stopping) {
2187
2494
  stopping = true;
2188
2495
  emit({ kind: "stopping" });
2496
+ stopController.abort();
2189
2497
  following.abort();
2190
2498
  startedWatch.stop();
2191
2499
  startedConfigWatch.stop();
2500
+ for (const later of laterWatches) later.stop();
2501
+ input.signal?.removeEventListener("abort", stopOnAbort);
2192
2502
  (async () => {
2503
+ await converging?.catch(() => void 0);
2193
2504
  for (const attachment of attachments) try {
2194
2505
  await attachment.stopApp();
2195
2506
  } catch (error) {
@@ -2205,6 +2516,11 @@ async function executeDevInner(input, deps, cwd, redaction) {
2205
2516
  }
2206
2517
  return closed;
2207
2518
  };
2519
+ function stopOnAbort() {
2520
+ stop();
2521
+ }
2522
+ if (input.signal?.aborted === true) stop();
2523
+ else input.signal?.addEventListener("abort", stopOnAbort, { once: true });
2208
2524
  return ok({
2209
2525
  endpoints,
2210
2526
  stop,
@@ -2223,4 +2539,4 @@ async function executeDevInner(input, deps, cwd, redaction) {
2223
2539
  //#endregion
2224
2540
  export { executeDev };
2225
2541
 
2226
- //# sourceMappingURL=execute-dev-BIyOI3Ys-DGpTd9rP.mjs.map
2542
+ //# sourceMappingURL=execute-dev-Cu9_LsQi-CsyIqphZ.mjs.map