Skip to content

Commit

Permalink
chore(deps): replace strip-ansi with native Node API (#6307)
Browse files Browse the repository at this point in the history
  • Loading branch information
Namchee authored Oct 5, 2024
1 parent 9b8e021 commit 5421710
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"file-entry-cache": "^9.1.0",
"get-stdin": "^9.0.0",
"semver": "^7.6.3",
"strip-ansi": "^7.1.0",
"tinyglobby": "^0.2.9"
},
"engines": {
Expand Down
3 changes: 1 addition & 2 deletions packages/cspell/src/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as Util from 'node:util';
import { toFileDirURL } from '@cspell/url';
import chalk from 'chalk';
import * as Commander from 'commander';
import stripAnsi from 'strip-ansi';
import { afterEach, beforeEach, type Constructable, describe, expect, test, vi } from 'vitest';

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

function normalizedHistory() {
let t = history.map((a) => a.replaceAll('\u001B[2K', '').trimEnd()).join('\n');
t = stripAnsi(t);
t = Util.stripVTControlCharacters(t);
t = t.replaceAll('\r', '');
t = t.replace(RegExp(escapeRegExp(projectRootUri.toString()), 'gi'), '.');
t = t.replace(RegExp(escapeRegExp(projectRoot), 'gi'), '.');
Expand Down
12 changes: 6 additions & 6 deletions packages/cspell/src/app/emitters/traceEmitter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { posix, win32 } from 'node:path';
import { stripVTControlCharacters } from 'node:util';

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

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

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

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

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

test('win32 format full', () => {
const lines: string[] = [];
vi.spyOn(console, 'log').mockImplementation((a) => lines.push(strip(a)));
vi.spyOn(console, 'log').mockImplementation((a) => lines.push(stripVTControlCharacters(a)));
const lineWidth = 80;
emitTraceResults('errorcode', true, sampleResultsWin32(), {
cwd: 'D:/this_is_a_very/long/path',
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell/src/app/util/pad.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import strip from 'strip-ansi';
import { stripVTControlCharacters } from "node:util";

export function pad(s: string, w: number): string {
const p = padWidth(s, w);
Expand Down Expand Up @@ -28,5 +28,5 @@ export function width(s: string): number {
}

export function ansiWidth(s: string): number {
return width(strip(s));
return width(stripVTControlCharacters(s));
}
5 changes: 3 additions & 2 deletions packages/cspell/src/app/util/table.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import strip from 'strip-ansi';
import { stripVTControlCharacters } from 'node:util';

import { describe, expect, test } from 'vitest';

import type { Table } from './table.js';
Expand All @@ -15,7 +16,7 @@ describe('Validate table.ts', () => {
],
};
const x = tableToLines(table);
expect(x.map(strip)).toEqual([
expect(x.map(stripVTControlCharacters)).toEqual([
'id | name ',
'27438 | Computer',
'273438 | Desk ',
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5421710

Please sign in to comment.