Skip to content

Commit 014e7aa

Browse files
43081jedmundhung
andauthored
chore: use native stripVTControlCharacters (#11853)
* chore: use native stripVTControlCharacters Since Node 16.x, there is a built-in function, `stripVTControlCharacters`. This does the same job as the `strip-ansi` package and makes it redundant going forward. The minimum node version in these projects is at least 16, so we should be good to switch. * chore: remove unnecessary package-lock.json from import-npm fixture * chore: remove private package from changeset * chore: fix formatting --------- Co-authored-by: Edmund Hung <edmund@cloudflare.com>
1 parent 3bd94e0 commit 014e7aa

File tree

19 files changed

+43
-243
lines changed

19 files changed

+43
-243
lines changed

.changeset/cuddly-shrimps-speak.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"miniflare": patch
3+
"wrangler": patch
4+
---
5+
6+
Use built-in stripVTControlCharacters utility rather than the `strip-ansi` package.

fixtures/import-npm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock.json

fixtures/import-npm/package-lock.json

Lines changed: 0 additions & 185 deletions
This file was deleted.

fixtures/interactive-dev-tests/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
},
88
"devDependencies": {
99
"@fixture/shared": "workspace:*",
10-
"strip-ansi": "^7.1.0",
1110
"undici": "catalog:default",
1211
"vitest": "catalog:default"
1312
},

fixtures/interactive-dev-tests/tests/index.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from "node:path";
66
import rl from "node:readline";
77
import stream from "node:stream";
88
import { setTimeout } from "node:timers/promises";
9-
import stripAnsi from "strip-ansi";
9+
import { stripVTControlCharacters } from "node:util";
1010
import { fetch } from "undici";
1111
import {
1212
afterAll,
@@ -151,7 +151,11 @@ if (process.platform === "win32") {
151151
if (!skipWaitingForReady) {
152152
let readyMatch: RegExpMatchArray | null = null;
153153
for await (const line of stdoutInterface) {
154-
if ((readyMatch = readyRegexp.exec(stripAnsi(line))) !== null) break;
154+
if (
155+
(readyMatch = readyRegexp.exec(stripVTControlCharacters(line))) !==
156+
null
157+
)
158+
break;
155159
}
156160
assert(readyMatch !== null, "Expected ready message");
157161
result.url = readyMatch[1];

fixtures/worker-logs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
},
1313
"devDependencies": {
1414
"@cloudflare/workers-tsconfig": "workspace:^",
15-
"strip-ansi": "^7.1.0",
1615
"typescript": "catalog:default",
1716
"vitest": "catalog:default",
1817
"wrangler": "workspace:*"

fixtures/worker-logs/tests/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { stripVTControlCharacters } from "node:util";
12
import { resolve } from "path";
2-
import stripAnsi from "strip-ansi";
33
import { describe, expect, onTestFinished, test, vi } from "vitest";
44
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";
55

@@ -43,7 +43,7 @@ async function getWranglerDevOutput(
4343
await response.text();
4444

4545
return () => {
46-
const output = stripAnsi(getOutput())
46+
const output = stripVTControlCharacters(getOutput())
4747
// Windows gets a different marker for ✘, so let's normalize it here
4848
// so that these tests can be platform independent
4949
.replaceAll("✘", "X")

packages/miniflare/src/shared/log.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from "node:path";
2+
import { stripVTControlCharacters } from "node:util";
23
import { Colorize, dim, green, grey, red, reset, yellow } from "kleur/colors";
34
import { LogLevel } from "../workers";
45

@@ -186,23 +187,6 @@ export class NoOpLog extends Log {
186187
error(_message: Error): void {}
187188
}
188189

189-
// Adapted from https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
190-
/*!
191-
* MIT License
192-
*
193-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
194-
*
195-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
196-
*
197-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
198-
*
199-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
200-
*/
201-
const ansiRegexpPattern = [
202-
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
203-
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
204-
].join("|");
205-
const ansiRegexp = new RegExp(ansiRegexpPattern, "g");
206190
export function stripAnsi(value: string) {
207-
return value.replace(ansiRegexp, "");
191+
return stripVTControlCharacters(value);
208192
}

packages/vite-plugin-cloudflare/playground/bindings/__tests__/shortcuts.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "node:path";
2-
import stripAnsi from "strip-ansi";
2+
import { stripVTControlCharacters } from "node:util";
33
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
44
import {
55
resetServerLogs,
@@ -12,7 +12,7 @@ import { resolvePluginConfig } from "../../../src/plugin-config";
1212
import { addBindingsShortcut } from "../../../src/plugins/shortcuts";
1313

1414
const normalize = (logs: string[]) =>
15-
stripAnsi(logs.join("\n"))
15+
stripVTControlCharacters(logs.join("\n"))
1616
.split("\n")
1717
.map((line: string) => line.trim())
1818
.join("\n");

packages/vite-plugin-cloudflare/playground/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"@cloudflare/workers-tsconfig": "workspace:*",
1919
"playwright-chromium": "catalog:default",
2020
"semver": "^7.7.1",
21-
"strip-ansi": "^7.1.0",
2221
"ts-dedent": "^2.2.0",
2322
"typescript": "catalog:default"
2423
}

0 commit comments

Comments
 (0)