From 833b22aef9c08c7939e93f944df9a9b4aeed048b Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Sat, 1 Apr 2023 12:38:04 +0200 Subject: [PATCH] feat: add `newArchEnabled` and `hermesEnabled` to `info` command --- packages/cli-doctor/package.json | 3 +- packages/cli-doctor/src/commands/info.ts | 79 +++++++++++++++++++++++- yarn.lock | 5 ++ 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/packages/cli-doctor/package.json b/packages/cli-doctor/package.json index 6926d666b..7e09570fb 100644 --- a/packages/cli-doctor/package.json +++ b/packages/cli-doctor/package.json @@ -24,7 +24,8 @@ "semver": "^6.3.0", "strip-ansi": "^5.2.0", "sudo-prompt": "^9.0.0", - "wcwidth": "^1.0.1" + "wcwidth": "^1.0.1", + "yaml": "^2.2.1" }, "files": [ "build", diff --git a/packages/cli-doctor/src/commands/info.ts b/packages/cli-doctor/src/commands/info.ts index e5b754a73..08117e2ef 100644 --- a/packages/cli-doctor/src/commands/info.ts +++ b/packages/cli-doctor/src/commands/info.ts @@ -8,12 +8,87 @@ import getEnvironmentInfo from '../tools/envinfo'; import {logger, version} from '@react-native-community/cli-tools'; import {Config} from '@react-native-community/cli-types'; +import {readFile} from 'fs-extra'; +import path from 'path'; +import {stringify} from 'yaml'; + +type PlatformValues = { + hermesEnabled: boolean | string; + newArchEnabled: boolean | string; +}; + +interface Platforms { + Android: PlatformValues; + iOS: PlatformValues; +} const info = async function getInfo(_argv: Array, ctx: Config) { try { logger.info('Fetching system and libraries information...'); - const output = await getEnvironmentInfo(false); - logger.log(output); + + const notFound = 'Not found'; + + const platforms: Platforms = { + Android: { + hermesEnabled: notFound, + newArchEnabled: notFound, + }, + iOS: { + hermesEnabled: notFound, + newArchEnabled: notFound, + }, + }; + + if (process.platform !== 'win32' && ctx.project.ios?.sourceDir) { + try { + const podfile = await readFile( + path.join(ctx.project.ios.sourceDir, '/Podfile.lock'), + 'utf8', + ); + + platforms.iOS.hermesEnabled = podfile.includes('hermes-engine'); + } catch (e) { + platforms.iOS.hermesEnabled = notFound; + } + + try { + const project = await readFile( + path.join( + ctx.project.ios.sourceDir, + '/Pods/Pods.xcodeproj/project.pbxproj', + ), + ); + + platforms.iOS.newArchEnabled = project.includes( + '-DRCT_NEW_ARCH_ENABLED=1', + ); + } catch { + platforms.iOS.newArchEnabled = notFound; + } + } + + if (ctx.project.android?.sourceDir) { + try { + const gradleProperties = await readFile( + path.join(ctx.project.android.sourceDir, '/gradle.properties'), + 'utf8', + ); + + platforms.Android.hermesEnabled = gradleProperties.includes( + 'hermesEnabled=true', + ); + platforms.Android.newArchEnabled = gradleProperties.includes( + 'newArchEnabled=true', + ); + } catch { + platforms.Android.hermesEnabled = notFound; + platforms.Android.newArchEnabled = notFound; + } + } + + const output = await getEnvironmentInfo(); + + logger.log(stringify({...output, ...platforms})); } catch (err) { logger.error(`Unable to print environment info.\n${err}`); } finally { diff --git a/yarn.lock b/yarn.lock index 7b05eee33..ede24f6ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13307,6 +13307,11 @@ yaml@^2.1.3: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.1.3.tgz#9b3a4c8aff9821b696275c79a8bee8399d945207" integrity sha512-AacA8nRULjKMX2DvWvOAdBZMOfQlypSFkjcOcu9FalllIDJ1kvlREzcdIZmidQUqqeMv7jorHjq2HlLv/+c2lg== +yaml@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.2.1.tgz#3014bf0482dcd15147aa8e56109ce8632cd60ce4" + integrity sha512-e0WHiYql7+9wr4cWMx3TVQrNwejKaEe7/rHNmQmqRjazfOP5W8PB6Jpebb5o6fIapbz9o9+2ipcaTM2ZwDI6lw== + yargs-parser@20.2.4: version "20.2.4" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"