Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cuddly-shrimps-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"miniflare": patch
"wrangler": patch
---

Use built-in stripVTControlCharacters utility rather than the `strip-ansi` package.
1 change: 1 addition & 0 deletions fixtures/import-npm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json
185 changes: 0 additions & 185 deletions fixtures/import-npm/package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion fixtures/interactive-dev-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"devDependencies": {
"@fixture/shared": "workspace:*",
"strip-ansi": "^7.1.0",
"undici": "catalog:default",
"vitest": "catalog:default"
},
Expand Down
8 changes: 6 additions & 2 deletions fixtures/interactive-dev-tests/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from "node:path";
import rl from "node:readline";
import stream from "node:stream";
import { setTimeout } from "node:timers/promises";
import stripAnsi from "strip-ansi";
import { stripVTControlCharacters } from "node:util";
import { fetch } from "undici";
import {
afterAll,
Expand Down Expand Up @@ -151,7 +151,11 @@ if (process.platform === "win32") {
if (!skipWaitingForReady) {
let readyMatch: RegExpMatchArray | null = null;
for await (const line of stdoutInterface) {
if ((readyMatch = readyRegexp.exec(stripAnsi(line))) !== null) break;
if (
(readyMatch = readyRegexp.exec(stripVTControlCharacters(line))) !==
null
)
break;
}
assert(readyMatch !== null, "Expected ready message");
result.url = readyMatch[1];
Expand Down
1 change: 0 additions & 1 deletion fixtures/worker-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:^",
"strip-ansi": "^7.1.0",
"typescript": "catalog:default",
"vitest": "catalog:default",
"wrangler": "workspace:*"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/worker-logs/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stripVTControlCharacters } from "node:util";
import { resolve } from "path";
import stripAnsi from "strip-ansi";
import { describe, expect, onTestFinished, test, vi } from "vitest";
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";

Expand Down Expand Up @@ -43,7 +43,7 @@ async function getWranglerDevOutput(
await response.text();

return () => {
const output = stripAnsi(getOutput())
const output = stripVTControlCharacters(getOutput())
// Windows gets a different marker for ✘, so let's normalize it here
// so that these tests can be platform independent
.replaceAll("✘", "X")
Expand Down
20 changes: 2 additions & 18 deletions packages/miniflare/src/shared/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path";
import { stripVTControlCharacters } from "node:util";
import { Colorize, dim, green, grey, red, reset, yellow } from "kleur/colors";
import { LogLevel } from "../workers";

Expand Down Expand Up @@ -186,23 +187,6 @@ export class NoOpLog extends Log {
error(_message: Error): void {}
}

// Adapted from https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
/*!
* MIT License
*
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* 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.
*/
const ansiRegexpPattern = [
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
].join("|");
const ansiRegexp = new RegExp(ansiRegexpPattern, "g");
export function stripAnsi(value: string) {
return value.replace(ansiRegexp, "");
return stripVTControlCharacters(value);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import stripAnsi from "strip-ansi";
import { stripVTControlCharacters } from "node:util";
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
import {
resetServerLogs,
Expand All @@ -12,7 +12,7 @@ import { resolvePluginConfig } from "../../../src/plugin-config";
import { addBindingsShortcut } from "../../../src/plugins/shortcuts";

const normalize = (logs: string[]) =>
stripAnsi(logs.join("\n"))
stripVTControlCharacters(logs.join("\n"))
.split("\n")
.map((line: string) => line.trim())
.join("\n");
Expand Down
1 change: 0 additions & 1 deletion packages/vite-plugin-cloudflare/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@cloudflare/workers-tsconfig": "workspace:*",
"playwright-chromium": "catalog:default",
"semver": "^7.7.1",
"strip-ansi": "^7.1.0",
"ts-dedent": "^2.2.0",
"typescript": "catalog:default"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/e2e/helpers/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import stripAnsi from "strip-ansi";
import { stripVTControlCharacters } from "node:util";
import { expect } from "vitest";
import { CLOUDFLARE_ACCOUNT_ID } from "./account-id";

Expand All @@ -22,7 +22,7 @@ export function normalizeOutput(
normalizeSlashes,
normalizeTempDirs,
stripTimings,
stripAnsi,
stripVTControlCharacters,
removeTimestamp,
stripDevTimings,
stripEmptyNewlines,
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/e2e/helpers/read-until.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setTimeout } from "node:timers/promises";
import stripAnsi from "strip-ansi";
import { stripVTControlCharacters } from "node:util";
import type { ReadableStream } from "node:stream/web";

const TIMEOUT = Symbol.for("TIMEOUT");
Expand All @@ -12,7 +12,7 @@ export async function readUntil(
const timeoutPromise = setTimeout(timeout, TIMEOUT);
const reader = lines.getReader();
const readArray: string[] = [];
const read = () => stripAnsi(readArray.join("\n"));
const read = () => stripVTControlCharacters(readArray.join("\n"));
try {
while (true) {
const result = await Promise.race([reader.read(), timeoutPromise]);
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
"signal-exit": "^3.0.7",
"smol-toml": "catalog:default",
"source-map": "^0.6.1",
"strip-ansi": "^7.1.0",
"supports-color": "^9.2.2",
"timeago.js": "^4.0.2",
"ts-dedent": "^2.2.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/cli-hotkeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stripVTControlCharacters } from "node:util";
import { dim } from "@cloudflare/cli/colors";
import stripAnsi from "strip-ansi";
import { unwrapHook } from "./api/startDevWorker/utils";
import { logger } from "./logger";
import { onKeyPress } from "./utils/onKeyPress";
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function (
.map(({ keys, label }) => `[${keys[0]}] ${dim(unwrapHook(label))}`);

let stringifiedInstructions = instructions.join(" ");
const length = stripAnsi(stringifiedInstructions).length;
const length = stripVTControlCharacters(stringifiedInstructions).length;

const ADDITIONAL_CHARS = 6; // 3 chars on each side of the instructions for the box and spacing ("│ " and " │")
const willWrap = length + ADDITIONAL_CHARS > process.stdout.columns;
Expand All @@ -50,14 +50,14 @@ export default function (
const maxLineLength = Math.max(
...stringifiedInstructions
.split("\n")
.map((line) => stripAnsi(line).length)
.map((line) => stripVTControlCharacters(line).length)
);

stringifiedInstructions = stringifiedInstructions
.split("\n")
.map(
(line) =>
`│ ${line + " ".repeat(Math.max(0, maxLineLength - stripAnsi(line).length))} │`
`│ ${line + " ".repeat(Math.max(0, maxLineLength - stripVTControlCharacters(line).length))} │`
)
.join("\n");

Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/utils/log-file.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { appendFile } from "node:fs/promises";
import path from "node:path";
import { stripVTControlCharacters } from "node:util";
import {
getEnvironmentVariableFactory,
getGlobalWranglerConfigPath,
} from "@cloudflare/workers-utils";
import { Mutex } from "miniflare";
import onExit from "signal-exit";
import stripAnsi from "strip-ansi";
import { logger } from "../logger";
import { ensureDirectoryExists } from "./filesystem";
import type { LoggerLevel } from "../logger";
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function appendToDebugLogFile(
) {
const entry = `
--- ${new Date().toISOString()} ${messageLevel}
${stripAnsi(message)}
${stripVTControlCharacters(message)}
---
`;

Expand Down
Loading
Loading