cleanup(react-native): migrate react-native to picocolors (#29566)

This commit is contained in:
Phillip Barta 2025-01-24 13:47:49 +01:00 committed by GitHub
parent 3e4f16f8b0
commit c8865badac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 30 deletions

View File

@ -52,6 +52,10 @@
{ {
"name": "fs-extra", "name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead." "message": "Please use equivalent utilities from `node:fs` instead."
},
{
"name": "chalk",
"message": "Please use `picocolors` in place of `chalk` for rendering terminal colors"
} }
] ]
} }

View File

@ -27,13 +27,13 @@
"types": "index.d.ts", "types": "index.d.ts",
"dependencies": { "dependencies": {
"ajv": "^8.12.0", "ajv": "^8.12.0",
"chalk": "^4.1.0",
"enhanced-resolve": "^5.8.3", "enhanced-resolve": "^5.8.3",
"glob": "7.1.4", "glob": "7.1.4",
"ignore": "^5.0.4", "ignore": "^5.0.4",
"metro-config": "~0.80.4", "metro-config": "~0.80.4",
"metro-resolver": "~0.80.4", "metro-resolver": "~0.80.4",
"node-fetch": "^2.6.7", "node-fetch": "^2.6.7",
"picocolors": "^1.1.0",
"tsconfig-paths": "^4.1.2", "tsconfig-paths": "^4.1.2",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"@nx/devkit": "file:../devkit", "@nx/devkit": "file:../devkit",

View File

@ -1,7 +1,7 @@
import * as metroResolver from 'metro-resolver'; import * as metroResolver from 'metro-resolver';
import type { MatchPath } from 'tsconfig-paths'; import type { MatchPath } from 'tsconfig-paths';
import { createMatchPath, loadConfig } from 'tsconfig-paths'; import { createMatchPath, loadConfig } from 'tsconfig-paths';
import * as chalk from 'chalk'; import * as pc from 'picocolors';
import { CachedInputFileSystem, ResolverFactory } from 'enhanced-resolve'; import { CachedInputFileSystem, ResolverFactory } from 'enhanced-resolve';
import { dirname, join } from 'path'; import { dirname, join } from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
@ -56,10 +56,10 @@ export function getResolveRequest(
} }
if (debug) { if (debug) {
console.log( console.log(
chalk.red(`[Nx] Unable to resolve with any resolver: ${realModuleName}`) pc.red(`[Nx] Unable to resolve with any resolver: ${realModuleName}`)
); );
} }
throw new Error(`Cannot resolve ${chalk.bold(realModuleName)}`); throw new Error(`Cannot resolve ${pc.bold(realModuleName)}`);
}; };
} }
@ -75,7 +75,7 @@ function resolveRequestFromContext(
} catch { } catch {
if (debug) if (debug)
console.log( console.log(
chalk.cyan( pc.cyan(
`[Nx] Unable to resolve with default resolveRequest: ${realModuleName}` `[Nx] Unable to resolve with default resolveRequest: ${realModuleName}`
) )
); );
@ -97,7 +97,7 @@ function defaultMetroResolver(
} catch { } catch {
if (debug) if (debug)
console.log( console.log(
chalk.cyan( pc.cyan(
`[Nx] Unable to resolve with default Metro resolver: ${realModuleName}` `[Nx] Unable to resolve with default Metro resolver: ${realModuleName}`
) )
); );
@ -131,7 +131,7 @@ function pnpmResolver(
} catch { } catch {
if (debug) if (debug)
console.log( console.log(
chalk.cyan( pc.cyan(
`[Nx] Unable to resolve with default PNPM resolver: ${realModuleName}` `[Nx] Unable to resolve with default PNPM resolver: ${realModuleName}`
) )
); );
@ -160,12 +160,10 @@ function tsconfigPathsResolver(
return metroResolver.resolve(context, match, platform); return metroResolver.resolve(context, match, platform);
} catch { } catch {
if (debug) { if (debug) {
console.log(pc.cyan(`[Nx] Failed to resolve ${pc.bold(realModuleName)}`));
console.log( console.log(
chalk.cyan(`[Nx] Failed to resolve ${chalk.bold(realModuleName)}`) pc.cyan(
); `[Nx] The following tsconfig paths was used:\n:${pc.bold(
console.log(
chalk.cyan(
`[Nx] The following tsconfig paths was used:\n:${chalk.bold(
JSON.stringify(paths, null, 2) JSON.stringify(paths, null, 2)
)}` )}`
) )
@ -186,11 +184,11 @@ function getMatcher(debug: boolean) {
paths = result.paths; paths = result.paths;
if (debug) { if (debug) {
console.log( console.log(
chalk.cyan(`[Nx] Located tsconfig at ${chalk.bold(absoluteBaseUrl)}`) pc.cyan(`[Nx] Located tsconfig at ${pc.bold(absoluteBaseUrl)}`)
); );
console.log( console.log(
chalk.cyan( pc.cyan(
`[Nx] Found the following paths:\n:${chalk.bold( `[Nx] Found the following paths:\n:${pc.bold(
JSON.stringify(paths, null, 2) JSON.stringify(paths, null, 2)
)}` )}`
) )
@ -198,7 +196,7 @@ function getMatcher(debug: boolean) {
} }
matcher = createMatchPath(absoluteBaseUrl, paths); matcher = createMatchPath(absoluteBaseUrl, paths);
} else { } else {
console.log(chalk.cyan(`[Nx] Failed to locate tsconfig}`)); console.log(pc.cyan(`[Nx] Failed to locate tsconfig}`));
throw new Error(`Could not load tsconfig for project`); throw new Error(`Could not load tsconfig for project`);
} }
} }

View File

@ -2,7 +2,7 @@ import { writeFileSync } from 'node:fs';
import { join, relative, resolve, dirname } from 'path'; import { join, relative, resolve, dirname } from 'path';
import { ExecutorContext, logger, readJsonFile } from '@nx/devkit'; import { ExecutorContext, logger, readJsonFile } from '@nx/devkit';
import { fileExists } from '@nx/workspace/src/utilities/fileutils'; import { fileExists } from '@nx/workspace/src/utilities/fileutils';
import * as chalk from 'chalk'; import * as pc from 'picocolors';
import { sync as globSync } from 'glob'; import { sync as globSync } from 'glob';
import { ReactNativeStorybookOptions } from './schema'; import { ReactNativeStorybookOptions } from './schema';
@ -25,8 +25,8 @@ export default async function* reactNativeStorybookExecutor(
const projectRoot = const projectRoot =
context.projectsConfigurations.projects[context.projectName].root; context.projectsConfigurations.projects[context.projectName].root;
logger.info( logger.info(
`${chalk.bold.cyan( `${pc.bold(
'info' pc.cyan('info')
)} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).` )} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).`
); );
@ -78,7 +78,7 @@ export function runCliStorybook(
}); });
if (storiesFiles.length === 0) { if (storiesFiles.length === 0) {
logger.warn(`${chalk.bold.yellow('warn')} No stories found.`); logger.warn(`${pc.bold(pc.yellow('warn'))} No stories found.`);
} }
const newContents = `// Auto-generated file created by nx const newContents = `// Auto-generated file created by nx

View File

@ -1,5 +1,5 @@
import { join } from 'path'; import { join } from 'path';
import * as chalk from 'chalk'; import * as pc from 'picocolors';
import { import {
ExecutorContext, ExecutorContext,
ProjectGraph, ProjectGraph,
@ -126,14 +126,14 @@ export function displayNewlyAddedDepsMessage(
deps: string[] deps: string[]
) { ) {
if (deps.length > 0) { if (deps.length > 0) {
logger.info(`${chalk.bold.cyan( logger.info(`${pc.bold(
'info' pc.cyan('info')
)} Added entries to 'package.json' for '${projectName}' (for autolink): )} Added entries to 'package.json' for '${projectName}' (for autolink):
${deps.map((d) => chalk.bold.cyan(`"${d}": "*"`)).join('\n ')}`); ${deps.map((d) => pc.bold(pc.cyan(`"${d}": "*"`))).join('\n ')}`);
} else { } else {
logger.info( logger.info(
`${chalk.bold.cyan( `${pc.bold(
'info' pc.cyan('info')
)} Dependencies for '${projectName}' are up to date! No changes made.` )} Dependencies for '${projectName}' are up to date! No changes made.`
); );
} }

View File

@ -2,18 +2,18 @@ import { execSync } from 'child_process';
import { existsSync } from 'node:fs'; import { existsSync } from 'node:fs';
import { platform } from 'os'; import { platform } from 'os';
import { join } from 'path'; import { join } from 'path';
import * as chalk from 'chalk'; import * as pc from 'picocolors';
import { GeneratorCallback, logger } from '@nx/devkit'; import { GeneratorCallback, logger } from '@nx/devkit';
const podInstallErrorMessage = ` const podInstallErrorMessage = `
Running ${chalk.bold('pod install')} failed, see above. Running ${pc.bold('pod install')} failed, see above.
Do you have CocoaPods (https://cocoapods.org/) installed? Do you have CocoaPods (https://cocoapods.org/) installed?
Check that your XCode path is correct: Check that your XCode path is correct:
${chalk.bold('sudo xcode-select --print-path')} ${pc.bold('sudo xcode-select --print-path')}
If the path is wrong, switch the path: (your path may be different) If the path is wrong, switch the path: (your path may be different)
${chalk.bold('sudo xcode-select --switch /Applications/Xcode.app')} ${pc.bold('sudo xcode-select --switch /Applications/Xcode.app')}
`; `;
/** /**