Skip to content

Commit

Permalink
Allow setting raw per command when using the API (#411)
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Jufer <[email protected]>
  • Loading branch information
chbiel and paescuj authored May 21, 2023
1 parent a0dcbd9 commit 655d9fd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ For more details, visit https://github.com/open-cli-tools/concurrently
Prefix colors specified per-command take precedence over this list.
- `prefixLength`: how many characters to show when prefixing with `command`. Default: `10`
- `raw`: whether raw mode should be used, meaning strictly process output will
be logged, without any prefixes, coloring or extra stuff.
be logged, without any prefixes, coloring or extra stuff. Can be overriden per command.
- `successCondition`: the condition to consider the run was successful.
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.
Anything else means all processes should exit successfully.
Expand Down
5 changes: 5 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export interface CommandInfo {
* Color to use on prefix of the command.
*/
prefixColor?: string;

/**
* Output command in raw format.
*/
raw?: boolean;
}

export interface CloseEvent {
Expand Down
40 changes: 40 additions & 0 deletions src/concurrently.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,46 @@ it('uses overridden cwd option for each command if specified', () => {
);
});

it('uses raw from options for each command', () => {
create([{ command: 'echo' }, 'kill'], {
raw: true,
});

expect(spawn).toHaveBeenCalledTimes(2);
expect(spawn).toHaveBeenCalledWith(
'echo',
expect.objectContaining({
stdio: 'inherit',
})
);
expect(spawn).toHaveBeenCalledWith(
'kill',
expect.objectContaining({
stdio: 'inherit',
})
);
});

it('uses overridden raw option for each command if specified', () => {
create([{ command: 'echo', raw: false }, { command: 'echo' }], {
raw: true,
});

expect(spawn).toHaveBeenCalledTimes(2);
expect(spawn).toHaveBeenCalledWith(
'echo',
expect.not.objectContaining({
stdio: expect.anything(),
})
);
expect(spawn).toHaveBeenCalledWith(
'echo',
expect.objectContaining({
stdio: 'inherit',
})
);
});

it('argument placeholders are properly replaced when additional arguments are passed', () => {
create(
[
Expand Down
7 changes: 6 additions & 1 deletion src/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function concurrently(
...command,
},
getSpawnOpts({
raw: options.raw,
raw: command.raw ?? options.raw,
env: command.env,
cwd: command.cwd || options.cwd,
}),
Expand Down Expand Up @@ -235,6 +235,11 @@ function mapToCommandInfo(command: ConcurrentlyCommandInput): CommandInfo {
prefixColor: command.prefixColor,
}
: {}),
...(command.raw !== undefined
? {
raw: command.raw,
}
: {}),
};
}

Expand Down

0 comments on commit 655d9fd

Please sign in to comment.