From 5a4f2bcd607ca4c35cc03188b12b9518937845c5 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 18 Jan 2024 12:54:29 -0800 Subject: [PATCH] fix: use util.stripVTControlCharacters instead of strip-ansi --- lib/commands/outdated.js | 8 ++++---- lib/commands/search.js | 3 +-- lib/utils/format-search-stream.js | 19 +++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/commands/outdated.js b/lib/commands/outdated.js index 9b9283e497727..4216f1cdb1437 100644 --- a/lib/commands/outdated.js +++ b/lib/commands/outdated.js @@ -1,5 +1,6 @@ -const os = require('os') -const { resolve } = require('path') +const os = require('node:os') +const { resolve } = require('node:path') +const { stripVTControlCharacters } = require('node:util') const pacote = require('pacote') const table = require('text-table') const npa = require('npm-package-arg') @@ -22,7 +23,6 @@ class Outdated extends ArboristWorkspaceCmd { ] async exec (args) { - const { default: stripAnsi } = await import('strip-ansi') const global = resolve(this.npm.globalDir, '..') const where = this.npm.global ? global @@ -106,7 +106,7 @@ class Outdated extends ArboristWorkspaceCmd { const tableOpts = { align: ['l', 'r', 'r', 'r', 'l'], - stringLength: s => stripAnsi(s).length, + stringLength: s => stripVTControlCharacters(s).length, } this.npm.output(table(outTable, tableOpts)) } diff --git a/lib/commands/search.js b/lib/commands/search.js index 2af4daa211dca..f4a4ce3249142 100644 --- a/lib/commands/search.js +++ b/lib/commands/search.js @@ -81,12 +81,11 @@ class Search extends BaseCommand { const filterStream = new FilterStream() - const { default: stripAnsi } = await import('strip-ansi') // Grab a configured output stream that will spit out packages in the desired format. const outputStream = await formatSearchStream({ args, // --searchinclude options are not highlighted ...opts, - }, stripAnsi) + }) log.silly('search', 'searching packages') const p = new Pipeline( diff --git a/lib/utils/format-search-stream.js b/lib/utils/format-search-stream.js index cb29151e7c2e7..046a4b1e20587 100644 --- a/lib/utils/format-search-stream.js +++ b/lib/utils/format-search-stream.js @@ -1,3 +1,4 @@ +const { stripVTControlCharacters } = require('node:util') const { Minipass } = require('minipass') const columnify = require('columnify') @@ -15,8 +16,8 @@ const columnify = require('columnify') // The returned stream will format this package data // into a byte stream of formatted, displayable output. -module.exports = async (opts, clean) => { - return opts.json ? new JSONOutputStream() : new TextOutputStream(opts, clean) +module.exports = async (opts) => { + return opts.json ? new JSONOutputStream() : new TextOutputStream(opts) } class JSONOutputStream extends Minipass { @@ -40,13 +41,11 @@ class JSONOutputStream extends Minipass { } class TextOutputStream extends Minipass { - #clean #opts #line = 0 - constructor (opts, clean) { + constructor (opts) { super() - this.#clean = clean this.#opts = opts } @@ -56,17 +55,17 @@ class TextOutputStream extends Minipass { #prettify (data) { const pkg = { - author: data.maintainers.map((m) => `=${this.#clean(m.username)}`).join(' '), + author: data.maintainers.map((m) => `=${stripVTControlCharacters(m.username)}`).join(' '), date: 'prehistoric', - description: this.#clean(data.description ?? ''), + description: stripVTControlCharacters(data.description ?? ''), keywords: '', - name: this.#clean(data.name), + name: stripVTControlCharacters(data.name), version: data.version, } if (Array.isArray(data.keywords)) { - pkg.keywords = data.keywords.map((k) => this.#clean(k)).join(' ') + pkg.keywords = data.keywords.map((k) => stripVTControlCharacters(k)).join(' ') } else if (typeof data.keywords === 'string') { - pkg.keywords = this.#clean(data.keywords.replace(/[,\s]+/, ' ')) + pkg.keywords = stripVTControlCharacters(data.keywords.replace(/[,\s]+/, ' ')) } if (data.date) { pkg.date = data.date.toISOString().split('T')[0] // remove time