aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Cristopher <32661241+Namchee@users.noreply.github.com> 2024-10-04 16:21:03 +0700
committerGravatar GitHub <noreply@github.com> 2024-10-04 11:21:03 +0200
commitf47b347da899c6e1dcd0b2e7887f7fce6ec8e270 (patch)
tree98b3af845f3fd5ba8b5905f49d539e7a4ac07d0e
parent657d1973719e20470c3934d086b971e474fee3c6 (diff)
downloadastro-f47b347da899c6e1dcd0b2e7887f7fce6ec8e270.tar.gz
astro-f47b347da899c6e1dcd0b2e7887f7fce6ec8e270.tar.zst
astro-f47b347da899c6e1dcd0b2e7887f7fce6ec8e270.zip
chore(deps): replace strip-ansi with native module (#12118)
* chore(deps): replace strip-ansi with native module * chore: changeset --------- Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
-rw-r--r--.changeset/large-phones-compare.md8
-rw-r--r--packages/astro/package.json1
-rw-r--r--packages/astro/src/core/errors/dev/utils.ts10
-rw-r--r--packages/astro/src/core/logger/vite.ts4
-rw-r--r--packages/astro/test/cli.test.js4
-rw-r--r--packages/astro/test/test-utils.js6
-rw-r--r--packages/astro/test/units/config/config-validate.test.js6
-rw-r--r--packages/create-astro/package.json1
-rw-r--r--packages/create-astro/src/messages.ts4
-rw-r--r--packages/create-astro/test/utils.js4
-rw-r--r--packages/db/package.json1
-rw-r--r--packages/db/src/core/cli/migration-queries.ts4
-rw-r--r--packages/upgrade/package.json5
-rw-r--r--packages/upgrade/test/utils.js4
-rw-r--r--pnpm-lock.yaml12
15 files changed, 33 insertions, 41 deletions
diff --git a/.changeset/large-phones-compare.md b/.changeset/large-phones-compare.md
new file mode 100644
index 000000000..a603ea0a2
--- /dev/null
+++ b/.changeset/large-phones-compare.md
@@ -0,0 +1,8 @@
+---
+'create-astro': patch
+'@astrojs/upgrade': patch
+'astro': patch
+'@astrojs/db': patch
+---
+
+Removes the `strip-ansi` dependency in favor of the native Node API
diff --git a/packages/astro/package.json b/packages/astro/package.json
index c12e8233b..4af70bb69 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 03ba7d2df..c0caa1d60 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 f1ed49dce..e8c9717b2 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 5e3ef984f..01c2ba654 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 68fab03b0..51606e815 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 fc69b595f..7eead0fd6 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 fcae9af3d..d48c7065d 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 ba765f723..898c9c728 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 5412c8cab..dfae93c33 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 8b111edbe..d54cc4260 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 6f0e0a5e2..28dac318f 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 286a0be78..c036f8366 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 8b80bc2e5..20063ec53 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 2ec7374ce..e2fbae2cc 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: