Skip to content

Commit

Permalink
Replace strip-ansi with native module
Browse files Browse the repository at this point in the history
stripVTControlCharacters from Node core utilities provide the same
functionality, and is available since Node 16.11. This project currently
requires minimum Node 18.18.

See es-tooling/ecosystem-cleanup#122 for
similar efforts to replace this dependency in other projects.
  • Loading branch information
stianjensen committed Oct 6, 2024
1 parent 3b3e0aa commit 4a6b533
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/metro-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"devDependencies": {
"@types/connect": "^3.4.35",
"metro-babel-register": "0.80.11",
"pretty-format": "^29.7.0",
"strip-ansi": "^6.0.0"
"pretty-format": "^29.7.0"
},
"engines": {
"node": ">=18.18"
Expand Down
6 changes: 3 additions & 3 deletions packages/metro-config/src/__tests__/loadConfig-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {loadConfig} = require('../loadConfig');
const cosmiconfig = require('cosmiconfig');
const path = require('path');
const prettyFormat = require('pretty-format');
const stripAnsi = require('strip-ansi');
const util = require('util');

describe('loadConfig', () => {
beforeEach(() => {
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('loadConfig', () => {
try {
await loadConfig({});
} catch (error) {
expect(stripAnsi(error.message)).toMatchSnapshot();
expect(util.stripVTControlCharacters(error.message)).toMatchSnapshot();
}
});

Expand All @@ -198,7 +198,7 @@ describe('loadConfig', () => {
try {
await loadConfig({});
} catch (error) {
expect(stripAnsi(error.message)).toMatchSnapshot();
expect(util.stripVTControlCharacters(error.message)).toMatchSnapshot();
}
});

Expand Down
1 change: 0 additions & 1 deletion packages/metro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"nullthrows": "^1.1.1",
"serialize-error": "^2.1.0",
"source-map": "^0.5.6",
"strip-ansi": "^6.0.0",
"throat": "^5.0.0",
"ws": "^7.5.10",
"yargs": "^17.6.2"
Expand Down
3 changes: 1 addition & 2 deletions packages/metro/src/lib/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {CustomResolverOptions} from 'metro-resolver';
import type {CustomTransformOptions} from 'metro-transform-worker';

const chalk = require('chalk');
const stripAnsi = require('strip-ansi');
const util = require('util');

export type BundleDetails = {
Expand Down Expand Up @@ -207,7 +206,7 @@ function logError(
// in various places outside of where Metro is currently running.
// If the current terminal does not support color, we'll strip the colors
// here.
util.format(chalk.supportsColor ? format : stripAnsi(format), ...args),
util.format(chalk.supportsColor ? format : util.stripVTControlCharacters(format), ...args),
);
}

Expand Down

0 comments on commit 4a6b533

Please sign in to comment.