Skip to content

Commit 5421710

Browse files
authored
chore(deps): replace strip-ansi with native Node API (#6307)
1 parent 9b8e021 commit 5421710

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

packages/cspell/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
"file-entry-cache": "^9.1.0",
100100
"get-stdin": "^9.0.0",
101101
"semver": "^7.6.3",
102-
"strip-ansi": "^7.1.0",
103102
"tinyglobby": "^0.2.9"
104103
},
105104
"engines": {

packages/cspell/src/app/app.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as Util from 'node:util';
66
import { toFileDirURL } from '@cspell/url';
77
import chalk from 'chalk';
88
import * as Commander from 'commander';
9-
import stripAnsi from 'strip-ansi';
109
import { afterEach, beforeEach, type Constructable, describe, expect, test, vi } from 'vitest';
1110

1211
import * as app from './app.mjs';
@@ -393,7 +392,7 @@ function makeLogger() {
393392

394393
function normalizedHistory() {
395394
let t = history.map((a) => a.replaceAll('\u001B[2K', '').trimEnd()).join('\n');
396-
t = stripAnsi(t);
395+
t = Util.stripVTControlCharacters(t);
397396
t = t.replaceAll('\r', '');
398397
t = t.replace(RegExp(escapeRegExp(projectRootUri.toString()), 'gi'), '.');
399398
t = t.replace(RegExp(escapeRegExp(projectRoot), 'gi'), '.');

packages/cspell/src/app/emitters/traceEmitter.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { posix, win32 } from 'node:path';
2+
import { stripVTControlCharacters } from 'node:util';
23

3-
import strip from 'strip-ansi';
44
import { describe, expect, test, vi } from 'vitest';
55

66
import type { TraceResult } from '../application.mjs';
@@ -17,7 +17,7 @@ describe('traceEmitter', () => {
1717
dictionaryPathFormat: 'long',
1818
iPath: posix,
1919
});
20-
expect(strip(report.table)).toEqual('Word F Dictionary Dictionary Location');
20+
expect(stripVTControlCharacters(report.table)).toEqual('Word F Dictionary Dictionary Location');
2121
});
2222

2323
test('posix format long', () => {
@@ -28,7 +28,7 @@ describe('traceEmitter', () => {
2828
dictionaryPathFormat: 'long',
2929
iPath: posix,
3030
});
31-
const lines = report.table.split('\n').map(strip);
31+
const lines = report.table.split('\n').map(stripVTControlCharacters);
3232
expect(lines.reduce((a, b) => Math.max(a, b.length), 0)).toBeLessThanOrEqual(lineWidth);
3333
const output = lines.join('\n');
3434
expect(output).toEqual(`\
@@ -42,7 +42,7 @@ errorcode - softwareTerms* node_modules/@cspell/.../dict/softwareTerms.txt`)
4242

4343
test('posix format short', () => {
4444
const consoleLines: string[] = [];
45-
vi.spyOn(console, 'log').mockImplementation((a) => consoleLines.push(strip(a)));
45+
vi.spyOn(console, 'log').mockImplementation((a) => consoleLines.push(stripVTControlCharacters(a)));
4646
const lineWidth = 80;
4747
emitTraceResults('errorcode', true, sampleResults(), {
4848
cwd: '/this_is_a_very/long/path',
@@ -64,7 +64,7 @@ errorcode - softwareTerms* node_modules/@cspell/.../dict/softwareTerms.txt`)
6464

6565
test('win32 format long', () => {
6666
const consoleLines: string[] = [];
67-
vi.spyOn(console, 'log').mockImplementation((a) => consoleLines.push(strip(a)));
67+
vi.spyOn(console, 'log').mockImplementation((a) => consoleLines.push(stripVTControlCharacters(a)));
6868
const lineWidth = 80;
6969
emitTraceResults('errorcode', true, sampleResultsWin32(), {
7070
cwd: 'D:/this_is_a_very/long/path',
@@ -88,7 +88,7 @@ errorcode - softwareTerms* node_modules/@cspell/.../dict/softwareTerms.txt`)
8888

8989
test('win32 format full', () => {
9090
const lines: string[] = [];
91-
vi.spyOn(console, 'log').mockImplementation((a) => lines.push(strip(a)));
91+
vi.spyOn(console, 'log').mockImplementation((a) => lines.push(stripVTControlCharacters(a)));
9292
const lineWidth = 80;
9393
emitTraceResults('errorcode', true, sampleResultsWin32(), {
9494
cwd: 'D:/this_is_a_very/long/path',

packages/cspell/src/app/util/pad.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import strip from 'strip-ansi';
1+
import { stripVTControlCharacters } from "node:util";
22

33
export function pad(s: string, w: number): string {
44
const p = padWidth(s, w);
@@ -28,5 +28,5 @@ export function width(s: string): number {
2828
}
2929

3030
export function ansiWidth(s: string): number {
31-
return width(strip(s));
31+
return width(stripVTControlCharacters(s));
3232
}

packages/cspell/src/app/util/table.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import strip from 'strip-ansi';
1+
import { stripVTControlCharacters } from 'node:util';
2+
23
import { describe, expect, test } from 'vitest';
34

45
import type { Table } from './table.js';
@@ -15,7 +16,7 @@ describe('Validate table.ts', () => {
1516
],
1617
};
1718
const x = tableToLines(table);
18-
expect(x.map(strip)).toEqual([
19+
expect(x.map(stripVTControlCharacters)).toEqual([
1920
'id | name ',
2021
'27438 | Computer',
2122
'273438 | Desk ',

pnpm-lock.yaml

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)