@prisma/composer-cli 0.39.0-dev.7 → 0.39.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-converge-CVlo9uw2-BZDypKX6.mjs +88 -0
- package/dist/app-converge-CVlo9uw2-BZDypKX6.mjs.map +1 -0
- package/dist/composer-config-QKdY85G--CEXrb2Uc.mjs +254 -0
- package/dist/composer-config-QKdY85G--CEXrb2Uc.mjs.map +1 -0
- package/dist/{validate-environment-XwVDifWN-BdYUHyVF.mjs → deploy-Br1yvLe3.mjs} +204 -1010
- package/dist/deploy-Br1yvLe3.mjs.map +1 -0
- package/dist/dev-converge-messages-DML4rTz7-B6uxtpZG.mjs +256 -0
- package/dist/dev-converge-messages-DML4rTz7-B6uxtpZG.mjs.map +1 -0
- package/dist/dev-converge-worker.d.mts +1 -0
- package/dist/dev-converge-worker.mjs +143 -0
- package/dist/dev-converge-worker.mjs.map +1 -0
- package/dist/{dev-current-gQnmjB4V-DrQ4Zzbl.mjs → dev-current-ByY2RrbK-Cni2T65J.mjs} +12 -18
- package/dist/dev-current-ByY2RrbK-Cni2T65J.mjs.map +1 -0
- package/dist/dev-environment-name-6eEr5PW8-CCY7WNWz.mjs +43 -0
- package/dist/dev-environment-name-6eEr5PW8-CCY7WNWz.mjs.map +1 -0
- package/dist/{dist-CRSv_9L8.mjs → dist-C0OGaDnj.mjs} +4 -3
- package/dist/{dist-CRSv_9L8.mjs.map → dist-C0OGaDnj.mjs.map} +1 -1
- package/dist/errors-CVYwN2km.mjs +93 -0
- package/dist/errors-CVYwN2km.mjs.map +1 -0
- package/dist/{execute-deploy-destroy-DKbsBkqK-D8pniqZg.mjs → execute-deploy-destroy-D1jnaYqU-L5pBQMUx.mjs} +245 -244
- package/dist/execute-deploy-destroy-D1jnaYqU-L5pBQMUx.mjs.map +1 -0
- package/dist/{execute-dev-DVCWURmI-D91UZq1o.mjs → execute-dev-BP0Shlpd-C6-D196L.mjs} +422 -166
- package/dist/execute-dev-BP0Shlpd-C6-D196L.mjs.map +1 -0
- package/dist/{execute-dev-current-Dt_9srY2-D8mAcSv4.mjs → execute-dev-current-B792f_1m-7ZE6ulr0.mjs} +9 -6
- package/dist/{execute-dev-current-Dt_9srY2-D8mAcSv4.mjs.map → execute-dev-current-B792f_1m-7ZE6ulr0.mjs.map} +1 -1
- package/dist/{family-D52hWFMF-FfSJ5SN2.d.mts → family-DfwviKFj-CS1L-EvS.d.mts} +171 -69
- package/dist/family-DfwviKFj-CS1L-EvS.d.mts.map +1 -0
- package/dist/family.d.mts +1 -1
- package/dist/family.mjs +87 -137
- package/dist/family.mjs.map +1 -1
- package/dist/internal-error-Dfur7Zqt-B8J8e7ac.mjs +58 -0
- package/dist/internal-error-Dfur7Zqt-B8J8e7ac.mjs.map +1 -0
- package/dist/{list-deployed-CIaiiV_l.mjs → list-deployed-bMQ8GJVV.mjs} +5 -4
- package/dist/{list-deployed-CIaiiV_l.mjs.map → list-deployed-bMQ8GJVV.mjs.map} +1 -1
- package/dist/local-target-CZzICh5R.mjs +34 -0
- package/dist/local-target-CZzICh5R.mjs.map +1 -0
- package/dist/preflight-transport-2d6iIchu-ArIJUY1L.mjs +56 -0
- package/dist/preflight-transport-2d6iIchu-ArIJUY1L.mjs.map +1 -0
- package/dist/{redaction-CjMYXtGp-CYefSG9A.mjs → redaction-DY6eDC12-BrK1aSN5.mjs} +17 -256
- package/dist/redaction-DY6eDC12-BrK1aSN5.mjs.map +1 -0
- package/dist/result-CttmabB6.mjs +91 -0
- package/dist/result-CttmabB6.mjs.map +1 -0
- package/dist/rolldown-runtime-C7HZzL1F.mjs +26 -0
- package/dist/steps-BZXNqW6U-BM2Aa8Bp.mjs +287 -0
- package/dist/steps-BZXNqW6U-BM2Aa8Bp.mjs.map +1 -0
- package/dist/testing.d.mts +2 -42
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +2 -5
- package/dist/testing.mjs.map +1 -1
- package/dist/validate-environment-DCZiNSlR-idVge-kq.mjs +983 -0
- package/dist/validate-environment-DCZiNSlR-idVge-kq.mjs.map +1 -0
- package/dist/value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs +15 -0
- package/dist/value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs.map +1 -0
- package/package.json +7 -7
- package/src/exports/dev-converge-worker.ts +2 -0
- package/src/exports/testing.ts +1 -4
- package/dist/app-configuration-file-Bbfq5PR3-CYdGtitc.mjs +0 -137
- package/dist/app-configuration-file-Bbfq5PR3-CYdGtitc.mjs.map +0 -1
- package/dist/dev-current-gQnmjB4V-DrQ4Zzbl.mjs.map +0 -1
- package/dist/dev-environment-name-6eEr5PW8-kDiScOL8.mjs +0 -71
- package/dist/dev-environment-name-6eEr5PW8-kDiScOL8.mjs.map +0 -1
- package/dist/execute-deploy-destroy-DKbsBkqK-D8pniqZg.mjs.map +0 -1
- package/dist/execute-dev-DVCWURmI-D91UZq1o.mjs.map +0 -1
- package/dist/family-D52hWFMF-FfSJ5SN2.d.mts.map +0 -1
- package/dist/generate-dev-stack-BEpqJ3AH-B7o7JyER.mjs +0 -100
- package/dist/generate-dev-stack-BEpqJ3AH-B7o7JyER.mjs.map +0 -1
- package/dist/redaction-CjMYXtGp-CYefSG9A.mjs.map +0 -1
- package/dist/result-DlBttLS8.mjs +0 -234
- package/dist/result-DlBttLS8.mjs.map +0 -1
- package/dist/run-alchemy-BlYyc4Oh-BnFv0AaY.mjs +0 -302
- package/dist/run-alchemy-BlYyc4Oh-BnFv0AaY.mjs.map +0 -1
- package/dist/validate-environment-XwVDifWN-BdYUHyVF.mjs.map +0 -1
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
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";
|
|
5
5
|
import { r as devEnvironmentDir } from "./app-config-CErnR6NK-DnKH4Kqc.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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-ByY2RrbK-Cni2T65J.mjs";
|
|
8
|
+
import { t as valueReadsChangeText } from "./value-reads-change-text-DcRCv7Zy-Ca8m3bal.mjs";
|
|
9
|
+
import { t as loadAppConvergeEntry } from "./app-converge-CVlo9uw2-BZDypKX6.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";
|
|
10
15
|
import * as fs from "node:fs";
|
|
11
16
|
import * as path from "node:path";
|
|
12
17
|
import { join, relative, resolve, sep } from "node:path";
|
|
13
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
25
|
import { createHash } from "node:crypto";
|
|
19
26
|
import { lstat, open, readdir, realpath, stat as stat$1 } from "fs/promises";
|
|
20
27
|
import { EventEmitter } from "events";
|
|
21
28
|
import { lstat as lstat$1, readdir as readdir$1, realpath as realpath$1, stat as stat$2 } from "node:fs/promises";
|
|
22
|
-
import { Readable } from "node:stream";
|
|
23
29
|
//#region ../../0-framework/3-tooling/cli/dist/emulator-retry-CV8rl69G.mjs
|
|
24
30
|
/**
|
|
25
31
|
* An emulator admin call right after a converge that just PUT dozens of
|
|
@@ -1596,48 +1602,7 @@ var esm_default = {
|
|
|
1596
1602
|
FSWatcher
|
|
1597
1603
|
};
|
|
1598
1604
|
//#endregion
|
|
1599
|
-
//#region ../../0-framework/3-tooling/cli/dist/execute-dev-
|
|
1600
|
-
const readKey = (read) => JSON.stringify([
|
|
1601
|
-
read.reader,
|
|
1602
|
-
read.resource,
|
|
1603
|
-
read.path
|
|
1604
|
-
]);
|
|
1605
|
-
function readsByResource(graph) {
|
|
1606
|
-
const byResource = /* @__PURE__ */ new Map();
|
|
1607
|
-
for (const read of graph.valueReads) {
|
|
1608
|
-
const keys = byResource.get(read.resource) ?? /* @__PURE__ */ new Set();
|
|
1609
|
-
keys.add(readKey(read));
|
|
1610
|
-
byResource.set(read.resource, keys);
|
|
1611
|
-
}
|
|
1612
|
-
return byResource;
|
|
1613
|
-
}
|
|
1614
|
-
function propsAt(graph, address) {
|
|
1615
|
-
const found = graph.nodes.find((entry) => entry.id === address)?.node;
|
|
1616
|
-
return found?.kind === "resource" ? found.props : void 0;
|
|
1617
|
-
}
|
|
1618
|
-
const hasMemberNotIn = (keys, other) => [...keys].some((key) => !other.has(key));
|
|
1619
|
-
function valueReadsChange(started, rebuilt) {
|
|
1620
|
-
const before = readsByResource(started);
|
|
1621
|
-
const after = readsByResource(rebuilt);
|
|
1622
|
-
const added = [];
|
|
1623
|
-
const removed = [];
|
|
1624
|
-
const changed = [];
|
|
1625
|
-
for (const address of /* @__PURE__ */ new Set([...before.keys(), ...after.keys()])) {
|
|
1626
|
-
const was = before.get(address) ?? /* @__PURE__ */ new Set();
|
|
1627
|
-
const is = after.get(address) ?? /* @__PURE__ */ new Set();
|
|
1628
|
-
const gained = hasMemberNotIn(is, was);
|
|
1629
|
-
const lost = hasMemberNotIn(was, is);
|
|
1630
|
-
if (was.size > 0 && is.size > 0 && !isDeepStrictEqual(propsAt(started, address), propsAt(rebuilt, address)) || gained && lost) changed.push(address);
|
|
1631
|
-
else if (gained) added.push(address);
|
|
1632
|
-
else if (lost) removed.push(address);
|
|
1633
|
-
}
|
|
1634
|
-
if (added.length + removed.length + changed.length === 0) return void 0;
|
|
1635
|
-
return {
|
|
1636
|
-
added,
|
|
1637
|
-
removed,
|
|
1638
|
-
changed
|
|
1639
|
-
};
|
|
1640
|
-
}
|
|
1605
|
+
//#region ../../0-framework/3-tooling/cli/dist/execute-dev-BP0Shlpd.mjs
|
|
1641
1606
|
/**
|
|
1642
1607
|
* Local-dev spec § 6 `watch.ts`: watches each assembled bundle's declared
|
|
1643
1608
|
* `watch` paths and every authoring module (ADR-0056) — a directory watched
|
|
@@ -1713,7 +1678,9 @@ function authoringModuleTargets(entryPath, graph) {
|
|
|
1713
1678
|
* watched file; proven by the delete-recreate test failing on Linux CI
|
|
1714
1679
|
* only). Directory targets are watched recursively as themselves; a
|
|
1715
1680
|
* nonexistent path is treated as a file target, so it starts reporting the
|
|
1716
|
-
* 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.
|
|
1717
1684
|
*/
|
|
1718
1685
|
function startWatch(targets, onChange, onError) {
|
|
1719
1686
|
let timer;
|
|
@@ -1727,6 +1694,7 @@ function startWatch(targets, onChange, onError) {
|
|
|
1727
1694
|
const fileTargets = /* @__PURE__ */ new Set();
|
|
1728
1695
|
const directoryRoots = /* @__PURE__ */ new Set();
|
|
1729
1696
|
const parentRoots = /* @__PURE__ */ new Set();
|
|
1697
|
+
const filesInMissingDirectories = /* @__PURE__ */ new Set();
|
|
1730
1698
|
for (const target of targets) for (const p of target.paths) {
|
|
1731
1699
|
const abs = path.resolve(p);
|
|
1732
1700
|
let isDirectory = false;
|
|
@@ -1736,7 +1704,8 @@ function startWatch(targets, onChange, onError) {
|
|
|
1736
1704
|
if (isDirectory) directoryRoots.add(abs);
|
|
1737
1705
|
else {
|
|
1738
1706
|
fileTargets.add(abs);
|
|
1739
|
-
parentRoots.add(path.dirname(abs));
|
|
1707
|
+
if (fs.existsSync(path.dirname(abs))) parentRoots.add(path.dirname(abs));
|
|
1708
|
+
else filesInMissingDirectories.add(abs);
|
|
1740
1709
|
}
|
|
1741
1710
|
}
|
|
1742
1711
|
const reportError = (error) => {
|
|
@@ -1760,6 +1729,21 @@ function startWatch(targets, onChange, onError) {
|
|
|
1760
1729
|
parentWatcher.on("error", reportError);
|
|
1761
1730
|
watchers.push(parentWatcher);
|
|
1762
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
|
+
}
|
|
1763
1747
|
let markReady = () => {};
|
|
1764
1748
|
const allReady = Promise.all(watchers.map((watcher) => new Promise((resolve) => watcher.on("ready", () => resolve())))).then(() => {});
|
|
1765
1749
|
return {
|
|
@@ -1772,13 +1756,151 @@ function startWatch(targets, onChange, onError) {
|
|
|
1772
1756
|
};
|
|
1773
1757
|
}
|
|
1774
1758
|
/**
|
|
1775
|
-
*
|
|
1776
|
-
*
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
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
|
|
1780
1891
|
* provider tree, so the control entry must never import it statically.
|
|
1781
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
|
+
}
|
|
1782
1904
|
function failureMessage(error) {
|
|
1783
1905
|
return error instanceof Error ? error.message : String(error);
|
|
1784
1906
|
}
|
|
@@ -1844,11 +1966,90 @@ function isDevPreflightResult(value) {
|
|
|
1844
1966
|
return (payload === void 0 || typeof payload === "string") && typeof plainVariableText === "object" && plainVariableText !== null && Object.values(plainVariableText).every((text) => typeof text === "string");
|
|
1845
1967
|
}
|
|
1846
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
|
+
};
|
|
1847
2048
|
/** Runs the full dev pipeline; resolves to a running session or a structured failure. */
|
|
1848
2049
|
async function executeDev(input, deps, cwd) {
|
|
1849
|
-
const redaction = new SecretRedaction(process.env);
|
|
2050
|
+
const redaction = deps.redaction ?? new SecretRedaction(process.env);
|
|
1850
2051
|
try {
|
|
1851
|
-
const result = await executeDevInner(input, deps, cwd, redaction);
|
|
2052
|
+
const result = await executeDevInner(input, deps, realPath(cwd), redaction);
|
|
1852
2053
|
return result.ok ? result : notOk(redactError(result.failure, redaction));
|
|
1853
2054
|
} catch (error) {
|
|
1854
2055
|
throw redactThrown(error, redaction);
|
|
@@ -1862,8 +2063,9 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
1862
2063
|
removeLeftoverAppConfigurationFiles(cwd);
|
|
1863
2064
|
let pipeline;
|
|
1864
2065
|
let resolved;
|
|
2066
|
+
let definitionFiles;
|
|
1865
2067
|
const containers = /* @__PURE__ */ new Map();
|
|
1866
|
-
|
|
2068
|
+
const preflightPayloads = /* @__PURE__ */ new Map();
|
|
1867
2069
|
const plainVariableText = {};
|
|
1868
2070
|
const attachmentsById = /* @__PURE__ */ new Map();
|
|
1869
2071
|
const emit = (event) => {
|
|
@@ -1882,6 +2084,8 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
1882
2084
|
pipeline = await runPipeline(input.entry, input.name, environment, cwd, input.config, pipelineDeps);
|
|
1883
2085
|
const { graph, name } = pipeline;
|
|
1884
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));
|
|
1885
2089
|
resolved = await resolveLocalTargets(config);
|
|
1886
2090
|
for (const [id, dev] of resolved) {
|
|
1887
2091
|
let container;
|
|
@@ -1908,7 +2112,6 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
1908
2112
|
throw toStructured("DEV.TEARDOWN_FAILED", error);
|
|
1909
2113
|
}
|
|
1910
2114
|
}
|
|
1911
|
-
const preflightPayloads = /* @__PURE__ */ new Map();
|
|
1912
2115
|
for (const [id, dev] of resolved) {
|
|
1913
2116
|
if (dev.preflight === void 0) continue;
|
|
1914
2117
|
try {
|
|
@@ -1930,12 +2133,6 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
1930
2133
|
throw toStructured("DEV.PREFLIGHT_FAILED", error);
|
|
1931
2134
|
}
|
|
1932
2135
|
}
|
|
1933
|
-
try {
|
|
1934
|
-
preflightTransportEnv = preflightEnv(preflightPayloads);
|
|
1935
|
-
} catch (error) {
|
|
1936
|
-
throw toStructured("DEV.PREFLIGHT_FAILED", error);
|
|
1937
|
-
}
|
|
1938
|
-
for (const extension of config.extensions) preflightTransportEnv[preflightEnvVarName(extension.id)] ??= "";
|
|
1939
2136
|
for (const [id, dev] of resolved) {
|
|
1940
2137
|
if (dev.emulators === void 0) continue;
|
|
1941
2138
|
try {
|
|
@@ -1968,69 +2165,66 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
1968
2165
|
if (CliStructuredError.is(error)) return notOk(error);
|
|
1969
2166
|
throw error;
|
|
1970
2167
|
}
|
|
1971
|
-
const
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
command: "deploy",
|
|
1984
|
-
stackFileRelativePath: devStackRelativePath(environment),
|
|
1985
|
-
cwd,
|
|
1986
|
-
stage: environment,
|
|
1987
|
-
containerEnv: containerEnv(containers),
|
|
1988
|
-
preflightEnv: preflightTransportEnv,
|
|
1989
|
-
env: handover.env,
|
|
1990
|
-
redactedValues: redaction.allValues()
|
|
1991
|
-
}),
|
|
1992
|
-
handover
|
|
1993
|
-
};
|
|
1994
|
-
};
|
|
1995
|
-
const converge = async (p) => {
|
|
1996
|
-
const { invocation, handover } = invocationFor(p);
|
|
1997
|
-
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);
|
|
1998
2180
|
try {
|
|
1999
2181
|
claimDevEnvironmentName(devDir, environment);
|
|
2000
|
-
stackPath = writeDevStackFile({
|
|
2001
|
-
entryPath: p.entryModule.path,
|
|
2002
|
-
cwd,
|
|
2003
|
-
environment,
|
|
2004
|
-
configFile: p.configSource.file,
|
|
2005
|
-
name: p.name,
|
|
2006
|
-
assembled: p.assembled
|
|
2007
|
-
});
|
|
2008
|
-
handover.writeFile();
|
|
2009
2182
|
} catch (error) {
|
|
2010
|
-
throw toStructured("DEV.
|
|
2183
|
+
throw toStructured("DEV.ENVIRONMENT_WRITE_FAILED", error);
|
|
2011
2184
|
}
|
|
2012
|
-
|
|
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);
|
|
2013
2196
|
try {
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
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);
|
|
2026
2225
|
} finally {
|
|
2027
|
-
|
|
2226
|
+
output.end();
|
|
2028
2227
|
}
|
|
2029
|
-
return {
|
|
2030
|
-
outcome,
|
|
2031
|
-
stackPath,
|
|
2032
|
-
invocation
|
|
2033
|
-
};
|
|
2034
2228
|
};
|
|
2035
2229
|
const stopStartedServices = async () => {
|
|
2036
2230
|
for (const attachment of attachmentsById.values()) try {
|
|
@@ -2062,27 +2256,49 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2062
2256
|
if (restarted) onRestarted?.(address, server);
|
|
2063
2257
|
}
|
|
2064
2258
|
};
|
|
2065
|
-
let
|
|
2259
|
+
let firstResult;
|
|
2066
2260
|
try {
|
|
2067
|
-
|
|
2261
|
+
firstResult = await converge(pipeline, input.signal, "dev.converge");
|
|
2068
2262
|
} catch (error) {
|
|
2069
2263
|
await stopStartedServices();
|
|
2070
2264
|
if (CliStructuredError.is(error)) return notOk(error);
|
|
2071
2265
|
throw error;
|
|
2072
2266
|
}
|
|
2073
|
-
|
|
2074
|
-
if (firstStatus !== 0) {
|
|
2267
|
+
if (firstResult.kind === "value-reads-changed") {
|
|
2075
2268
|
await stopStartedServices();
|
|
2076
|
-
return notOk(new CliStructuredError("DEV.CONVERGE_FAILED",
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
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]));
|
|
2086
2302
|
}
|
|
2087
2303
|
const attachments = [...attachmentsById.values()];
|
|
2088
2304
|
const started = [];
|
|
@@ -2092,6 +2308,8 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2092
2308
|
const stopBeforeExit = () => {
|
|
2093
2309
|
for (const attachment of attachments) attachment.stopAppBeforeExit?.();
|
|
2094
2310
|
};
|
|
2311
|
+
const stopController = new AbortController();
|
|
2312
|
+
const convergeSignal = stopController.signal;
|
|
2095
2313
|
try {
|
|
2096
2314
|
for (const attachment of attachments) {
|
|
2097
2315
|
started.push(attachment);
|
|
@@ -2138,11 +2356,26 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2138
2356
|
})();
|
|
2139
2357
|
}
|
|
2140
2358
|
const bundleWatch = watchTargetsFrom(pipeline.assembled.bundles);
|
|
2141
|
-
const
|
|
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)];
|
|
2142
2365
|
for (const address of bundleWatch.unwatchable) emit({
|
|
2143
2366
|
kind: "unwatchable",
|
|
2144
2367
|
address
|
|
2145
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
|
+
};
|
|
2146
2379
|
const watchDeps = {
|
|
2147
2380
|
runAssembler: deps.runAssembler,
|
|
2148
2381
|
devServers: true,
|
|
@@ -2161,13 +2394,15 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2161
2394
|
let readsChanged = false;
|
|
2162
2395
|
const paused = () => {
|
|
2163
2396
|
if (valuesChanged || readsChanged) return true;
|
|
2164
|
-
if (
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
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;
|
|
2171
2406
|
};
|
|
2172
2407
|
configWatch = watchFiles([{
|
|
2173
2408
|
address: configFile,
|
|
@@ -2176,30 +2411,43 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2176
2411
|
const rebuild = async () => {
|
|
2177
2412
|
try {
|
|
2178
2413
|
const rePipeline = await runPipeline(input.entry, input.name, environment, cwd, input.config, watchDeps);
|
|
2414
|
+
if (stopping) return;
|
|
2179
2415
|
if (!sameValues(pipeline, rePipeline)) {
|
|
2180
2416
|
if (!valuesChanged) emit({ kind: "values-changed" });
|
|
2181
2417
|
valuesChanged = true;
|
|
2182
2418
|
return;
|
|
2183
2419
|
}
|
|
2184
|
-
|
|
2185
|
-
|
|
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") {
|
|
2186
2427
|
if (!readsChanged) emit({
|
|
2187
2428
|
kind: "value-reads-changed",
|
|
2188
|
-
...change
|
|
2429
|
+
...result.change
|
|
2189
2430
|
});
|
|
2190
2431
|
readsChanged = true;
|
|
2191
2432
|
return;
|
|
2192
2433
|
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2434
|
+
if (result.kind === "error") {
|
|
2435
|
+
emit({
|
|
2436
|
+
kind: "converge-failed",
|
|
2437
|
+
...errorFailure(result.error, redact, result.lookupKept === true)
|
|
2438
|
+
});
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
const { outcome } = result;
|
|
2442
|
+
if (outcome.kind === "interrupted") return;
|
|
2443
|
+
if (outcome.kind !== "applied") {
|
|
2195
2444
|
emit({
|
|
2196
2445
|
kind: "converge-failed",
|
|
2197
|
-
|
|
2198
|
-
reproduceCommand: reproduceCommand(invocation, outcome),
|
|
2199
|
-
cwd
|
|
2446
|
+
...convergeFailure(outcome, redact)
|
|
2200
2447
|
});
|
|
2201
2448
|
return;
|
|
2202
2449
|
}
|
|
2450
|
+
if (stopping) return;
|
|
2203
2451
|
await serveDevServers(rePipeline.graph, rePipeline.assembled.devServers, (address, server) => emit({
|
|
2204
2452
|
kind: "dev-server-restarted",
|
|
2205
2453
|
address,
|
|
@@ -2216,28 +2464,27 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2216
2464
|
});
|
|
2217
2465
|
}
|
|
2218
2466
|
};
|
|
2219
|
-
let rebuilding
|
|
2467
|
+
let rebuilding;
|
|
2220
2468
|
let changedDuringRebuild = false;
|
|
2221
2469
|
const rebuildUntilSettled = async () => {
|
|
2222
|
-
rebuilding = true;
|
|
2223
2470
|
do {
|
|
2224
2471
|
changedDuringRebuild = false;
|
|
2225
2472
|
await rebuild();
|
|
2226
|
-
} while (changedDuringRebuild && !paused());
|
|
2227
|
-
rebuilding =
|
|
2473
|
+
} while (changedDuringRebuild && !stopping && !paused());
|
|
2474
|
+
rebuilding = void 0;
|
|
2228
2475
|
};
|
|
2229
|
-
|
|
2230
|
-
if (paused()) return;
|
|
2231
|
-
if (rebuilding) {
|
|
2476
|
+
function onChange() {
|
|
2477
|
+
if (stopping || paused()) return;
|
|
2478
|
+
if (rebuilding !== void 0) {
|
|
2232
2479
|
changedDuringRebuild = true;
|
|
2233
2480
|
return;
|
|
2234
2481
|
}
|
|
2235
|
-
rebuildUntilSettled();
|
|
2236
|
-
}
|
|
2482
|
+
rebuilding = rebuildUntilSettled();
|
|
2483
|
+
}
|
|
2484
|
+
watch = watchFiles(targets, onChange, onWatchError);
|
|
2237
2485
|
const startedWatch = watch;
|
|
2238
2486
|
const startedConfigWatch = configWatch;
|
|
2239
2487
|
await Promise.all([watch.ready, configWatch.ready]);
|
|
2240
|
-
let stopping = false;
|
|
2241
2488
|
let resolveClosed = () => void 0;
|
|
2242
2489
|
const closed = new Promise((resolve) => {
|
|
2243
2490
|
resolveClosed = resolve;
|
|
@@ -2246,10 +2493,14 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2246
2493
|
if (!stopping) {
|
|
2247
2494
|
stopping = true;
|
|
2248
2495
|
emit({ kind: "stopping" });
|
|
2496
|
+
stopController.abort();
|
|
2249
2497
|
following.abort();
|
|
2250
2498
|
startedWatch.stop();
|
|
2251
2499
|
startedConfigWatch.stop();
|
|
2500
|
+
for (const later of laterWatches) later.stop();
|
|
2501
|
+
input.signal?.removeEventListener("abort", stopOnAbort);
|
|
2252
2502
|
(async () => {
|
|
2503
|
+
await converging?.catch(() => void 0);
|
|
2253
2504
|
for (const attachment of attachments) try {
|
|
2254
2505
|
await attachment.stopApp();
|
|
2255
2506
|
} catch (error) {
|
|
@@ -2265,6 +2516,11 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2265
2516
|
}
|
|
2266
2517
|
return closed;
|
|
2267
2518
|
};
|
|
2519
|
+
function stopOnAbort() {
|
|
2520
|
+
stop();
|
|
2521
|
+
}
|
|
2522
|
+
if (input.signal?.aborted === true) stop();
|
|
2523
|
+
else input.signal?.addEventListener("abort", stopOnAbort, { once: true });
|
|
2268
2524
|
return ok({
|
|
2269
2525
|
endpoints,
|
|
2270
2526
|
stop,
|
|
@@ -2283,4 +2539,4 @@ async function executeDevInner(input, deps, cwd, redaction) {
|
|
|
2283
2539
|
//#endregion
|
|
2284
2540
|
export { executeDev };
|
|
2285
2541
|
|
|
2286
|
-
//# sourceMappingURL=execute-dev-
|
|
2542
|
+
//# sourceMappingURL=execute-dev-BP0Shlpd-C6-D196L.mjs.map
|