Skip to content

Commit

Permalink
fix: use ansis
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 17, 2024
1 parent 7000ad6 commit e488ab7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -59,6 +60,7 @@ function makeLoadOptions(loadOpts?: Interfaces.LoadOptions): Interfaces.LoadOpti
*/
export async function captureOutput<T>(fn: () => Promise<unknown>, opts?: CaptureOptions): Promise<CaptureResult<T>> {
const print = opts?.print ?? false
const stripAnsi = opts?.stripAnsi ?? true

const originals = {
NODE_ENV: process.env.NODE_ENV,
Expand All @@ -71,8 +73,7 @@ export async function captureOutput<T>(fn: () => Promise<unknown>, 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('')

Expand Down
3 changes: 1 addition & 2 deletions test/capture-output.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit e488ab7

Please sign in to comment.