Skip to content

Commit

Permalink
fix: use strip-ansi module instead of internal regex (#6823)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored Sep 20, 2023
1 parent 03912db commit 2207628
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 23 deletions.
1 change: 1 addition & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ graph LR;
npm-->sigstore-tuf["@sigstore/tuf"];
npm-->spawk;
npm-->ssri;
npm-->strip-ansi;
npm-->supports-color;
npm-->tap;
npm-->tar;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const npa = require('npm-package-arg')
const pickManifest = require('npm-pick-manifest')
const localeCompare = require('@isaacs/string-locale-compare')('en')

const ansiTrim = require('../utils/ansi-trim.js')
const ansiTrim = require('strip-ansi')
const ArboristWorkspaceCmd = require('../arborist-cmd.js')

class Outdated extends ArboristWorkspaceCmd {
Expand Down
3 changes: 0 additions & 3 deletions lib/utils/ansi-trim.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/utils/format-search-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Minipass } = require('minipass')
const columnify = require('columnify')
const ansiTrim = require('../utils/ansi-trim.js')
const ansiTrim = require('strip-ansi')

// This module consumes package data in the following format:
//
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"read",
"semver",
"ssri",
"strip-ansi",
"supports-color",
"tar",
"text-table",
Expand Down Expand Up @@ -146,6 +147,7 @@
"read": "^2.1.0",
"semver": "^7.5.4",
"ssri": "^10.0.5",
"strip-ansi": "^6.0.1",
"supports-color": "^9.4.0",
"tar": "^6.1.15",
"text-table": "~0.2.0",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"read": "^2.1.0",
"semver": "^7.5.4",
"ssri": "^10.0.5",
"strip-ansi": "^6.0.1",
"supports-color": "^9.4.0",
"tar": "^6.1.15",
"text-table": "~0.2.0",
Expand Down Expand Up @@ -181,6 +182,7 @@
"read",
"semver",
"ssri",
"strip-ansi",
"supports-color",
"tar",
"text-table",
Expand Down
14 changes: 7 additions & 7 deletions tap-snapshots/test/lib/commands/search.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NAME | DESCRIPTION | AUTHOR | DATE
libnpmhook | programmatic API… | =nlf… | 2020-11-03 | 6.0.1 | npm hooks registry npm api
libnpmpublish | Programmatic API… | =nlf… | 2020-11-03 | 4.0.0 |
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli [31mlibnpm[0m cli workspaces map-workspaces
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm bad map npmcli [31mlibnpm[0m cli workspaces map-workspaces
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 |
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
Expand All @@ -39,7 +39,7 @@ NAME | DESCRIPTION | AUTHOR | DATE
libnpmhook | programmatic API… | =nlf… | 2020-11-03 | 6.0.1 | npm hooks registry npm api
libnpmpublish | Programmatic API… | =nlf… | 2020-11-03 | 4.0.0 | 
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli [31mlibnpm[0m cli workspaces map-workspaces[31m[0m
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm bad map npmcli [31mlibnpm[0m cli workspaces map-workspaces[31m[0m
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 | 
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 | 
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 | 
Expand All @@ -56,7 +56,7 @@ libnpmteam npm Team management APIs =nlf =ruyadorno =darcyclarke =isaacs 2020-11
libnpmhook programmatic API for managing npm registry hooks =nlf =ruyadorno =darcyclarke =isaacs 2020-11-03 6.0.1 npm hooks registry npm api
libnpmpublish Programmatic API for the bits behind npm publish and unpublish =nlf =ruyadorno =darcyclarke =isaacs 2020-11-03 4.0.0
libnpmfund Programmatic API for npm fund =nlf =ruyadorno =darcyclarke =isaacs 2020-12-08 1.0.2 npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces Retrieves a name:pathname Map for a given workspaces config =nlf =ruyadorno =darcyclarke =isaacs 2020-09-30 1.0.1 npm npmcli libnpm cli workspaces map-workspaces
@npmcli/map-workspaces Retrieves a name:pathname Map for a given workspaces config =nlf =ruyadorno =darcyclarke =isaacs 2020-09-30 1.0.1 npm bad map npmcli libnpm cli workspaces map-workspaces
libnpmversion library to do the things that 'npm version' does =nlf =ruyadorno =darcyclarke =isaacs 2020-11-04 1.0.7
@types/libnpmsearch TypeScript definitions for libnpmsearch =types 2019-09-26 2.0.1
pkg-no-desc =lukekarrys 2019-09-26 1.0.0
Expand All @@ -80,7 +80,7 @@ libnpmteam | npm Team management… | =nlf… | 2020-11
libnpmhook | programmatic API… | =nlf… | 2020-11-03 | 6.0.1 | npm hooks registry npm api
libnpmpublish | Programmatic API… | =nlf… | 2020-11-03 | 4.0.0 |
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm bad map npmcli libnpm cli workspaces map-workspaces
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 |
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
Expand All @@ -98,7 +98,7 @@ libnpmteam | npm Team management… | =nlf… | 2020-11
libnpmhook | programmatic API… | =nlf… | 2020-11-03 | 6.0.1 | npm hooks registry npm api
libnpmpublish | Programmatic API… | =nlf… | 2020-11-03 | 4.0.0 |
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm bad map npmcli libnpm cli workspaces map-workspaces
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`
Expand All @@ -115,7 +115,7 @@ libnpmteam | npm Team management… | =nlf… | 2020-11
libnpmhook | programmatic API… | =nlf… | 2020-11-03 | 6.0.1 | npm hooks registry npm api
libnpmpublish | Programmatic API… | =nlf… | 2020-11-03 | 4.0.0 |
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm bad map npmcli libnpm cli workspaces map-workspaces
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`
Expand All @@ -132,7 +132,7 @@ libnpmteam | npm Team management… | =nlf… | 2020-11
libnpmhook | programmatic API… | =nlf… | 2020-11-03 | 6.0.1 | npm hooks registry npm api
libnpmpublish | Programmatic API… | =nlf… | 2020-11-03 | 4.0.0 |
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm bad map npmcli libnpm cli workspaces map-workspaces
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/libnpmsearch-stream-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ module.exports = [
description: 'Retrieves a name:pathname Map for a given workspaces config',
keywords: [
'\x1B[33mnpm\x1B[39m',
// eslint-disable-next-line no-octal-escape
'\x1b]4;0;?\007',
'\u001b[Hbad map',
'npmcli',
'libnpm',
'cli',
Expand Down
4 changes: 2 additions & 2 deletions test/lib/commands/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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 out = require('../../../lib/utils/ansi-trim')(outputs[1][0])
const out = require('strip-ansi')(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')
Expand Down Expand Up @@ -292,7 +292,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 out = require('../../../lib/utils/ansi-trim')(outputs[1][0])
const out = require('strip-ansi')(outputs[1][0])
t.match(out, /semver.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints package hook')
})

Expand Down
2 changes: 1 addition & 1 deletion test/lib/commands/org.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = require('tap')
const ansiTrim = require('../../../lib/utils/ansi-trim.js')
const ansiTrim = require('strip-ansi')
const mockNpm = require('../../fixtures/mock-npm')

const mockOrg = async (t, { orgSize = 1, orgList = {}, ...npmOpts } = {}) => {
Expand Down
8 changes: 0 additions & 8 deletions test/lib/utils/ansi-trim.js

This file was deleted.

0 comments on commit 2207628

Please sign in to comment.