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 5d7adcf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 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
14 changes: 5 additions & 9 deletions src/command-parser/expand-npm-wildcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ module.exports = class ExpandNpmWildcard {
const postWildcard = _.escapeRegExp(cmdName.substr(wildcardPosition + 1));
const wildcardRegex = new RegExp(`^${preWildcard}(.*?)${postWildcard}$`);

let prefixColor;
return this.scripts
.filter(script => wildcardRegex.test(script))
.map((script, index) => {
prefixColor = (commandInfo.prefixColors && commandInfo.prefixColors[index] || commandInfo.prefixColor) || prefixColor;
return Object.assign({}, commandInfo, {
command: `${npmCmd} run ${script}${args}`,
name: script,
prefixColor
});
});
.map(script => Object.assign({}, commandInfo, {
command: `${npmCmd} run ${script}${args}`,
name: script,
prefixColor
}));
}
};
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 5d7adcf

Please sign in to comment.