Skip to content

Commit 655d9fd

Browse files
chbielpaescuj
andauthored
Allow setting raw per command when using the API (#411)
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
1 parent a0dcbd9 commit 655d9fd

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ For more details, visit https://github.com/open-cli-tools/concurrently
340340
Prefix colors specified per-command take precedence over this list.
341341
- `prefixLength`: how many characters to show when prefixing with `command`. Default: `10`
342342
- `raw`: whether raw mode should be used, meaning strictly process output will
343-
be logged, without any prefixes, coloring or extra stuff.
343+
be logged, without any prefixes, coloring or extra stuff. Can be overriden per command.
344344
- `successCondition`: the condition to consider the run was successful.
345345
If `first`, only the first process to exit will make up the success of the run; if `last`, the last process that exits will determine whether the run succeeds.
346346
Anything else means all processes should exit successfully.

src/command.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export interface CommandInfo {
3232
* Color to use on prefix of the command.
3333
*/
3434
prefixColor?: string;
35+
36+
/**
37+
* Output command in raw format.
38+
*/
39+
raw?: boolean;
3540
}
3641

3742
export interface CloseEvent {

src/concurrently.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,46 @@ it('uses overridden cwd option for each command if specified', () => {
253253
);
254254
});
255255

256+
it('uses raw from options for each command', () => {
257+
create([{ command: 'echo' }, 'kill'], {
258+
raw: true,
259+
});
260+
261+
expect(spawn).toHaveBeenCalledTimes(2);
262+
expect(spawn).toHaveBeenCalledWith(
263+
'echo',
264+
expect.objectContaining({
265+
stdio: 'inherit',
266+
})
267+
);
268+
expect(spawn).toHaveBeenCalledWith(
269+
'kill',
270+
expect.objectContaining({
271+
stdio: 'inherit',
272+
})
273+
);
274+
});
275+
276+
it('uses overridden raw option for each command if specified', () => {
277+
create([{ command: 'echo', raw: false }, { command: 'echo' }], {
278+
raw: true,
279+
});
280+
281+
expect(spawn).toHaveBeenCalledTimes(2);
282+
expect(spawn).toHaveBeenCalledWith(
283+
'echo',
284+
expect.not.objectContaining({
285+
stdio: expect.anything(),
286+
})
287+
);
288+
expect(spawn).toHaveBeenCalledWith(
289+
'echo',
290+
expect.objectContaining({
291+
stdio: 'inherit',
292+
})
293+
);
294+
});
295+
256296
it('argument placeholders are properly replaced when additional arguments are passed', () => {
257297
create(
258298
[

src/concurrently.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function concurrently(
162162
...command,
163163
},
164164
getSpawnOpts({
165-
raw: options.raw,
165+
raw: command.raw ?? options.raw,
166166
env: command.env,
167167
cwd: command.cwd || options.cwd,
168168
}),
@@ -235,6 +235,11 @@ function mapToCommandInfo(command: ConcurrentlyCommandInput): CommandInfo {
235235
prefixColor: command.prefixColor,
236236
}
237237
: {}),
238+
...(command.raw !== undefined
239+
? {
240+
raw: command.raw,
241+
}
242+
: {}),
238243
};
239244
}
240245

0 commit comments

Comments
 (0)