From de83f1baef9934d612a70edb8e55443e718870ea Mon Sep 17 00:00:00 2001 From: Ben Meyrick Date: Thu, 3 Oct 2024 13:12:26 +0100 Subject: [PATCH] Custom strip ansi and chalk (#25) * use custom strip-ansi function * strip-ansi and chalk --- src/concurrently.ts | 6 +++--- src/strip-ansi-and-chalk.ts | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/strip-ansi-and-chalk.ts diff --git a/src/concurrently.ts b/src/concurrently.ts index 85217e9..ec2f90b 100644 --- a/src/concurrently.ts +++ b/src/concurrently.ts @@ -3,7 +3,7 @@ import { ConcurrentCommand } from './command'; import { getName } from './get-name'; import { logError } from './log-error'; import { runCommand } from './run-command'; -import { stripAnsi } from './strip-ansi'; +import { stripAnsiAndChalk } from './strip-ansi-and-chalk'; import { WaitCondition } from './wait-condition'; /** @@ -46,7 +46,7 @@ export function concurrently(commands: ConcurrentCommand[], index = 0): void { } case WaitCondition.Includes: { runCommand(command.command, index, name, command.longestName, message => { - if (!conditionMet && stripAnsi(message).toLowerCase().includes(command.value!.toLowerCase())) { + if (!conditionMet && stripAnsiAndChalk(message).toLowerCase().includes(command.value!.toLowerCase())) { conditionMet = true; concurrently(commands, nextIndex); @@ -64,7 +64,7 @@ export function concurrently(commands: ConcurrentCommand[], index = 0): void { } case WaitCondition.Matches: { runCommand(command.command, index, name, command.longestName, message => { - if (!conditionMet && stripAnsi(message) === command.value) { + if (!conditionMet && stripAnsiAndChalk(message) === command.value) { conditionMet = true; concurrently(commands, nextIndex); diff --git a/src/strip-ansi-and-chalk.ts b/src/strip-ansi-and-chalk.ts new file mode 100644 index 0000000..34cba6d --- /dev/null +++ b/src/strip-ansi-and-chalk.ts @@ -0,0 +1,5 @@ +import stripAnsi from 'strip-ansi'; + +export function stripAnsiAndChalk(value: string): string { + return stripAnsi(value).replace(/\u001b[^m]*?m/g, ''); +}