Skip to content

Commit

Permalink
chore(deps): replace strip-ansi with native module
Browse files Browse the repository at this point in the history
  • Loading branch information
Namchee committed Oct 4, 2024
1 parent a46839a commit 2a63e87
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 41 deletions.
1 change: 0 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/core/errors/dev/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
}
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/logger/vite.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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))) {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/units/config/config-validate.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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:
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion packages/create-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"devDependencies": {
"arg": "^5.0.2",
"astro-scripts": "workspace:*",
"strip-ansi": "^7.1.0",
"strip-json-comments": "^5.0.1"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-astro/src/messages.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/create-astro/test/utils.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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;
},
}),
Expand Down
1 change: 0 additions & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/core/cli/migration-queries.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
5 changes: 2 additions & 3 deletions packages/upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/upgrade/test/utils.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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;
},
}),
Expand Down
12 changes: 0 additions & 12 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 2a63e87

Please sign in to comment.