@tdk-landscape/tdk-cli-core 1.3.105 → 1.3.106

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.
@@ -1,11 +1,82 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { getDeferredResourceNames, parseTiltResourceFailures } from "./doctor-runtime.js";
3
3
  import { findOnPath } from "./which.js";
4
- function tiltGetUiResources(port) {
4
+ export function tiltGetUiResources(port) {
5
5
  return new Promise((resolve) => {
6
6
  execFile(findOnPath("tilt") ?? "tilt", ["get", "uiresources", "-o", "json", "--port", String(port)], { timeout: 15_000, maxBuffer: 16 * 1024 * 1024 }, (error, stdout) => resolve(error ? null : stdout));
7
7
  });
8
8
  }
9
+ /**
10
+ * Tilt lists resources outside the current focus (the other release phases, or everything but a `--only` selection) with
11
+ * `disableStatus.state: Disabled` and both statuses `none`, which would read as pending forever. A resource whose update
12
+ * status is `not_applicable` (a serve-only local resource) has nothing to build, so it counts as built.
13
+ */
14
+ export function onlyEnabledResources(jsonText) {
15
+ const parsed = JSON.parse(jsonText);
16
+ const items = (parsed.items ?? [])
17
+ .filter((item) => item.status?.disableStatus?.state !== "Disabled")
18
+ .map((item) => item.status?.updateStatus === "not_applicable"
19
+ ? { ...item, status: { ...item.status, updateStatus: "ok" } }
20
+ : item);
21
+ return JSON.stringify({ items });
22
+ }
23
+ function enabledNames(jsonText) {
24
+ return (JSON.parse(jsonText).items ?? [])
25
+ .filter((item) => item.status?.disableStatus?.state !== "Disabled")
26
+ .flatMap((item) => (item.metadata?.name ? [item.metadata.name] : []));
27
+ }
28
+ /**
29
+ * Services the caller asked for must not vanish into the disabled filter: one that Tilt lists as disabled (it can be
30
+ * disabled while running) is a failure, and one Tilt does not list yet is still pending.
31
+ */
32
+ export function checkExpectedResources(jsonText, expected) {
33
+ const items = JSON.parse(jsonText).items ?? [];
34
+ const byName = new Map(items.map((item) => [item.metadata?.name, item]));
35
+ return {
36
+ missing: expected.filter((name) => !byName.has(name)),
37
+ disabled: expected.filter((name) => byName.get(name)?.status?.disableStatus?.state === "Disabled"),
38
+ };
39
+ }
40
+ /**
41
+ * One look at `tilt get uiresources -o json`. `settled` means polling can stop: everything is ready, or the rest has
42
+ * finished with a failure (an errored resource, or an expected service Tilt has disabled).
43
+ */
44
+ export function evaluateTiltReadiness(jsonText, deferred, expected) {
45
+ const parsed = parseTiltResourceFailures(onlyEnabledResources(jsonText), deferred);
46
+ let result = {
47
+ ready: parsed.failures.length === 0 && parsed.pendingCount === 0 && parsed.okCount > 0,
48
+ failures: parsed.failures.map((failure) => ({
49
+ name: failure.name,
50
+ message: failure.error || `${failure.updateStatus}/${failure.runtimeStatus}`,
51
+ })),
52
+ pending: parsed.pendingCount,
53
+ timedOut: false,
54
+ enabled: enabledNames(jsonText),
55
+ };
56
+ if (expected && expected.length > 0) {
57
+ const { missing, disabled } = checkExpectedResources(jsonText, expected);
58
+ if (missing.length > 0) {
59
+ result = { ...result, ready: false, pending: result.pending + missing.length };
60
+ }
61
+ if (disabled.length > 0) {
62
+ return {
63
+ settled: true,
64
+ result: {
65
+ ...result,
66
+ ready: false,
67
+ failures: [
68
+ ...result.failures,
69
+ ...disabled.map((name) => ({ name, message: "disabled in Tilt" })),
70
+ ],
71
+ },
72
+ };
73
+ }
74
+ }
75
+ return {
76
+ result,
77
+ settled: result.ready || (result.failures.length > 0 && result.pending === 0),
78
+ };
79
+ }
9
80
  /**
10
81
  * Waits until every non-deferred Tilt resource is built and running. Resolves not-ready as soon as the rest has settled
11
82
  * with an errored resource, or at the deadline. Sablier-deferred resources are excluded: they stay idle by design.
@@ -16,24 +87,20 @@ export async function waitForTiltResourcesReady(port, options = {}) {
16
87
  const fetchJson = options.fetchJson ?? tiltGetUiResources;
17
88
  const deferred = options.deferred ?? getDeferredResourceNames();
18
89
  const deadline = Date.now() + timeoutMs;
19
- let last = { ready: false, failures: [], pending: 0, timedOut: false };
90
+ let last = {
91
+ ready: false,
92
+ failures: [],
93
+ pending: 0,
94
+ timedOut: false,
95
+ enabled: [],
96
+ };
20
97
  for (;;) {
21
98
  const text = await fetchJson(port);
22
99
  if (text) {
23
100
  try {
24
- const parsed = parseTiltResourceFailures(text, deferred);
25
- last = {
26
- ready: parsed.failures.length === 0 && parsed.pendingCount === 0 && parsed.okCount > 0,
27
- failures: parsed.failures.map((failure) => ({
28
- name: failure.name,
29
- message: failure.error || `${failure.updateStatus}/${failure.runtimeStatus}`,
30
- })),
31
- pending: parsed.pendingCount,
32
- timedOut: false,
33
- };
34
- if (last.ready)
35
- return last;
36
- if (last.failures.length > 0 && last.pending === 0)
101
+ const evaluation = evaluateTiltReadiness(text, deferred, options.expected);
102
+ last = evaluation.result;
103
+ if (evaluation.settled)
37
104
  return last;
38
105
  }
39
106
  catch {
package/cli/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tdk-cli-internal",
3
3
  "private": true,
4
- "version": "1.3.105",
4
+ "version": "1.3.106",
5
5
  "description": "TDK CLI — start services on your laptop.",
6
6
  "keywords": [
7
7
  "tdk",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tdk-landscape/tdk-cli-core",
3
- "version": "1.3.105",
3
+ "version": "1.3.106",
4
4
  "description": "TDK CLI — start services on your laptop.",
5
5
  "homepage": "https://tdk-landscape.github.io/tdk-website",
6
6
  "repository": {