-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react-native-info - added simple copy of @react-native-community's im…
…plementation Summary: This current consists of a bunch of TypeScript code, which will be ported to Flow in the stack. Changelog: [Internal] bypass-github-export-checks Reviewed By: huntie Differential Revision: D55741526 fbshipit-source-id: 1dc30d2ab63e0526dd6fed17ccf7cce9f57bdbee
- Loading branch information
1 parent
51552e6
commit 177f2bf
Showing
7 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "react-native-info", | ||
"version": "1.0.0", | ||
"main": "build/index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"types": "build/index.d.ts", | ||
"files": [ | ||
"build", | ||
"!*.d.ts", | ||
"!*.map" | ||
], | ||
"homepage": "https://github.com/facebook//react-native/tree/main/packages/react-native-info", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/facebook/react-native.git", | ||
"directory": "packages/react-native-info" | ||
}, | ||
"dependencies": { | ||
"@react-native-community/cli-config": "^13.6.4", | ||
"@react-native-community/cli-platform-apple": "^13.6.4", | ||
"@react-native-community/cli-tools": "^13.6.4", | ||
"@react-native-community/cli-types": "^13.6.4", | ||
"commander": "^12.0.0", | ||
"fs-extra": "^11.2.0", | ||
"yaml": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"@types/envinfo": "^7.8.3", | ||
"@types/fs-extra": "^11.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import envinfo from 'envinfo'; | ||
import {platform} from 'os'; | ||
import {EnvironmentInfo} from './types'; | ||
|
||
/** | ||
* Returns information about the running system. | ||
* If `json === true`, or no options are passed, | ||
* the return type will be an `EnvironmentInfo`. | ||
* If set to `false`, it will be a `string`. | ||
*/ | ||
export async function getEnvironmentInfoAsString(): Promise<string> { | ||
return getEnvironmentInfo(false); | ||
} | ||
|
||
export async function getEnvironmentInfoAsJson(): Promise<EnvironmentInfo> { | ||
return JSON.parse(await getEnvironmentInfo(true)); | ||
} | ||
|
||
async function getEnvironmentInfo(json: boolean): Promise<string> { | ||
const options = {json, showNotFound: true}; | ||
|
||
const packages = ['react', 'react-native', '@react-native-community/cli']; | ||
|
||
const outOfTreePlatforms: {[key: string]: string} = { | ||
darwin: 'react-native-macos', | ||
win32: 'react-native-windows', | ||
}; | ||
|
||
const outOfTreePlatformPackage = outOfTreePlatforms[platform()]; | ||
if (outOfTreePlatformPackage) { | ||
packages.push(outOfTreePlatformPackage); | ||
} | ||
|
||
const info = await envinfo.run( | ||
{ | ||
System: ['OS', 'CPU', 'Memory', 'Shell'], | ||
Binaries: ['Node', 'Yarn', 'npm', 'Watchman'], | ||
IDEs: ['Xcode', 'Android Studio', 'Visual Studio'], | ||
Managers: ['CocoaPods'], | ||
Languages: ['Java', 'Ruby'], | ||
SDKs: ['iOS SDK', 'Android SDK', 'Windows SDK'], | ||
npmPackages: packages, | ||
npmGlobalPackages: ['*react-native*'], | ||
}, | ||
options, | ||
); | ||
|
||
return info.trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import loadConfig from '@react-native-community/cli-config'; | ||
|
||
import {program} from 'commander'; | ||
import info from './info'; | ||
import {CliOptions} from './types'; | ||
|
||
program | ||
.name('react-native-info') | ||
.description('Get relevant version info about OS, toolchain and libraries') | ||
.version(require('../package.json').version) | ||
.option('--json', 'Output in JSON format') | ||
.parse(process.argv); | ||
|
||
async function main() { | ||
const config = loadConfig(); | ||
const options: CliOptions = program.opts(); | ||
await info(options, config); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {getEnvironmentInfoAsJson} from './envinfo'; | ||
import {logger, version} from '@react-native-community/cli-tools'; | ||
import {Config} from '@react-native-community/cli-types'; | ||
import {getArchitecture} from '@react-native-community/cli-platform-apple'; | ||
import {readFile} from 'fs-extra'; | ||
import path from 'path'; | ||
import {stringify} from 'yaml'; | ||
import {CliOptions} from './types'; | ||
|
||
type PlatformValues = { | ||
hermesEnabled: boolean | string; | ||
newArchEnabled: boolean | string; | ||
}; | ||
|
||
interface Platforms { | ||
Android: PlatformValues; | ||
iOS: PlatformValues; | ||
} | ||
|
||
export default async function getInfo(options: CliOptions, ctx: Config) { | ||
try { | ||
logger.info('Fetching system and libraries information...'); | ||
|
||
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 isNewArchitecture = await getArchitecture( | ||
ctx.project.ios.sourceDir, | ||
); | ||
|
||
platforms.iOS.newArchEnabled = isNewArchitecture; | ||
} 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 getEnvironmentInfoAsJson(), | ||
...platforms, | ||
}; | ||
|
||
if (options.json) { | ||
logger.log(JSON.stringify(output, null, 2)); | ||
} else { | ||
logger.log(stringify(output)); | ||
} | ||
} catch (err) { | ||
logger.error(`Unable to print environment info.\n${err}`); | ||
} finally { | ||
await version.logIfUpdateAvailable(ctx.root); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type {Config} from '@react-native-community/cli-types'; | ||
|
||
export interface CliOptions { | ||
json?: boolean; | ||
} | ||
|
||
export type NotFound = 'Not Found'; | ||
|
||
type AvailableInformation = { | ||
version: string; | ||
path: string; | ||
}; | ||
|
||
type Information = AvailableInformation | NotFound; | ||
|
||
export type EnvironmentInfo = { | ||
System: { | ||
OS: string; | ||
CPU: string; | ||
Memory: string; | ||
Shell: AvailableInformation; | ||
}; | ||
Binaries: { | ||
Node: AvailableInformation; | ||
Yarn: AvailableInformation; | ||
npm: AvailableInformation; | ||
bun: AvailableInformation; | ||
Watchman: AvailableInformation; | ||
}; | ||
Managers: { | ||
CocoaPods: AvailableInformation; | ||
}; | ||
SDKs: { | ||
'iOS SDK': { | ||
Platforms: string[]; | ||
}; | ||
'Android SDK': | ||
| { | ||
'API Levels': string[] | NotFound; | ||
'Build Tools': string[] | NotFound; | ||
'System Images': string[] | NotFound; | ||
'Android NDK': string | NotFound; | ||
} | ||
| NotFound; | ||
}; | ||
IDEs: { | ||
'Android Studio': AvailableInformation | NotFound; | ||
Emacs: AvailableInformation; | ||
Nano: AvailableInformation; | ||
VSCode: AvailableInformation; | ||
Vim: AvailableInformation; | ||
Xcode: AvailableInformation; | ||
}; | ||
Languages: { | ||
Java: Information; | ||
Ruby: AvailableInformation; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"lib": ["es2017"], | ||
"declaration": true, | ||
"declarationMap": true, | ||
"composite": true, | ||
"emitDeclarationOnly": true, | ||
|
||
"strict": true, | ||
|
||
/* Additional Checks */ | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
|
||
/* Module Resolution Options */ | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true, | ||
|
||
"rootDir": "src", | ||
"outDir": "build" | ||
}, | ||
"exclude": ["**/__tests__/**/*", "**/build/**/*"] | ||
} |
Oops, something went wrong.