From 4870ac55811d9c1491f2730088f3cb96f4f3c049 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 9 Sep 2019 19:05:12 +0200 Subject: [PATCH] imp: Migrate `platform-ios` to TypeScript (#620) * imp: move `platform-ios` to Typescript * imp: Move tests and fixtures * Add missing types * Review fixes * More review suggestions * adjust tsdoc * remove flowfixmes * fix any from process --- packages/cli-types/package.json | 7 ++ packages/cli-types/src/android.ts | 39 ++++++ .../src/types.ts => cli-types/src/index.ts} | 107 +++++++++-------- packages/cli-types/src/ios.ts | 33 ++++++ packages/cli-types/tsconfig.json | 7 ++ packages/platform-android/package.json | 1 + .../src/commands/runAndroid/index.ts | 2 +- packages/platform-android/src/config/index.ts | 9 +- .../src/link/patches/applyParams.ts | 4 +- .../src/link/patches/makePackagePatch.ts | 4 +- .../src/link/patches/makeStringsPatch.ts | 4 +- .../src/link/registerNativeModule.ts | 14 +-- .../src/link/unregisterNativeModule.ts | 9 +- .../src/link/warnAboutManuallyLinkedLibs.ts | 2 +- packages/platform-android/tsconfig.json | 2 +- .../platform-ios/definitions/xcode/index.d.ts | 5 + .../definitions/xcode/lib/index.d.ts | 5 + packages/platform-ios/package.json | 4 + .../src/commands/{index.js => index.ts} | 3 - .../commands/logIOS/{index.js => index.ts} | 10 +- ...-test.js => findMatchingSimulator.test.ts} | 18 +-- ...oject-test.js => findXcodeProject.test.ts} | 2 - ...st-test.js => parseIOSDevicesList.test.ts} | 2 - ...gSimulator.js => findMatchingSimulator.ts} | 20 ++-- ...indXcodeProject.js => findXcodeProject.ts} | 10 +- .../commands/runIOS/{index.js => index.ts} | 112 ++++++++++++------ ...SDevicesList.js => parseIOSDevicesList.ts} | 14 +-- .../__fixtures__/{projects.js => projects.ts} | 6 +- ...lePath-test.js => findPodfilePath.test.ts} | 0 ...indPodspec-test.js => findPodspec.test.ts} | 5 - ...indProject-test.js => findProject.test.ts} | 2 - ...onfig-test.js => getProjectConfig.test.ts} | 2 - ...{findPodfilePath.js => findPodfilePath.ts} | 2 - .../config/{findPodspec.js => findPodspec.ts} | 4 - .../config/{findProject.js => findProject.ts} | 2 - .../{getPodspecName.js => getPodspecName.ts} | 1 - .../src/config/{index.js => index.ts} | 13 +- .../platform-ios/src/{index.js => index.ts} | 2 - ...ddPod-test.js => findLineToAddPod.test.ts} | 2 - ...st.js => findMarkedLinesInPodfile.test.ts} | 11 +- ...Line-test.js => findPodTargetLine.test.ts} | 2 - ...sInstalled-test.js => isInstalled.test.ts} | 6 +- ...odEntry-test.js => removePodEntry.test.ts} | 2 - .../{addPodEntry.js => addPodEntry.ts} | 11 +- ...indLineToAddPod.js => findLineToAddPod.ts} | 6 +- ...Podfile.js => findMarkedLinesInPodfile.ts} | 1 - ...dPodTargetLine.js => findPodTargetLine.ts} | 6 +- .../{isInstalled.js => isInstalled.ts} | 10 +- .../{readPodfile.js => readPodfile.ts} | 3 +- ...ativeModule.js => registerNativeModule.ts} | 10 +- .../{removePodEntry.js => removePodEntry.ts} | 6 +- .../{savePodFile.js => savePodFile.ts} | 6 +- ...iveModule.js => unregisterNativeModule.ts} | 10 +- ...oject-test.js => addFileToProject.test.ts} | 2 - ...-test.js => addProjectToLibraries.test.ts} | 2 - ...ies-test.js => addSharedLibraries.test.ts} | 2 - ...reateGroup-test.js => createGroup.test.ts} | 2 - ...perty-test.js => getBuildProperty.test.ts} | 2 - .../{getGroup-test.js => getGroup.test.ts} | 2 - ...th-test.js => getHeaderSearchPath.test.ts} | 2 - ...der-test.js => getHeadersInFolder.test.ts} | 2 - .../{getPlist-test.js => getPlist.test.ts} | 2 - ...PlistPath-test.js => getPlistPath.test.ts} | 2 - ...{getTargets-test.js => getTargets.test.ts} | 2 - ...ted-test.js => hasLibraryImported.test.ts} | 2 - ...sInstalled-test.js => isInstalled.test.ts} | 5 +- ...s-test.js => mapHeaderSearchPaths.test.ts} | 2 - ....js => removeProjectFromLibraries.test.ts} | 2 - ...st.js => removeProjectFromProject.test.ts} | 2 - ...ry-test.js => removeSharedLibrary.test.ts} | 2 - ...{writePlist-test.js => writePlist.test.ts} | 4 +- ...ddFileToProject.js => addFileToProject.ts} | 2 - ...oLibraries.js => addProjectToLibraries.ts} | 6 +- ...aredLibraries.js => addSharedLibraries.ts} | 6 +- ...archPaths.js => addToHeaderSearchPaths.ts} | 3 +- .../common/{isInstalled.js => isInstalled.ts} | 13 +- ...ativeModule.js => registerNativeModule.ts} | 14 ++- ...iveModule.js => unregisterNativeModule.ts} | 14 ++- .../src/link/{copyAssets.js => copyAssets.ts} | 9 +- .../link/{createGroup.js => createGroup.ts} | 9 +- ...thMessage.js => createGroupWithMessage.ts} | 3 +- ...etBuildProperty.js => getBuildProperty.ts} | 3 +- .../src/link/{getGroup.js => getGroup.ts} | 12 +- ...erSearchPath.js => getHeaderSearchPath.ts} | 8 +- ...adersInFolder.js => getHeadersInFolder.ts} | 3 +- .../src/link/{getPlist.js => getPlist.ts} | 3 +- .../link/{getPlistPath.js => getPlistPath.ts} | 3 +- .../src/link/{getTargets.js => getTargets.ts} | 11 +- ...braryImported.js => hasLibraryImported.ts} | 6 +- .../src/link/{index.js => index.ts} | 1 - .../link/{isInstalled.js => isInstalled.ts} | 10 +- ...SearchPaths.js => mapHeaderSearchPaths.ts} | 6 +- ...ativeModule.js => registerNativeModule.ts} | 12 +- ...aths.js => removeFromHeaderSearchPaths.ts} | 3 +- ...removeFromPbxItemContainerProxySection.ts} | 6 +- ... => removeFromPbxReferenceProxySection.ts} | 6 +- ...nces.js => removeFromProjectReferences.ts} | 5 +- ...raries.js => removeFromStaticLibraries.ts} | 7 +- ...eProductGroup.js => removeProductGroup.ts} | 3 +- ...aries.js => removeProjectFromLibraries.ts} | 5 +- ...Project.js => removeProjectFromProject.ts} | 6 +- ...dLibraries.js => removeSharedLibraries.ts} | 6 +- .../link/{unlinkAssets.js => unlinkAssets.ts} | 9 +- ...iveModule.js => unregisterNativeModule.ts} | 14 ++- ...Libs.js => warnAboutManuallyLinkedLibs.ts} | 14 +-- .../src/link/{writePlist.js => writePlist.ts} | 10 +- packages/platform-ios/src/types.ts | 9 ++ packages/platform-ios/tsconfig.json | 9 ++ tsconfig.json | 6 +- yarn.lock | 13 ++ 110 files changed, 540 insertions(+), 369 deletions(-) create mode 100644 packages/cli-types/package.json create mode 100644 packages/cli-types/src/android.ts rename packages/{platform-android/src/types.ts => cli-types/src/index.ts} (65%) create mode 100644 packages/cli-types/src/ios.ts create mode 100644 packages/cli-types/tsconfig.json create mode 100644 packages/platform-ios/definitions/xcode/index.d.ts create mode 100644 packages/platform-ios/definitions/xcode/lib/index.d.ts rename packages/platform-ios/src/commands/{index.js => index.ts} (84%) rename packages/platform-ios/src/commands/logIOS/{index.js => index.ts} (84%) rename packages/platform-ios/src/commands/runIOS/__tests__/{findMatchingSimulator-test.js => findMatchingSimulator.test.ts} (98%) rename packages/platform-ios/src/commands/runIOS/__tests__/{findXcodeProject-test.js => findXcodeProject.test.ts} (96%) rename packages/platform-ios/src/commands/runIOS/__tests__/{parseIOSDevicesList-test.js => parseIOSDevicesList.test.ts} (96%) rename packages/platform-ios/src/commands/runIOS/{findMatchingSimulator.js => findMatchingSimulator.ts} (84%) rename packages/platform-ios/src/commands/runIOS/{findXcodeProject.js => findXcodeProject.ts} (81%) rename packages/platform-ios/src/commands/runIOS/{index.js => index.ts} (85%) rename packages/platform-ios/src/commands/runIOS/{parseIOSDevicesList.js => parseIOSDevicesList.ts} (78%) rename packages/platform-ios/src/config/__fixtures__/{projects.js => projects.ts} (91%) rename packages/platform-ios/src/config/__tests__/{findPodfilePath-test.js => findPodfilePath.test.ts} (100%) rename packages/platform-ios/src/config/__tests__/{findPodspec-test.js => findPodspec.test.ts} (94%) rename packages/platform-ios/src/config/__tests__/{findProject-test.js => findProject.test.ts} (97%) rename packages/platform-ios/src/config/__tests__/{getProjectConfig-test.js => getProjectConfig.test.ts} (96%) rename packages/platform-ios/src/config/{findPodfilePath.js => findPodfilePath.ts} (95%) rename packages/platform-ios/src/config/{findPodspec.js => findPodspec.ts} (96%) rename packages/platform-ios/src/config/{findProject.js => findProject.ts} (98%) rename packages/platform-ios/src/config/{getPodspecName.js => getPodspecName.ts} (97%) rename packages/platform-ios/src/config/{index.js => index.ts} (87%) rename packages/platform-ios/src/{index.js => index.ts} (93%) rename packages/platform-ios/src/link-pods/__tests__/{findLineToAddPod-test.js => findLineToAddPod.test.ts} (96%) rename packages/platform-ios/src/link-pods/__tests__/{findMarkedLinesInPodfile-test.js => findMarkedLinesInPodfile.test.ts} (76%) rename packages/platform-ios/src/link-pods/__tests__/{findPodTargetLine-test.js => findPodTargetLine.test.ts} (95%) rename packages/platform-ios/src/link-pods/__tests__/{isInstalled-test.js => isInstalled.test.ts} (90%) rename packages/platform-ios/src/link-pods/__tests__/{removePodEntry-test.js => removePodEntry.test.ts} (97%) rename packages/platform-ios/src/link-pods/{addPodEntry.js => addPodEntry.ts} (84%) rename packages/platform-ios/src/link-pods/{findLineToAddPod.js => findLineToAddPod.ts} (92%) rename packages/platform-ios/src/link-pods/{findMarkedLinesInPodfile.js => findMarkedLinesInPodfile.ts} (98%) rename packages/platform-ios/src/link-pods/{findPodTargetLine.js => findPodTargetLine.ts} (85%) rename packages/platform-ios/src/link-pods/{isInstalled.js => isInstalled.ts} (83%) rename packages/platform-ios/src/link-pods/{readPodfile.js => readPodfile.ts} (86%) rename packages/platform-ios/src/link-pods/{registerNativeModule.js => registerNativeModule.ts} (89%) rename packages/platform-ios/src/link-pods/{removePodEntry.js => removePodEntry.ts} (89%) rename packages/platform-ios/src/link-pods/{savePodFile.js => savePodFile.ts} (82%) rename packages/platform-ios/src/link-pods/{unregisterNativeModule.js => unregisterNativeModule.ts} (73%) rename packages/platform-ios/src/link/__tests__/{addFileToProject-test.js => addFileToProject.test.ts} (94%) rename packages/platform-ios/src/link/__tests__/{addProjectToLibraries-test.js => addProjectToLibraries.test.ts} (94%) rename packages/platform-ios/src/link/__tests__/{addSharedLibraries-test.js => addSharedLibraries.test.ts} (96%) rename packages/platform-ios/src/link/__tests__/{createGroup-test.js => createGroup.test.ts} (96%) rename packages/platform-ios/src/link/__tests__/{getBuildProperty-test.js => getBuildProperty.test.ts} (93%) rename packages/platform-ios/src/link/__tests__/{getGroup-test.js => getGroup.test.ts} (96%) rename packages/platform-ios/src/link/__tests__/{getHeaderSearchPath-test.js => getHeaderSearchPath.test.ts} (98%) rename packages/platform-ios/src/link/__tests__/{getHeadersInFolder-test.js => getHeadersInFolder.test.ts} (95%) rename packages/platform-ios/src/link/__tests__/{getPlist-test.js => getPlist.test.ts} (92%) rename packages/platform-ios/src/link/__tests__/{getPlistPath-test.js => getPlistPath.test.ts} (92%) rename packages/platform-ios/src/link/__tests__/{getTargets-test.js => getTargets.test.ts} (93%) rename packages/platform-ios/src/link/__tests__/{hasLibraryImported-test.js => hasLibraryImported.test.ts} (94%) rename packages/platform-ios/src/link/__tests__/{isInstalled-test.js => isInstalled.test.ts} (90%) rename packages/platform-ios/src/link/__tests__/{mapHeaderSearchPaths-test.js => mapHeaderSearchPaths.test.ts} (95%) rename packages/platform-ios/src/link/__tests__/{removeProjectFromLibraries-test.js => removeProjectFromLibraries.test.ts} (95%) rename packages/platform-ios/src/link/__tests__/{removeProjectFromProject-test.js => removeProjectFromProject.test.ts} (96%) rename packages/platform-ios/src/link/__tests__/{removeSharedLibrary-test.js => removeSharedLibrary.test.ts} (95%) rename packages/platform-ios/src/link/__tests__/{writePlist-test.js => writePlist.test.ts} (97%) rename packages/platform-ios/src/link/{addFileToProject.js => addFileToProject.ts} (96%) rename packages/platform-ios/src/link/{addProjectToLibraries.js => addProjectToLibraries.ts} (75%) rename packages/platform-ios/src/link/{addSharedLibraries.js => addSharedLibraries.ts} (85%) rename packages/platform-ios/src/link/{addToHeaderSearchPaths.js => addToHeaderSearchPaths.ts} (85%) rename packages/platform-ios/src/link/common/{isInstalled.js => isInstalled.ts} (66%) rename packages/platform-ios/src/link/common/{registerNativeModule.js => registerNativeModule.ts} (72%) rename packages/platform-ios/src/link/common/{unregisterNativeModule.js => unregisterNativeModule.ts} (79%) rename packages/platform-ios/src/link/{copyAssets.js => copyAssets.ts} (87%) rename packages/platform-ios/src/link/{createGroup.js => createGroup.ts} (76%) rename packages/platform-ios/src/link/{createGroupWithMessage.js => createGroupWithMessage.ts} (91%) rename packages/platform-ios/src/link/{getBuildProperty.js => getBuildProperty.ts} (94%) rename packages/platform-ios/src/link/{getGroup.js => getGroup.ts} (73%) rename packages/platform-ios/src/link/{getHeaderSearchPath.js => getHeaderSearchPath.ts} (92%) rename packages/platform-ios/src/link/{getHeadersInFolder.js => getHeadersInFolder.ts} (90%) rename packages/platform-ios/src/link/{getPlist.js => getPlist.ts} (89%) rename packages/platform-ios/src/link/{getPlistPath.js => getPlistPath.ts} (86%) rename packages/platform-ios/src/link/{getTargets.js => getTargets.ts} (85%) rename packages/platform-ios/src/link/{hasLibraryImported.js => hasLibraryImported.ts} (79%) rename packages/platform-ios/src/link/{index.js => index.ts} (98%) rename packages/platform-ios/src/link/{isInstalled.js => isInstalled.ts} (84%) rename packages/platform-ios/src/link/{mapHeaderSearchPaths.js => mapHeaderSearchPaths.ts} (92%) rename packages/platform-ios/src/link/{registerNativeModule.js => registerNativeModule.ts} (92%) rename packages/platform-ios/src/link/{removeFromHeaderSearchPaths.js => removeFromHeaderSearchPaths.ts} (88%) rename packages/platform-ios/src/link/{removeFromPbxItemContainerProxySection.js => removeFromPbxItemContainerProxySection.ts} (86%) rename packages/platform-ios/src/link/{removeFromPbxReferenceProxySection.js => removeFromPbxReferenceProxySection.ts} (84%) rename packages/platform-ios/src/link/{removeFromProjectReferences.js => removeFromProjectReferences.ts} (87%) rename packages/platform-ios/src/link/{removeFromStaticLibraries.js => removeFromStaticLibraries.ts} (86%) rename packages/platform-ios/src/link/{removeProductGroup.js => removeProductGroup.ts} (81%) rename packages/platform-ios/src/link/{removeProjectFromLibraries.js => removeProjectFromLibraries.ts} (79%) rename packages/platform-ios/src/link/{removeProjectFromProject.js => removeProjectFromProject.ts} (92%) rename packages/platform-ios/src/link/{removeSharedLibraries.js => removeSharedLibraries.ts} (80%) rename packages/platform-ios/src/link/{unlinkAssets.js => unlinkAssets.ts} (87%) rename packages/platform-ios/src/link/{unregisterNativeModule.js => unregisterNativeModule.ts} (89%) rename packages/platform-ios/src/link/{warnAboutManuallyLinkedLibs.js => warnAboutManuallyLinkedLibs.ts} (88%) rename packages/platform-ios/src/link/{writePlist.js => writePlist.ts} (80%) create mode 100644 packages/platform-ios/src/types.ts create mode 100644 packages/platform-ios/tsconfig.json diff --git a/packages/cli-types/package.json b/packages/cli-types/package.json new file mode 100644 index 000000000..6a9a1ec18 --- /dev/null +++ b/packages/cli-types/package.json @@ -0,0 +1,7 @@ +{ + "name": "@react-native-community/cli-types", + "version": "2.8.3", + "main": "build", + "types": "build/index.d.ts", + "license": "MIT" +} diff --git a/packages/cli-types/src/android.ts b/packages/cli-types/src/android.ts new file mode 100644 index 000000000..54fd885b7 --- /dev/null +++ b/packages/cli-types/src/android.ts @@ -0,0 +1,39 @@ +export interface AndroidProjectConfig { + sourceDir: string; + isFlat: boolean; + folder: string; + stringsPath: string; + manifestPath: string; + buildGradlePath: string; + settingsGradlePath: string; + assetsPath: string; + mainFilePath: string; + packageName: string; +} + +export interface AndroidProjectParams { + sourceDir?: string; + manifestPath?: string; + packageName?: string; + packageFolder?: string; + mainFilePath?: string; + stringsPath?: string; + settingsGradlePath?: string; + assetsPath?: string; + buildGradlePath?: string; +} + +export interface AndroidDependencyConfig { + sourceDir: string; + folder: string; + packageImportPath: string; + packageInstance: string; +} + +export interface AndroidDependencyParams { + packageName?: string; + sourceDir?: string; + manifestPath?: string; + packageImportPath?: string; + packageInstance?: string; +} diff --git a/packages/platform-android/src/types.ts b/packages/cli-types/src/index.ts similarity index 65% rename from packages/platform-android/src/types.ts rename to packages/cli-types/src/index.ts index 7058e4070..15eca2521 100644 --- a/packages/platform-android/src/types.ts +++ b/packages/cli-types/src/index.ts @@ -1,4 +1,17 @@ -export type InquirerPromptT = any; +import { + IOSProjectConfig, + IOSProjectParams, + IOSDependencyConfig, + IOSDependencyParams, +} from './ios'; +import { + AndroidProjectConfig, + AndroidProjectParams, + AndroidDependencyConfig, + AndroidDependencyParams, +} from './android'; + +export type InquirerPrompt = any; export interface Command { name: string; @@ -25,10 +38,10 @@ export interface Command { } interface PlatformConfig< - ProjectParams, - DependencyParams, ProjectConfig, - DependencyConfig + ProjectParams, + DependencyConfig, + DependencyParams > { projectConfig: ( projectRoot: string, @@ -60,6 +73,7 @@ interface PlatformConfig< unlinkAssets: (assets: string[], projectConfig: ProjectConfig) => void; }; } + /** * @property root - Root where the configuration has been resolved from * @property reactNativePath - Path to React Native source @@ -74,7 +88,8 @@ export interface Config { root: string; reactNativePath: string; project: { - android?: ProjectConfigAndroid; + android?: AndroidProjectConfig; + ios?: IOSProjectConfig; [key: string]: any; }; assets: string[]; @@ -83,7 +98,8 @@ export interface Config { name: string; root: string; platforms: { - android?: DependencyConfigAndroid | null; + android?: AndroidDependencyConfig | null; + ios?: IOSDependencyConfig | null; [key: string]: any; }; assets: string[]; @@ -91,15 +107,21 @@ export interface Config { prelink?: string; postlink?: string; }; - params: InquirerPromptT[]; + params: InquirerPrompt[]; }; }; platforms: { android: PlatformConfig< - ProjectParamsAndroid, - DependencyParamsAndroid, - ProjectConfigAndroid, - DependencyConfigAndroid + AndroidProjectConfig, + AndroidProjectParams, + AndroidDependencyConfig, + AndroidDependencyParams + >; + ios: PlatformConfig< + IOSProjectConfig, + IOSProjectParams, + IOSDependencyConfig, + IOSDependencyParams >; [name: string]: PlatformConfig; }; @@ -110,42 +132,33 @@ export interface Config { }; } -export interface ProjectConfigAndroid { - sourceDir: string; - isFlat: boolean; - folder: string; - stringsPath: string; - manifestPath: string; - buildGradlePath: string; - settingsGradlePath: string; - assetsPath: string; - mainFilePath: string; - packageName: string; -} +type Diff = T extends U ? never : T; -export interface ProjectParamsAndroid { - sourceDir?: string; - manifestPath?: string; - packageName?: string; - packageFolder?: string; - mainFilePath?: string; - stringsPath?: string; - settingsGradlePath?: string; - assetsPath?: string; - buildGradlePath?: string; -} +/** + * Shares some structure with ConfigT, except that haste and root + * are calculated and can't be defined + */ +export type UserConfig = Diff & { + reactNativePath: string | void; -export interface DependencyConfigAndroid { - sourceDir: string; - folder: string; - packageImportPath: string; - packageInstance: string; -} + // Additional project settings + project: { + android?: AndroidProjectParams; + ios?: IOSProjectParams; + [key: string]: any; + }; +}; -export interface DependencyParamsAndroid { - packageName?: string; - sourceDir?: string; - manifestPath?: string; - packageImportPath?: string; - packageInstance?: string; -} +export { + IOSProjectConfig, + IOSProjectParams, + IOSDependencyConfig, + IOSDependencyParams, +}; + +export { + AndroidProjectConfig, + AndroidProjectParams, + AndroidDependencyConfig, + AndroidDependencyParams, +}; diff --git a/packages/cli-types/src/ios.ts b/packages/cli-types/src/ios.ts new file mode 100644 index 000000000..173f2116d --- /dev/null +++ b/packages/cli-types/src/ios.ts @@ -0,0 +1,33 @@ +/** + * Settings that user can define in the project configuration for iOS. + * Same for dependency - we share the type. + * + * See UserDependencyConfigT and UserConfigT for details + */ +export interface IOSProjectParams { + project?: string; + podspecPath?: string; + sharedLibraries?: string[]; + libraryFolder?: string; + plist: Array; + scriptPhases: Array; +} + +export interface IOSDependencyParams extends IOSProjectParams {} + +// The following types are used in untyped-parts of the codebase, so I am leaving them +// until we actually need them. +export interface IOSProjectConfig { + sourceDir: string; + folder: string; + pbxprojPath: string; + podfile: string; + podspecPath: string; + projectPath: string; + projectName: string; + libraryFolder: string; + sharedLibraries: Array; + plist: Array; +} + +export interface IOSDependencyConfig extends IOSProjectConfig {} diff --git a/packages/cli-types/tsconfig.json b/packages/cli-types/tsconfig.json new file mode 100644 index 000000000..7bb06bce6 --- /dev/null +++ b/packages/cli-types/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + } +} diff --git a/packages/platform-android/package.json b/packages/platform-android/package.json index c5854d324..4c037299a 100644 --- a/packages/platform-android/package.json +++ b/packages/platform-android/package.json @@ -17,6 +17,7 @@ "native_modules.gradle" ], "devDependencies": { + "@react-native-community/cli-types": "^2.8.3", "@types/execa": "^0.9.0", "@types/fs-extra": "^8.0.0", "@types/glob": "^7.1.1", diff --git a/packages/platform-android/src/commands/runAndroid/index.ts b/packages/platform-android/src/commands/runAndroid/index.ts index b764be593..373e582c7 100644 --- a/packages/platform-android/src/commands/runAndroid/index.ts +++ b/packages/platform-android/src/commands/runAndroid/index.ts @@ -10,7 +10,7 @@ import path from 'path'; import execa from 'execa'; import chalk from 'chalk'; import fs from 'fs'; -import {Config} from '../../types'; +import {Config} from '@react-native-community/cli-types'; import adb from './adb'; import runOnAllDevices from './runOnAllDevices'; import tryRunAdbReverse from './tryRunAdbReverse'; diff --git a/packages/platform-android/src/config/index.ts b/packages/platform-android/src/config/index.ts index 15ea6e2ad..db069bb2d 100644 --- a/packages/platform-android/src/config/index.ts +++ b/packages/platform-android/src/config/index.ts @@ -11,7 +11,10 @@ import findAndroidAppFolder from './findAndroidAppFolder'; import findManifest from './findManifest'; import findPackageClassName from './findPackageClassName'; import readManifest from './readManifest'; -import {ProjectParamsAndroid, DependencyParamsAndroid} from '../types'; +import { + AndroidProjectParams, + AndroidDependencyParams, +} from '@react-native-community/cli-types'; import {XmlDocument} from 'xmldoc'; const getPackageName = (manifest: XmlDocument) => manifest.attr.package; @@ -22,7 +25,7 @@ const getPackageName = (manifest: XmlDocument) => manifest.attr.package; */ export function projectConfig( folder: string, - userConfig: ProjectParamsAndroid = {}, + userConfig: AndroidProjectParams = {}, ) { const src = userConfig.sourceDir || findAndroidAppFolder(folder); @@ -98,7 +101,7 @@ export function projectConfig( */ export function dependencyConfig( folder: string, - userConfig: DependencyParamsAndroid = {}, + userConfig: AndroidDependencyParams = {}, ) { const src = userConfig.sourceDir || findAndroidAppFolder(folder); diff --git a/packages/platform-android/src/link/patches/applyParams.ts b/packages/platform-android/src/link/patches/applyParams.ts index 6a7164ced..aea97fe3c 100644 --- a/packages/platform-android/src/link/patches/applyParams.ts +++ b/packages/platform-android/src/link/patches/applyParams.ts @@ -7,11 +7,11 @@ */ import {camelCase as toCamelCase} from 'lodash'; -import {ProjectParamsAndroid} from '../../types'; +import {AndroidProjectParams} from '@react-native-community/cli-types'; export default function applyParams( str: string, - params: ProjectParamsAndroid, + params: AndroidProjectParams, prefix: string, ) { return str.replace(/\$\{(\w+)\}/g, (_pattern: string, param: string) => { diff --git a/packages/platform-android/src/link/patches/makePackagePatch.ts b/packages/platform-android/src/link/patches/makePackagePatch.ts index 6a2007ee6..3e983cab3 100644 --- a/packages/platform-android/src/link/patches/makePackagePatch.ts +++ b/packages/platform-android/src/link/patches/makePackagePatch.ts @@ -7,11 +7,11 @@ */ import applyParams from './applyParams'; -import {ProjectParamsAndroid} from '../../types'; +import {AndroidProjectParams} from '@react-native-community/cli-types'; export default function makePackagePatch( packageInstance: string, - params: ProjectParamsAndroid, + params: AndroidProjectParams, prefix: string, ) { const processedInstance = applyParams(packageInstance, params, prefix); diff --git a/packages/platform-android/src/link/patches/makeStringsPatch.ts b/packages/platform-android/src/link/patches/makeStringsPatch.ts index 585e286ad..817c005f1 100644 --- a/packages/platform-android/src/link/patches/makeStringsPatch.ts +++ b/packages/platform-android/src/link/patches/makeStringsPatch.ts @@ -7,10 +7,10 @@ */ import {camelCase as toCamelCase} from 'lodash'; -import {ProjectParamsAndroid} from '../../types'; +import {AndroidProjectParams} from '@react-native-community/cli-types'; export default function makeStringsPatch( - params: ProjectParamsAndroid, + params: AndroidProjectParams, prefix: string, ) { const values = Object.keys(params).map(param => { diff --git a/packages/platform-android/src/link/registerNativeModule.ts b/packages/platform-android/src/link/registerNativeModule.ts index 8f9d0e674..e02a03583 100644 --- a/packages/platform-android/src/link/registerNativeModule.ts +++ b/packages/platform-android/src/link/registerNativeModule.ts @@ -13,16 +13,16 @@ import makeBuildPatch from './patches/makeBuildPatch'; import makeImportPatch from './patches/makeImportPatch'; import makePackagePatch from './patches/makePackagePatch'; import { - ProjectConfigAndroid, - DependencyConfigAndroid, - ProjectParamsAndroid, -} from '../types'; + AndroidProjectConfig, + AndroidDependencyConfig, + AndroidProjectParams, +} from '@react-native-community/cli-types'; export default function registerNativeAndroidModule( name: string, - androidConfig: DependencyConfigAndroid, - params: ProjectParamsAndroid, - projectConfig: ProjectConfigAndroid, + androidConfig: AndroidDependencyConfig, + params: AndroidProjectParams, + projectConfig: AndroidProjectConfig, ) { const buildPatch = makeBuildPatch(name); diff --git a/packages/platform-android/src/link/unregisterNativeModule.ts b/packages/platform-android/src/link/unregisterNativeModule.ts index 8b1ffb5ff..457e28aeb 100644 --- a/packages/platform-android/src/link/unregisterNativeModule.ts +++ b/packages/platform-android/src/link/unregisterNativeModule.ts @@ -15,12 +15,15 @@ import makeBuildPatch from './patches/makeBuildPatch'; import makeStringsPatch from './patches/makeStringsPatch'; import makeImportPatch from './patches/makeImportPatch'; import makePackagePatch from './patches/makePackagePatch'; -import {ProjectConfigAndroid, DependencyConfigAndroid} from '../types'; +import { + AndroidProjectConfig, + AndroidDependencyConfig, +} from '@react-native-community/cli-types'; export default function unregisterNativeAndroidModule( name: string, - androidConfig: DependencyConfigAndroid, - projectConfig: ProjectConfigAndroid, + androidConfig: AndroidDependencyConfig, + projectConfig: AndroidProjectConfig, ) { const buildPatch = makeBuildPatch(name, projectConfig.buildGradlePath); const strings = fs.readFileSync(projectConfig.stringsPath, 'utf8'); diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts index 0b92d31bc..57d02c727 100644 --- a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts +++ b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import {logger} from '@react-native-community/cli-tools'; import getLinkConfig from './index'; -import {Config} from '../types'; +import {Config} from '@react-native-community/cli-types'; // TODO: move to cli-tools once platform-ios and platform-android are migrated // to TS and unify with iOS implementation diff --git a/packages/platform-android/tsconfig.json b/packages/platform-android/tsconfig.json index 79beacdd0..1ec7ea396 100644 --- a/packages/platform-android/tsconfig.json +++ b/packages/platform-android/tsconfig.json @@ -4,5 +4,5 @@ "rootDir": "src", "outDir": "build" }, - "references": [{"path": "../tools"}] + "references": [{"path": "../tools"}, {"path": "../cli-types"}] } diff --git a/packages/platform-ios/definitions/xcode/index.d.ts b/packages/platform-ios/definitions/xcode/index.d.ts new file mode 100644 index 000000000..d56c14d09 --- /dev/null +++ b/packages/platform-ios/definitions/xcode/index.d.ts @@ -0,0 +1,5 @@ +declare module 'xcode' { + const module: any; + + export default module; +} diff --git a/packages/platform-ios/definitions/xcode/lib/index.d.ts b/packages/platform-ios/definitions/xcode/lib/index.d.ts new file mode 100644 index 000000000..b8f98f04f --- /dev/null +++ b/packages/platform-ios/definitions/xcode/lib/index.d.ts @@ -0,0 +1,5 @@ +declare module 'xcode/lib/pbxFile' { + const module: any; + + export default module; +} diff --git a/packages/platform-ios/package.json b/packages/platform-ios/package.json index 852b18408..09d2bd0dd 100644 --- a/packages/platform-ios/package.json +++ b/packages/platform-ios/package.json @@ -8,6 +8,10 @@ "chalk": "^2.4.2", "xcode": "^2.0.0" }, + "devDependencies": { + "@react-native-community/cli-types": "^2.8.3", + "@types/plist": "^3.0.2" + }, "files": [ "build", "native_modules.rb" diff --git a/packages/platform-ios/src/commands/index.js b/packages/platform-ios/src/commands/index.ts similarity index 84% rename from packages/platform-ios/src/commands/index.js rename to packages/platform-ios/src/commands/index.ts index dc8a7abab..2dc3c640e 100644 --- a/packages/platform-ios/src/commands/index.js +++ b/packages/platform-ios/src/commands/index.ts @@ -1,6 +1,3 @@ -/** - * @flow - */ import logIOS from './logIOS'; import runIOS from './runIOS'; diff --git a/packages/platform-ios/src/commands/logIOS/index.js b/packages/platform-ios/src/commands/logIOS/index.ts similarity index 84% rename from packages/platform-ios/src/commands/logIOS/index.js rename to packages/platform-ios/src/commands/logIOS/index.ts index 9e4e5524d..8cb2d424d 100644 --- a/packages/platform-ios/src/commands/logIOS/index.js +++ b/packages/platform-ios/src/commands/logIOS/index.ts @@ -4,15 +4,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import {execFileSync, spawnSync} from 'child_process'; import os from 'os'; import path from 'path'; import {logger} from '@react-native-community/cli-tools'; +import {Device} from '../../types'; -function findAvailableDevice(devices) { +function findAvailableDevice(devices: {[index: string]: Array}) { for (const key of Object.keys(devices)) { for (const device of devices[key]) { if (device.availability === '(available)' && device.state === 'Booted') { @@ -33,7 +33,9 @@ async function logIOS() { {encoding: 'utf8'}, ); - const {devices} = JSON.parse(rawDevices); + const {devices} = JSON.parse(rawDevices) as { + devices: {[index: string]: Array}; + }; const device = findAvailableDevice(devices); if (device === null) { @@ -44,7 +46,7 @@ async function logIOS() { tailDeviceLogs(device.udid); } -function tailDeviceLogs(udid) { +function tailDeviceLogs(udid: string) { const logDir = path.join( os.homedir(), 'Library', diff --git a/packages/platform-ios/src/commands/runIOS/__tests__/findMatchingSimulator-test.js b/packages/platform-ios/src/commands/runIOS/__tests__/findMatchingSimulator.test.ts similarity index 98% rename from packages/platform-ios/src/commands/runIOS/__tests__/findMatchingSimulator-test.js rename to packages/platform-ios/src/commands/runIOS/__tests__/findMatchingSimulator.test.ts index 6a181328f..cc5118970 100644 --- a/packages/platform-ios/src/commands/runIOS/__tests__/findMatchingSimulator-test.js +++ b/packages/platform-ios/src/commands/runIOS/__tests__/findMatchingSimulator.test.ts @@ -5,8 +5,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import findMatchingSimulator from '../findMatchingSimulator'; @@ -71,33 +69,33 @@ describe('findMatchingSimulator', () => { 'iOS 12.1': [ { state: 'Shutdown', - isAvailable: 'YES', + isAvailable: true, name: 'iPhone 6s', udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508', }, { state: 'Shutdown', - isAvailable: 'YES', + isAvailable: true, name: 'iPhone 6', udid: 'BA0D93BD-07E6-4182-9B0A-F60A2474139C', }, { state: 'Shutdown', - isAvailable: 'YES', + isAvailable: true, name: 'iPhone XS Max', udid: 'B9B5E161-416B-43C4-A78F-729CB96CC8C6', availabilityError: '', }, { state: 'Shutdown', - isAvailable: 'YES', + isAvailable: true, name: 'iPad Air', udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB', availabilityError: '', }, { state: 'Shutdown', - isAvailable: 'YES', + isAvailable: true, name: 'iPad (5th generation)', udid: '9564ABEE-9EC2-4B4A-B443-D3710929A45A', availabilityError: '', @@ -159,12 +157,6 @@ describe('findMatchingSimulator', () => { ).toEqual(null); }); - it('should return null if an odd input', () => { - expect(findMatchingSimulator('random string input', 'iPhone 6')).toEqual( - null, - ); - }); - it('should return the first simulator in list if none is defined', () => { expect( findMatchingSimulator( diff --git a/packages/platform-ios/src/commands/runIOS/__tests__/findXcodeProject-test.js b/packages/platform-ios/src/commands/runIOS/__tests__/findXcodeProject.test.ts similarity index 96% rename from packages/platform-ios/src/commands/runIOS/__tests__/findXcodeProject-test.js rename to packages/platform-ios/src/commands/runIOS/__tests__/findXcodeProject.test.ts index a3d79a0df..b496155b0 100644 --- a/packages/platform-ios/src/commands/runIOS/__tests__/findXcodeProject-test.js +++ b/packages/platform-ios/src/commands/runIOS/__tests__/findXcodeProject.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import findXcodeProject from '../findXcodeProject'; diff --git a/packages/platform-ios/src/commands/runIOS/__tests__/parseIOSDevicesList-test.js b/packages/platform-ios/src/commands/runIOS/__tests__/parseIOSDevicesList.test.ts similarity index 96% rename from packages/platform-ios/src/commands/runIOS/__tests__/parseIOSDevicesList-test.js rename to packages/platform-ios/src/commands/runIOS/__tests__/parseIOSDevicesList.test.ts index b5ebb2372..2a2639a12 100644 --- a/packages/platform-ios/src/commands/runIOS/__tests__/parseIOSDevicesList-test.js +++ b/packages/platform-ios/src/commands/runIOS/__tests__/parseIOSDevicesList.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import parseIOSDevicesList from '../parseIOSDevicesList'; diff --git a/packages/platform-ios/src/commands/runIOS/findMatchingSimulator.js b/packages/platform-ios/src/commands/runIOS/findMatchingSimulator.ts similarity index 84% rename from packages/platform-ios/src/commands/runIOS/findMatchingSimulator.js rename to packages/platform-ios/src/commands/runIOS/findMatchingSimulator.ts index b26e08e61..af9d9de11 100644 --- a/packages/platform-ios/src/commands/runIOS/findMatchingSimulator.js +++ b/packages/platform-ios/src/commands/runIOS/findMatchingSimulator.ts @@ -4,9 +4,10 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ +import {Device} from '../../types'; + /** * Takes in a parsed simulator list and a desired name, and returns an object with the matching simulator. The desired * name can optionally include the iOS version in between parenthesis after the device name. Ex: "iPhone 6 (9.2)" in @@ -15,24 +16,28 @@ * If the simulatorString argument is null, we'll go into default mode and return the currently booted simulator, or if * none is booted, it will be the first in the list. * - * @param Object simulators a parsed list from `xcrun simctl list --json devices` command - * @param String|null simulatorString the string with the name of desired simulator. If null, it will use the currently + * @param simulators a parsed list from `xcrun simctl list --json devices` command + * @param simulatorString the string with the name of desired simulator. If null, it will use the currently * booted simulator, or if none are booted, the first in the list. - * @returns {Object} {udid, name, version} */ -function findMatchingSimulator(simulators, simulatorString) { +function findMatchingSimulator( + simulators: {devices: {[index: string]: Array}}, + simulatorString: string, +) { if (!simulators.devices) { return null; } const devices = simulators.devices; + let simulatorVersion; + let simulatorName; const parsedSimulatorName = simulatorString ? simulatorString.match(/(.*)? (?:\((\d+\.\d+)?\))$/) : []; if (parsedSimulatorName && parsedSimulatorName[2] !== undefined) { - var simulatorVersion = parsedSimulatorName[2]; - var simulatorName = parsedSimulatorName[1]; + simulatorVersion = parsedSimulatorName[2]; + simulatorName = parsedSimulatorName[1]; } else { simulatorName = simulatorString; } @@ -62,6 +67,7 @@ function findMatchingSimulator(simulators, simulatorString) { // Skipping non-available simulator if ( simulator.availability !== '(available)' && + // @ts-ignore verify isAvailable parameter simulator.isAvailable !== 'YES' && simulator.isAvailable !== true ) { diff --git a/packages/platform-ios/src/commands/runIOS/findXcodeProject.js b/packages/platform-ios/src/commands/runIOS/findXcodeProject.ts similarity index 81% rename from packages/platform-ios/src/commands/runIOS/findXcodeProject.js rename to packages/platform-ios/src/commands/runIOS/findXcodeProject.ts index d259bdccd..bed01013e 100644 --- a/packages/platform-ios/src/commands/runIOS/findXcodeProject.js +++ b/packages/platform-ios/src/commands/runIOS/findXcodeProject.ts @@ -4,18 +4,16 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @flow strict */ import path from 'path'; -type ProjectInfo = { - name: string, - isWorkspace: boolean, +export type ProjectInfo = { + name: string; + isWorkspace: boolean; }; -function findXcodeProject(files: Array): ?ProjectInfo { +function findXcodeProject(files: Array): ProjectInfo | null { const sortedFiles = files.sort(); for (let i = sortedFiles.length - 1; i >= 0; i--) { const fileName = files[i]; diff --git a/packages/platform-ios/src/commands/runIOS/index.js b/packages/platform-ios/src/commands/runIOS/index.ts similarity index 85% rename from packages/platform-ios/src/commands/runIOS/index.js rename to packages/platform-ios/src/commands/runIOS/index.ts index 5b7b3f5ae..097db9b44 100644 --- a/packages/platform-ios/src/commands/runIOS/index.js +++ b/packages/platform-ios/src/commands/runIOS/index.ts @@ -4,15 +4,17 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ -import child_process from 'child_process'; +import child_process, { + ChildProcess, + SpawnOptionsWithoutStdio, +} from 'child_process'; import fs from 'fs'; import path from 'path'; import chalk from 'chalk'; -import type {ConfigT} from 'types'; -import findXcodeProject from './findXcodeProject'; +import {Config} from '@react-native-community/cli-types'; +import findXcodeProject, {ProjectInfo} from './findXcodeProject'; import parseIOSDevicesList from './parseIOSDevicesList'; import findMatchingSimulator from './findMatchingSimulator'; import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs'; @@ -21,21 +23,22 @@ import { CLIError, getDefaultUserTerminal, } from '@react-native-community/cli-tools'; +import {Device} from '../../types'; type FlagsT = { - simulator: string, - configuration: string, - scheme: ?string, - projectPath: string, - device: ?(string | true), - udid: ?string, - packager: boolean, - verbose: boolean, - port: number, - terminal: ?string, + simulator: string; + configuration: string; + scheme?: string; + projectPath: string; + device?: string | true; + udid?: string; + packager: boolean; + verbose: boolean; + port: number; + terminal: string | undefined; }; -function runIOS(_: Array, ctx: ConfigT, args: FlagsT) { +function runIOS(_: Array, ctx: Config, args: FlagsT) { if (!fs.existsSync(args.projectPath)) { throw new CLIError( 'iOS project folder not found. Are you sure this is a React Native project?', @@ -105,11 +108,14 @@ function runIOS(_: Array, ctx: ConfigT, args: FlagsT) { } } -async function runOnSimulator(xcodeProject, scheme, args: FlagsT) { - let simulators; +async function runOnSimulator( + xcodeProject: ProjectInfo, + scheme: string, + args: FlagsT, +) { + let simulators: {devices: {[index: string]: Array}}; try { simulators = JSON.parse( - // $FlowIssue: https://github.com/facebook/flow/issues/5675 child_process.execFileSync( 'xcrun', ['simctl', 'list', '--json', 'devices'], @@ -194,7 +200,12 @@ async function runOnSimulator(xcodeProject, scheme, args: FlagsT) { } } -async function runOnDevice(selectedDevice, scheme, xcodeProject, args: FlagsT) { +async function runOnDevice( + selectedDevice: Device, + scheme: string, + xcodeProject: ProjectInfo, + args: FlagsT, +) { const isIOSDeployInstalled = child_process.spawnSync( 'ios-deploy', ['--version'], @@ -243,7 +254,12 @@ async function runOnDevice(selectedDevice, scheme, xcodeProject, args: FlagsT) { return logger.success('Installed the app on the device.'); } -function buildProject(xcodeProject, udid, scheme, args: FlagsT) { +function buildProject( + xcodeProject: ProjectInfo, + udid: string | undefined, + scheme: string, + args: FlagsT, +): Promise { return new Promise((resolve, reject) => { const xcodebuildArgs = [ xcodeProject.isWorkspace ? '-workspace' : '-project', @@ -262,7 +278,7 @@ function buildProject(xcodeProject, udid, scheme, args: FlagsT) { `(using "xcodebuild ${xcodebuildArgs.join(' ')}")`, )}`, ); - let xcpretty; + let xcpretty: ChildProcess | any; if (!args.verbose) { xcpretty = xcprettyAvailable() && @@ -277,7 +293,7 @@ function buildProject(xcodeProject, udid, scheme, args: FlagsT) { ); let buildOutput = ''; let errorOutput = ''; - buildProcess.stdout.on('data', data => { + buildProcess.stdout.on('data', (data: Buffer) => { const stringData = data.toString(); buildOutput += stringData; if (xcpretty) { @@ -290,10 +306,10 @@ function buildProject(xcodeProject, udid, scheme, args: FlagsT) { } } }); - buildProcess.stderr.on('data', data => { + buildProcess.stderr.on('data', (data: Buffer) => { errorOutput += data; }); - buildProcess.on('close', code => { + buildProcess.on('close', (code: number) => { if (xcpretty) { xcpretty.stdin.end(); } else { @@ -319,7 +335,7 @@ function buildProject(xcodeProject, udid, scheme, args: FlagsT) { }); } -function bootSimulator(selectedSimulator) { +function bootSimulator(selectedSimulator: Device) { const simulatorFullName = formattedDeviceName(selectedSimulator); logger.info(`Launching ${simulatorFullName}`); try { @@ -334,7 +350,12 @@ function bootSimulator(selectedSimulator) { } } -function getBuildPath(configuration, appName, isDevice, scheme) { +function getBuildPath( + configuration: string, + appName: string, + isDevice: boolean, + scheme: string, +) { let device; if (isDevice) { @@ -354,7 +375,7 @@ function getBuildPath(configuration, appName, isDevice, scheme) { return buildPath; } -function getProductName(buildOutput) { +function getProductName(buildOutput: string) { const productNameMatch = /export FULL_PRODUCT_NAME="?(.+).app"?$/m.exec( buildOutput, ); @@ -372,7 +393,11 @@ function xcprettyAvailable() { return true; } -function matchingDevice(devices, deviceName, udid) { +function matchingDevice( + devices: Array, + deviceName: string | true | undefined, + udid: string | undefined, +) { if (udid) { return matchingDeviceByUdid(devices, udid); } @@ -390,30 +415,49 @@ function matchingDevice(devices, deviceName, udid) { ); } -function matchingDeviceByUdid(devices, udid) { +function matchingDeviceByUdid( + devices: Array, + udid: string | undefined, +) { return devices.find(device => device.udid === udid); } -function formattedDeviceName(simulator) { +function formattedDeviceName(simulator: Device) { return `${simulator.name} (${simulator.version})`; } -function printFoundDevices(devices) { +function printFoundDevices(devices: Array) { return [ 'Available devices:', ...devices.map(device => ` - ${device.name} (${device.udid})`), ].join('\n'); } -function getProcessOptions({packager, terminal, port}) { +function getProcessOptions({ + packager, + terminal, + port, +}: { + packager: boolean; + terminal: string | undefined; + port: number; +}): SpawnOptionsWithoutStdio { if (packager) { return { - env: {...process.env, RCT_TERMINAL: terminal, RCT_METRO_PORT: port}, + env: { + ...process.env, + RCT_TERMINAL: terminal, + RCT_METRO_PORT: port.toString(), + }, }; } return { - env: {...process.env, RCT_TERMINAL: terminal, RCT_NO_LAUNCH_PACKAGER: true}, + env: { + ...process.env, + RCT_TERMINAL: terminal, + RCT_NO_LAUNCH_PACKAGER: 'true', + }, }; } diff --git a/packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.js b/packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.ts similarity index 78% rename from packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.js rename to packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.ts index 2cacf661a..0416d27ff 100644 --- a/packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.js +++ b/packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.ts @@ -4,21 +4,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @flow strict */ - -type IOSDeviceInfo = { - name: string, - udid: string, - version: string, -}; +import {Device} from '../../types'; /** * Parses the output of `xcrun simctl list devices` command */ -function parseIOSDevicesList(text: string): Array { - const devices = []; +function parseIOSDevicesList(text: string): Array { + const devices: Array = []; + text.split('\n').forEach(line => { const device = line.match(/(.*?) \((.*?)\) \[(.*?)\]/); const noSimulator = line.match(/(.*?) \((.*?)\) \[(.*?)\] \((.*?)\)/); diff --git a/packages/platform-ios/src/config/__fixtures__/projects.js b/packages/platform-ios/src/config/__fixtures__/projects.ts similarity index 91% rename from packages/platform-ios/src/config/__fixtures__/projects.js rename to packages/platform-ios/src/config/__fixtures__/projects.ts index b347fcae0..1a5af665d 100644 --- a/packages/platform-ios/src/config/__fixtures__/projects.js +++ b/packages/platform-ios/src/config/__fixtures__/projects.ts @@ -1,8 +1,6 @@ -/** - * @flow - */ - +// @ts-ignore FIXME: Add global types for jest const path = jest.requireActual('path'); +// @ts-ignore const fs = jest.requireActual('fs'); const ios = { diff --git a/packages/platform-ios/src/config/__tests__/findPodfilePath-test.js b/packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts similarity index 100% rename from packages/platform-ios/src/config/__tests__/findPodfilePath-test.js rename to packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts diff --git a/packages/platform-ios/src/config/__tests__/findPodspec-test.js b/packages/platform-ios/src/config/__tests__/findPodspec.test.ts similarity index 94% rename from packages/platform-ios/src/config/__tests__/findPodspec-test.js rename to packages/platform-ios/src/config/__tests__/findPodspec.test.ts index 16b05b714..42faa57a1 100644 --- a/packages/platform-ios/src/config/__tests__/findPodspec-test.js +++ b/packages/platform-ios/src/config/__tests__/findPodspec.test.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import findPodspec from '../findPodspec'; @@ -17,19 +16,16 @@ const fs = require('fs'); describe('ios::findPodspec', () => { it('returns null if there is not podspec file', () => { - // $FlowFixMe fs.__setMockFilesystem(projects.flat); expect(findPodspec('')).toBeNull(); }); it('returns podspec name if only one exists', () => { - // $FlowFixMe fs.__setMockFilesystem(projects.withPods.ios); expect(findPodspec('/')).toBe('/TestPod.podspec'); }); it('returns podspec name that match packet directory', () => { - // $FlowFixMe fs.__setMockFilesystem({ user: { PacketName: { @@ -44,7 +40,6 @@ describe('ios::findPodspec', () => { }); it('returns first podspec name if not match in directory', () => { - // $FlowFixMe fs.__setMockFilesystem({ user: { packet: { diff --git a/packages/platform-ios/src/config/__tests__/findProject-test.js b/packages/platform-ios/src/config/__tests__/findProject.test.ts similarity index 97% rename from packages/platform-ios/src/config/__tests__/findProject-test.js rename to packages/platform-ios/src/config/__tests__/findProject.test.ts index 8c5e029e7..bdcf9106a 100644 --- a/packages/platform-ios/src/config/__tests__/findProject-test.js +++ b/packages/platform-ios/src/config/__tests__/findProject.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import findProject from '../findProject'; diff --git a/packages/platform-ios/src/config/__tests__/getProjectConfig-test.js b/packages/platform-ios/src/config/__tests__/getProjectConfig.test.ts similarity index 96% rename from packages/platform-ios/src/config/__tests__/getProjectConfig-test.js rename to packages/platform-ios/src/config/__tests__/getProjectConfig.test.ts index e804796c3..cfe0cc9b0 100644 --- a/packages/platform-ios/src/config/__tests__/getProjectConfig-test.js +++ b/packages/platform-ios/src/config/__tests__/getProjectConfig.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import * as projects from '../__fixtures__/projects'; diff --git a/packages/platform-ios/src/config/findPodfilePath.js b/packages/platform-ios/src/config/findPodfilePath.ts similarity index 95% rename from packages/platform-ios/src/config/findPodfilePath.js rename to packages/platform-ios/src/config/findPodfilePath.ts index ab5e47fc7..695be0888 100644 --- a/packages/platform-ios/src/config/findPodfilePath.js +++ b/packages/platform-ios/src/config/findPodfilePath.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @flow */ import fs from 'fs'; diff --git a/packages/platform-ios/src/config/findPodspec.js b/packages/platform-ios/src/config/findPodspec.ts similarity index 96% rename from packages/platform-ios/src/config/findPodspec.js rename to packages/platform-ios/src/config/findPodspec.ts index 30ab98d00..c0d5e979a 100644 --- a/packages/platform-ios/src/config/findPodspec.js +++ b/packages/platform-ios/src/config/findPodspec.ts @@ -1,7 +1,3 @@ -/** - * @flow - */ - import glob from 'glob'; import path from 'path'; diff --git a/packages/platform-ios/src/config/findProject.js b/packages/platform-ios/src/config/findProject.ts similarity index 98% rename from packages/platform-ios/src/config/findProject.js rename to packages/platform-ios/src/config/findProject.ts index d798fea24..78bd718a3 100644 --- a/packages/platform-ios/src/config/findProject.js +++ b/packages/platform-ios/src/config/findProject.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @flow */ import glob from 'glob'; diff --git a/packages/platform-ios/src/config/getPodspecName.js b/packages/platform-ios/src/config/getPodspecName.ts similarity index 97% rename from packages/platform-ios/src/config/getPodspecName.js rename to packages/platform-ios/src/config/getPodspecName.ts index 19fc35fc9..923eb5be6 100644 --- a/packages/platform-ios/src/config/getPodspecName.js +++ b/packages/platform-ios/src/config/getPodspecName.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import path from 'path'; diff --git a/packages/platform-ios/src/config/index.js b/packages/platform-ios/src/config/index.ts similarity index 87% rename from packages/platform-ios/src/config/index.js rename to packages/platform-ios/src/config/index.ts index 52af841a2..27f9cdfa8 100644 --- a/packages/platform-ios/src/config/index.js +++ b/packages/platform-ios/src/config/index.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @flow */ import path from 'path'; @@ -13,7 +11,7 @@ import {memoize} from 'lodash'; import findProject from './findProject'; import findPodfilePath from './findPodfilePath'; import findPodspec from './findPodspec'; -import type {UserConfigT} from 'types'; +import {IOSProjectParams} from '@react-native-community/cli-types'; const memoizedFindProject = memoize(findProject); @@ -21,8 +19,8 @@ const memoizedFindProject = memoize(findProject); * For libraries specified without an extension, add '.tbd' for those that * start with 'lib' and '.framework' to the rest. */ -const mapSharedLibaries = libraries => - libraries.map(name => { +const mapSharedLibaries = (libraries: Array) => + libraries.map(name => { if (path.extname(name)) { return name; } @@ -33,10 +31,7 @@ const mapSharedLibaries = libraries => * Returns project config by analyzing given folder and applying some user defaults * when constructing final object */ -export function projectConfig( - folder: string, - userConfig: $PropertyType<$PropertyType, 'ios'>, -) { +export function projectConfig(folder: string, userConfig: IOSProjectParams) { if (!userConfig) { return; } diff --git a/packages/platform-ios/src/index.js b/packages/platform-ios/src/index.ts similarity index 93% rename from packages/platform-ios/src/index.js rename to packages/platform-ios/src/index.ts index ced0990f6..389b3a219 100644 --- a/packages/platform-ios/src/index.js +++ b/packages/platform-ios/src/index.ts @@ -1,7 +1,5 @@ /** * iOS platform files - * - * @flow */ export {default as linkConfig} from './link'; diff --git a/packages/platform-ios/src/link-pods/__tests__/findLineToAddPod-test.js b/packages/platform-ios/src/link-pods/__tests__/findLineToAddPod.test.ts similarity index 96% rename from packages/platform-ios/src/link-pods/__tests__/findLineToAddPod-test.js rename to packages/platform-ios/src/link-pods/__tests__/findLineToAddPod.test.ts index a3d4e4e46..a4e3b6f6a 100644 --- a/packages/platform-ios/src/link-pods/__tests__/findLineToAddPod-test.js +++ b/packages/platform-ios/src/link-pods/__tests__/findLineToAddPod.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import findLineToAddPod from '../findLineToAddPod'; diff --git a/packages/platform-ios/src/link-pods/__tests__/findMarkedLinesInPodfile-test.js b/packages/platform-ios/src/link-pods/__tests__/findMarkedLinesInPodfile.test.ts similarity index 76% rename from packages/platform-ios/src/link-pods/__tests__/findMarkedLinesInPodfile-test.js rename to packages/platform-ios/src/link-pods/__tests__/findMarkedLinesInPodfile.test.ts index 43b52ecfc..5f2951f83 100644 --- a/packages/platform-ios/src/link-pods/__tests__/findMarkedLinesInPodfile-test.js +++ b/packages/platform-ios/src/link-pods/__tests__/findMarkedLinesInPodfile.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import readPodfile from '../readPodfile'; @@ -14,7 +12,6 @@ import findMarkedLinesInPodfile from '../findMarkedLinesInPodfile'; const path = require('path'); const PODFILES_PATH = path.join(__dirname, '../__fixtures__'); -const LINE_AFTER_TARGET_IN_TEST_PODFILE = 4; describe('pods::findMarkedLinesInPodfile', () => { it('returns empty array if file is not Podfile', () => { @@ -24,9 +21,7 @@ describe('pods::findMarkedLinesInPodfile', () => { it('returns empty array for Simple Podfile', () => { const podfile = readPodfile(path.join(PODFILES_PATH, 'PodfileSimple')); - expect( - findMarkedLinesInPodfile(podfile, LINE_AFTER_TARGET_IN_TEST_PODFILE), - ).toEqual([]); + expect(findMarkedLinesInPodfile(podfile)).toEqual([]); }); it('returns correct line numbers for Podfile with marker', () => { @@ -35,8 +30,6 @@ describe('pods::findMarkedLinesInPodfile', () => { {line: 18, indentation: 2}, {line: 31, indentation: 4}, ]; - expect( - findMarkedLinesInPodfile(podfile, LINE_AFTER_TARGET_IN_TEST_PODFILE), - ).toEqual(expectedObject); + expect(findMarkedLinesInPodfile(podfile)).toEqual(expectedObject); }); }); diff --git a/packages/platform-ios/src/link-pods/__tests__/findPodTargetLine-test.js b/packages/platform-ios/src/link-pods/__tests__/findPodTargetLine.test.ts similarity index 95% rename from packages/platform-ios/src/link-pods/__tests__/findPodTargetLine-test.js rename to packages/platform-ios/src/link-pods/__tests__/findPodTargetLine.test.ts index 8c45c7871..e8fdd24ce 100644 --- a/packages/platform-ios/src/link-pods/__tests__/findPodTargetLine-test.js +++ b/packages/platform-ios/src/link-pods/__tests__/findPodTargetLine.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import findPodTargetLine from '../findPodTargetLine'; diff --git a/packages/platform-ios/src/link-pods/__tests__/isInstalled-test.js b/packages/platform-ios/src/link-pods/__tests__/isInstalled.test.ts similarity index 90% rename from packages/platform-ios/src/link-pods/__tests__/isInstalled-test.js rename to packages/platform-ios/src/link-pods/__tests__/isInstalled.test.ts index 2b606b104..13621191e 100644 --- a/packages/platform-ios/src/link-pods/__tests__/isInstalled-test.js +++ b/packages/platform-ios/src/link-pods/__tests__/isInstalled.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import isInstalled from '../isInstalled'; @@ -18,18 +16,21 @@ describe('pods::isInstalled', () => { it('returns false if pod is missing', () => { const project = {podfile: path.join(PODFILES_PATH, 'PodfileSimple')}; const podspecName = {podspecPath: '/path/NotExisting'}; + // @ts-ignore FIXME: Improve types expect(isInstalled(project, podspecName)).toBe(false); }); it('returns true for existing pod with version number', () => { const project = {podfile: path.join(PODFILES_PATH, 'PodfileSimple')}; const podspecName = {podspecPath: '/path/TestPod.podspec'}; + // @ts-ignore FIXME: Improve types expect(isInstalled(project, podspecName)).toBe(true); }); it('returns true for existing pod with path', () => { const project = {podfile: path.join(PODFILES_PATH, 'PodfileWithTarget')}; const podspecName = {podspecPath: '/path/Yoga.podspec'}; + // @ts-ignore FIXME: Improve types expect(isInstalled(project, podspecName)).toBe(true); }); @@ -38,6 +39,7 @@ describe('pods::isInstalled', () => { podfile: path.join(PODFILES_PATH, 'PodfileWithFunction'), }; const podspecName = {podspecPath: '/path/React.podspec'}; + // @ts-ignore FIXME: Improve types expect(isInstalled(project, podspecName)).toBe(true); }); }); diff --git a/packages/platform-ios/src/link-pods/__tests__/removePodEntry-test.js b/packages/platform-ios/src/link-pods/__tests__/removePodEntry.test.ts similarity index 97% rename from packages/platform-ios/src/link-pods/__tests__/removePodEntry-test.js rename to packages/platform-ios/src/link-pods/__tests__/removePodEntry.test.ts index 525fc0422..5e9e25472 100644 --- a/packages/platform-ios/src/link-pods/__tests__/removePodEntry-test.js +++ b/packages/platform-ios/src/link-pods/__tests__/removePodEntry.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import removePodEntry from '../removePodEntry'; diff --git a/packages/platform-ios/src/link-pods/addPodEntry.js b/packages/platform-ios/src/link-pods/addPodEntry.ts similarity index 84% rename from packages/platform-ios/src/link-pods/addPodEntry.js rename to packages/platform-ios/src/link-pods/addPodEntry.ts index 86d327feb..2a76cb889 100644 --- a/packages/platform-ios/src/link-pods/addPodEntry.js +++ b/packages/platform-ios/src/link-pods/addPodEntry.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import {logger} from '@react-native-community/cli-tools'; @@ -12,9 +11,11 @@ import getPodspecName from '../config/getPodspecName'; export default function addPodEntry( podLines: Array, - linesToAddEntry?: - | Array<{line: number, indentation: number}> - | {line: number, indentation: number}, + linesToAddEntry: + | Array<{line: number; indentation: number}> + | {line: number; indentation: number} + | null + | undefined, podspecPath: string, nodeModulePath: string, ) { @@ -37,7 +38,7 @@ export default function addPodEntry( } } -function getLineToAdd(newEntry, indentation) { +function getLineToAdd(newEntry: string, indentation: number) { const spaces = Array(indentation + 1).join(' '); return spaces + newEntry; } diff --git a/packages/platform-ios/src/link-pods/findLineToAddPod.js b/packages/platform-ios/src/link-pods/findLineToAddPod.ts similarity index 92% rename from packages/platform-ios/src/link-pods/findLineToAddPod.js rename to packages/platform-ios/src/link-pods/findLineToAddPod.ts index 691a6629c..8a35d730b 100644 --- a/packages/platform-ios/src/link-pods/findLineToAddPod.js +++ b/packages/platform-ios/src/link-pods/findLineToAddPod.ts @@ -4,10 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ -export default function findLineToAddPod(podLines, firstTargetLine) { +export default function findLineToAddPod( + podLines: Array, + firstTargetLine: number, +) { // match line with new target: target 'project_name' do (most likely target inside podfile main target) const nextTarget = /target ('|")\w+('|") do/g; // match line that has only 'end' (if we don't catch new target or function, this would mean this is end of current target) diff --git a/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js b/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.ts similarity index 98% rename from packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js rename to packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.ts index 13cae2c14..1e9551025 100644 --- a/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js +++ b/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ export const MARKER_TEXT = '# Add new pods below this line'; diff --git a/packages/platform-ios/src/link-pods/findPodTargetLine.js b/packages/platform-ios/src/link-pods/findPodTargetLine.ts similarity index 85% rename from packages/platform-ios/src/link-pods/findPodTargetLine.js rename to packages/platform-ios/src/link-pods/findPodTargetLine.ts index 71bd8353e..f18e41bba 100644 --- a/packages/platform-ios/src/link-pods/findPodTargetLine.js +++ b/packages/platform-ios/src/link-pods/findPodTargetLine.ts @@ -4,10 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ -export default function findPodTargetLine(podLines, projectName) { +export default function findPodTargetLine( + podLines: Array, + projectName: string, +) { const targetName = projectName.replace('.xcodeproj', ''); // match first target definition in file: target 'target_name' do const targetRegex = new RegExp(`target ('|")${targetName}('|") do`, 'g'); diff --git a/packages/platform-ios/src/link-pods/isInstalled.js b/packages/platform-ios/src/link-pods/isInstalled.ts similarity index 83% rename from packages/platform-ios/src/link-pods/isInstalled.js rename to packages/platform-ios/src/link-pods/isInstalled.ts index caf97eb71..6972cd4c7 100644 --- a/packages/platform-ios/src/link-pods/isInstalled.js +++ b/packages/platform-ios/src/link-pods/isInstalled.ts @@ -4,16 +4,18 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import readPodfile from './readPodfile'; import getPodspecName from '../config/getPodspecName'; -import type {ProjectConfigIOST, DependencyConfigIOST} from 'types'; +import { + IOSProjectConfig, + IOSDependencyConfig, +} from '@react-native-community/cli-types'; export default function isInstalled( - iOSProject: ProjectConfigIOST, - dependencyConfig: DependencyConfigIOST, + iOSProject: IOSProjectConfig, + dependencyConfig: IOSDependencyConfig, ) { if (!iOSProject.podfile || !dependencyConfig.podspecPath) { return false; diff --git a/packages/platform-ios/src/link-pods/readPodfile.js b/packages/platform-ios/src/link-pods/readPodfile.ts similarity index 86% rename from packages/platform-ios/src/link-pods/readPodfile.js rename to packages/platform-ios/src/link-pods/readPodfile.ts index ab613e2e0..cfbccf020 100644 --- a/packages/platform-ios/src/link-pods/readPodfile.js +++ b/packages/platform-ios/src/link-pods/readPodfile.ts @@ -4,13 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import fs from 'fs'; import {logger} from '@react-native-community/cli-tools'; -export default function readPodfile(podfilePath) { +export default function readPodfile(podfilePath: string) { logger.debug(`Reading ${podfilePath}`); const podContent = fs.readFileSync(podfilePath, 'utf8'); return podContent.split(/\r?\n/g); diff --git a/packages/platform-ios/src/link-pods/registerNativeModule.js b/packages/platform-ios/src/link-pods/registerNativeModule.ts similarity index 89% rename from packages/platform-ios/src/link-pods/registerNativeModule.js rename to packages/platform-ios/src/link-pods/registerNativeModule.ts index 4cbb21ba6..ab8e6b909 100644 --- a/packages/platform-ios/src/link-pods/registerNativeModule.js +++ b/packages/platform-ios/src/link-pods/registerNativeModule.ts @@ -4,11 +4,10 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import chalk from 'chalk'; import {CLIError} from '@react-native-community/cli-tools'; -import type {ProjectConfigIOST} from 'types'; +import {IOSProjectConfig} from '@react-native-community/cli-types'; import readPodfile from './readPodfile'; import findPodTargetLine from './findPodTargetLine'; import findLineToAddPod from './findLineToAddPod'; @@ -21,7 +20,7 @@ import savePodFile from './savePodFile'; export default function registerNativeModulePods( name: string, podspecPath: string, - iOSProject: ProjectConfigIOST, + iOSProject: IOSProjectConfig, ) { const podLines = readPodfile(iOSProject.podfile); const linesToAddEntry = getLinesToAddEntry(podLines, iOSProject); @@ -29,7 +28,10 @@ export default function registerNativeModulePods( savePodFile(iOSProject.podfile, podLines); } -function getLinesToAddEntry(podLines, {projectName}) { +function getLinesToAddEntry( + podLines: Array, + {projectName}: IOSProjectConfig, +) { const linesToAddPodWithMarker = findMarkedLinesInPodfile(podLines); if (linesToAddPodWithMarker.length > 0) { return linesToAddPodWithMarker; diff --git a/packages/platform-ios/src/link-pods/removePodEntry.js b/packages/platform-ios/src/link-pods/removePodEntry.ts similarity index 89% rename from packages/platform-ios/src/link-pods/removePodEntry.js rename to packages/platform-ios/src/link-pods/removePodEntry.ts index 7ee8f9eea..a9339cf36 100644 --- a/packages/platform-ios/src/link-pods/removePodEntry.js +++ b/packages/platform-ios/src/link-pods/removePodEntry.ts @@ -4,13 +4,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import {logger} from '@react-native-community/cli-tools'; import getPodspecName from '../config/getPodspecName'; -export default function removePodEntry(podfileContent, podspecPath) { +export default function removePodEntry( + podfileContent: string, + podspecPath: string, +) { const podName = getPodspecName(podspecPath); // this regex should catch line(s) with full pod definition, like: pod 'podname', :path => '../node_modules/podname', :subspecs => ['Sub2', 'Sub1'] const podRegex = new RegExp( diff --git a/packages/platform-ios/src/link-pods/savePodFile.js b/packages/platform-ios/src/link-pods/savePodFile.ts similarity index 82% rename from packages/platform-ios/src/link-pods/savePodFile.js rename to packages/platform-ios/src/link-pods/savePodFile.ts index aca383867..a26cdf438 100644 --- a/packages/platform-ios/src/link-pods/savePodFile.js +++ b/packages/platform-ios/src/link-pods/savePodFile.ts @@ -4,13 +4,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import fs from 'fs'; import {logger} from '@react-native-community/cli-tools'; -export default function savePodFile(podfilePath, podLines) { +export default function savePodFile( + podfilePath: string, + podLines: Array, +) { const newPodfile = podLines.join('\n'); logger.debug(`Writing changes to ${podfilePath}`); fs.writeFileSync(podfilePath, newPodfile); diff --git a/packages/platform-ios/src/link-pods/unregisterNativeModule.js b/packages/platform-ios/src/link-pods/unregisterNativeModule.ts similarity index 73% rename from packages/platform-ios/src/link-pods/unregisterNativeModule.js rename to packages/platform-ios/src/link-pods/unregisterNativeModule.ts index 6ac7ca71d..18d0acdde 100644 --- a/packages/platform-ios/src/link-pods/unregisterNativeModule.js +++ b/packages/platform-ios/src/link-pods/unregisterNativeModule.ts @@ -4,17 +4,23 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import fs from 'fs'; import removePodEntry from './removePodEntry'; import {logger} from '@react-native-community/cli-tools'; +import { + IOSDependencyConfig, + IOSProjectConfig, +} from '@react-native-community/cli-types'; /** * Unregister native module IOS with CocoaPods */ -export default function unregisterNativeModule(dependencyConfig, iOSProject) { +export default function unregisterNativeModule( + dependencyConfig: IOSDependencyConfig, + iOSProject: IOSProjectConfig, +) { const podContent = fs.readFileSync(iOSProject.podfile, 'utf8'); const removed = removePodEntry(podContent, dependencyConfig.podspecPath); logger.debug(`Writing changes to ${iOSProject.podfile}`); diff --git a/packages/platform-ios/src/link/__tests__/addFileToProject-test.js b/packages/platform-ios/src/link/__tests__/addFileToProject.test.ts similarity index 94% rename from packages/platform-ios/src/link/__tests__/addFileToProject-test.js rename to packages/platform-ios/src/link/__tests__/addFileToProject.test.ts index 100f384fb..c429f0918 100644 --- a/packages/platform-ios/src/link/__tests__/addFileToProject-test.js +++ b/packages/platform-ios/src/link/__tests__/addFileToProject.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import addFileToProject from '../addFileToProject'; diff --git a/packages/platform-ios/src/link/__tests__/addProjectToLibraries-test.js b/packages/platform-ios/src/link/__tests__/addProjectToLibraries.test.ts similarity index 94% rename from packages/platform-ios/src/link/__tests__/addProjectToLibraries-test.js rename to packages/platform-ios/src/link/__tests__/addProjectToLibraries.test.ts index c6c173ec6..e520f8026 100644 --- a/packages/platform-ios/src/link/__tests__/addProjectToLibraries-test.js +++ b/packages/platform-ios/src/link/__tests__/addProjectToLibraries.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import addProjectToLibraries from '../addProjectToLibraries'; diff --git a/packages/platform-ios/src/link/__tests__/addSharedLibraries-test.js b/packages/platform-ios/src/link/__tests__/addSharedLibraries.test.ts similarity index 96% rename from packages/platform-ios/src/link/__tests__/addSharedLibraries-test.js rename to packages/platform-ios/src/link/__tests__/addSharedLibraries.test.ts index 9ce7e1a97..49a14d879 100644 --- a/packages/platform-ios/src/link/__tests__/addSharedLibraries-test.js +++ b/packages/platform-ios/src/link/__tests__/addSharedLibraries.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import addSharedLibraries from '../addSharedLibraries'; diff --git a/packages/platform-ios/src/link/__tests__/createGroup-test.js b/packages/platform-ios/src/link/__tests__/createGroup.test.ts similarity index 96% rename from packages/platform-ios/src/link/__tests__/createGroup-test.js rename to packages/platform-ios/src/link/__tests__/createGroup.test.ts index e23f2232f..a2d38ad06 100644 --- a/packages/platform-ios/src/link/__tests__/createGroup-test.js +++ b/packages/platform-ios/src/link/__tests__/createGroup.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import createGroup from '../createGroup'; diff --git a/packages/platform-ios/src/link/__tests__/getBuildProperty-test.js b/packages/platform-ios/src/link/__tests__/getBuildProperty.test.ts similarity index 93% rename from packages/platform-ios/src/link/__tests__/getBuildProperty-test.js rename to packages/platform-ios/src/link/__tests__/getBuildProperty.test.ts index 8b009acd1..672c31bd6 100644 --- a/packages/platform-ios/src/link/__tests__/getBuildProperty-test.js +++ b/packages/platform-ios/src/link/__tests__/getBuildProperty.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getBuildProperty from '../getBuildProperty'; diff --git a/packages/platform-ios/src/link/__tests__/getGroup-test.js b/packages/platform-ios/src/link/__tests__/getGroup.test.ts similarity index 96% rename from packages/platform-ios/src/link/__tests__/getGroup-test.js rename to packages/platform-ios/src/link/__tests__/getGroup.test.ts index 00aa02049..9c8f0dd0f 100644 --- a/packages/platform-ios/src/link/__tests__/getGroup-test.js +++ b/packages/platform-ios/src/link/__tests__/getGroup.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getGroup from '../getGroup'; diff --git a/packages/platform-ios/src/link/__tests__/getHeaderSearchPath-test.js b/packages/platform-ios/src/link/__tests__/getHeaderSearchPath.test.ts similarity index 98% rename from packages/platform-ios/src/link/__tests__/getHeaderSearchPath-test.js rename to packages/platform-ios/src/link/__tests__/getHeaderSearchPath.test.ts index 341c2b4bc..c0103da5a 100644 --- a/packages/platform-ios/src/link/__tests__/getHeaderSearchPath-test.js +++ b/packages/platform-ios/src/link/__tests__/getHeaderSearchPath.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getHeaderSearchPath from '../getHeaderSearchPath'; diff --git a/packages/platform-ios/src/link/__tests__/getHeadersInFolder-test.js b/packages/platform-ios/src/link/__tests__/getHeadersInFolder.test.ts similarity index 95% rename from packages/platform-ios/src/link/__tests__/getHeadersInFolder-test.js rename to packages/platform-ios/src/link/__tests__/getHeadersInFolder.test.ts index e55a46f1b..2b0ef8970 100644 --- a/packages/platform-ios/src/link/__tests__/getHeadersInFolder-test.js +++ b/packages/platform-ios/src/link/__tests__/getHeadersInFolder.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getHeadersInFolder from '../getHeadersInFolder'; diff --git a/packages/platform-ios/src/link/__tests__/getPlist-test.js b/packages/platform-ios/src/link/__tests__/getPlist.test.ts similarity index 92% rename from packages/platform-ios/src/link/__tests__/getPlist-test.js rename to packages/platform-ios/src/link/__tests__/getPlist.test.ts index 1bfa611b5..c2ddbaa58 100644 --- a/packages/platform-ios/src/link/__tests__/getPlist-test.js +++ b/packages/platform-ios/src/link/__tests__/getPlist.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getPlist from '../getPlist'; diff --git a/packages/platform-ios/src/link/__tests__/getPlistPath-test.js b/packages/platform-ios/src/link/__tests__/getPlistPath.test.ts similarity index 92% rename from packages/platform-ios/src/link/__tests__/getPlistPath-test.js rename to packages/platform-ios/src/link/__tests__/getPlistPath.test.ts index 8a88f869f..8f33048e6 100644 --- a/packages/platform-ios/src/link/__tests__/getPlistPath-test.js +++ b/packages/platform-ios/src/link/__tests__/getPlistPath.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getPlistPath from '../getPlistPath'; diff --git a/packages/platform-ios/src/link/__tests__/getTargets-test.js b/packages/platform-ios/src/link/__tests__/getTargets.test.ts similarity index 93% rename from packages/platform-ios/src/link/__tests__/getTargets-test.js rename to packages/platform-ios/src/link/__tests__/getTargets.test.ts index de704e6c5..547806896 100644 --- a/packages/platform-ios/src/link/__tests__/getTargets-test.js +++ b/packages/platform-ios/src/link/__tests__/getTargets.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getTargets from '../getTargets'; diff --git a/packages/platform-ios/src/link/__tests__/hasLibraryImported-test.js b/packages/platform-ios/src/link/__tests__/hasLibraryImported.test.ts similarity index 94% rename from packages/platform-ios/src/link/__tests__/hasLibraryImported-test.js rename to packages/platform-ios/src/link/__tests__/hasLibraryImported.test.ts index 1256040cc..6b2b2159d 100644 --- a/packages/platform-ios/src/link/__tests__/hasLibraryImported-test.js +++ b/packages/platform-ios/src/link/__tests__/hasLibraryImported.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import hasLibraryImported from '../hasLibraryImported'; diff --git a/packages/platform-ios/src/link/__tests__/isInstalled-test.js b/packages/platform-ios/src/link/__tests__/isInstalled.test.ts similarity index 90% rename from packages/platform-ios/src/link/__tests__/isInstalled-test.js rename to packages/platform-ios/src/link/__tests__/isInstalled.test.ts index 65757214e..340aa3f99 100644 --- a/packages/platform-ios/src/link/__tests__/isInstalled-test.js +++ b/packages/platform-ios/src/link/__tests__/isInstalled.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import isInstalled from '../isInstalled'; @@ -20,11 +18,13 @@ const baseProjectConfig = { describe('ios::isInstalled', () => { it('should return true when .xcodeproj in Libraries', () => { const dependencyConfig = {projectName: 'React.xcodeproj'}; + // @ts-ignore FIXME: Improve types expect(isInstalled(baseProjectConfig, dependencyConfig)).toBeTruthy(); }); it('should return false when .xcodeproj not in Libraries', () => { const dependencyConfig = {projectName: 'Missing.xcodeproj'}; + // @ts-ignore FIXME: Improve types expect(isInstalled(baseProjectConfig, dependencyConfig)).toBeFalsy(); }); @@ -33,6 +33,7 @@ describe('ios::isInstalled', () => { const projectConfig = Object.assign({}, baseProjectConfig, { libraryFolder: 'Missing', }); + // @ts-ignore FIXME: Improve types expect(isInstalled(projectConfig, dependencyConfig)).toBeFalsy(); }); }); diff --git a/packages/platform-ios/src/link/__tests__/mapHeaderSearchPaths-test.js b/packages/platform-ios/src/link/__tests__/mapHeaderSearchPaths.test.ts similarity index 95% rename from packages/platform-ios/src/link/__tests__/mapHeaderSearchPaths-test.js rename to packages/platform-ios/src/link/__tests__/mapHeaderSearchPaths.test.ts index 1d55ff318..0ced635c5 100644 --- a/packages/platform-ios/src/link/__tests__/mapHeaderSearchPaths-test.js +++ b/packages/platform-ios/src/link/__tests__/mapHeaderSearchPaths.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import mapHeaderSearchPaths from '../mapHeaderSearchPaths'; diff --git a/packages/platform-ios/src/link/__tests__/removeProjectFromLibraries-test.js b/packages/platform-ios/src/link/__tests__/removeProjectFromLibraries.test.ts similarity index 95% rename from packages/platform-ios/src/link/__tests__/removeProjectFromLibraries-test.js rename to packages/platform-ios/src/link/__tests__/removeProjectFromLibraries.test.ts index 62c5ae58b..3308e83a1 100644 --- a/packages/platform-ios/src/link/__tests__/removeProjectFromLibraries-test.js +++ b/packages/platform-ios/src/link/__tests__/removeProjectFromLibraries.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import addProjectToLibraries from '../addProjectToLibraries'; diff --git a/packages/platform-ios/src/link/__tests__/removeProjectFromProject-test.js b/packages/platform-ios/src/link/__tests__/removeProjectFromProject.test.ts similarity index 96% rename from packages/platform-ios/src/link/__tests__/removeProjectFromProject-test.js rename to packages/platform-ios/src/link/__tests__/removeProjectFromProject.test.ts index 1a537395d..7ea04df4f 100644 --- a/packages/platform-ios/src/link/__tests__/removeProjectFromProject-test.js +++ b/packages/platform-ios/src/link/__tests__/removeProjectFromProject.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import addFileToProject from '../addFileToProject'; diff --git a/packages/platform-ios/src/link/__tests__/removeSharedLibrary-test.js b/packages/platform-ios/src/link/__tests__/removeSharedLibrary.test.ts similarity index 95% rename from packages/platform-ios/src/link/__tests__/removeSharedLibrary-test.js rename to packages/platform-ios/src/link/__tests__/removeSharedLibrary.test.ts index edfd00cfe..f48da6480 100644 --- a/packages/platform-ios/src/link/__tests__/removeSharedLibrary-test.js +++ b/packages/platform-ios/src/link/__tests__/removeSharedLibrary.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import addSharedLibraries from '../addSharedLibraries'; diff --git a/packages/platform-ios/src/link/__tests__/writePlist-test.js b/packages/platform-ios/src/link/__tests__/writePlist.test.ts similarity index 97% rename from packages/platform-ios/src/link/__tests__/writePlist-test.js rename to packages/platform-ios/src/link/__tests__/writePlist.test.ts index 8fcf37c5f..7393ee39c 100644 --- a/packages/platform-ios/src/link/__tests__/writePlist-test.js +++ b/packages/platform-ios/src/link/__tests__/writePlist.test.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @emails oncall+javascript_foundation */ import getPlistPath from '../getPlistPath'; @@ -43,6 +41,7 @@ describe('ios::writePlist', () => { }); it('should write a `.plist` file', () => { + // @ts-ignore getPlistPath.mockImplementation(() => '/Basic/Info.plist'); writePlist(project, '/', plist); const infoPlist = readFileSync(infoPlistPath).toString(); @@ -53,6 +52,7 @@ describe('ios::writePlist', () => { }); it('when plistPath is null it should return null', () => { + // @ts-ignore getPlistPath.mockImplementation(() => null); expect(writePlist(project, '/', plist)).toBeNull(); expect(fs.writeFileSync).not.toHaveBeenCalled(); diff --git a/packages/platform-ios/src/link/addFileToProject.js b/packages/platform-ios/src/link/addFileToProject.ts similarity index 96% rename from packages/platform-ios/src/link/addFileToProject.js rename to packages/platform-ios/src/link/addFileToProject.ts index abcbc948b..6d5162c10 100644 --- a/packages/platform-ios/src/link/addFileToProject.js +++ b/packages/platform-ios/src/link/addFileToProject.ts @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format - * @flow */ import PbxFile from 'xcode/lib/pbxFile'; diff --git a/packages/platform-ios/src/link/addProjectToLibraries.js b/packages/platform-ios/src/link/addProjectToLibraries.ts similarity index 75% rename from packages/platform-ios/src/link/addProjectToLibraries.js rename to packages/platform-ios/src/link/addProjectToLibraries.ts index 72c8e2de1..8c7af5fd8 100644 --- a/packages/platform-ios/src/link/addProjectToLibraries.js +++ b/packages/platform-ios/src/link/addProjectToLibraries.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** @@ -14,7 +13,10 @@ * Important: That function mutates `libraries` and it's not pure. * It's mainly due to limitations of `xcode` library. */ -export default function addProjectToLibraries(libraries, file) { +export default function addProjectToLibraries( + libraries: {children: Array<{value: string; comment: string}>}, + file: {fileRef: string; basename: string}, +) { return libraries.children.push({ value: file.fileRef, comment: file.basename, diff --git a/packages/platform-ios/src/link/addSharedLibraries.js b/packages/platform-ios/src/link/addSharedLibraries.ts similarity index 85% rename from packages/platform-ios/src/link/addSharedLibraries.js rename to packages/platform-ios/src/link/addSharedLibraries.ts index 13d611b20..652243125 100644 --- a/packages/platform-ios/src/link/addSharedLibraries.js +++ b/packages/platform-ios/src/link/addSharedLibraries.ts @@ -4,12 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import createGroupWithMessage from './createGroupWithMessage'; -export default function addSharedLibraries(project, libraries) { +export default function addSharedLibraries( + project: any, + libraries: Array, +) { if (!libraries.length) { return; } diff --git a/packages/platform-ios/src/link/addToHeaderSearchPaths.js b/packages/platform-ios/src/link/addToHeaderSearchPaths.ts similarity index 85% rename from packages/platform-ios/src/link/addToHeaderSearchPaths.js rename to packages/platform-ios/src/link/addToHeaderSearchPaths.ts index 2efd5df5f..896ec3148 100644 --- a/packages/platform-ios/src/link/addToHeaderSearchPaths.js +++ b/packages/platform-ios/src/link/addToHeaderSearchPaths.ts @@ -4,13 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import mapHeaderSearchPaths from './mapHeaderSearchPaths'; import {logger} from '@react-native-community/cli-tools'; -export default function addToHeaderSearchPaths(project, path) { +export default function addToHeaderSearchPaths(project: any, path: string) { logger.debug(`Adding ${path} to header search paths`); mapHeaderSearchPaths(project, searchPaths => searchPaths.concat(path)); } diff --git a/packages/platform-ios/src/link/common/isInstalled.js b/packages/platform-ios/src/link/common/isInstalled.ts similarity index 66% rename from packages/platform-ios/src/link/common/isInstalled.js rename to packages/platform-ios/src/link/common/isInstalled.ts index fcb5fab00..9afd3c660 100644 --- a/packages/platform-ios/src/link/common/isInstalled.js +++ b/packages/platform-ios/src/link/common/isInstalled.ts @@ -4,17 +4,20 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import isInstalledIOS from '../isInstalled'; import isInstalledPods from '../../link-pods/isInstalled'; -import type {ProjectConfigIOST, DependencyConfigIOST} from 'types'; +import { + IOSProjectConfig, + IOSDependencyConfig, +} from '@react-native-community/cli-types'; export default function isInstalled( - projectConfig: ProjectConfigIOST, - name?: string, - dependencyConfig: DependencyConfigIOST, + projectConfig: IOSProjectConfig, + // FIXME: name is never used + _name: string | undefined, + dependencyConfig: IOSDependencyConfig, ) { return ( isInstalledIOS(projectConfig, dependencyConfig) || diff --git a/packages/platform-ios/src/link/common/registerNativeModule.js b/packages/platform-ios/src/link/common/registerNativeModule.ts similarity index 72% rename from packages/platform-ios/src/link/common/registerNativeModule.js rename to packages/platform-ios/src/link/common/registerNativeModule.ts index 041e60cb8..e5b26f1ad 100644 --- a/packages/platform-ios/src/link/common/registerNativeModule.js +++ b/packages/platform-ios/src/link/common/registerNativeModule.ts @@ -4,18 +4,22 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ -import type {DependencyConfigIOST, ProjectConfigIOST} from 'types'; +import { + IOSDependencyConfig, + IOSProjectConfig, +} from '@react-native-community/cli-types'; import registerDependencyIOS from '../registerNativeModule'; import registerDependencyPods from '../../link-pods/registerNativeModule'; export default function registerNativeModule( name: string, - dependencyConfig: DependencyConfigIOST, - params?: any, - projectConfig: ProjectConfigIOST, + dependencyConfig: IOSDependencyConfig, + // FIXME: Params is never used + _params?: any, + // @ts-ignore + projectConfig: IOSProjectConfig, ) { if (projectConfig.podfile && dependencyConfig.podspecPath) { registerDependencyPods(name, dependencyConfig.podspecPath, projectConfig); diff --git a/packages/platform-ios/src/link/common/unregisterNativeModule.js b/packages/platform-ios/src/link/common/unregisterNativeModule.ts similarity index 79% rename from packages/platform-ios/src/link/common/unregisterNativeModule.js rename to packages/platform-ios/src/link/common/unregisterNativeModule.ts index 1fd689344..ff2b20470 100644 --- a/packages/platform-ios/src/link/common/unregisterNativeModule.js +++ b/packages/platform-ios/src/link/common/unregisterNativeModule.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import {compact} from 'lodash'; @@ -12,12 +11,17 @@ import isInstalledIOS from '../isInstalled'; import isInstalledPods from '../../link-pods/isInstalled'; import unregisterDependencyIOS from '../unregisterNativeModule'; import unregisterDependencyPods from '../../link-pods/unregisterNativeModule'; +import { + IOSDependencyConfig, + IOSProjectConfig, +} from '@react-native-community/cli-types'; export default function unregisterNativeModule( - name, - dependencyConfig, - projectConfig, - otherDependencies, + _name: string, + dependencyConfig: IOSDependencyConfig, + projectConfig: IOSProjectConfig, + // FIXME: Add type signature here + otherDependencies: Array, ) { const isIosInstalled = isInstalledIOS(projectConfig, dependencyConfig); const isPodInstalled = isInstalledPods(projectConfig, dependencyConfig); diff --git a/packages/platform-ios/src/link/copyAssets.js b/packages/platform-ios/src/link/copyAssets.ts similarity index 87% rename from packages/platform-ios/src/link/copyAssets.js rename to packages/platform-ios/src/link/copyAssets.ts index 862aa3ed2..37987bf28 100644 --- a/packages/platform-ios/src/link/copyAssets.js +++ b/packages/platform-ios/src/link/copyAssets.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import fs from 'fs'; @@ -14,7 +13,7 @@ import createGroupWithMessage from './createGroupWithMessage'; import getPlist from './getPlist'; import writePlist from './writePlist'; import {logger, groupFilesByType} from '@react-native-community/cli-tools'; -import type {ProjectConfigIOST} from '../../../../types'; +import {IOSProjectConfig} from '@react-native-community/cli-types'; /** * This function works in a similar manner to its Android version, @@ -22,7 +21,7 @@ import type {ProjectConfigIOST} from '../../../../types'; */ export default function linkAssetsIOS( files: Array, - projectConfig: ProjectConfigIOST, + projectConfig: IOSProjectConfig, ) { const project = xcode.project(projectConfig.pbxprojPath).parseSync(); const assets = groupFilesByType(files); @@ -30,7 +29,7 @@ export default function linkAssetsIOS( createGroupWithMessage(project, 'Resources'); - function addResourceFile(f) { + function addResourceFile(f: Array) { return (f || []) .map(asset => { logger.debug(`Linking asset ${asset}`); @@ -47,8 +46,10 @@ export default function linkAssetsIOS( const fonts = addResourceFile(assets.font); + // @ts-ignore Type mismatch with the lib const existingFonts = plist.UIAppFonts || []; const allFonts = [...existingFonts, ...fonts]; + // @ts-ignore Type mismatch with the lib plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing fs.writeFileSync(projectConfig.pbxprojPath, project.writeSync()); diff --git a/packages/platform-ios/src/link/createGroup.js b/packages/platform-ios/src/link/createGroup.ts similarity index 76% rename from packages/platform-ios/src/link/createGroup.js rename to packages/platform-ios/src/link/createGroup.ts index 7d623edeb..44aac1faa 100644 --- a/packages/platform-ios/src/link/createGroup.js +++ b/packages/platform-ios/src/link/createGroup.ts @@ -4,13 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import getGroup from './getGroup'; -const hasGroup = (pbxGroup, name) => - pbxGroup.children.find(group => group.comment === name); +const hasGroup = ( + pbxGroup: {children: Array<{comment: string}>}, + name: string, +) => pbxGroup.children.find(group => group.comment === name); /** * Given project and path of the group, it deeply creates a given group @@ -18,7 +19,7 @@ const hasGroup = (pbxGroup, name) => * * Returns newly created group */ -export default function createGroup(project, path) { +export default function createGroup(project: any, path: string) { return path.split('/').reduce((group, name) => { if (!hasGroup(group, name)) { const uuid = project.pbxCreateGroup(name, '""'); diff --git a/packages/platform-ios/src/link/createGroupWithMessage.js b/packages/platform-ios/src/link/createGroupWithMessage.ts similarity index 91% rename from packages/platform-ios/src/link/createGroupWithMessage.js rename to packages/platform-ios/src/link/createGroupWithMessage.ts index aad426e4f..c569e6783 100644 --- a/packages/platform-ios/src/link/createGroupWithMessage.js +++ b/packages/platform-ios/src/link/createGroupWithMessage.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import {logger} from '@react-native-community/cli-tools'; @@ -17,7 +16,7 @@ import getGroup from './getGroup'; * * Returns the existing or newly created group */ -export default function createGroupWithMessage(project, path) { +export default function createGroupWithMessage(project: any, path: string) { let group = getGroup(project, path); if (!group) { diff --git a/packages/platform-ios/src/link/getBuildProperty.js b/packages/platform-ios/src/link/getBuildProperty.ts similarity index 94% rename from packages/platform-ios/src/link/getBuildProperty.js rename to packages/platform-ios/src/link/getBuildProperty.ts index a87c03355..3eb7e9c6a 100644 --- a/packages/platform-ios/src/link/getBuildProperty.js +++ b/packages/platform-ios/src/link/getBuildProperty.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** @@ -18,7 +17,7 @@ * without the property defined (e.g. CocoaPods sections appended to project * miss INFOPLIST_FILE), see: https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L1765 */ -export default function getBuildProperty(project, prop) { +export default function getBuildProperty(project: any, prop: string) { const target = project.getFirstTarget().firstTarget; const config = project.pbxXCConfigurationList()[ target.buildConfigurationList diff --git a/packages/platform-ios/src/link/getGroup.js b/packages/platform-ios/src/link/getGroup.ts similarity index 73% rename from packages/platform-ios/src/link/getGroup.js rename to packages/platform-ios/src/link/getGroup.ts index 6db8a67de..37acfc708 100644 --- a/packages/platform-ios/src/link/getGroup.js +++ b/packages/platform-ios/src/link/getGroup.ts @@ -4,13 +4,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ -const getFirstProject = project => project.getFirstProject().firstProject; +const getFirstProject = (project: any) => + project.getFirstProject().firstProject; -const findGroup = (groups, name) => - groups.children.find(group => group.comment === name); +const findGroup = ( + groups: {children: Array<{comment: string; value: string}>}, + name: string, +) => groups.children.find(group => group.comment === name); /** * Returns group from .xcodeproj if one exists, null otherwise @@ -20,7 +22,7 @@ const findGroup = (groups, name) => * * If path is not provided, it returns top-level group */ -export default function getGroup(project, path) { +export default function getGroup(project: any, path?: string) { const firstProject = getFirstProject(project); let groups = project.getPBXGroupByKey(firstProject.mainGroup); diff --git a/packages/platform-ios/src/link/getHeaderSearchPath.js b/packages/platform-ios/src/link/getHeaderSearchPath.ts similarity index 92% rename from packages/platform-ios/src/link/getHeaderSearchPath.js rename to packages/platform-ios/src/link/getHeaderSearchPath.ts index 30ec7ca96..119450e59 100644 --- a/packages/platform-ios/src/link/getHeaderSearchPath.js +++ b/packages/platform-ios/src/link/getHeaderSearchPath.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import {posix as path} from 'path'; @@ -20,7 +19,7 @@ import {last, union} from 'lodash'; * * Check `getHeaderSearchPath.spec.js` for more use-cases. */ -const getOuterDirectory = directories => +const getOuterDirectory = (directories: Array) => directories.reduce((topDir, currentDir) => { const currentFolders = currentDir.split(path.sep); const topMostFolders = topDir.split(path.sep); @@ -49,7 +48,10 @@ const getOuterDirectory = directories => * the end so Xcode marks that location as `recursive` and will look inside * every folder of it to locate correct headers. */ -export default function getHeaderSearchPath(sourceDir, headers) { +export default function getHeaderSearchPath( + sourceDir: string, + headers: Array, +) { const directories = union(headers.map(path.dirname)); return directories.length === 1 diff --git a/packages/platform-ios/src/link/getHeadersInFolder.js b/packages/platform-ios/src/link/getHeadersInFolder.ts similarity index 90% rename from packages/platform-ios/src/link/getHeadersInFolder.js rename to packages/platform-ios/src/link/getHeadersInFolder.ts index 41a83e5ed..90bdd7a44 100644 --- a/packages/platform-ios/src/link/getHeadersInFolder.js +++ b/packages/platform-ios/src/link/getHeadersInFolder.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import glob from 'glob'; @@ -21,7 +20,7 @@ const GLOB_EXCLUDE_PATTERN = [ * Given folder, it returns an array of all header files * inside it, ignoring node_modules and examples */ -export default function getHeadersInFolder(folder) { +export default function getHeadersInFolder(folder: string) { return glob .sync('**/*.h', { cwd: folder, diff --git a/packages/platform-ios/src/link/getPlist.js b/packages/platform-ios/src/link/getPlist.ts similarity index 89% rename from packages/platform-ios/src/link/getPlist.js rename to packages/platform-ios/src/link/getPlist.ts index 5292b482c..f7bb3c497 100644 --- a/packages/platform-ios/src/link/getPlist.js +++ b/packages/platform-ios/src/link/getPlist.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import plistParser from 'plist'; @@ -16,7 +15,7 @@ import getPlistPath from './getPlistPath'; * * Returns `null` if INFOPLIST_FILE is not specified. */ -export default function getPlist(project, sourceDir) { +export default function getPlist(project: any, sourceDir: string) { const plistPath = getPlistPath(project, sourceDir); if (!plistPath || !fs.existsSync(plistPath)) { diff --git a/packages/platform-ios/src/link/getPlistPath.js b/packages/platform-ios/src/link/getPlistPath.ts similarity index 86% rename from packages/platform-ios/src/link/getPlistPath.js rename to packages/platform-ios/src/link/getPlistPath.ts index b0e613309..ce8cafd7d 100644 --- a/packages/platform-ios/src/link/getPlistPath.js +++ b/packages/platform-ios/src/link/getPlistPath.ts @@ -4,13 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import path from 'path'; import getBuildProperty from './getBuildProperty'; -export default function getPlistPath(project, sourceDir) { +export default function getPlistPath(project: string, sourceDir: string) { const plistFile = getBuildProperty(project, 'INFOPLIST_FILE'); if (!plistFile) { diff --git a/packages/platform-ios/src/link/getTargets.js b/packages/platform-ios/src/link/getTargets.ts similarity index 85% rename from packages/platform-ios/src/link/getTargets.js rename to packages/platform-ios/src/link/getTargets.ts index 3c8a84146..784c3803d 100644 --- a/packages/platform-ios/src/link/getTargets.js +++ b/packages/platform-ios/src/link/getTargets.ts @@ -4,20 +4,23 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ +interface Target { + value: string; +} + /** * Given xcodeproj it returns list of targets */ -export default function getTargets(project) { +export default function getTargets(project: any) { const { firstProject: {targets}, } = project.getFirstProject(); const nativeTargetSection = project.pbxNativeTargetSection(); return targets - .filter(target => nativeTargetSection[target.value] !== undefined) - .map(target => { + .filter((target: Target) => nativeTargetSection[target.value] !== undefined) + .map((target: Target) => { const key = target.value; const configurationListId = nativeTargetSection[key].buildConfigurationList; diff --git a/packages/platform-ios/src/link/hasLibraryImported.js b/packages/platform-ios/src/link/hasLibraryImported.ts similarity index 79% rename from packages/platform-ios/src/link/hasLibraryImported.js rename to packages/platform-ios/src/link/hasLibraryImported.ts index 0c6ba5ab7..e99d9d72b 100644 --- a/packages/platform-ios/src/link/hasLibraryImported.js +++ b/packages/platform-ios/src/link/hasLibraryImported.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** @@ -12,7 +11,10 @@ * added, returns true or false depending on whether the library is already linked * or not */ -export default function hasLibraryImported(libraries, packageName) { +export default function hasLibraryImported( + libraries: {children: Array<{comment: string}>}, + packageName: string, +) { return ( libraries.children.filter(library => library.comment === packageName) .length > 0 diff --git a/packages/platform-ios/src/link/index.js b/packages/platform-ios/src/link/index.ts similarity index 98% rename from packages/platform-ios/src/link/index.js rename to packages/platform-ios/src/link/index.ts index 687e922f4..4b38b1556 100644 --- a/packages/platform-ios/src/link/index.js +++ b/packages/platform-ios/src/link/index.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import isInstalled from './common/isInstalled'; diff --git a/packages/platform-ios/src/link/isInstalled.js b/packages/platform-ios/src/link/isInstalled.ts similarity index 84% rename from packages/platform-ios/src/link/isInstalled.js rename to packages/platform-ios/src/link/isInstalled.ts index 13c74cdc1..3e9ac3812 100644 --- a/packages/platform-ios/src/link/isInstalled.js +++ b/packages/platform-ios/src/link/isInstalled.ts @@ -4,13 +4,15 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import xcode from 'xcode'; import getGroup from './getGroup'; import hasLibraryImported from './hasLibraryImported'; -import type {ProjectConfigIOST, DependencyConfigIOST} from 'types'; +import { + IOSProjectConfig, + IOSDependencyConfig, +} from '@react-native-community/cli-types'; const memo = new Map(); @@ -19,8 +21,8 @@ const memo = new Map(); * in a top level `libraryFolder` */ export default function isInstalled( - projectConfig: ProjectConfigIOST, - dependencyConfig: DependencyConfigIOST, + projectConfig: IOSProjectConfig, + dependencyConfig: IOSDependencyConfig, ) { let project; diff --git a/packages/platform-ios/src/link/mapHeaderSearchPaths.js b/packages/platform-ios/src/link/mapHeaderSearchPaths.ts similarity index 92% rename from packages/platform-ios/src/link/mapHeaderSearchPaths.js rename to packages/platform-ios/src/link/mapHeaderSearchPaths.ts index eda6341e8..af8976fb0 100644 --- a/packages/platform-ios/src/link/mapHeaderSearchPaths.js +++ b/packages/platform-ios/src/link/mapHeaderSearchPaths.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** @@ -24,7 +23,10 @@ */ const defaultHeaderPaths = ['"$(inherited)"']; -export default function headerSearchPathIter(project, func) { +export default function headerSearchPathIter( + project: any, + func: (searchPaths: Array) => Array, +) { const config = project.pbxXCBuildConfigurationSection(); Object.keys(config) diff --git a/packages/platform-ios/src/link/registerNativeModule.js b/packages/platform-ios/src/link/registerNativeModule.ts similarity index 92% rename from packages/platform-ios/src/link/registerNativeModule.js rename to packages/platform-ios/src/link/registerNativeModule.ts index 698f89139..e86bc56d3 100644 --- a/packages/platform-ios/src/link/registerNativeModule.js +++ b/packages/platform-ios/src/link/registerNativeModule.ts @@ -4,14 +4,16 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import xcode from 'xcode'; import fs from 'fs'; import path from 'path'; import {isEmpty} from 'lodash'; -import type {DependencyConfigIOST, ProjectConfigIOST} from 'types'; +import { + IOSDependencyConfig, + IOSProjectConfig, +} from '@react-native-community/cli-types'; import addToHeaderSearchPaths from './addToHeaderSearchPaths'; import getHeadersInFolder from './getHeadersInFolder'; import getHeaderSearchPath from './getHeaderSearchPath'; @@ -30,8 +32,8 @@ import {logger} from '@react-native-community/cli-tools'; * If library is already linked, this action is a no-op. */ export default function registerNativeModuleIOS( - dependencyConfig: DependencyConfigIOST, - projectConfig: ProjectConfigIOST, + dependencyConfig: IOSDependencyConfig, + projectConfig: IOSProjectConfig, ) { logger.debug(`Reading ${projectConfig.pbxprojPath}`); const project = xcode.project(projectConfig.pbxprojPath).parseSync(); @@ -52,7 +54,7 @@ export default function registerNativeModuleIOS( addProjectToLibraries(libraries, file); - getTargets(dependencyProject).forEach(product => { + getTargets(dependencyProject).forEach((product: any) => { let i; if (!product.isTVOS) { for (i = 0; i < targets.length; i++) { diff --git a/packages/platform-ios/src/link/removeFromHeaderSearchPaths.js b/packages/platform-ios/src/link/removeFromHeaderSearchPaths.ts similarity index 88% rename from packages/platform-ios/src/link/removeFromHeaderSearchPaths.js rename to packages/platform-ios/src/link/removeFromHeaderSearchPaths.ts index 0eacd74e1..27266de1f 100644 --- a/packages/platform-ios/src/link/removeFromHeaderSearchPaths.js +++ b/packages/platform-ios/src/link/removeFromHeaderSearchPaths.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import mapHeaderSearchPaths from './mapHeaderSearchPaths'; @@ -13,7 +12,7 @@ import {logger} from '@react-native-community/cli-tools'; /** * Given Xcode project and absolute path, it makes sure there are no headers referring to it */ -export default function addToHeaderSearchPaths(project, path) { +export default function addToHeaderSearchPaths(project: any, path: string) { logger.debug(`Removing ${path} from header search paths`); mapHeaderSearchPaths(project, searchPaths => searchPaths.filter(searchPath => searchPath !== path), diff --git a/packages/platform-ios/src/link/removeFromPbxItemContainerProxySection.js b/packages/platform-ios/src/link/removeFromPbxItemContainerProxySection.ts similarity index 86% rename from packages/platform-ios/src/link/removeFromPbxItemContainerProxySection.js rename to packages/platform-ios/src/link/removeFromPbxItemContainerProxySection.ts index c8d8bb0e7..6ca7e4356 100644 --- a/packages/platform-ios/src/link/removeFromPbxItemContainerProxySection.js +++ b/packages/platform-ios/src/link/removeFromPbxItemContainerProxySection.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** @@ -12,7 +11,10 @@ * a new PBXItemContainerProxy is created that contains `containerPortal` value * which equals to xcodeproj file.uuid from PBXFileReference section. */ -export default function removeFromPbxItemContainerProxySection(project, file) { +export default function removeFromPbxItemContainerProxySection( + project: any, + file: any, +) { const section = project.hash.project.objects.PBXContainerItemProxy; for (const key of Object.keys(section)) { diff --git a/packages/platform-ios/src/link/removeFromPbxReferenceProxySection.js b/packages/platform-ios/src/link/removeFromPbxReferenceProxySection.ts similarity index 84% rename from packages/platform-ios/src/link/removeFromPbxReferenceProxySection.js rename to packages/platform-ios/src/link/removeFromPbxReferenceProxySection.ts index 5c62e5fde..214cb98de 100644 --- a/packages/platform-ios/src/link/removeFromPbxReferenceProxySection.js +++ b/packages/platform-ios/src/link/removeFromPbxReferenceProxySection.ts @@ -4,14 +4,16 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** * Every file added to the project from another project is attached to * `PBXItemContainerProxy` through `PBXReferenceProxy`. */ -export default function removeFromPbxReferenceProxySection(project, file) { +export default function removeFromPbxReferenceProxySection( + project: any, + file: any, +) { const section = project.hash.project.objects.PBXReferenceProxy; for (const key of Object.keys(section)) { diff --git a/packages/platform-ios/src/link/removeFromProjectReferences.js b/packages/platform-ios/src/link/removeFromProjectReferences.ts similarity index 87% rename from packages/platform-ios/src/link/removeFromProjectReferences.js rename to packages/platform-ios/src/link/removeFromProjectReferences.ts index 6382c844c..f2ba588e9 100644 --- a/packages/platform-ios/src/link/removeFromProjectReferences.js +++ b/packages/platform-ios/src/link/removeFromProjectReferences.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ /** @@ -17,11 +16,11 @@ * * Otherwise returns null */ -export default function removeFromProjectReferences(project, file) { +export default function removeFromProjectReferences(project: any, file: any) { const {firstProject} = project.getFirstProject(); const projectRef = firstProject.projectReferences.find( - item => item.ProjectRef === file.uuid, + (item: any) => item.ProjectRef === file.uuid, ); if (!projectRef) { diff --git a/packages/platform-ios/src/link/removeFromStaticLibraries.js b/packages/platform-ios/src/link/removeFromStaticLibraries.ts similarity index 86% rename from packages/platform-ios/src/link/removeFromStaticLibraries.js rename to packages/platform-ios/src/link/removeFromStaticLibraries.ts index 3d821cd95..264ec34f2 100644 --- a/packages/platform-ios/src/link/removeFromStaticLibraries.js +++ b/packages/platform-ios/src/link/removeFromStaticLibraries.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import PbxFile from 'xcode/lib/pbxFile'; @@ -15,7 +14,11 @@ import removeFromPbxReferenceProxySection from './removeFromPbxReferenceProxySec * * Similar to `node-xcode` addStaticLibrary */ -export default function removeFromStaticLibraries(project, path, opts) { +export default function removeFromStaticLibraries( + project: any, + path: string, + opts: {[key: string]: any}, +) { const file = new PbxFile(path); file.target = opts ? opts.target : undefined; diff --git a/packages/platform-ios/src/link/removeProductGroup.js b/packages/platform-ios/src/link/removeProductGroup.ts similarity index 81% rename from packages/platform-ios/src/link/removeProductGroup.js rename to packages/platform-ios/src/link/removeProductGroup.ts index e5f2f60fe..75cfd52e5 100644 --- a/packages/platform-ios/src/link/removeProductGroup.js +++ b/packages/platform-ios/src/link/removeProductGroup.ts @@ -4,10 +4,9 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ -export default function removeProductGroup(project, productGroupId) { +export default function removeProductGroup(project: any, productGroupId: any) { const section = project.hash.project.objects.PBXGroup; for (const key of Object.keys(section)) { diff --git a/packages/platform-ios/src/link/removeProjectFromLibraries.js b/packages/platform-ios/src/link/removeProjectFromLibraries.ts similarity index 79% rename from packages/platform-ios/src/link/removeProjectFromLibraries.js rename to packages/platform-ios/src/link/removeProjectFromLibraries.ts index 80f8068e4..9630c149c 100644 --- a/packages/platform-ios/src/link/removeProjectFromLibraries.js +++ b/packages/platform-ios/src/link/removeProjectFromLibraries.ts @@ -12,7 +12,10 @@ * Important: That function mutates `libraries` and it's not pure. * It's mainly due to limitations of `xcode` library. */ -export default function removeProjectFromLibraries(libraries, file) { +export default function removeProjectFromLibraries( + libraries: {children: Array<{comment: string}>}, + file: {basename: string}, +) { libraries.children = libraries.children.filter( library => library.comment !== file.basename, ); diff --git a/packages/platform-ios/src/link/removeProjectFromProject.js b/packages/platform-ios/src/link/removeProjectFromProject.ts similarity index 92% rename from packages/platform-ios/src/link/removeProjectFromProject.js rename to packages/platform-ios/src/link/removeProjectFromProject.ts index 16a324645..a22c311c1 100644 --- a/packages/platform-ios/src/link/removeProjectFromProject.js +++ b/packages/platform-ios/src/link/removeProjectFromProject.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import PbxFile from 'xcode/lib/pbxFile'; @@ -21,7 +20,10 @@ import removeProductGroup from './removeProductGroup'; * * Returns removed file (that one will have UUID) */ -export default function removeProjectFromProject(project, filePath) { +export default function removeProjectFromProject( + project: any, + filePath: string, +) { const file = project.removeFromPbxFileReferenceSection(new PbxFile(filePath)); const projectRef = removeFromProjectReferences(project, file); diff --git a/packages/platform-ios/src/link/removeSharedLibraries.js b/packages/platform-ios/src/link/removeSharedLibraries.ts similarity index 80% rename from packages/platform-ios/src/link/removeSharedLibraries.js rename to packages/platform-ios/src/link/removeSharedLibraries.ts index 35882b08b..540f2cf35 100644 --- a/packages/platform-ios/src/link/removeSharedLibraries.js +++ b/packages/platform-ios/src/link/removeSharedLibraries.ts @@ -4,10 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ -export default function removeSharedLibraries(project, libraries) { +export default function removeSharedLibraries( + project: any, + libraries: Array, +) { if (!libraries.length) { return; } diff --git a/packages/platform-ios/src/link/unlinkAssets.js b/packages/platform-ios/src/link/unlinkAssets.ts similarity index 87% rename from packages/platform-ios/src/link/unlinkAssets.js rename to packages/platform-ios/src/link/unlinkAssets.ts index c8ae6ab2e..55323baf3 100644 --- a/packages/platform-ios/src/link/unlinkAssets.js +++ b/packages/platform-ios/src/link/unlinkAssets.ts @@ -14,12 +14,16 @@ import {difference} from 'lodash'; import getPlist from './getPlist'; import writePlist from './writePlist'; import {logger, groupFilesByType} from '@react-native-community/cli-tools'; +import {IOSProjectConfig} from '@react-native-community/cli-types'; /** * Unlinks assets from iOS project. Removes references for fonts from `Info.plist` * fonts provided by application and from `Resources` group */ -export default function unlinkAssetsIOS(files, projectConfig) { +export default function unlinkAssetsIOS( + files: any, + projectConfig: IOSProjectConfig, +) { const project = xcode.project(projectConfig.pbxprojPath).parseSync(); const assets = groupFilesByType(files); const plist = getPlist(project, projectConfig.sourceDir); @@ -38,7 +42,7 @@ export default function unlinkAssetsIOS(files, projectConfig) { return; } - const removeResourceFiles = (f = []) => + const removeResourceFiles = (f: Array = []) => (f || []) .map(asset => { logger.debug(`Unlinking asset ${asset}`); @@ -53,6 +57,7 @@ export default function unlinkAssetsIOS(files, projectConfig) { const fonts = removeResourceFiles(assets.font); + // @ts-ignore Type mismatch plist.UIAppFonts = difference(plist.UIAppFonts || [], fonts); fs.writeFileSync(projectConfig.pbxprojPath, project.writeSync()); diff --git a/packages/platform-ios/src/link/unregisterNativeModule.js b/packages/platform-ios/src/link/unregisterNativeModule.ts similarity index 89% rename from packages/platform-ios/src/link/unregisterNativeModule.js rename to packages/platform-ios/src/link/unregisterNativeModule.ts index 442c59c22..57192354f 100644 --- a/packages/platform-ios/src/link/unregisterNativeModule.js +++ b/packages/platform-ios/src/link/unregisterNativeModule.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ import xcode from 'xcode'; @@ -22,6 +21,11 @@ import removeFromStaticLibraries from './removeFromStaticLibraries'; import removeFromHeaderSearchPaths from './removeFromHeaderSearchPaths'; import removeSharedLibraries from './removeSharedLibraries'; import {logger} from '@react-native-community/cli-tools'; +import { + IOSDependencyConfig, + IOSProjectConfig, + IOSProjectParams, +} from '@react-native-community/cli-types'; /** * Unregister native module IOS @@ -29,9 +33,9 @@ import {logger} from '@react-native-community/cli-tools'; * If library is already unlinked, this action is a no-op. */ export default function unregisterNativeModule( - dependencyConfig, - projectConfig, - iOSDependencies, + dependencyConfig: IOSDependencyConfig, + projectConfig: IOSProjectConfig, + iOSDependencies: Array, ) { logger.debug(`Reading ${projectConfig.pbxprojPath}`); const project = xcode.project(projectConfig.pbxprojPath).parseSync(); @@ -48,7 +52,7 @@ export default function unregisterNativeModule( removeProjectFromLibraries(libraries, file); - getTargets(dependencyProject).forEach(target => { + getTargets(dependencyProject).forEach((target: any) => { logger.debug( `Removing ${target.name} from ${ project.getFirstTarget().firstTarget.name diff --git a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts similarity index 88% rename from packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js rename to packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts index 78023df9c..ce3cac2cf 100644 --- a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js +++ b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts @@ -1,18 +1,18 @@ -// @flow - import chalk from 'chalk'; import {logger} from '@react-native-community/cli-tools'; -import type {ConfigT} from 'types'; +import {Config} from '@react-native-community/cli-types'; import getLinkConfig from './index'; // TODO: move to cli-tools once platform-ios and platform-android are migrated // to TS and unify with Android implementation export default function warnAboutManuallyLinkedLibs( - config: ConfigT, - platform?: string = 'ios', - linkConfig: $Call = getLinkConfig(), + config: Config, + platform: string = 'ios', + linkConfig: ReturnType< + Config['platforms']['ios']['linkConfig'] + > = getLinkConfig(), ) { - let deps = []; + let deps: Array = []; for (let key in config.dependencies) { const dependency = config.dependencies[key]; diff --git a/packages/platform-ios/src/link/writePlist.js b/packages/platform-ios/src/link/writePlist.ts similarity index 80% rename from packages/platform-ios/src/link/writePlist.js rename to packages/platform-ios/src/link/writePlist.ts index 38aaf6467..52b002d55 100644 --- a/packages/platform-ios/src/link/writePlist.js +++ b/packages/platform-ios/src/link/writePlist.ts @@ -4,10 +4,9 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format */ -import plistParser from 'plist'; +import plistParser, {PlistValue} from 'plist'; import fs from 'fs'; import getPlistPath from './getPlistPath'; @@ -16,7 +15,11 @@ import getPlistPath from './getPlistPath'; * * Returns `null` if INFOPLIST_FILE is not specified or file is non-existent. */ -export default function writePlist(project, sourceDir, plist) { +export default function writePlist( + project: any, + sourceDir: string, + plist: PlistValue | null, +) { const plistPath = getPlistPath(project, sourceDir); if (!plistPath) { @@ -28,6 +31,7 @@ export default function writePlist(project, sourceDir, plist) { // Ref: https://github.com/facebook/react-native/issues/11668 return fs.writeFileSync( plistPath, + // @ts-ignore Type mismatch `${plistParser.build(plist, {indent: '\t', offset: -1})}\n`, ); } diff --git a/packages/platform-ios/src/types.ts b/packages/platform-ios/src/types.ts new file mode 100644 index 000000000..21ddbf763 --- /dev/null +++ b/packages/platform-ios/src/types.ts @@ -0,0 +1,9 @@ +export interface Device { + availability?: string; + state?: string; + isAvailable?: boolean; + name: string; + udid: string; + version?: string; + availabilityError?: string; +} diff --git a/packages/platform-ios/tsconfig.json b/packages/platform-ios/tsconfig.json new file mode 100644 index 000000000..bd36878c1 --- /dev/null +++ b/packages/platform-ios/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build", + "typeRoots": ["definitions"] + }, + "references": [{"path": "../tools"}, {"path": "../cli-types"}] +} diff --git a/tsconfig.json b/tsconfig.json index 0a931118a..bc0c60880 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,11 +19,7 @@ /* Module Resolution Options */ "moduleResolution": "node", "esModuleInterop": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "types": ["./types"] - } + "resolveJsonModule": true }, "exclude": ["**/__tests__/**/*", "**/build/**/*"] } diff --git a/yarn.lock b/yarn.lock index 56578dcd9..8b530e076 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2025,6 +2025,14 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.51.tgz#80600857c0a47a8e8bafc2dae6daed6db58e3627" integrity sha512-cArrlJp3Yv6IyFT/DYe+rlO8o3SIHraALbBW/+CcCYW/a9QucpLI+n2p4sRxAvl2O35TiecpX2heSZtJjvEO+Q== +"@types/plist@^3.0.2": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@types/plist/-/plist-3.0.2.tgz#61b3727bba0f5c462fe333542534a0c3e19ccb01" + integrity sha512-ULqvZNGMv0zRFvqn8/4LSPtnmN4MfhlPNtJCTpKuIIxGVGZ2rYWzFXrvEBoh9CVyqSE7D6YFRJ1hydLHI6kbWw== + dependencies: + "@types/node" "*" + xmlbuilder ">=11.0.1" + "@types/stack-utils@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" @@ -9298,6 +9306,11 @@ xml-name-validator@^3.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw== +xmlbuilder@>=11.0.1: + version "13.0.2" + resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-13.0.2.tgz#02ae33614b6a047d1c32b5389c1fdacb2bce47a7" + integrity sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ== + xmlbuilder@^9.0.7: version "9.0.7" resolved "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"