From 655d9fd6d1db9783249027fce9fb9a2aad07c480 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 22 May 2023 01:13:17 +0200 Subject: [PATCH] Allow setting `raw` per command when using the API (#411) Co-authored-by: Pascal Jufer --- README.md | 2 +- src/command.ts | 5 +++++ src/concurrently.spec.ts | 40 ++++++++++++++++++++++++++++++++++++++++ src/concurrently.ts | 7 ++++++- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e25f9419..b4fed234 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/command.ts b/src/command.ts index 17255f8b..920938a7 100644 --- a/src/command.ts +++ b/src/command.ts @@ -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 { diff --git a/src/concurrently.spec.ts b/src/concurrently.spec.ts index 726f9af3..86956237 100644 --- a/src/concurrently.spec.ts +++ b/src/concurrently.spec.ts @@ -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( [ diff --git a/src/concurrently.ts b/src/concurrently.ts index fbe832cb..ea3136a8 100644 --- a/src/concurrently.ts +++ b/src/concurrently.ts @@ -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, }), @@ -235,6 +235,11 @@ function mapToCommandInfo(command: ConcurrentlyCommandInput): CommandInfo { prefixColor: command.prefixColor, } : {}), + ...(command.raw !== undefined + ? { + raw: command.raw, + } + : {}), }; }