@jujulego/jill 3.0.0-alpha.7 → 3.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/jill.js CHANGED
File without changes
@@ -0,0 +1,81 @@
1
+ ;{try{(function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="29c66315-5920-4039-8e56-282b8595fd2c",e._sentryDebugIdIdentifier="sentry-dbid-29c66315-5920-4039-8e56-282b8595fd2c");})();}catch(e){}};!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"3.0.0-alpha.9"};}catch(e){}}();import { WorkloadState } from '@jujulego/tasks';
2
+ import { pipe$, map$, collect$ } from 'kyrielle';
3
+
4
+ function isScriptWorkflow(workload) {
5
+ return workload.type === 'script';
6
+ }
7
+
8
+ function buildFlatTree(workload, verbose = false) {
9
+ const tree = [];
10
+ const stack = pipe$(listRoots(workload), map$((workload)=>({
11
+ workload,
12
+ level: 0
13
+ })), collect$());
14
+ while(stack.length > 0){
15
+ const item = stack.pop();
16
+ const mustShow = [
17
+ WorkloadState.Starting,
18
+ WorkloadState.Running,
19
+ WorkloadState.Failed
20
+ ].includes(item.workload.state());
21
+ if (!verbose && !isWorkflow(item.workload) && !mustShow && item.level > 0) {
22
+ continue;
23
+ }
24
+ // Add to tree
25
+ let level = item.level;
26
+ if (item.workload.label !== '[hidden]') {
27
+ tree.push(item);
28
+ level++;
29
+ }
30
+ // Load "member" tasks
31
+ if (isWorkflow(item.workload)) {
32
+ const children = [
33
+ ...item.workload.workloads()
34
+ ].reverse();
35
+ for (const workload of children){
36
+ stack.push({
37
+ workload,
38
+ level
39
+ });
40
+ }
41
+ }
42
+ }
43
+ return tree;
44
+ }
45
+ function* listRoots(workload) {
46
+ const marks = new Set();
47
+ const queue = [
48
+ workload
49
+ ];
50
+ while(queue.length){
51
+ const item = queue.shift();
52
+ // Mark all member of workflows, so they're not added as root
53
+ if (isWorkflow(item)) {
54
+ for (const wkl of item.workloads()){
55
+ marks.add(wkl.id);
56
+ queue.unshift(wkl);
57
+ }
58
+ }
59
+ // Load job dependencies
60
+ if (isJob(item)) {
61
+ for (const dep of item.dependencies()){
62
+ queue.push(dep);
63
+ }
64
+ }
65
+ // Ignore marked workloads
66
+ if (marks.has(item.id)) {
67
+ continue;
68
+ }
69
+ yield item;
70
+ marks.add(item.id);
71
+ }
72
+ }
73
+ function isJob(workload) {
74
+ return 'dependencies' in workload && typeof workload.dependencies === 'function';
75
+ }
76
+ function isWorkflow(workload) {
77
+ return 'workloads' in workload && typeof workload.workloads === 'function';
78
+ }
79
+
80
+ export { buildFlatTree as b, isScriptWorkflow as i };
81
+ //# sourceMappingURL=flat-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flat-tree.js","sources":["../src/cli/utils/predicates.ts","../src/cli/utils/flat-tree.ts"],"sourcesContent":["import type { Workload$ } from '@jujulego/tasks';\nimport type { ScriptWorkflow$ } from '../jobs/run-script$.js';\n\nexport function isScriptWorkflow(workload: Workload$): workload is ScriptWorkflow$ {\n return workload.type === 'script';\n}\n","import { type Job$, type Workflow$, type Workload$, WorkloadState } from '@jujulego/tasks';\nimport { collect$, map$, pipe$ } from 'kyrielle';\n\nexport function buildFlatTree(workload: Workload$, verbose = false) {\n const tree: FlatTreeWorkload[] = [];\n const stack: FlatTreeWorkload[] = pipe$(\n listRoots(workload),\n map$((workload) => ({ workload, level: 0 })),\n collect$(),\n );\n\n while (stack.length > 0) {\n const item = stack.pop()!;\n const mustShow = [WorkloadState.Starting, WorkloadState.Running, WorkloadState.Failed].includes(item.workload.state());\n\n if (!verbose && !isWorkflow(item.workload) && !mustShow && item.level > 0) {\n continue;\n }\n\n // Add to tree\n let level = item.level;\n\n if (item.workload.label !== '[hidden]') {\n tree.push(item);\n level++;\n }\n\n // Load \"member\" tasks\n if (isWorkflow(item.workload)) {\n const children = [...item.workload.workloads()].reverse();\n\n for (const workload of children) {\n stack.push({ workload, level });\n }\n }\n }\n\n return tree;\n}\n\nfunction* listRoots(workload: Workload$) {\n const marks = new Set<string>();\n const queue = [workload];\n\n while (queue.length) {\n const item = queue.shift()!;\n\n // Mark all member of workflows, so they're not added as root\n if (isWorkflow(item)) {\n for (const wkl of item.workloads()) {\n marks.add(wkl.id);\n queue.unshift(wkl);\n }\n }\n\n // Load job dependencies\n if (isJob(item)) {\n for (const dep of item.dependencies()) {\n queue.push(dep);\n }\n }\n\n // Ignore marked workloads\n if (marks.has(item.id)) {\n continue;\n }\n\n yield item;\n marks.add(item.id);\n }\n}\n\nfunction isJob(workload: Workload$): workload is Job$ {\n return 'dependencies' in workload && typeof workload.dependencies === 'function';\n}\n\nfunction isWorkflow(workload: Workload$): workload is Workflow$ {\n return 'workloads' in workload && typeof workload.workloads === 'function';\n}\n\n// Types\nexport interface FlatTreeWorkload {\n readonly level: number;\n readonly workload: Workload$;\n}\n"],"names":["isScriptWorkflow","workload","type","buildFlatTree","verbose","tree","stack","pipe$","listRoots","map$","level","collect$","length","item","pop","mustShow","WorkloadState","Starting","Running","Failed","includes","state","isWorkflow","label","push","children","workloads","reverse","marks","Set","queue","shift","wkl","add","id","unshift","isJob","dep","dependencies","has"],"mappings":";;;AAGO,QAAA,CAASA,iBAAiBC,QAAmB,CAAA,CAAA,CAAA;IAClD,MAAA,CAAOA,QAAAA,CAASC,IAAI,KAAK,CAAA,MAAA,CAAA,CAAA;AAC3B,CAAA;;ACFO,QAAA,CAASC,aAAAA,CAAcF,QAAmB,EAAEG,UAAU,KAAK,CAAA,CAAA,CAAA;AAChE,CAAA,CAAA,CAAA,CAAA,KAAA,CAAMC,OAA2B,CAAA,CAAE,CAAA;AACnC,CAAA,CAAA,CAAA,CAAA,KAAA,C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!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="92368bb9-8978-4811-a19e-8d31de9120d2",e._sentryDebugIdIdentifier="sentry-dbid-92368bb9-8978-4811-a19e-8d31de9120d2");})();}catch(e){}};!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"3.0.0-alpha.7"};}catch(e){}}();import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
1
+ ;{try{(function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3eec4701-a123-4d9a-a1b0-8f526c05abe2",e._sentryDebugIdIdentifier="sentry-dbid-3eec4701-a123-4d9a-a1b0-8f526c05abe2");})();}catch(e){}};!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"3.0.0-alpha.9"};}catch(e){}}();import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { startSpan } from '@sentry/node';
3
3
  import { useStderr, render } from 'ink';
4
4
  import { inject$ } from '@kyrielle/injector';
@@ -1,4 +1,4 @@
1
- ;{try{(function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c983ba1b-dae6-4864-b164-e9932653ec2b",e._sentryDebugIdIdentifier="sentry-dbid-c983ba1b-dae6-4864-b164-e9932653ec2b");})();}catch(e){}};!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"3.0.0-alpha.7"};}catch(e){}}();import { init } from '@sentry/node';
1
+ ;{try{(function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="20252048-de02-4b47-9403-48cb816b7647",e._sentryDebugIdIdentifier="sentry-dbid-20252048-de02-4b47-9403-48cb816b7647");})();}catch(e){}};!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"3.0.0-alpha.9"};}catch(e){}}();import { init } from '@sentry/node';
2
2
 
3
3
  init({
4
4
  dsn: 'https://53e6d10c16975ebd025175d9836d039b@o4508229080055808.ingest.de.sentry.io/4509876546895952',
@@ -0,0 +1,529 @@
1
+ ;{try{(function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="23425764-a6e1-48a5-9890-d9b5cc8ddd39",e._sentryDebugIdIdentifier="sentry-dbid-23425764-a6e1-48a5-9890-d9b5cc8ddd39");})();}catch(e){}};!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"3.0.0-alpha.9"};}catch(e){}}();import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { WorkloadState, isWorkloadEnded } from '@jujulego/tasks';
3
+ import { inject$ } from '@kyrielle/injector';
4
+ import { pipe$, map$, collect$, off$, waitFor$, filter$ } from 'kyrielle';
5
+ import process from 'node:process';
6
+ import { S as SCHEDULER } from './main.js';
7
+ import { Text, Box, Static, useStdout, useInput, useStdin } from 'ink';
8
+ import { createHash } from 'node:crypto';
9
+ import { useState, useEffect, useMemo } from 'react';
10
+ import { b as buildFlatTree, i as isScriptWorkflow } from './flat-tree.js';
11
+ import Spinner from 'ink-spinner';
12
+ import ms from 'pretty-ms';
13
+ import isUnicodeSupported from 'is-unicode-supported';
14
+ import { c as capitalize } from './string.js';
15
+ import { i as inked } from './inked.js';
16
+ import '@sentry/node';
17
+ import 'yargs/helpers';
18
+ import 'yargs';
19
+ import '@kyrielle/logger';
20
+ import 'node:fs';
21
+ import 'path-scurry';
22
+ import '@swc/helpers/_/_apply_decs_2203_r';
23
+ import 'node:stream/consumers';
24
+ import 'node:path';
25
+ import 'glob';
26
+ import 'normalize-package-data';
27
+ import 'semver';
28
+ import 'moo';
29
+ import 'node:child_process';
30
+ import 'chalk';
31
+ import 'slugify';
32
+ import '@jujulego/quick-tag';
33
+ import 'ajv';
34
+ import 'node:os';
35
+ import 'cosmiconfig';
36
+ import 'chalk-template';
37
+
38
+ // Hook
39
+ function useWorkflowFlatTree(workload, verbose) {
40
+ const [tree, setTree] = useState(()=>buildFlatTree(workload, verbose));
41
+ useEffect(()=>{
42
+ const oldHash = hashTree(tree);
43
+ let dirty = false;
44
+ function update() {
45
+ if (!dirty) return;
46
+ const updated = buildFlatTree(workload, verbose);
47
+ if (hashTree(updated) !== oldHash) {
48
+ setTree(updated);
49
+ }
50
+ dirty = false;
51
+ }
52
+ const off = pipe$(tree, map$(({ workload })=>workload.state$.subscribe(()=>{
53
+ dirty = true;
54
+ queueMicrotask(update);
55
+ })), collect$(off$()));
56
+ return ()=>{
57
+ dirty = false;
58
+ off.unsubscribe();
59
+ };
60
+ }, [
61
+ tree,
62
+ verbose,
63
+ workload
64
+ ]);
65
+ return tree;
66
+ }
67
+ // Utils
68
+ function hashTree(tree) {
69
+ const hash = createHash('sha256');
70
+ for (const { workload } of tree){
71
+ hash.update(workload.id);
72
+ }
73
+ return hash.digest('hex');
74
+ }
75
+
76
+ const isSupported = !isUnicodeSupported();
77
+ const success = isSupported ? '✔' : '√';
78
+ const error = isSupported ? '✖' : '×';
79
+
80
+ // Component
81
+ function WorkloadName({ workload, withWorkspace, ...rest }) {
82
+ if (isScriptWorkflow(workload)) {
83
+ return /*#__PURE__*/ jsxs(Text, {
84
+ ...rest,
85
+ children: [
86
+ "Run ",
87
+ /*#__PURE__*/ jsx(Text, {
88
+ bold: true,
89
+ children: workload.script
90
+ }),
91
+ " script",
92
+ withWorkspace && /*#__PURE__*/ jsxs(Fragment, {
93
+ children: [
94
+ ' ',
95
+ "in ",
96
+ workload.workspace.name
97
+ ]
98
+ })
99
+ ]
100
+ });
101
+ }
102
+ let name = workload.label;
103
+ if (workload.type !== 'spawn') {
104
+ name = capitalize(name);
105
+ }
106
+ return /*#__PURE__*/ jsx(Text, {
107
+ ...rest,
108
+ children: name
109
+ });
110
+ }
111
+
112
+ // Component
113
+ function WorkloadSpinner({ workload }) {
114
+ // Track task state
115
+ const [state, setState] = useState(workload.state());
116
+ useEffect(()=>{
117
+ const sub = workload.state$.subscribe(setState);
118
+ return sub.unsubscribe;
119
+ }, [
120
+ workload.state$
121
+ ]);
122
+ // Render
123
+ const dim = workload.type === 'spawn';
124
+ const time = workload.duration().seconds() * 1000;
125
+ switch(state){
126
+ case WorkloadState.Blocked:
127
+ case WorkloadState.Ready:
128
+ case WorkloadState.Starting:
129
+ return /*#__PURE__*/ jsxs(Box, {
130
+ children: [
131
+ /*#__PURE__*/ jsx(Text, {
132
+ color: "grey",
133
+ children: '\u00B7'
134
+ }),
135
+ /*#__PURE__*/ jsx(Box, {
136
+ paddingLeft: 1,
137
+ children: /*#__PURE__*/ jsx(WorkloadName, {
138
+ color: "grey",
139
+ wrap: "truncate",
140
+ workload: workload,
141
+ withWorkspace: true
142
+ })
143
+ })
144
+ ]
145
+ });
146
+ case WorkloadState.Running:
147
+ return /*#__PURE__*/ jsxs(Box, {
148
+ children: [
149
+ /*#__PURE__*/ jsx(Text, {
150
+ dimColor: dim,
151
+ children: /*#__PURE__*/ jsx(Spinner, {})
152
+ }),
153
+ /*#__PURE__*/ jsx(Box, {
154
+ paddingLeft: 1,
155
+ children: /*#__PURE__*/ jsx(WorkloadName, {
156
+ dimColor: dim,
157
+ wrap: "truncate",
158
+ workload: workload,
159
+ withWorkspace: true
160
+ })
161
+ })
162
+ ]
163
+ });
164
+ case WorkloadState.Canceling:
165
+ return /*#__PURE__*/ jsxs(Box, {
166
+ children: [
167
+ /*#__PURE__*/ jsx(Text, {
168
+ dimColor: dim,
169
+ color: "grey",
170
+ children: /*#__PURE__*/ jsx(Spinner, {
171
+ type: "line2"
172
+ })
173
+ }),
174
+ /*#__PURE__*/ jsx(Box, {
175
+ paddingLeft: 1,
176
+ children: /*#__PURE__*/ jsx(WorkloadName, {
177
+ dimColor: dim,
178
+ color: "grey",
179
+ wrap: "truncate",
180
+ workload: workload,
181
+ withWorkspace: true
182
+ })
183
+ })
184
+ ]
185
+ });
186
+ case WorkloadState.Succeeded:
187
+ return /*#__PURE__*/ jsxs(Box, {
188
+ children: [
189
+ /*#__PURE__*/ jsx(Text, {
190
+ color: "green",
191
+ children: success
192
+ }),
193
+ /*#__PURE__*/ jsx(Box, {
194
+ paddingLeft: 1,
195
+ children: /*#__PURE__*/ jsx(WorkloadName, {
196
+ dimColor: dim,
197
+ wrap: "truncate",
198
+ workload: workload,
199
+ withWorkspace: true
200
+ })
201
+ }),
202
+ /*#__PURE__*/ jsx(Box, {
203
+ paddingLeft: 1,
204
+ flexShrink: 0,
205
+ children: /*#__PURE__*/ jsxs(Text, {
206
+ color: dim ? 'grey' : 'dim',
207
+ children: [
208
+ "(took ",
209
+ ms(time),
210
+ ")"
211
+ ]
212
+ })
213
+ })
214
+ ]
215
+ });
216
+ case WorkloadState.Failed:
217
+ return /*#__PURE__*/ jsxs(Box, {
218
+ children: [
219
+ /*#__PURE__*/ jsx(Text, {
220
+ color: "red",
221
+ children: error
222
+ }),
223
+ /*#__PURE__*/ jsx(Box, {
224
+ paddingLeft: 1,
225
+ children: /*#__PURE__*/ jsx(WorkloadName, {
226
+ dimColor: dim,
227
+ wrap: "truncate",
228
+ workload: workload,
229
+ withWorkspace: true
230
+ })
231
+ }),
232
+ /*#__PURE__*/ jsx(Box, {
233
+ paddingLeft: 1,
234
+ flexShrink: 0,
235
+ children: /*#__PURE__*/ jsxs(Text, {
236
+ color: dim ? 'grey' : 'dim',
237
+ children: [
238
+ "(took ",
239
+ ms(time),
240
+ ")"
241
+ ]
242
+ })
243
+ })
244
+ ]
245
+ });
246
+ case WorkloadState.Canceled:
247
+ return /*#__PURE__*/ jsxs(Box, {
248
+ children: [
249
+ /*#__PURE__*/ jsx(Text, {
250
+ dimColor: true,
251
+ children: "-"
252
+ }),
253
+ /*#__PURE__*/ jsx(Box, {
254
+ paddingLeft: 1,
255
+ children: /*#__PURE__*/ jsx(WorkloadName, {
256
+ dimColor: true,
257
+ wrap: "truncate",
258
+ workload: workload,
259
+ withWorkspace: true
260
+ })
261
+ }),
262
+ /*#__PURE__*/ jsx(Box, {
263
+ paddingLeft: 1,
264
+ flexShrink: 0,
265
+ children: /*#__PURE__*/ jsxs(Text, {
266
+ color: dim ? 'grey' : 'dim',
267
+ children: [
268
+ "(took ",
269
+ ms(time),
270
+ ")"
271
+ ]
272
+ })
273
+ })
274
+ ]
275
+ });
276
+ }
277
+ }
278
+
279
+ // Hook
280
+ function useScriptsStats(workloads) {
281
+ const [stats, setStats] = useState(()=>countScripts(workloads));
282
+ useEffect(()=>{
283
+ let dirty = false;
284
+ function recount() {
285
+ if (!dirty) return;
286
+ setStats(countScripts(workloads));
287
+ dirty = false;
288
+ }
289
+ const off = pipe$(workloads, map$((wkl)=>wkl.state$.subscribe(()=>{
290
+ dirty = true;
291
+ queueMicrotask(recount);
292
+ })), collect$(off$()));
293
+ return ()=>{
294
+ dirty = false;
295
+ off.unsubscribe();
296
+ };
297
+ }, [
298
+ workloads
299
+ ]);
300
+ return stats;
301
+ }
302
+ // Utils
303
+ function countScripts(workloads) {
304
+ const stats = {
305
+ [WorkloadState.Ready]: 0,
306
+ [WorkloadState.Blocked]: 0,
307
+ [WorkloadState.Starting]: 0,
308
+ [WorkloadState.Running]: 0,
309
+ [WorkloadState.Succeeded]: 0,
310
+ [WorkloadState.Failed]: 0,
311
+ [WorkloadState.Canceling]: 0,
312
+ [WorkloadState.Canceled]: 0
313
+ };
314
+ for (const workload of workloads){
315
+ if (workload.type === 'script') {
316
+ stats[workload.state()] += 1;
317
+ }
318
+ }
319
+ return stats;
320
+ }
321
+
322
+ // Component
323
+ function WorkloadTreeStats({ tree, ...rest }) {
324
+ const workloads = useMemo(()=>tree.map((item)=>item.workload), [
325
+ tree
326
+ ]);
327
+ const stats = useScriptsStats(workloads);
328
+ // Render
329
+ const running = stats[WorkloadState.Running] + stats[WorkloadState.Starting] + stats[WorkloadState.Canceling];
330
+ const done = stats[WorkloadState.Succeeded];
331
+ const failed = stats[WorkloadState.Failed];
332
+ const canceled = stats[WorkloadState.Canceled];
333
+ return /*#__PURE__*/ jsxs(Text, {
334
+ ...rest,
335
+ children: [
336
+ running > 0 && /*#__PURE__*/ jsxs(Fragment, {
337
+ children: [
338
+ /*#__PURE__*/ jsx(Spinner, {
339
+ type: "sand"
340
+ }),
341
+ " ",
342
+ /*#__PURE__*/ jsx(Text, {
343
+ bold: true,
344
+ children: running
345
+ }),
346
+ " running"
347
+ ]
348
+ }),
349
+ running > 0 && done > 0 && ', ',
350
+ done > 0 && /*#__PURE__*/ jsxs(Text, {
351
+ color: "green",
352
+ children: [
353
+ success,
354
+ " ",
355
+ done,
356
+ " done"
357
+ ]
358
+ }),
359
+ running + done > 0 && failed > 0 && ', ',
360
+ failed > 0 && /*#__PURE__*/ jsxs(Text, {
361
+ color: "red",
362
+ children: [
363
+ error,
364
+ " ",
365
+ failed,
366
+ " failed"
367
+ ]
368
+ }),
369
+ running + done + failed > 0 && canceled > 0 && ', ',
370
+ canceled > 0 && /*#__PURE__*/ jsxs(Text, {
371
+ dimColor: true,
372
+ children: [
373
+ "- ",
374
+ canceled,
375
+ " canceled"
376
+ ]
377
+ })
378
+ ]
379
+ });
380
+ }
381
+
382
+ // Component
383
+ function WorkloadTreeCompleted({ workload, verbose }) {
384
+ const tree = useWorkflowFlatTree(workload, verbose);
385
+ // Render
386
+ return /*#__PURE__*/ jsxs(Fragment, {
387
+ children: [
388
+ /*#__PURE__*/ jsx(Static, {
389
+ items: tree,
390
+ children: ({ workload, level })=>/*#__PURE__*/ jsx(Box, {
391
+ marginLeft: level * 2,
392
+ flexShrink: 0,
393
+ children: /*#__PURE__*/ jsx(WorkloadSpinner, {
394
+ workload: workload
395
+ })
396
+ }, workload.id)
397
+ }),
398
+ /*#__PURE__*/ jsx(WorkloadTreeStats, {
399
+ tree: tree
400
+ })
401
+ ]
402
+ });
403
+ }
404
+
405
+ // Component
406
+ function WorkloadTreeFullSpinner({ workload, verbose }) {
407
+ const tree = useWorkflowFlatTree(workload, verbose);
408
+ // Render
409
+ return /*#__PURE__*/ jsxs(Fragment, {
410
+ children: [
411
+ /*#__PURE__*/ jsx(Box, {
412
+ flexDirection: "column",
413
+ children: tree.map(({ workload, level })=>/*#__PURE__*/ jsx(Box, {
414
+ marginLeft: level * 2,
415
+ flexShrink: 0,
416
+ children: /*#__PURE__*/ jsx(WorkloadSpinner, {
417
+ workload: workload
418
+ })
419
+ }, workload.id))
420
+ }),
421
+ /*#__PURE__*/ jsx(WorkloadTreeStats, {
422
+ tree: tree
423
+ })
424
+ ]
425
+ });
426
+ }
427
+
428
+ function useStdoutDimensions() {
429
+ const { stdout } = useStdout();
430
+ const [dimensions, setDimensions] = useState({
431
+ columns: stdout.columns ?? Infinity,
432
+ rows: stdout.rows ?? Infinity
433
+ });
434
+ useEffect(()=>{
435
+ const handler = ()=>setDimensions({
436
+ columns: stdout.columns ?? Infinity,
437
+ rows: stdout.rows ?? Infinity
438
+ });
439
+ stdout.on('resize', handler);
440
+ return ()=>{
441
+ stdout.off('resize', handler);
442
+ };
443
+ }, [
444
+ stdout
445
+ ]);
446
+ return dimensions;
447
+ }
448
+
449
+ // Component
450
+ function WorkloadTreeScrollableSpinner({ workload, verbose }) {
451
+ const tree = useWorkflowFlatTree(workload, verbose);
452
+ // Manage scroll
453
+ const { rows: termRows } = useStdoutDimensions();
454
+ const [scroll, setScroll] = useState(0);
455
+ const maxRows = Math.min(termRows - 4, tree.length);
456
+ const firstIndex = Math.max(0, tree.length - scroll - maxRows);
457
+ const lastIndex = Math.min(tree.length, firstIndex + maxRows);
458
+ const effectiveScroll = tree.length - lastIndex;
459
+ useInput((_, key)=>{
460
+ if (key.upArrow) {
461
+ setScroll(Math.min(tree.length - maxRows, effectiveScroll + 1));
462
+ } else {
463
+ setScroll(Math.max(0, effectiveScroll - 1));
464
+ }
465
+ });
466
+ // Render
467
+ const slice = tree.slice(firstIndex, lastIndex);
468
+ return /*#__PURE__*/ jsxs(Fragment, {
469
+ children: [
470
+ /*#__PURE__*/ jsx(Box, {
471
+ flexDirection: "column",
472
+ children: slice.map(({ workload, level })=>/*#__PURE__*/ jsx(Box, {
473
+ marginLeft: level * 2,
474
+ flexShrink: 0,
475
+ children: /*#__PURE__*/ jsx(WorkloadSpinner, {
476
+ workload: workload
477
+ })
478
+ }, workload.id))
479
+ }),
480
+ /*#__PURE__*/ jsxs(Text, {
481
+ children: [
482
+ /*#__PURE__*/ jsx(WorkloadTreeStats, {
483
+ tree: tree
484
+ }),
485
+ termRows < tree.length && /*#__PURE__*/ jsx(Text, {
486
+ color: "grey",
487
+ children: " | use keyboard arrows to scroll"
488
+ })
489
+ ]
490
+ })
491
+ ]
492
+ });
493
+ }
494
+
495
+ // Component
496
+ function WorkloadTreeSpinner({ workload, verbose }) {
497
+ const stdin = useStdin();
498
+ if (stdin.isRawModeSupported) {
499
+ return /*#__PURE__*/ jsx(WorkloadTreeScrollableSpinner, {
500
+ workload: workload,
501
+ verbose: verbose
502
+ });
503
+ } else {
504
+ return /*#__PURE__*/ jsx(WorkloadTreeFullSpinner, {
505
+ workload: workload,
506
+ verbose: verbose
507
+ });
508
+ }
509
+ }
510
+
511
+ const JobExecInk = inked(async function*({ job, verbose }) {
512
+ const scheduler = await inject$(SCHEDULER);
513
+ yield /*#__PURE__*/ jsx(WorkloadTreeSpinner, {
514
+ workload: job,
515
+ verbose: verbose
516
+ });
517
+ scheduler.register(job);
518
+ const outcome = await waitFor$(pipe$(job.state$, filter$(isWorkloadEnded)));
519
+ yield /*#__PURE__*/ jsx(WorkloadTreeCompleted, {
520
+ workload: job,
521
+ verbose: verbose
522
+ });
523
+ if (outcome !== WorkloadState.Succeeded) {
524
+ process.exitCode = 1;
525
+ }
526
+ });
527
+
528
+ export { JobExecInk as default };
529
+ //# sourceMappingURL=job-exec.ink.js.map