Skip to content

Commit

Permalink
Replace strip-ansi with native module (#1366)
Browse files Browse the repository at this point in the history
Summary:
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.

Pull Request resolved: #1366

Reviewed By: huntie

Differential Revision: D63957530

Pulled By: robhogan

fbshipit-source-id: 0b6b3a7e7b076b1ff664b717ce77e1dcc203b0c7
  • Loading branch information
stianjensen authored and facebook-github-bot committed Oct 16, 2024
1 parent 4e5bd94 commit 0f8cabd
Show file tree
Hide file tree
Showing 4 changed files with 8 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.81.0",
"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
6 changes: 4 additions & 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,10 @@ 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 0f8cabd

Please sign in to comment.