diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 4414b66e9c66d..78fc8a9c457ca 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -557,7 +557,6 @@ graph LR; npm-->spawk; npm-->spdx-expression-parse; npm-->ssri; - npm-->strip-ansi; npm-->supports-color; npm-->tap; npm-->tar; 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 diff --git a/package-lock.json b/package-lock.json index 7da2f9e460fa5..a0cae4be64d6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,7 +70,6 @@ "semver", "spdx-expression-parse", "ssri", - "strip-ansi", "supports-color", "tar", "text-table", @@ -151,7 +150,6 @@ "semver": "^7.5.4", "spdx-expression-parse": "^3.0.1", "ssri": "^10.0.5", - "strip-ansi": "^7.1.0", "supports-color": "^9.4.0", "tar": "^6.2.0", "text-table": "~0.2.0", diff --git a/package.json b/package.json index ba379e92abe70..15cab8c704a1d 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,6 @@ "semver": "^7.5.4", "spdx-expression-parse": "^3.0.1", "ssri": "^10.0.5", - "strip-ansi": "^7.1.0", "supports-color": "^9.4.0", "tar": "^6.2.0", "text-table": "~0.2.0", @@ -186,7 +185,6 @@ "semver", "spdx-expression-parse", "ssri", - "strip-ansi", "supports-color", "tar", "text-table", diff --git a/test/lib/commands/hook.js b/test/lib/commands/hook.js index 448045cdd6916..382bc177e7001 100644 --- a/test/lib/commands/hook.js +++ b/test/lib/commands/hook.js @@ -1,5 +1,6 @@ const t = require('tap') const mockNpm = require('../../fixtures/mock-npm') +const { stripVTControlCharacters } = require('node:util') const mockHook = async (t, { hookResponse, ...npmOpts } = {}) => { const now = Date.now() @@ -243,8 +244,7 @@ t.test('npm hook ls', async t => { 'received the correct arguments' ) t.equal(outputs[0][0], 'You have 3 hooks configured.', 'prints the correct header') - const { default: stripAnsi } = await import('strip-ansi') - const out = stripAnsi(outputs[1][0]) + const out = stripVTControlCharacters(outputs[1][0]) t.match(out, /semver.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints package hook') t.match(out, /@npmcli.*https:\/\/google.com.*\n.*\n.*triggered just now/, 'prints scope hook') t.match(out, /~npm.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints owner hook') @@ -293,8 +293,7 @@ t.test('npm hook ls, single result', async t => { 'received the correct arguments' ) t.equal(outputs[0][0], 'You have one hook configured.', 'prints the correct header') - const { default: stripAnsi } = await import('strip-ansi') - const out = stripAnsi(outputs[1][0]) + const out = stripVTControlCharacters(outputs[1][0]) t.match(out, /semver.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints package hook') }) diff --git a/test/lib/commands/org.js b/test/lib/commands/org.js index ed8fb238c4b0d..0c343f028d6dc 100644 --- a/test/lib/commands/org.js +++ b/test/lib/commands/org.js @@ -1,5 +1,6 @@ const t = require('tap') const mockNpm = require('../../fixtures/mock-npm') +const { stripVTControlCharacters } = require('node:util') const mockOrg = async (t, { orgSize = 1, orgList = {}, ...npmOpts } = {}) => { let setArgs = null @@ -426,8 +427,7 @@ t.test('npm org ls', async t => { }, 'receieved the correct args' ) - const { default: stripAnsi } = await import('strip-ansi') - const out = stripAnsi(outputs[0][0]) + const out = stripVTControlCharacters(outputs[0][0]) t.match(out, /one.*developer/, 'contains the developer member') t.match(out, /two.*admin/, 'contains the admin member') t.match(out, /three.*owner/, 'contains the owner member') @@ -452,8 +452,7 @@ t.test('npm org ls - user filter', async t => { }, 'receieved the correct args' ) - const { default: stripAnsi } = await import('strip-ansi') - const out = stripAnsi(outputs[0][0]) + const out = stripVTControlCharacters(outputs[0][0]) t.match(out, /username.*admin/, 'contains the filtered member') t.notMatch(out, /missing.*admin/, 'does not contain other members') }) @@ -476,8 +475,7 @@ t.test('npm org ls - user filter, missing user', async t => { }, 'receieved the correct args' ) - const { default: stripAnsi } = await import('strip-ansi') - const out = stripAnsi(outputs[0][0]) + const out = stripVTControlCharacters(outputs[0][0]) t.notMatch(out, /username/, 'does not contain the requested member') t.notMatch(out, /missing.*admin/, 'does not contain other members') })