mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
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>
This commit is contained in:
parent
657d197371
commit
f47b347da8
15 changed files with 33 additions and 41 deletions
8
.changeset/large-phones-compare.md
Normal file
8
.changeset/large-phones-compare.md
Normal file
|
@ -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
|
|
@ -174,7 +174,6 @@
|
||||||
"semver": "^7.6.3",
|
"semver": "^7.6.3",
|
||||||
"shiki": "^1.21.0",
|
"shiki": "^1.21.0",
|
||||||
"string-width": "^7.2.0",
|
"string-width": "^7.2.0",
|
||||||
"strip-ansi": "^7.1.0",
|
|
||||||
"tinyexec": "^0.3.0",
|
"tinyexec": "^0.3.0",
|
||||||
"tsconfck": "^3.1.3",
|
"tsconfck": "^3.1.3",
|
||||||
"unist-util-visit": "^5.0.0",
|
"unist-util-visit": "^5.0.0",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import { isAbsolute, join } from 'node:path';
|
import { isAbsolute, join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import { escape } from 'html-escaper';
|
import { escape } from 'html-escaper';
|
||||||
import { bold, underline } from 'kleur/colors';
|
import { bold, underline } from 'kleur/colors';
|
||||||
import stripAnsi from 'strip-ansi';
|
|
||||||
import type { ESBuildTransformResult } from 'vite';
|
import type { ESBuildTransformResult } from 'vite';
|
||||||
import { normalizePath } from 'vite';
|
import { normalizePath } from 'vite';
|
||||||
import type { SSRError } from '../../../@types/astro.js';
|
import type { SSRError } from '../../../@types/astro.js';
|
||||||
|
@ -27,7 +27,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL): ErrorWithMetadat
|
||||||
if (e.stack) {
|
if (e.stack) {
|
||||||
const stackInfo = collectInfoFromStacktrace(e);
|
const stackInfo = collectInfoFromStacktrace(e);
|
||||||
try {
|
try {
|
||||||
error.stack = stripAnsi(stackInfo.stack);
|
error.stack = stripVTControlCharacters(stackInfo.stack);
|
||||||
} catch {}
|
} catch {}
|
||||||
error.loc = stackInfo.loc;
|
error.loc = stackInfo.loc;
|
||||||
error.plugin = stackInfo.plugin;
|
error.plugin = stackInfo.plugin;
|
||||||
|
@ -59,7 +59,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL): ErrorWithMetadat
|
||||||
|
|
||||||
if (!error.frame) {
|
if (!error.frame) {
|
||||||
const frame = codeFrame(fileContents, error.loc);
|
const frame = codeFrame(fileContents, error.loc);
|
||||||
error.frame = stripAnsi(frame);
|
error.frame = stripVTControlCharacters(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error.fullCode) {
|
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
|
// but it will be handled and added below, which is already ANSI-free
|
||||||
if (error.message) {
|
if (error.message) {
|
||||||
try {
|
try {
|
||||||
error.message = stripAnsi(error.message);
|
error.message = stripVTControlCharacters(error.message);
|
||||||
} catch {
|
} 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.
|
// 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
|
// normalize error stack line-endings to \n
|
||||||
stackInfo.stack = normalizeLF(error.stack);
|
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
|
// Try to find possible location from stack if we don't have one
|
||||||
if (!stackInfo.loc || (!stackInfo.loc.column && !stackInfo.loc.line)) {
|
if (!stackInfo.loc || (!stackInfo.loc.column && !stackInfo.loc.line)) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { fileURLToPath } from 'node:url';
|
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 type { LogLevel, Rollup, Logger as ViteLogger } from 'vite';
|
||||||
import { isAstroError } from '../errors/errors.js';
|
import { isAstroError } from '../errors/errors.js';
|
||||||
import { serverShortcuts as formatServerShortcuts } from '../messages.js';
|
import { serverShortcuts as formatServerShortcuts } from '../messages.js';
|
||||||
|
@ -34,7 +34,7 @@ export function createViteLogger(
|
||||||
info(msg) {
|
info(msg) {
|
||||||
if (!isLogLevelEnabled(viteLogLevel, 'info')) return;
|
if (!isLogLevelEnabled(viteLogLevel, 'info')) return;
|
||||||
|
|
||||||
const stripped = stripAnsi(msg);
|
const stripped = stripVTControlCharacters(msg);
|
||||||
let m;
|
let m;
|
||||||
// Rewrite HMR page reload message
|
// Rewrite HMR page reload message
|
||||||
if ((m = vitePageReloadMsg.exec(stripped))) {
|
if ((m = vitePageReloadMsg.exec(stripped))) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { join } from 'node:path';
|
||||||
import { Writable } from 'node:stream';
|
import { Writable } from 'node:stream';
|
||||||
import { describe, it } from 'node:test';
|
import { describe, it } from 'node:test';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import stripAnsi from 'strip-ansi';
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import { cli, cliServerLogSetup, loadFixture, parseCliDevStart } from './test-utils.js';
|
import { cli, cliServerLogSetup, loadFixture, parseCliDevStart } from './test-utils.js';
|
||||||
|
|
||||||
describe('astro cli', () => {
|
describe('astro cli', () => {
|
||||||
|
@ -45,7 +45,7 @@ describe('astro cli', () => {
|
||||||
dest: new Writable({
|
dest: new Writable({
|
||||||
objectMode: true,
|
objectMode: true,
|
||||||
write(event, _, callback) {
|
write(event, _, callback) {
|
||||||
logs.push({ ...event, message: stripAnsi(event.message) });
|
logs.push({ ...event, message: stripVTControlCharacters(event.message) });
|
||||||
if (event.message.includes('1 error')) {
|
if (event.message.includes('1 error')) {
|
||||||
messageResolve(logs);
|
messageResolve(logs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ import fs from 'node:fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import { execa } from 'execa';
|
import { execa } from 'execa';
|
||||||
import fastGlob from 'fast-glob';
|
import fastGlob from 'fast-glob';
|
||||||
import stripAnsi from 'strip-ansi';
|
|
||||||
import { Agent } from 'undici';
|
import { Agent } from 'undici';
|
||||||
import { check } from '../dist/cli/check/index.js';
|
import { check } from '../dist/cli/check/index.js';
|
||||||
import { globalContentLayer } from '../dist/content/content-layer.js';
|
import { globalContentLayer } from '../dist/content/content-layer.js';
|
||||||
|
@ -356,8 +356,8 @@ export async function parseCliDevStart(proc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
proc.kill();
|
proc.kill();
|
||||||
stdout = stripAnsi(stdout);
|
stdout = stripVTControlCharacters(stdout);
|
||||||
stderr = stripAnsi(stderr);
|
stderr = stripVTControlCharacters(stderr);
|
||||||
|
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
throw new Error(stderr);
|
throw new Error(stderr);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as assert from 'node:assert/strict';
|
import * as assert from 'node:assert/strict';
|
||||||
import { describe, it } from 'node:test';
|
import { describe, it } from 'node:test';
|
||||||
import stripAnsi from 'strip-ansi';
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { validateConfig } from '../../../dist/core/config/validate.js';
|
import { validateConfig } from '../../../dist/core/config/validate.js';
|
||||||
import { formatConfigErrorMessage } from '../../../dist/core/messages.js';
|
import { formatConfigErrorMessage } from '../../../dist/core/messages.js';
|
||||||
|
@ -19,7 +19,7 @@ describe('Config Validation', () => {
|
||||||
it('A validation error can be formatted correctly', async () => {
|
it('A validation error can be formatted correctly', async () => {
|
||||||
const configError = await validateConfig({ site: 42 }, process.cwd()).catch((err) => err);
|
const configError = await validateConfig({ site: 42 }, process.cwd()).catch((err) => err);
|
||||||
assert.equal(configError instanceof z.ZodError, true);
|
assert.equal(configError instanceof z.ZodError, true);
|
||||||
const formattedError = stripAnsi(formatConfigErrorMessage(configError));
|
const formattedError = stripVTControlCharacters(formatConfigErrorMessage(configError));
|
||||||
assert.equal(
|
assert.equal(
|
||||||
formattedError,
|
formattedError,
|
||||||
`[config] Astro found issue(s) with your configuration:
|
`[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);
|
const configError = await validateConfig(veryBadConfig, process.cwd()).catch((err) => err);
|
||||||
assert.equal(configError instanceof z.ZodError, true);
|
assert.equal(configError instanceof z.ZodError, true);
|
||||||
const formattedError = stripAnsi(formatConfigErrorMessage(configError));
|
const formattedError = stripVTControlCharacters(formatConfigErrorMessage(configError));
|
||||||
assert.equal(
|
assert.equal(
|
||||||
formattedError,
|
formattedError,
|
||||||
`[config] Astro found issue(s) with your configuration:
|
`[config] Astro found issue(s) with your configuration:
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"arg": "^5.0.2",
|
"arg": "^5.0.2",
|
||||||
"astro-scripts": "workspace:*",
|
"astro-scripts": "workspace:*",
|
||||||
"strip-ansi": "^7.1.0",
|
|
||||||
"strip-json-comments": "^5.0.1"
|
"strip-json-comments": "^5.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { exec } from 'node:child_process';
|
import { exec } from 'node:child_process';
|
||||||
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
/* eslint no-console: 'off' */
|
/* eslint no-console: 'off' */
|
||||||
import { color, say as houston, label, spinner as load } from '@astrojs/cli-kit';
|
import { color, say as houston, label, spinner as load } from '@astrojs/cli-kit';
|
||||||
import { align, sleep } from '@astrojs/cli-kit/utils';
|
import { align, sleep } from '@astrojs/cli-kit/utils';
|
||||||
import stripAnsi from 'strip-ansi';
|
|
||||||
import { shell } from './shell.js';
|
import { shell } from './shell.js';
|
||||||
|
|
||||||
// Users might lack access to the global npm registry, this function
|
// 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`,
|
`\n${prefix}Enter your project directory using`,
|
||||||
color.cyan(`cd ${projectDir}`, ''),
|
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(enter.join(len > max ? '\n' + prefix : ' '));
|
||||||
}
|
}
|
||||||
log(
|
log(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { before, beforeEach } from 'node:test';
|
import { before, beforeEach } from 'node:test';
|
||||||
import stripAnsi from 'strip-ansi';
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import { setStdout } from '../dist/index.js';
|
import { setStdout } from '../dist/index.js';
|
||||||
|
|
||||||
export function setup() {
|
export function setup() {
|
||||||
|
@ -9,7 +9,7 @@ export function setup() {
|
||||||
setStdout(
|
setStdout(
|
||||||
Object.assign({}, process.stdout, {
|
Object.assign({}, process.stdout, {
|
||||||
write(buf) {
|
write(buf) {
|
||||||
ctx.messages.push(stripAnsi(String(buf)).trim());
|
ctx.messages.push(stripVTControlCharacters(String(buf)).trim());
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -80,7 +80,6 @@
|
||||||
"open": "^10.1.0",
|
"open": "^10.1.0",
|
||||||
"ora": "^8.1.0",
|
"ora": "^8.1.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"strip-ansi": "^7.1.0",
|
|
||||||
"yargs-parser": "^21.1.1",
|
"yargs-parser": "^21.1.1",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import deepDiff from 'deep-diff';
|
import deepDiff from 'deep-diff';
|
||||||
import { sql } from 'drizzle-orm';
|
import { sql } from 'drizzle-orm';
|
||||||
import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core';
|
import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core';
|
||||||
import * as color from 'kleur/colors';
|
import * as color from 'kleur/colors';
|
||||||
import { customAlphabet } from 'nanoid';
|
import { customAlphabet } from 'nanoid';
|
||||||
import stripAnsi from 'strip-ansi';
|
|
||||||
import { hasPrimaryKey } from '../../runtime/index.js';
|
import { hasPrimaryKey } from '../../runtime/index.js';
|
||||||
import { createRemoteDatabaseClient } from '../../runtime/index.js';
|
import { createRemoteDatabaseClient } from '../../runtime/index.js';
|
||||||
import { isSerializedSQL } from '../../runtime/types.js';
|
import { isSerializedSQL } from '../../runtime/types.js';
|
||||||
|
@ -521,7 +521,7 @@ export function formatDataLossMessage(confirmations: string[], isColor = true):
|
||||||
);
|
);
|
||||||
let finalMessage = messages.join('\n');
|
let finalMessage = messages.join('\n');
|
||||||
if (!isColor) {
|
if (!isColor) {
|
||||||
finalMessage = stripAnsi(finalMessage);
|
finalMessage = stripVTControlCharacters(finalMessage);
|
||||||
}
|
}
|
||||||
return finalMessage;
|
return finalMessage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,14 @@
|
||||||
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
|
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/cli-kit": "^0.4.1",
|
"@astrojs/cli-kit": "^0.4.1",
|
||||||
"semver": "^7.6.3",
|
|
||||||
"preferred-pm": "^4.0.0",
|
"preferred-pm": "^4.0.0",
|
||||||
|
"semver": "^7.6.3",
|
||||||
"terminal-link": "^3.0.0"
|
"terminal-link": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"arg": "^5.0.2",
|
"arg": "^5.0.2",
|
||||||
"astro-scripts": "workspace:*",
|
"astro-scripts": "workspace:*"
|
||||||
"strip-ansi": "^7.1.0"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { before, beforeEach } from 'node:test';
|
import { before, beforeEach } from 'node:test';
|
||||||
import stripAnsi from 'strip-ansi';
|
import { stripVTControlCharacters } from 'node:util';
|
||||||
import { setStdout } from '../dist/index.js';
|
import { setStdout } from '../dist/index.js';
|
||||||
|
|
||||||
export function setup() {
|
export function setup() {
|
||||||
|
@ -8,7 +8,7 @@ export function setup() {
|
||||||
setStdout(
|
setStdout(
|
||||||
Object.assign({}, process.stdout, {
|
Object.assign({}, process.stdout, {
|
||||||
write(buf) {
|
write(buf) {
|
||||||
ctx.messages.push(stripAnsi(String(buf)).trim());
|
ctx.messages.push(stripVTControlCharacters(String(buf)).trim());
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -708,9 +708,6 @@ importers:
|
||||||
string-width:
|
string-width:
|
||||||
specifier: ^7.2.0
|
specifier: ^7.2.0
|
||||||
version: 7.2.0
|
version: 7.2.0
|
||||||
strip-ansi:
|
|
||||||
specifier: ^7.1.0
|
|
||||||
version: 7.1.0
|
|
||||||
tinyexec:
|
tinyexec:
|
||||||
specifier: ^0.3.0
|
specifier: ^0.3.0
|
||||||
version: 0.3.0
|
version: 0.3.0
|
||||||
|
@ -4293,9 +4290,6 @@ importers:
|
||||||
astro-scripts:
|
astro-scripts:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../scripts
|
version: link:../../scripts
|
||||||
strip-ansi:
|
|
||||||
specifier: ^7.1.0
|
|
||||||
version: 7.1.0
|
|
||||||
strip-json-comments:
|
strip-json-comments:
|
||||||
specifier: ^5.0.1
|
specifier: ^5.0.1
|
||||||
version: 5.0.1
|
version: 5.0.1
|
||||||
|
@ -4337,9 +4331,6 @@ importers:
|
||||||
prompts:
|
prompts:
|
||||||
specifier: ^2.4.2
|
specifier: ^2.4.2
|
||||||
version: 2.4.2
|
version: 2.4.2
|
||||||
strip-ansi:
|
|
||||||
specifier: ^7.1.0
|
|
||||||
version: 7.1.0
|
|
||||||
yargs-parser:
|
yargs-parser:
|
||||||
specifier: ^21.1.1
|
specifier: ^21.1.1
|
||||||
version: 21.1.1
|
version: 21.1.1
|
||||||
|
@ -5628,9 +5619,6 @@ importers:
|
||||||
astro-scripts:
|
astro-scripts:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../scripts
|
version: link:../../scripts
|
||||||
strip-ansi:
|
|
||||||
specifier: ^7.1.0
|
|
||||||
version: 7.1.0
|
|
||||||
|
|
||||||
scripts:
|
scripts:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in a new issue