Skip to content

Commit

Permalink
Fix color option for for wildcards and edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloraisi committed Sep 23, 2021
1 parent 5b0bd70 commit 31d6cc7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
16 changes: 7 additions & 9 deletions bin/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,11 @@ let lastColor;
concurrently(args._.map((command, index) => {
// Use documented behaviour of repeating last colour when specifying more commands than colours
lastColor = prefixColors[index] || lastColor;
return Object.assign({},
{
command,
prefixColor: lastColor,
name: names[index]
},
/^(npm|yarn|pnpm):(\S+)(.*)/.test(command) ? { prefixColors } : null
);
return {
command,
prefixColor: lastColor,
name: names[index]
};
}), {
handleInput: args.handleInput,
defaultInputTarget: args.defaultInputTarget,
Expand All @@ -172,7 +169,8 @@ concurrently(args._.map((command, index) => {
restartDelay: args.restartAfter,
restartTries: args.restartTries,
successCondition: args.success,
timestampFormat: args.timestampFormat
timestampFormat: args.timestampFormat,
prefixColors
}).then(
() => process.exit(0),
() => process.exit(1)
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module.exports = exports = (commands, options = {}) => {
logger,
conditions: options.killOthers
})
]
],
prefixColors: options.prefixColors || []
});
};

Expand Down
31 changes: 19 additions & 12 deletions src/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module.exports = (commands, options) => {
assert.ok(Array.isArray(commands), '[concurrently] commands should be an array');
assert.notStrictEqual(commands.length, 0, '[concurrently] no commands provided');

const prefixColors = options.prefixColors;

delete options.prefixColors;
options = _.defaults(options, defaults);

const commandParsers = [
Expand All @@ -32,21 +35,25 @@ module.exports = (commands, options) => {
new ExpandNpmWildcard()
];

let lastColor = undefined;
commands = _(commands)
.map(mapToCommandInfo)
.flatMap(command => parseCommand(command, commandParsers))
.map((command, index) => new Command(
Object.assign({
index,
spawnOpts: getSpawnOpts({
raw: options.raw,
env: command.env,
cwd: command.cwd || options.cwd,
}),
killProcess: options.kill,
spawn: options.spawn,
}, command)
))
.map((command, index) => {
lastColor = prefixColors && prefixColors[index] || lastColor;
return new Command(
Object.assign({
index,
spawnOpts: getSpawnOpts({
raw: options.raw,
env: command.env,
cwd: command.cwd || options.cwd,
}),
killProcess: options.kill,
spawn: options.spawn,
}, command, lastColor ? { prefixColor: lastColor } : null)
);
})
.value();

const handleResult = options.controllers.reduce(
Expand Down

0 comments on commit 31d6cc7

Please sign in to comment.