From 2a63e872f438bbbedbc3572026baa26c8b74f8f0 Mon Sep 17 00:00:00 2001 From: Cristopher Date: Fri, 4 Oct 2024 08:56:55 +0700 Subject: [PATCH] chore(deps): replace strip-ansi with native module --- packages/astro/package.json | 1 - packages/astro/src/core/errors/dev/utils.ts | 10 +++++----- packages/astro/src/core/logger/vite.ts | 4 ++-- packages/astro/test/cli.test.js | 4 ++-- packages/astro/test/test-utils.js | 6 +++--- .../astro/test/units/config/config-validate.test.js | 6 +++--- packages/create-astro/package.json | 1 - packages/create-astro/src/messages.ts | 4 ++-- packages/create-astro/test/utils.js | 4 ++-- packages/db/package.json | 1 - packages/db/src/core/cli/migration-queries.ts | 4 ++-- packages/upgrade/package.json | 5 ++--- packages/upgrade/test/utils.js | 4 ++-- pnpm-lock.yaml | 12 ------------ 14 files changed, 25 insertions(+), 41 deletions(-) diff --git a/packages/astro/package.json b/packages/astro/package.json index c12e8233b448..4af70bb6984f 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -174,7 +174,6 @@ "semver": "^7.6.3", "shiki": "^1.21.0", "string-width": "^7.2.0", - "strip-ansi": "^7.1.0", "tinyexec": "^0.3.0", "tsconfck": "^3.1.3", "unist-util-visit": "^5.0.0", diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index 03ba7d2dff01..c0caa1d60bc6 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -1,9 +1,9 @@ import * as fs from 'node:fs'; import { isAbsolute, join } from 'node:path'; import { fileURLToPath } from 'node:url'; +import { stripVTControlCharacters } from 'node:util'; import { escape } from 'html-escaper'; import { bold, underline } from 'kleur/colors'; -import stripAnsi from 'strip-ansi'; import type { ESBuildTransformResult } from 'vite'; import { normalizePath } from 'vite'; import type { SSRError } from '../../../@types/astro.js'; @@ -27,7 +27,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL): ErrorWithMetadat if (e.stack) { const stackInfo = collectInfoFromStacktrace(e); try { - error.stack = stripAnsi(stackInfo.stack); + error.stack = stripVTControlCharacters(stackInfo.stack); } catch {} error.loc = stackInfo.loc; error.plugin = stackInfo.plugin; @@ -59,7 +59,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL): ErrorWithMetadat if (!error.frame) { const frame = codeFrame(fileContents, error.loc); - error.frame = stripAnsi(frame); + error.frame = stripVTControlCharacters(frame); } if (!error.fullCode) { @@ -75,7 +75,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL): ErrorWithMetadat // but it will be handled and added below, which is already ANSI-free if (error.message) { try { - error.message = stripAnsi(error.message); + error.message = stripVTControlCharacters(error.message); } catch { // Setting `error.message` can fail here if the message is read-only, which for the vast majority of cases will never happen, however some somewhat obscure cases can cause this to happen. } @@ -170,7 +170,7 @@ function collectInfoFromStacktrace(error: SSRError & { stack: string }): StackIn // normalize error stack line-endings to \n stackInfo.stack = normalizeLF(error.stack); - const stackText = stripAnsi(error.stack); + const stackText = stripVTControlCharacters(error.stack); // Try to find possible location from stack if we don't have one if (!stackInfo.loc || (!stackInfo.loc.column && !stackInfo.loc.line)) { diff --git a/packages/astro/src/core/logger/vite.ts b/packages/astro/src/core/logger/vite.ts index f1ed49dce0d2..e8c9717b273c 100644 --- a/packages/astro/src/core/logger/vite.ts +++ b/packages/astro/src/core/logger/vite.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from 'node:url'; -import stripAnsi from 'strip-ansi'; +import { stripVTControlCharacters } from 'node:util'; import type { LogLevel, Rollup, Logger as ViteLogger } from 'vite'; import { isAstroError } from '../errors/errors.js'; import { serverShortcuts as formatServerShortcuts } from '../messages.js'; @@ -34,7 +34,7 @@ export function createViteLogger( info(msg) { if (!isLogLevelEnabled(viteLogLevel, 'info')) return; - const stripped = stripAnsi(msg); + const stripped = stripVTControlCharacters(msg); let m; // Rewrite HMR page reload message if ((m = vitePageReloadMsg.exec(stripped))) { diff --git a/packages/astro/test/cli.test.js b/packages/astro/test/cli.test.js index 5e3ef984f8c2..01c2ba6546e9 100644 --- a/packages/astro/test/cli.test.js +++ b/packages/astro/test/cli.test.js @@ -5,7 +5,7 @@ import { join } from 'node:path'; import { Writable } from 'node:stream'; import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; -import stripAnsi from 'strip-ansi'; +import { stripVTControlCharacters } from 'node:util'; import { cli, cliServerLogSetup, loadFixture, parseCliDevStart } from './test-utils.js'; describe('astro cli', () => { @@ -45,7 +45,7 @@ describe('astro cli', () => { dest: new Writable({ objectMode: true, write(event, _, callback) { - logs.push({ ...event, message: stripAnsi(event.message) }); + logs.push({ ...event, message: stripVTControlCharacters(event.message) }); if (event.message.includes('1 error')) { messageResolve(logs); } diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index 68fab03b04d1..51606e815762 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -2,9 +2,9 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; +import { stripVTControlCharacters } from 'node:util'; import { execa } from 'execa'; import fastGlob from 'fast-glob'; -import stripAnsi from 'strip-ansi'; import { Agent } from 'undici'; import { check } from '../dist/cli/check/index.js'; import { globalContentLayer } from '../dist/content/content-layer.js'; @@ -356,8 +356,8 @@ export async function parseCliDevStart(proc) { } proc.kill(); - stdout = stripAnsi(stdout); - stderr = stripAnsi(stderr); + stdout = stripVTControlCharacters(stdout); + stderr = stripVTControlCharacters(stderr); if (stderr) { throw new Error(stderr); diff --git a/packages/astro/test/units/config/config-validate.test.js b/packages/astro/test/units/config/config-validate.test.js index fc69b595fa4f..7eead0fd63d0 100644 --- a/packages/astro/test/units/config/config-validate.test.js +++ b/packages/astro/test/units/config/config-validate.test.js @@ -1,6 +1,6 @@ import * as assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import stripAnsi from 'strip-ansi'; +import { stripVTControlCharacters } from 'node:util'; import { z } from 'zod'; import { validateConfig } from '../../../dist/core/config/validate.js'; import { formatConfigErrorMessage } from '../../../dist/core/messages.js'; @@ -19,7 +19,7 @@ describe('Config Validation', () => { it('A validation error can be formatted correctly', async () => { const configError = await validateConfig({ site: 42 }, process.cwd()).catch((err) => err); assert.equal(configError instanceof z.ZodError, true); - const formattedError = stripAnsi(formatConfigErrorMessage(configError)); + const formattedError = stripVTControlCharacters(formatConfigErrorMessage(configError)); assert.equal( formattedError, `[config] Astro found issue(s) with your configuration: @@ -34,7 +34,7 @@ describe('Config Validation', () => { }; const configError = await validateConfig(veryBadConfig, process.cwd()).catch((err) => err); assert.equal(configError instanceof z.ZodError, true); - const formattedError = stripAnsi(formatConfigErrorMessage(configError)); + const formattedError = stripVTControlCharacters(formatConfigErrorMessage(configError)); assert.equal( formattedError, `[config] Astro found issue(s) with your configuration: diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index fcae9af3d07c..d48c7065d294 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -37,7 +37,6 @@ "devDependencies": { "arg": "^5.0.2", "astro-scripts": "workspace:*", - "strip-ansi": "^7.1.0", "strip-json-comments": "^5.0.1" }, "engines": { diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index ba765f723258..898c9c728e28 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -1,8 +1,8 @@ import { exec } from 'node:child_process'; +import { stripVTControlCharacters } from 'node:util'; /* eslint no-console: 'off' */ import { color, say as houston, label, spinner as load } from '@astrojs/cli-kit'; import { align, sleep } from '@astrojs/cli-kit/utils'; -import stripAnsi from 'strip-ansi'; import { shell } from './shell.js'; // Users might lack access to the global npm registry, this function @@ -122,7 +122,7 @@ export const nextSteps = async ({ projectDir, devCmd }: { projectDir: string; de `\n${prefix}Enter your project directory using`, color.cyan(`cd ${projectDir}`, ''), ]; - const len = enter[0].length + stripAnsi(enter[1]).length; + const len = enter[0].length + stripVTControlCharacters(enter[1]).length; log(enter.join(len > max ? '\n' + prefix : ' ')); } log( diff --git a/packages/create-astro/test/utils.js b/packages/create-astro/test/utils.js index 5412c8cabce2..dfae93c33026 100644 --- a/packages/create-astro/test/utils.js +++ b/packages/create-astro/test/utils.js @@ -1,6 +1,6 @@ import fs from 'node:fs'; import { before, beforeEach } from 'node:test'; -import stripAnsi from 'strip-ansi'; +import { stripVTControlCharacters } from 'node:util'; import { setStdout } from '../dist/index.js'; export function setup() { @@ -9,7 +9,7 @@ export function setup() { setStdout( Object.assign({}, process.stdout, { write(buf) { - ctx.messages.push(stripAnsi(String(buf)).trim()); + ctx.messages.push(stripVTControlCharacters(String(buf)).trim()); return true; }, }), diff --git a/packages/db/package.json b/packages/db/package.json index 8b111edbe79e..d54cc4260c07 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -80,7 +80,6 @@ "open": "^10.1.0", "ora": "^8.1.0", "prompts": "^2.4.2", - "strip-ansi": "^7.1.0", "yargs-parser": "^21.1.1", "zod": "^3.23.8" }, diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index 6f0e0a5e26cf..28dac318f0ec 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -1,9 +1,9 @@ +import { stripVTControlCharacters } from 'node:util'; import deepDiff from 'deep-diff'; import { sql } from 'drizzle-orm'; import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core'; import * as color from 'kleur/colors'; import { customAlphabet } from 'nanoid'; -import stripAnsi from 'strip-ansi'; import { hasPrimaryKey } from '../../runtime/index.js'; import { createRemoteDatabaseClient } from '../../runtime/index.js'; import { isSerializedSQL } from '../../runtime/types.js'; @@ -521,7 +521,7 @@ export function formatDataLossMessage(confirmations: string[], isColor = true): ); let finalMessage = messages.join('\n'); if (!isColor) { - finalMessage = stripAnsi(finalMessage); + finalMessage = stripVTControlCharacters(finalMessage); } return finalMessage; } diff --git a/packages/upgrade/package.json b/packages/upgrade/package.json index 286a0be7813c..c036f8366a74 100644 --- a/packages/upgrade/package.json +++ b/packages/upgrade/package.json @@ -30,15 +30,14 @@ "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES", "dependencies": { "@astrojs/cli-kit": "^0.4.1", - "semver": "^7.6.3", "preferred-pm": "^4.0.0", + "semver": "^7.6.3", "terminal-link": "^3.0.0" }, "devDependencies": { "@types/semver": "^7.5.8", "arg": "^5.0.2", - "astro-scripts": "workspace:*", - "strip-ansi": "^7.1.0" + "astro-scripts": "workspace:*" }, "engines": { "node": "^18.17.1 || ^20.3.0 || >=21.0.0" diff --git a/packages/upgrade/test/utils.js b/packages/upgrade/test/utils.js index 8b80bc2e5b7e..20063ec53255 100644 --- a/packages/upgrade/test/utils.js +++ b/packages/upgrade/test/utils.js @@ -1,5 +1,5 @@ import { before, beforeEach } from 'node:test'; -import stripAnsi from 'strip-ansi'; +import { stripVTControlCharacters } from 'node:util'; import { setStdout } from '../dist/index.js'; export function setup() { @@ -8,7 +8,7 @@ export function setup() { setStdout( Object.assign({}, process.stdout, { write(buf) { - ctx.messages.push(stripAnsi(String(buf)).trim()); + ctx.messages.push(stripVTControlCharacters(String(buf)).trim()); return true; }, }), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2ec7374ce90c..e2fbae2cc678 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -708,9 +708,6 @@ importers: string-width: specifier: ^7.2.0 version: 7.2.0 - strip-ansi: - specifier: ^7.1.0 - version: 7.1.0 tinyexec: specifier: ^0.3.0 version: 0.3.0 @@ -4293,9 +4290,6 @@ importers: astro-scripts: specifier: workspace:* version: link:../../scripts - strip-ansi: - specifier: ^7.1.0 - version: 7.1.0 strip-json-comments: specifier: ^5.0.1 version: 5.0.1 @@ -4337,9 +4331,6 @@ importers: prompts: specifier: ^2.4.2 version: 2.4.2 - strip-ansi: - specifier: ^7.1.0 - version: 7.1.0 yargs-parser: specifier: ^21.1.1 version: 21.1.1 @@ -5628,9 +5619,6 @@ importers: astro-scripts: specifier: workspace:* version: link:../../scripts - strip-ansi: - specifier: ^7.1.0 - version: 7.1.0 scripts: dependencies: