Skip to content

Commit b0ea0d8

Browse files
authored
Chore(*): Replace strip-ansi with node:util stripVTControlCharacters (#1646)
Fix #1643
1 parent c6a37cd commit b0ea0d8

File tree

6 files changed

+8
-12
lines changed

6 files changed

+8
-12
lines changed

packages/core/core.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AsyncResource } from 'node:async_hooks';
22
import { Stream } from 'node:stream';
33
import { describe, it, expect, vi } from 'vitest';
44
import { render } from '@inquirer/testing';
5-
import stripAnsi from 'strip-ansi';
5+
import { stripVTControlCharacters } from 'node:util';
66
import ansiEscapes from 'ansi-escapes';
77
import {
88
createPrompt,
@@ -744,7 +744,7 @@ describe('Separator', () => {
744744
});
745745

746746
it('renders separator', () => {
747-
expect(stripAnsi(new Separator().separator)).toMatchInlineSnapshot(
747+
expect(stripVTControlCharacters(new Separator().separator)).toMatchInlineSnapshot(
748748
'"──────────────"',
749749
);
750750
expect(new Separator('===').separator).toEqual('===');

packages/core/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"cli-width": "^4.1.0",
8181
"mute-stream": "^2.0.0",
8282
"signal-exit": "^4.1.0",
83-
"strip-ansi": "^6.0.1",
8483
"wrap-ansi": "^6.2.0",
8584
"yoctocolors-cjs": "^2.1.2"
8685
},

packages/core/src/lib/screen-manager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import stripAnsi from 'strip-ansi';
1+
import { stripVTControlCharacters } from 'node:util';
22
import ansiEscapes from 'ansi-escapes';
33
import { breakLines, readlineWidth } from './utils.js';
44
import type { InquirerReadline } from '@inquirer/type';
@@ -33,7 +33,7 @@ export default class ScreenManager {
3333
render(content: string, bottomContent: string = '') {
3434
// Write message to screen and setPrompt to control backspace
3535
const promptLine = lastLine(content);
36-
const rawPromptLine = stripAnsi(promptLine);
36+
const rawPromptLine = stripVTControlCharacters(promptLine);
3737

3838
// Remove the rl.line from our prompt. We can't rely on the content of
3939
// rl.line (mainly because of the password prompt), so just rely on it's

packages/testing/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@
7979
"dependencies": {
8080
"@inquirer/type": "^3.0.2",
8181
"ansi-escapes": "^4.3.2",
82-
"mute-stream": "^2.0.0",
83-
"strip-ansi": "^6.0.1"
82+
"mute-stream": "^2.0.0"
8483
},
8584
"devDependencies": {
8685
"@arethetypeswrong/cli": "^0.17.2",

packages/testing/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Stream } from 'node:stream';
2+
import { stripVTControlCharacters } from 'node:util';
23
import MuteStream from 'mute-stream';
3-
import stripAnsi from 'strip-ansi';
44
import ansiEscapes from 'ansi-escapes';
55
import type { Prompt, Context } from '@inquirer/type';
66

@@ -25,7 +25,7 @@ class BufferedStream extends Stream.Writable {
2525
// Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
2626
// This is probably fine since we don't care about those for testing; but this could become
2727
// an issue if we ever want to test for those.
28-
if (stripAnsi(str).trim().length > 0) {
28+
if (stripVTControlCharacters(str).trim().length > 0) {
2929
this.#_chunks.push(str);
3030
}
3131
callback();
@@ -89,7 +89,7 @@ export async function render<const Props, const Value>(
8989
events,
9090
getScreen: ({ raw }: { raw?: boolean } = {}): string => {
9191
const lastScreen = output.getLastChunk({ raw });
92-
return raw ? lastScreen : stripAnsi(lastScreen).trim();
92+
return raw ? lastScreen : stripVTControlCharacters(lastScreen).trim();
9393
},
9494
getFullOutput: (): string => {
9595
return output.getFullOutput();

yarn.lock

-2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ __metadata:
551551
cli-width: "npm:^4.1.0"
552552
mute-stream: "npm:^2.0.0"
553553
signal-exit: "npm:^4.1.0"
554-
strip-ansi: "npm:^6.0.1"
555554
tshy: "npm:^3.0.2"
556555
wrap-ansi: "npm:^6.2.0"
557556
yoctocolors-cjs: "npm:^2.1.2"
@@ -789,7 +788,6 @@ __metadata:
789788
"@types/node": "npm:^22.10.5"
790789
ansi-escapes: "npm:^4.3.2"
791790
mute-stream: "npm:^2.0.0"
792-
strip-ansi: "npm:^6.0.1"
793791
tshy: "npm:^3.0.2"
794792
peerDependencies:
795793
"@types/node": ">=18"

0 commit comments

Comments
 (0)