diff --git a/package.json b/package.json index 32cc031..6d42e09 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "author": "Salesforce", "bugs": "https://github.com/oclif/test/issues", "dependencies": { - "debug": "^4.3.4", - "strip-ansi": "^7.1.0" + "ansis": "^3.2.0", + "debug": "^4.3.4" }, "peerDependencies": { "@oclif/core": ">= 3.0.0" diff --git a/src/index.ts b/src/index.ts index d0ff4e4..9f33fb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import {Config, Errors, Interfaces, run} from '@oclif/core' +import ansis from 'ansis' import makeDebug from 'debug' import {dirname} from 'node:path' @@ -59,6 +60,7 @@ function makeLoadOptions(loadOpts?: Interfaces.LoadOptions): Interfaces.LoadOpti */ export async function captureOutput(fn: () => Promise, opts?: CaptureOptions): Promise> { const print = opts?.print ?? false + const stripAnsi = opts?.stripAnsi ?? true const originals = { NODE_ENV: process.env.NODE_ENV, @@ -71,8 +73,7 @@ export async function captureOutput(fn: () => Promise, opts?: Captur stdout: [], } - const {default: stripAnsi} = opts?.stripAnsi ?? true ? await import('strip-ansi') : {default: (str: string) => str} - const toString = (str: Uint8Array | string): string => stripAnsi(str.toString()) + const toString = (str: Uint8Array | string): string => (stripAnsi ? ansis.strip(str.toString()) : str.toString()) const getStderr = (): string => output.stderr.map((b) => toString(b)).join('') const getStdout = (): string => output.stdout.map((b) => toString(b)).join('') diff --git a/test/capture-output.test.ts b/test/capture-output.test.ts index 9e70501..504c8dd 100644 --- a/test/capture-output.test.ts +++ b/test/capture-output.test.ts @@ -1,10 +1,9 @@ import {Command, Errors, Flags} from '@oclif/core' +import {bold} from 'ansis' import {expect} from 'chai' import {captureOutput} from '../src' -const bold = (s: string) => `\u001B[1m${s}\u001B[22m` - class MyCommand extends Command { static flags = { channel: Flags.option({ diff --git a/yarn.lock b/yarn.lock index 1f9a3d0..a402f25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -690,7 +690,7 @@ ansi-styles@^6.0.0, ansi-styles@^6.2.1: resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5" integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== -ansis@^3.0.1: +ansis@^3.0.1, ansis@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ansis/-/ansis-3.2.0.tgz#0e050c5be94784f32ffdac4b84fccba064aeae4b" integrity sha512-Yk3BkHH9U7oPyCN3gL5Tc7CpahG/+UFv/6UG03C311Vy9lzRmA5uoxDTpU9CO3rGHL6KzJz/pdDeXZCZ5Mu/Sg==