Skip to content

Commit d4ebfba

Browse files
committed
fix: use util.stripVTControlCharacters instead of strip-ansi
1 parent 0d96080 commit d4ebfba

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

Diff for: lib/commands/outdated.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const os = require('os')
2-
const { resolve } = require('path')
1+
const os = require('node:os')
2+
const { resolve } = require('node:path')
3+
const { stripVTControlCharacters } = require('node:util')
34
const pacote = require('pacote')
45
const table = require('text-table')
56
const npa = require('npm-package-arg')
@@ -22,7 +23,6 @@ class Outdated extends ArboristWorkspaceCmd {
2223
]
2324

2425
async exec (args) {
25-
const { default: stripAnsi } = await import('strip-ansi')
2626
const global = resolve(this.npm.globalDir, '..')
2727
const where = this.npm.global
2828
? global
@@ -106,7 +106,7 @@ class Outdated extends ArboristWorkspaceCmd {
106106

107107
const tableOpts = {
108108
align: ['l', 'r', 'r', 'r', 'l'],
109-
stringLength: s => stripAnsi(s).length,
109+
stringLength: s => stripVTControlCharacters(s).length,
110110
}
111111
this.npm.output(table(outTable, tableOpts))
112112
}

Diff for: lib/commands/search.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ class Search extends BaseCommand {
8181

8282
const filterStream = new FilterStream()
8383

84-
const { default: stripAnsi } = await import('strip-ansi')
8584
// Grab a configured output stream that will spit out packages in the desired format.
8685
const outputStream = await formatSearchStream({
8786
args, // --searchinclude options are not highlighted
8887
...opts,
89-
}, stripAnsi)
88+
})
9089

9190
log.silly('search', 'searching packages')
9291
const p = new Pipeline(

Diff for: lib/utils/format-search-stream.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { stripVTControlCharacters } = require('node:util')
12
const { Minipass } = require('minipass')
23
const columnify = require('columnify')
34

@@ -15,8 +16,8 @@ const columnify = require('columnify')
1516
// The returned stream will format this package data
1617
// into a byte stream of formatted, displayable output.
1718

18-
module.exports = async (opts, clean) => {
19-
return opts.json ? new JSONOutputStream() : new TextOutputStream(opts, clean)
19+
module.exports = async (opts) => {
20+
return opts.json ? new JSONOutputStream() : new TextOutputStream(opts)
2021
}
2122

2223
class JSONOutputStream extends Minipass {
@@ -40,13 +41,11 @@ class JSONOutputStream extends Minipass {
4041
}
4142

4243
class TextOutputStream extends Minipass {
43-
#clean
4444
#opts
4545
#line = 0
4646

47-
constructor (opts, clean) {
47+
constructor (opts) {
4848
super()
49-
this.#clean = clean
5049
this.#opts = opts
5150
}
5251

@@ -56,17 +55,17 @@ class TextOutputStream extends Minipass {
5655

5756
#prettify (data) {
5857
const pkg = {
59-
author: data.maintainers.map((m) => `=${this.#clean(m.username)}`).join(' '),
58+
author: data.maintainers.map((m) => `=${stripVTControlCharacters(m.username)}`).join(' '),
6059
date: 'prehistoric',
61-
description: this.#clean(data.description ?? ''),
60+
description: stripVTControlCharacters(data.description ?? ''),
6261
keywords: '',
63-
name: this.#clean(data.name),
62+
name: stripVTControlCharacters(data.name),
6463
version: data.version,
6564
}
6665
if (Array.isArray(data.keywords)) {
67-
pkg.keywords = data.keywords.map((k) => this.#clean(k)).join(' ')
66+
pkg.keywords = data.keywords.map((k) => stripVTControlCharacters(k)).join(' ')
6867
} else if (typeof data.keywords === 'string') {
69-
pkg.keywords = this.#clean(data.keywords.replace(/[,\s]+/, ' '))
68+
pkg.keywords = stripVTControlCharacters(data.keywords.replace(/[,\s]+/, ' '))
7069
}
7170
if (data.date) {
7271
pkg.date = data.date.toISOString().split('T')[0] // remove time

0 commit comments

Comments
 (0)