Skip to content

Commit 523a3fe

Browse files
committed
Provide commands hide state to getSpawnOpts()
1 parent 51b9638 commit 523a3fe

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

bin/concurrently.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ describe('--hide', () => {
234234
expect(lines).toContainEqual(expect.stringContaining('foo'));
235235
expect(lines).not.toContainEqual(expect.stringContaining('bar'));
236236
});
237+
238+
it('hides the output of a process by its index in raw mode', async () => {
239+
const lines = await run('--hide 1 --raw "echo foo" "echo bar"').getLogLines();
240+
241+
expect(lines).toHaveLength(1);
242+
expect(lines).toContainEqual(expect.stringContaining('foo'));
243+
expect(lines).not.toContainEqual(expect.stringContaining('bar'));
244+
});
245+
246+
it('hides the output of a process by its name in raw mode', async () => {
247+
const lines = await run('-n foo,bar --hide bar --raw "echo foo" "echo bar"').getLogLines();
248+
249+
expect(lines).toHaveLength(1);
250+
expect(lines).toContainEqual(expect.stringContaining('foo'));
251+
expect(lines).not.toContainEqual(expect.stringContaining('bar'));
252+
});
237253
});
238254

239255
describe('--group', () => {

src/concurrently.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { cpus } from 'os';
44
import { Writable } from 'stream';
55
import treeKill from 'tree-kill';
66

7-
import { CloseEvent, Command, CommandInfo, KillProcess, SpawnCommand } from './command';
7+
import {
8+
CloseEvent,
9+
Command,
10+
CommandIdentifier,
11+
CommandInfo,
12+
KillProcess,
13+
SpawnCommand,
14+
} from './command';
815
import { CommandParser } from './command-parser/command-parser';
916
import { ExpandArguments } from './command-parser/expand-arguments';
1017
import { ExpandNpmShortcut } from './command-parser/expand-npm-shortcut';
@@ -94,6 +101,11 @@ export type ConcurrentlyOptions = {
94101
*/
95102
raw?: boolean;
96103

104+
/**
105+
* Which command(s) should have their output hidden.
106+
*/
107+
hide?: CommandIdentifier | CommandIdentifier[];
108+
97109
/**
98110
* The current working directory of commands which didn't specify one.
99111
* Defaults to `process.cwd()`.
@@ -169,6 +181,13 @@ export function concurrently(
169181
commandParsers.push(new ExpandArguments(options.additionalArguments));
170182
}
171183

184+
// To avoid empty strings from hiding the output of commands that don't have a name,
185+
// keep in the list of commands to hide only strings with some length.
186+
// This might happen through the CLI when no `--hide` argument is specified, for example.
187+
const hide = _.castArray(options.hide)
188+
.filter((name) => name || name === 0)
189+
.map(String);
190+
172191
let commands = _(baseCommands)
173192
.map(mapToCommandInfo)
174193
.flatMap((command) => parseCommand(command, commandParsers))
@@ -183,6 +202,7 @@ export function concurrently(
183202
raw: command.raw ?? options.raw,
184203
env: command.env,
185204
cwd: command.cwd || options.cwd,
205+
hide: hide.includes(String(index)) || hide.includes(command.name),
186206
}),
187207
options.spawn,
188208
options.kill,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export function concurrently(
110110
raw: options.raw,
111111
successCondition: options.successCondition,
112112
cwd: options.cwd,
113+
hide: options.hide,
113114
logger,
114115
outputStream: options.outputStream || process.stdout,
115116
group: options.group,

0 commit comments

Comments
 (0)