Skip to content

Commit

Permalink
Merge e72e5bf into 23c3217
Browse files Browse the repository at this point in the history
  • Loading branch information
chbiel committed Mar 31, 2023
2 parents 23c3217 + e72e5bf commit b47c949
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 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
11 changes: 6 additions & 5 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 Expand Up @@ -97,9 +102,6 @@ export class Command implements CommandInfo {
/** @inheritdoc */
readonly env: Record<string, unknown>;

/** @inheritdoc */
readonly cwd?: string;

readonly close = new Rx.Subject<CloseEvent>();
readonly error = new Rx.Subject<unknown>();
readonly stdout = new Rx.Subject<Buffer>();
Expand All @@ -118,7 +120,7 @@ export class Command implements CommandInfo {
}

constructor(
{ index, name, command, prefixColor, env, cwd }: CommandInfo & { index: number },
{ index, name, command, prefixColor, env }: CommandInfo & { index: number },
spawnOpts: SpawnOptions,
spawn: SpawnCommand,
killProcess: KillProcess
Expand All @@ -128,7 +130,6 @@ export class Command implements CommandInfo {
this.command = command;
this.prefixColor = prefixColor;
this.env = env || {};
this.cwd = cwd;
this.killProcess = killProcess;
this.spawn = spawn;
this.spawnOpts = spawnOpts;
Expand Down
56 changes: 56 additions & 0 deletions src/concurrently.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,62 @@ it('uses overridden cwd option for each command if specified', () => {
);
});

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

expect(spawn).toHaveBeenCalledTimes(3);
expect(spawn).toHaveBeenCalledWith(
'echo',
expect.objectContaining({
env: expect.objectContaining({ foo: 'bar' }),
stdio: 'inherit',
})
);
expect(spawn).toHaveBeenCalledWith(
'echo',
expect.objectContaining({
env: expect.objectContaining({ foo: 'baz' }),
stdio: 'inherit',
})
);
expect(spawn).toHaveBeenCalledWith(
'kill',
expect.objectContaining({
env: expect.not.objectContaining({ foo: expect.anything() }),
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 !== undefined ? 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 b47c949

Please sign in to comment.