Skip to content

Commit c1f50e0

Browse files
committed
fix: sub task dependencies
1 parent b9b25db commit c1f50e0

File tree

3 files changed

+118
-50
lines changed

3 files changed

+118
-50
lines changed

src/components/taskListEntry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function TaskListEntry({ command: { keepOutput, forever, outputLength, di
3838
) : status === 'done' ? (
3939
<Text color="green">{statusIcons.done}</Text>
4040
) : (
41-
<Text color="red">{statusIcons.error}</Text>
41+
<Text color="red">{statusIcons[status]}</Text>
4242
)}
4343
<Text>&nbsp;</Text>
4444

src/task.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ export function task(command: RunpCommand, allTasks: () => Task[], q = createQue
2626
const fullCmd = [cmd, ...args].join(' ');
2727
const cwdDisplay =
2828
cwd && cwd !== process.cwd() ? (cwd.startsWith(process.cwd()) ? ` (./${cwd.slice(process.cwd().length + 1)})` : ` (${cwd})`) : '';
29+
30+
const subTasks: Task[] = command.subCommands?.map((subCommand) => task(subCommand, () => subTasks, q)) ?? [];
31+
2932
const state = createStore<TaskState>({
3033
status: 'pending',
3134
title: (name ?? fullCmd) + cwdDisplay,
3235
rawOutput: '',
3336
output: '',
34-
subTasks: command.subCommands?.map((subCommand) => task(subCommand, allTasks, q)) ?? [],
37+
subTasks,
3538
});
3639

3740
const result = new Promise<RunpResult>((resolve) => {
@@ -146,10 +149,10 @@ export function task(command: RunpCommand, allTasks: () => Task[], q = createQue
146149
if (delegationStart >= 0 && delegationEnd > delegationStart) {
147150
const json = rawOutput.slice(delegationStart + RUNP_TASK_DELEGATE.length, delegationEnd);
148151
const commands = JSON.parse(json) as RunpCommand[];
149-
const tasks: Task[] = commands.map((command) => task(command, () => tasks, q));
152+
const subTasks: Task[] = commands.map((command) => task(command, () => subTasks, q));
150153

151154
state.set('output', '');
152-
state.set('subTasks', (subTasks) => [...tasks, ...subTasks]);
155+
state.set('subTasks', (subTasks) => [...subTasks, ...subTasks]);
153156
}
154157

155158
resolve();
@@ -169,8 +172,6 @@ export function task(command: RunpCommand, allTasks: () => Task[], q = createQue
169172
state.set('status', 'done');
170173
} catch {
171174
state.set('status', 'error');
172-
// state.set('output', String(error));
173-
// writeLine(String(error), thisTask);
174175
} finally {
175176
state.set('time', performance.now() - start);
176177
}

test/subCommands.test.ts

Lines changed: 111 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,117 @@
1-
import { test } from 'vitest';
1+
import { describe, test } from 'vitest';
22
import { runp } from '../src';
33
import { TestTerminal } from './_helpers';
44

5-
test('subCommands', async ({ expect }) => {
6-
const term = new TestTerminal({ cols: 30, rows: 20 });
7-
8-
await runp({
9-
commands: [
10-
{
11-
name: 'command',
12-
subCommands: [
13-
{
14-
name: 'subCommand 1',
15-
cmd: 'echo',
16-
args: ['subCommand 1'],
17-
},
18-
'echo subCommand 2',
19-
],
20-
},
21-
],
22-
target: term,
23-
linearOutput: true,
5+
describe('subCommands', () => {
6+
test('success', async ({ expect }) => {
7+
const term = new TestTerminal({ cols: 30, rows: 20 });
8+
9+
await runp({
10+
commands: [
11+
{
12+
name: 'command',
13+
subCommands: [
14+
{
15+
name: 'subCommand 1',
16+
cmd: 'echo',
17+
args: ['subCommand 1'],
18+
},
19+
'echo subCommand 2',
20+
],
21+
},
22+
],
23+
target: term,
24+
linearOutput: true,
25+
});
26+
27+
expect(term.getBuffer()).toMatchInlineSnapshot(`
28+
[
29+
" ",
30+
"-- [subCommand 1] -> ",
31+
" ",
32+
"subCommand 1 ",
33+
" ",
34+
"<- [subCommand 1] -- ",
35+
" ",
36+
"-- [echo subCommand 2] -> ",
37+
" ",
38+
"subCommand 2 ",
39+
" ",
40+
"<- [echo subCommand 2] -- ",
41+
" ",
42+
"✓ command [#.###s] ",
43+
" ✓ subCommand 1 [#.###s] ",
44+
" ✓ echo subCommand 2 [#.###s]",
45+
" ",
46+
" ",
47+
" ",
48+
" ",
49+
]
50+
`);
2451
});
2552

26-
expect(term.getBuffer()).toMatchInlineSnapshot(`
27-
[
28-
" ",
29-
"-- [subCommand 1] -> ",
30-
" ",
31-
"subCommand 1 ",
32-
" ",
33-
"<- [subCommand 1] -- ",
34-
" ",
35-
"-- [echo subCommand 2] -> ",
36-
" ",
37-
"subCommand 2 ",
38-
" ",
39-
"<- [echo subCommand 2] -- ",
40-
" ",
41-
"✓ command [#.###s] ",
42-
" ✓ subCommand 1 [#.###s] ",
43-
" ✓ echo subCommand 2 [#.###s]",
44-
" ",
45-
" ",
46-
" ",
47-
" ",
48-
]
49-
`);
53+
test('parallel failure', async ({ expect }) => {
54+
const term = new TestTerminal({ cols: 30, rows: 15 });
55+
56+
await runp({
57+
commands: [
58+
{
59+
name: 'command',
60+
subCommands: ['exit 1', 'echo ok'],
61+
},
62+
],
63+
target: term,
64+
linearOutput: true,
65+
});
66+
67+
expect(term.getBuffer()).toMatchInlineSnapshot(`
68+
[
69+
" ",
70+
"-- [echo ok] -> ",
71+
" ",
72+
"ok ",
73+
" ",
74+
"<- [echo ok] -- ",
75+
" ",
76+
"✕ command [#.###s] ",
77+
" ✕ exit 1 [#.###s] ",
78+
" ✓ echo ok [#.###s] ",
79+
" ",
80+
" ",
81+
" ",
82+
" ",
83+
" ",
84+
]
85+
`);
86+
});
87+
88+
test('sequential failure', async ({ expect }) => {
89+
const term = new TestTerminal({ cols: 30, rows: 10 });
90+
91+
await runp({
92+
commands: [
93+
{
94+
name: 'command',
95+
subCommands: [':s', 'exit 1', 'echo ok'],
96+
},
97+
],
98+
target: term,
99+
linearOutput: true,
100+
});
101+
102+
expect(term.getBuffer()).toMatchInlineSnapshot(`
103+
[
104+
" ",
105+
"✕ command [#.###s] ",
106+
" ✕ exit 1 [#.###s] ",
107+
" ↳ echo ok ",
108+
" ",
109+
" ",
110+
" ",
111+
" ",
112+
" ",
113+
" ",
114+
]
115+
`);
116+
});
50117
});

0 commit comments

Comments
 (0)