Skip to content

Commit d20b58c

Browse files
authored
chore: migrate from chalk to picocolors (#2631)
* build: migrate `cli` to picocolors * build: migrate `cli-config-*` to picocolors * build: migrate `cli-doctor` to picocolors * build: migrate `cli-platform-*` to picocolors * build: migrate `cli-tools` to picocolors * build: migrate remaining packages to picocolors * build: migrate scripts/jest to picocolors * fix: convert boolean to string when logging * test: clarify comments this only disables the colouring, not formatting functions (e.g. bold). * test: disable colours in jest helper function * test: revert unnecessary snapshot change * fix: remove packageManager field * fix: remove accidental re-addition * fix: restore bracket
1 parent d465ac2 commit d20b58c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+226
-209
lines changed

jest/helpers.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os from 'os';
33
import path from 'path';
44
import {createDirectory} from 'jest-util';
55
import execa from 'execa';
6-
import chalk from 'chalk';
6+
import pico from 'picocolors';
77
import slash from 'slash';
88

99
const CLI_PATH = path.resolve(__dirname, '../packages/cli/build/bin.js');
@@ -121,7 +121,7 @@ function getExecaOptions(options: SpawnOptions) {
121121

122122
const cwd = isRelative ? path.resolve(__dirname, options.cwd) : options.cwd;
123123

124-
let env = Object.assign({}, process.env, {FORCE_COLOR: '0'}, options.env);
124+
let env = Object.assign({}, process.env, {NO_COLOR: 1}, options.env);
125125

126126
if (options.nodeOptions) {
127127
env.NODE_OPTIONS = options.nodeOptions;
@@ -147,12 +147,12 @@ function handleTestFailure(
147147
) {
148148
if (!options.expectedFailure && result.exitCode !== 0) {
149149
console.log(`Running ${cmd} command failed for unexpected reason. Here's more info:
150-
${chalk.bold('cmd:')} ${cmd}
151-
${chalk.bold('options:')} ${JSON.stringify(options)}
152-
${chalk.bold('args:')} ${(args || []).join(' ')}
153-
${chalk.bold('stderr:')} ${result.stderr}
154-
${chalk.bold('stdout:')} ${result.stdout}
155-
${chalk.bold('exitCode:')}${result.exitCode}`);
150+
${pico.bold('cmd:')} ${cmd}
151+
${pico.bold('options:')} ${JSON.stringify(options)}
152+
${pico.bold('args:')} ${(args || []).join(' ')}
153+
${pico.bold('stderr:')} ${result.stderr}
154+
${pico.bold('stdout:')} ${result.stdout}
155+
${pico.bold('exitCode:')}${result.exitCode}`);
156156
} else if (options.expectedFailure && result.exitCode === 0) {
157157
throw new Error("Expected command to fail, but it didn't");
158158
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"@types/node": "^20.0.0",
3434
"babel-jest": "^26.6.2",
3535
"babel-plugin-module-resolver": "^3.2.0",
36-
"chalk": "^4.1.2",
3736
"chokidar": "^3.3.1",
3837
"eslint": "^8.23.1",
3938
"eslint-import-resolver-alias": "^1.1.2",
@@ -50,6 +49,7 @@
5049
"lint-staged": "^13.1.0",
5150
"metro-memory-fs": "0.78.0",
5251
"micromatch": "^4.0.4",
52+
"picocolors": "^1.1.1",
5353
"prettier": "2.8.8",
5454
"slash": "^3.0.0",
5555
"string-length": "^2.0.0",

packages/cli-clean/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"types": "build/index.d.ts",
1010
"dependencies": {
1111
"@react-native-community/cli-tools": "20.0.2",
12-
"chalk": "^4.1.2",
1312
"execa": "^5.0.0",
14-
"fast-glob": "^3.3.2"
13+
"fast-glob": "^3.3.2",
14+
"picocolors": "^1.1.1"
1515
},
1616
"files": [
1717
"build",

packages/cli-clean/src/clean.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {getLoader, logger, prompt} from '@react-native-community/cli-tools';
22
import type {Config as CLIConfig} from '@react-native-community/cli-types';
3-
import chalk from 'chalk';
3+
import pico from 'picocolors';
44
import execa from 'execa';
55
import {existsSync as fileExists, rm} from 'fs';
66
import os from 'os';
@@ -62,7 +62,7 @@ async function promptForCaches(
6262
name: 'caches',
6363
message: 'Select all caches to clean',
6464
choices: Object.entries(groups).map(([cmd, group]) => ({
65-
title: `${cmd} ${chalk.dim(`(${group.description})`)}`,
65+
title: `${cmd} ${pico.dim(`(${group.description})`)}`,
6666
value: cmd,
6767
selected: DEFAULT_GROUPS.includes(cmd),
6868
})),

packages/cli-config-android/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
},
99
"dependencies": {
1010
"@react-native-community/cli-tools": "20.0.2",
11-
"chalk": "^4.1.2",
1211
"fast-glob": "^3.3.2",
13-
"fast-xml-parser": "^4.4.1"
12+
"fast-xml-parser": "^4.4.1",
13+
"picocolors": "^1.1.1"
1414
},
1515
"files": [
1616
"build",

packages/cli-config-android/src/config/getAndroidProject.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Config} from '@react-native-community/cli-types';
22
import {logger, CLIError} from '@react-native-community/cli-tools';
33
import fs from 'fs';
4-
import chalk from 'chalk';
4+
import pico from 'picocolors';
55

66
export function getAndroidProject(config: Config) {
77
const androidProject = config.project.android;
@@ -48,11 +48,11 @@ function discoverPackageName(
4848

4949
throw new CLIError(
5050
`Failed to build the app: No package name found.
51-
We couldn't parse the namespace from neither your build.gradle[.kts] file at ${chalk.underline.dim(
52-
`${buildGradlePath}`,
51+
We couldn't parse the namespace from neither your build.gradle[.kts] file at ${pico.underline(
52+
pico.dim(`${buildGradlePath}`),
5353
)}
54-
nor your package in the AndroidManifest at ${chalk.underline.dim(
55-
`${manifestPath}`,
54+
nor your package in the AndroidManifest at ${pico.underline(
55+
pico.dim(`${manifestPath}`),
5656
)}
5757
`,
5858
);
@@ -70,10 +70,10 @@ export function getPackageName(
7070
let packageName = discoverPackageName(manifestPath, buildGradlePath);
7171
if (!validatePackageName(packageName)) {
7272
logger.warn(
73-
`Invalid application's package name "${chalk.bgRed(
73+
`Invalid application's package name "${pico.bgRed(
7474
packageName,
75-
)}" in either 'AndroidManifest.xml' or 'build.gradle'. Read guidelines for setting the package name here: ${chalk.underline.dim(
76-
'https://developer.android.com/studio/build/application-id',
75+
)}" in either 'AndroidManifest.xml' or 'build.gradle'. Read guidelines for setting the package name here: ${pico.underline(
76+
pico.dim('https://developer.android.com/studio/build/application-id'),
7777
)}`,
7878
);
7979
}

packages/cli-config-apple/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
},
99
"dependencies": {
1010
"@react-native-community/cli-tools": "20.0.2",
11-
"chalk": "^4.1.2",
1211
"execa": "^5.0.0",
13-
"fast-glob": "^3.3.2"
12+
"fast-glob": "^3.3.2",
13+
"picocolors": "^1.1.1"
1414
},
1515
"devDependencies": {
1616
"@react-native-community/cli-types": "20.0.2",

packages/cli-config-apple/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
*/
8-
import chalk from 'chalk';
98
import path from 'path';
9+
import pico from 'picocolors';
1010
import fs from 'fs';
1111
import findPodfilePath from './findPodfilePath';
1212
import findXcodeProject from './findXcodeProject';
@@ -85,7 +85,7 @@ export const getDependencyConfig =
8585
}
8686
} catch {
8787
throw new CLIError(
88-
`Failed to locate package.json file from ${chalk.underline(
88+
`Failed to locate package.json file from ${pico.underline(
8989
folder,
9090
)}. This is most likely issue with your node_modules folder being corrupted. Please force install dependencies and try again`,
9191
);

packages/cli-config-apple/src/tools/installPods.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import execa from 'execa';
33
import type {Ora} from 'ora';
4-
import chalk from 'chalk';
4+
import pico from 'picocolors';
55
import {
66
logger,
77
NoopLoader,
@@ -27,9 +27,9 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
2727
const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
2828
try {
2929
loader.start(
30-
`Installing CocoaPods dependencies ${chalk.bold(
30+
`Installing CocoaPods dependencies ${pico.bold(
3131
options?.newArchEnabled ? 'with New Architecture' : '',
32-
)} ${chalk.dim('(this may take a few minutes)')}`,
32+
)} ${pico.dim('(this may take a few minutes)')}`,
3333
);
3434

3535
await execaPod(['install'], {
@@ -83,7 +83,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
8383
async function runPodUpdate(loader: Ora) {
8484
try {
8585
loader.start(
86-
`Updating CocoaPods repositories ${chalk.dim(
86+
`Updating CocoaPods repositories ${pico.dim(
8787
'(this may take a few minutes)',
8888
)}`,
8989
);
@@ -94,8 +94,8 @@ async function runPodUpdate(loader: Ora) {
9494
loader.fail();
9595

9696
throw new CLIError(
97-
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline(
98-
'https://cocoapods.org/',
97+
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${pico.dim(
98+
pico.underline('https://cocoapods.org/'),
9999
)}`,
100100
);
101101
}
@@ -127,8 +127,8 @@ async function installCocoaPods(loader: Ora) {
127127
logger.error((error as any).stderr);
128128

129129
throw new CLIError(
130-
`An error occured while trying to install CocoaPods, which is required by this template.\nPlease try again manually: sudo gem install cocoapods.\nCocoaPods documentation: ${chalk.dim.underline(
131-
'https://cocoapods.org/',
130+
`An error occured while trying to install CocoaPods, which is required by this template.\nPlease try again manually: sudo gem install cocoapods.\nCocoaPods documentation: ${pico.dim(
131+
pico.underline('https://cocoapods.org/'),
132132
)}`,
133133
);
134134
}

packages/cli-config-apple/src/tools/pods.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import fs from 'fs-extra';
33
import {createHash} from 'crypto';
4-
import chalk from 'chalk';
4+
import pico from 'picocolors';
55
import {
66
CLIError,
77
cacheManager,
@@ -112,7 +112,7 @@ async function install(
112112
} catch (error) {
113113
loader.fail();
114114
throw new CLIError(
115-
`Something went wrong while installing CocoaPods. Please run ${chalk.bold(
115+
`Something went wrong while installing CocoaPods. Please run ${pico.bold(
116116
'pod install',
117117
)} manually`,
118118
error as Error,
@@ -208,7 +208,7 @@ export default async function resolvePods(
208208
} catch (error) {
209209
loader.fail();
210210
throw new CLIError(
211-
`Something went wrong while installing CocoaPods. Please run ${chalk.bold(
211+
`Something went wrong while installing CocoaPods. Please run ${pico.bold(
212212
'pod install',
213213
)} manually`,
214214
error as Error,

0 commit comments

Comments
 (0)