From e7a9322bdfec9ddc2f08fb8b16872a105c1ae7e4 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 29 May 2025 07:52:38 -0700 Subject: [PATCH] RN: Flowify `packages/react-native-scripts` (#51671) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51671 Adds `flow` (or `noflow`) to all files in this directory and ensures that Flow succeeds (by adding type annotations, using minor refactors, or suppressing errors due to intentionally dynamic logic). This will help improve type safety when making changes both in these files as well as files that these depend on. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D75581879 fbshipit-source-id: 6dcd8cc55d0021973eeae2670c1ebceb6d69fa8f --- packages/react-native/scripts/bundle.js | 11 ++- .../scripts/codegen/__fixtures__/fixtures.js | 2 + .../generate-artifacts-executor-test.js | 9 +-- .../generate-specs-cli-executor-test.js | 1 + .../scripts/codegen/codegen-utils.js | 13 ++-- .../generate-artifacts-executor/constants.js | 62 +++++++++------- .../generateAppDependencyProvider.js | 3 +- .../generateCustomURLHandlers.js | 13 ++-- .../generateFBReactNativeSpecIOS.js | 1 + .../generateNativeCode.js | 34 ++++++--- .../generateRCTModuleProviders.js | 13 ++-- .../generateRCTThirdPartyComponents.js | 19 +++-- .../generateRNCoreComponentsIOS.js | 1 + .../generateReactCodegenPodspec.js | 15 ++-- .../generateSchemaInfos.js | 20 ++++-- ...eModulesRequiringMainQueueSetupProvider.js | 7 +- .../generate-artifacts-executor/index.js | 34 ++++++--- .../generate-artifacts-executor/utils.js | 72 +++++++++++++------ .../codegen/generate-specs-cli-executor.js | 66 +++++++++-------- .../scripts/compose-source-maps.js | 5 +- .../scripts/featureflags/index.js | 1 + .../ReactNativeFeatureFlags.kt-template.js | 7 -- .../scripts/generate-codegen-artifacts.js | 2 + .../scripts/generate-provider-cli.js | 16 +++-- .../scripts/generate-specs-cli.js | 7 ++ .../hermes/__tests__/hermes-utils-test.js | 7 +- .../scripts/hermes/bump-hermes-version.js | 5 +- .../scripts/hermes/create-tarball.js | 7 +- .../scripts/hermes/get-tarball-name.js | 4 +- .../scripts/hermes/hermes-utils.js | 4 +- .../hermes/prepare-hermes-for-build.js | 5 +- .../react-native/scripts/packager-reporter.js | 10 ++- 32 files changed, 313 insertions(+), 163 deletions(-) diff --git a/packages/react-native/scripts/bundle.js b/packages/react-native/scripts/bundle.js index ec2b42b2b1b..5a9e7035a59 100644 --- a/packages/react-native/scripts/bundle.js +++ b/packages/react-native/scripts/bundle.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -16,6 +17,7 @@ const {readFileSync} = require('fs'); const path = require('path'); // Commander 12.0.0 changes from the global to named export +// $FlowFixMe[signature-verification-failure] const program = commander.program ?? commander; program.version( @@ -37,7 +39,14 @@ program .allowUnknownOption() .action(async function handleAction() { let config = null; - let options = program.opts(); + let options = program + .opts /*::<{ + configCmd?: string, + loadConfig?: string, + verbose: boolean, + ... + }>*/ + (); if (options.loadConfig != null) { config = JSON.parse( options.loadConfig.replace(/^\W*'/, '').replace(/'\W*$/, ''), diff --git a/packages/react-native/scripts/codegen/__fixtures__/fixtures.js b/packages/react-native/scripts/codegen/__fixtures__/fixtures.js index 472242abe9b..61166c9abb1 100644 --- a/packages/react-native/scripts/codegen/__fixtures__/fixtures.js +++ b/packages/react-native/scripts/codegen/__fixtures__/fixtures.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -120,6 +121,7 @@ const SCHEMA_TEXT = ` } `; +// $FlowFixMe[signature-verification-failure] const SCHEMA = JSON.parse(SCHEMA_TEXT); module.exports = { diff --git a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js index 01953bacd8e..5e5150b33f5 100644 --- a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js +++ b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -243,7 +244,7 @@ describe('delete empty files and folders', () => { it("when path is folder and it's empty, removes it", () => { const targetFolder = 'build'; - const content = []; + const content = [] as Array; let statSyncInvocationCount = 0; let readdirInvocationCount = 0; @@ -290,8 +291,8 @@ describe('delete empty files and folders', () => { path.normalize('build/notEmptyFile'), ]; - const emptyContent = []; - let fileSizes = {}; + const emptyContent = [] as Array; + let fileSizes = {} as {[string]: number}; fileSizes[path.normalize('build/emptyFile')] = 0; fileSizes[path.normalize('build/notEmptyFile')] = 32; @@ -344,7 +345,7 @@ describe('delete empty files and folders', () => { it('when path is folder and it contains only empty folders, removes everything', () => { const targetFolder = 'build'; const content = ['emptyFolder1', 'emptyFolder2']; - const emptyContent = []; + const emptyContent = [] as Array; let statSyncInvocation = []; let rmSyncInvocation = []; diff --git a/packages/react-native/scripts/codegen/__tests__/generate-specs-cli-executor-test.js b/packages/react-native/scripts/codegen/__tests__/generate-specs-cli-executor-test.js index f3c74200f43..d0ec7ab82dd 100644 --- a/packages/react-native/scripts/codegen/__tests__/generate-specs-cli-executor-test.js +++ b/packages/react-native/scripts/codegen/__tests__/generate-specs-cli-executor-test.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ diff --git a/packages/react-native/scripts/codegen/codegen-utils.js b/packages/react-native/scripts/codegen/codegen-utils.js index d151bda6eff..4c03007bce3 100644 --- a/packages/react-native/scripts/codegen/codegen-utils.js +++ b/packages/react-native/scripts/codegen/codegen-utils.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -19,11 +20,13 @@ * * @return an object that can generate the code for the New Architecture. */ -function getCodegen() { +function getCodegen() /*: $FlowFixMe */ { let RNCodegen; try { + // $FlowIgnore[cannot-resolve-module] RNCodegen = require('../../packages/react-native-codegen/lib/generators/RNCodegen.js'); } catch (e) { + // $FlowIgnore[cannot-resolve-module] RNCodegen = require('@react-native/codegen/lib/generators/RNCodegen.js'); } if (!RNCodegen) { @@ -32,11 +35,13 @@ function getCodegen() { return RNCodegen; } -function getCombineJSToSchema() { +function getCombineJSToSchema() /*: $FlowFixMe */ { let combineJSToSchema; try { + // $FlowIgnore[cannot-resolve-module] combineJSToSchema = require('../../packages/react-native-codegen/lib/cli/combine/combine-js-to-schema.js'); } catch (e) { + // $FlowIgnore[cannot-resolve-module] combineJSToSchema = require('@react-native/codegen/lib/cli/combine/combine-js-to-schema.js'); } if (!combineJSToSchema) { @@ -46,6 +51,6 @@ function getCombineJSToSchema() { } module.exports = { - getCodegen: getCodegen, - getCombineJSToSchema: getCombineJSToSchema, + getCodegen, + getCombineJSToSchema, }; diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/constants.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/constants.js index 6f828737daa..9a8b7c4a6dc 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/constants.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/constants.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -21,11 +22,19 @@ const REACT_NATIVE_REPOSITORY_ROOT = path.join( '..', ); -const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..', '..'); +const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join( + __dirname, + '..', + '..', + '..', + ) /*:: as string */; const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`; const RNCORE_CONFIGS = { - ios: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'), + ios: path.join( + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'ReactCommon', + ) /*:: as string */, android: path.join( REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactAndroid', @@ -33,42 +42,43 @@ const RNCORE_CONFIGS = { 'generated', 'source', 'codegen', - ), + ) /*:: as string */, }; const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = { - rncore: RNCORE_CONFIGS, - FBReactNativeSpec: { - ios: path.join( - REACT_NATIVE_PACKAGE_ROOT_FOLDER, - 'React', - 'FBReactNativeSpec', - ), - android: path.join( - REACT_NATIVE_PACKAGE_ROOT_FOLDER, - 'ReactAndroid', - 'build', - 'generated', - 'source', - 'codegen', - ), - }, -}; + rncore: RNCORE_CONFIGS, + FBReactNativeSpec: { + ios: path.join( + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'React', + 'FBReactNativeSpec', + ) /*:: as string */, + android: path.join( + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'ReactAndroid', + 'build', + 'generated', + 'source', + 'codegen', + ) /*:: as string */, + }, + } /*:: as {[string]: $FlowFixMe} */; const packageJsonPath = path.join( REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'package.json', ); -const packageJson = JSON.parse(fs.readFileSync(packageJsonPath)); +// $FlowFixMe[signature-verification-failure] +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const REACT_NATIVE = packageJson.name; const TEMPLATES_FOLDER_PATH = path.join( - REACT_NATIVE_PACKAGE_ROOT_FOLDER, - 'scripts', - 'codegen', - 'templates', -); + REACT_NATIVE_PACKAGE_ROOT_FOLDER, + 'scripts', + 'codegen', + 'templates', + ) /*:: as string */; module.exports = { CODEGEN_REPO_PATH, diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateAppDependencyProvider.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateAppDependencyProvider.js index 8e3e60615ad..bf1a24b4732 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateAppDependencyProvider.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateAppDependencyProvider.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -28,7 +29,7 @@ const APP_DEPENDENCY_PROVIDER_PODSPEC_TEMPLATE_PATH = path.join( 'ReactAppDependencyProvider.podspec.template', ); -function generateAppDependencyProvider(outputDir) { +function generateAppDependencyProvider(outputDir /*: string */) { fs.mkdirSync(outputDir, {recursive: true}); codegenLog('Generating RCTAppDependencyProvider'); diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js index ed5c2696fb7..85e1b3e7e06 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -23,13 +24,17 @@ const MODULES_PROTOCOLS_MM_TEMPLATE_PATH = path.join( 'RCTModulesConformingToProtocolsProviderMM.template', ); -function generateCustomURLHandlers(libraries, outputDir) { +function generateCustomURLHandlers( + libraries /*: $ReadOnlyArray<$FlowFixMe> */, + outputDir /*: string */, +) { const iosAnnotations = parseiOSAnnotations(libraries); - const imageURLLoaderModules = new Set(); - const imageDataDecoderModules = new Set(); - const urlRequestHandlersModules = new Set(); + const imageURLLoaderModules = new Set /*::*/(); + const imageDataDecoderModules = new Set /*::*/(); + const urlRequestHandlersModules = new Set /*::*/(); + // $FlowFixMe[missing-local-annot]] const wrapInArrayIfNecessary = value => Array.isArray(value) || value == null ? value : [value]; // Old API diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateFBReactNativeSpecIOS.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateFBReactNativeSpecIOS.js index 9b029c58943..70ceacf800c 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateFBReactNativeSpecIOS.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateFBReactNativeSpecIOS.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateNativeCode.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateNativeCode.js index f505a32c185..daba7206e4f 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateNativeCode.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateNativeCode.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -17,17 +18,22 @@ const os = require('os'); const path = require('path'); function generateNativeCode( - outputPath, - schemaInfos, - includesGeneratedCode, - platform, -) { + outputPath /*: string */, + schemaInfos /*: $ReadOnlyArray<$FlowFixMe> */, + includesGeneratedCode /*: boolean */, + platform /*: string */, +) /*: Array */ { return schemaInfos.map(schemaInfo => { generateCode(outputPath, schemaInfo, includesGeneratedCode, platform); }); } -function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) { +function generateCode( + outputPath /*: string */, + schemaInfo /*: $FlowFixMe */, + includesGeneratedCode /*: boolean */, + platform /*: string */, +) { if (shouldSkipGenerationForRncore(schemaInfo, platform)) { codegenLog( '[Codegen - rncore] Skipping iOS code generation for rncore as it has been generated already.', @@ -65,11 +71,15 @@ function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) { const outputDir = reactNativeCoreLibraryOutputPath(libraryName, platform) ?? outputPath; fs.mkdirSync(outputDir, {recursive: true}); + // $FlowIssue[prop-missing] - `fs.cpSync` is missing in Flow libdefs. fs.cpSync(tmpOutputDir, outputDir, {recursive: true}); codegenLog(`Generated artifacts: ${outputDir}`); } -function shouldSkipGenerationForRncore(schemaInfo, platform) { +function shouldSkipGenerationForRncore( + schemaInfo /*: $FlowFixMe */, + platform /*: string */, +) { if (platform !== 'ios' || schemaInfo.library.config.name !== 'rncore') { return false; } @@ -82,13 +92,19 @@ function shouldSkipGenerationForRncore(schemaInfo, platform) { ); } -function reactNativeCoreLibraryOutputPath(libraryName, platform) { +function reactNativeCoreLibraryOutputPath( + libraryName /*: string */, + platform /*: string */, +) { return CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName] ? CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName][platform] : null; } -function shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform) { +function shouldSkipGenerationForFBReactNativeSpec( + schemaInfo /*: $FlowFixMe */, + platform /*: string */, +) { if ( platform !== 'ios' || schemaInfo.library.config.name !== 'FBReactNativeSpec' diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTModuleProviders.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTModuleProviders.js index a9d484f9627..cba1e1d3017 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTModuleProviders.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTModuleProviders.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -28,10 +29,10 @@ const MODULE_PROVIDERS_MM_TEMPLATE_PATH = path.join( ); function generateRCTModuleProviders( - projectRoot, - pkgJson, - libraries, - outputDir, + projectRoot /*: string */, + pkgJson /*: $FlowFixMe */, + libraries /*: $ReadOnlyArray<$FlowFixMe> */, + outputDir /*: string */, ) { fs.mkdirSync(outputDir, {recursive: true}); // Generate Header File @@ -42,7 +43,7 @@ function generateRCTModuleProviders( codegenLog(`Generated artifact: ${finalPathH}`); codegenLog('Generating RCTModuleProviders.mm'); - let modulesInLibraries = {}; + let modulesInLibraries = {} /*:: as {[string]: Array<$FlowFixMe>} */; let app = pkgJson.codegenConfig ? {config: pkgJson.codegenConfig, libraryPath: projectRoot} @@ -64,7 +65,7 @@ function generateRCTModuleProviders( // Old API moduleLibraries.forEach(({config, libraryPath}) => { const libraryName = JSON.parse( - fs.readFileSync(path.join(libraryPath, 'package.json')), + fs.readFileSync(path.join(libraryPath, 'package.json'), 'utf8'), ).name; if (config.ios?.modulesProvider) { diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js index 53669facbd7..4aea9f734bf 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -28,7 +29,10 @@ const THIRD_PARTY_COMPONENTS_MM_TEMPLATE_PATH = path.join( 'RCTThirdPartyComponentsProviderMM.template', ); -function generateRCTThirdPartyComponents(libraries, outputDir) { +function generateRCTThirdPartyComponents( + libraries /*: $ReadOnlyArray<$FlowFixMe> */, + outputDir /*: string */, +) { fs.mkdirSync(outputDir, {recursive: true}); // Generate Header File codegenLog('Generating RCTThirdPartyComponentsProvider.h'); @@ -41,7 +45,7 @@ function generateRCTThirdPartyComponents(libraries, outputDir) { codegenLog(`Generated artifact: ${finalPathH}`); codegenLog('Generating RCTThirdPartyComponentsProvider.mm'); - let componentsInLibraries = {}; + let componentsInLibraries = {} /*:: as {[string]: Array<$FlowFixMe>} */; const componentLibraries = libraries.filter(({config, libraryPath}) => { if (isReactNativeCoreLibrary(config.name) || config.type === 'modules') { @@ -50,13 +54,13 @@ function generateRCTThirdPartyComponents(libraries, outputDir) { return true; }); - const librariesToCrawl = {}; + const librariesToCrawl = {} /*:: as {[string]: $FlowFixMe} */; // Old API componentLibraries.forEach(library => { const {config, libraryPath} = library; const libraryName = JSON.parse( - fs.readFileSync(path.join(libraryPath, 'package.json')), + fs.readFileSync(path.join(libraryPath, 'package.json'), 'utf8'), ).name; librariesToCrawl[libraryName] = library; @@ -140,7 +144,10 @@ function generateRCTThirdPartyComponents(libraries, outputDir) { // Given a path, return the paths of all the files with extension .mm in // the path dir and all its subdirectories. -function findFilesWithExtension(filePath, extension) { +function findFilesWithExtension( + filePath /*: string */, + extension /*: string */, +) /*: Array */ { const files = []; const dir = fs.readdirSync(filePath); dir.forEach(file => { @@ -172,7 +179,7 @@ function findFilesWithExtension(filePath, extension) { // Given a filepath, read the file and look for a string that starts with 'Class ' // and ends with 'Cls(void)'. Return the string between the two. -function findRCTComponentViewProtocolClass(filepath) { +function findRCTComponentViewProtocolClass(filepath /*: string */) { const fileContent = fs.readFileSync(filepath, 'utf8'); const regex = /Class (.*)Cls\(/; const match = fileContent.match(regex); diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRNCoreComponentsIOS.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRNCoreComponentsIOS.js index ced30a1a3c1..908d4e10ac8 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRNCoreComponentsIOS.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRNCoreComponentsIOS.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js index 8ec3091e732..d5d932229dc 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -25,10 +26,10 @@ const REACT_CODEGEN_PODSPEC_TEMPLATE_PATH = path.join( ); function generateReactCodegenPodspec( - appPath, - appPkgJson, - outputPath, - baseOutputPath, + appPath /*: string */, + appPkgJson /*: $FlowFixMe */, + outputPath /*: string */, + baseOutputPath /*: string */, ) { const inputFiles = getInputFiles(appPath, appPkgJson); const codegenScript = codegenScripts(appPath, baseOutputPath); @@ -42,8 +43,8 @@ function generateReactCodegenPodspec( codegenLog(`Generated podspec: ${finalPathPodspec}`); } -function getInputFiles(appPath, appPkgJSon) { - const jsSrcsDir = appPkgJSon.codegenConfig?.jsSrcsDir; +function getInputFiles(appPath /*: string */, appPkgJson /*: $FlowFixMe */) { + const jsSrcsDir = appPkgJson.codegenConfig?.jsSrcsDir; if (!jsSrcsDir) { return '[]'; } @@ -70,7 +71,7 @@ function getInputFiles(appPath, appPkgJSon) { return `[${list}]`; } -function codegenScripts(appPath, outputPath) { +function codegenScripts(appPath /*: string */, outputPath /*: string */) { const relativeAppPath = path.relative(outputPath, appPath); return `<<-SCRIPT pushd "$PODS_ROOT/../" > /dev/null diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js index a222b7f211e..2137c5f9eab 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -15,11 +16,17 @@ const fs = require('fs'); const glob = require('glob'); const path = require('path'); -function generateSchemaInfos(libraries) { +function generateSchemaInfos( + libraries /*: $ReadOnlyArray<$FlowFixMe> */, +) /*: Array<$FlowFixMe> */ { + // $FlowFixMe[incompatible-call] return libraries.map(generateSchemaInfo); } -function generateSchemaInfo(library, platform) { +function generateSchemaInfo( + library /*: $FlowFixMe */, + platform /*: string */, +) /*: $FlowFixMe */ { const pathToJavaScriptSources = path.join( library.libraryPath, library.config.jsSrcsDir, @@ -45,7 +52,10 @@ function generateSchemaInfo(library, platform) { const APPLE_PLATFORMS = ['ios', 'macos', 'tvos', 'visionos']; -function extractSupportedApplePlatforms(dependency, dependencyPath) { +function extractSupportedApplePlatforms( + dependency /*: string */, + dependencyPath /*: string */, +) /*: ?{[string]: boolean} */ { codegenLog('Searching for podspec in the project dependencies.', true); const podspecs = glob.sync('*.podspec', {cwd: dependencyPath}); @@ -80,7 +90,7 @@ function extractSupportedApplePlatforms(dependency, dependencyPath) { getCocoaPodsPlatformKey(platform), ), }), - {}, + {} /*:: as {[string]: boolean} */, ); const supportedPlatformsList = Object.keys(supportedPlatformsMap).filter( @@ -99,7 +109,7 @@ function extractSupportedApplePlatforms(dependency, dependencyPath) { } // Cocoapods specific platform keys -function getCocoaPodsPlatformKey(platformName) { +function getCocoaPodsPlatformKey(platformName /*: string */) { if (platformName === 'macos') { return 'osx'; } diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateUnstableModulesRequiringMainQueueSetupProvider.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateUnstableModulesRequiringMainQueueSetupProvider.js index 4187a53bf2d..4d2ea86017e 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateUnstableModulesRequiringMainQueueSetupProvider.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateUnstableModulesRequiringMainQueueSetupProvider.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -27,12 +28,12 @@ const UNSTABLE_MODULES_REQUIRING_MAIN_QUEUE_SETUP_PROVIDER_MM_TEMPLATE_PATH = ); function generateUnstableModulesRequiringMainQueueSetupProvider( - libraries, - outputDir, + libraries /*: $ReadOnlyArray<$FlowFixMe> */, + outputDir /*: string */, ) { const iosAnnotations = parseiOSAnnotations(libraries); - const modulesRequiringMainQueueSetup = new Set(); + const modulesRequiringMainQueueSetup = new Set /*::*/(); // Old API libraries.forEach(library => { diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js index b062ad6d798..002273410bd 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -58,11 +59,11 @@ const path = require('path'); * @throws If it can't find a cli for the CodeGen. */ function execute( - projectRoot, - targetPlatform, - baseOutputPath, - source, - runReactNativeCodegen = true, + projectRoot /*: string */, + targetPlatform /*: string */, + baseOutputPath /*: string */, + source /*: string */, + runReactNativeCodegen /*: boolean */ = true, ) { try { codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`); @@ -161,7 +162,10 @@ function execute( return; } -function readOutputDirFromPkgJson(pkgJson, platform) { +function readOutputDirFromPkgJson( + pkgJson /*: $FlowFixMe */, + platform /*: string */, +) { const codegenConfig = pkgJson.codegenConfig; if (codegenConfig == null || typeof codegenConfig !== 'object') { return null; @@ -179,12 +183,19 @@ function readOutputDirFromPkgJson(pkgJson, platform) { return null; } -function computeOutputPath(projectRoot, baseOutputPath, pkgJson, platform) { +function computeOutputPath( + projectRoot /*: string */, + baseOutputPath /*: string */, + pkgJson /*: $FlowFixMe */, + platform /*: string */, +) { if (baseOutputPath == null) { const outputDirFromPkgJson = readOutputDirFromPkgJson(pkgJson, platform); if (outputDirFromPkgJson != null) { + // $FlowFixMe[reassign-const] baseOutputPath = path.join(projectRoot, outputDirFromPkgJson); } else { + // $FlowFixMe[reassign-const] baseOutputPath = projectRoot; } } @@ -201,7 +212,7 @@ function computeOutputPath(projectRoot, baseOutputPath, pkgJson, platform) { return baseOutputPath; } -function defaultOutputPathForAndroid(baseOutputPath) { +function defaultOutputPathForAndroid(baseOutputPath /*: string */) { return path.join( baseOutputPath, 'android', @@ -213,11 +224,14 @@ function defaultOutputPathForAndroid(baseOutputPath) { ); } -function defaultOutputPathForIOS(baseOutputPath) { +function defaultOutputPathForIOS(baseOutputPath /*: string */) { return path.join(baseOutputPath, 'build', 'generated', 'ios'); } -function mustGenerateNativeCode(includeLibraryPath, schemaInfo) { +function mustGenerateNativeCode( + includeLibraryPath /*: string */, + schemaInfo /*: $FlowFixMe */, +) { // If library's 'codegenConfig' sets 'includesGeneratedCode' to 'true', // then we assume that native code is shipped with the library, // and we don't need to generate it. diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index d78cd074878..d5c573d5c5a 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -17,11 +18,13 @@ const {execSync} = require('child_process'); const fs = require('fs'); const path = require('path'); -function pkgJsonIncludesGeneratedCode(pkgJson) { +function pkgJsonIncludesGeneratedCode( + pkgJson /*: $FlowFixMe */, +) /*: boolean */ { return pkgJson.codegenConfig && pkgJson.codegenConfig.includesGeneratedCode; } -const codegenLog = (text, info = false) => { +const codegenLog = (text /*: string */, info /*: boolean */ = false) => { // ANSI escape codes for colors and formatting const reset = '\x1b[0m'; const cyan = '\x1b[36m'; @@ -32,12 +35,12 @@ const codegenLog = (text, info = false) => { console.log(`${cyan}${bold}[Codegen]${reset} ${color}${text}${reset}`); }; -function readPkgJsonInDirectory(dir) { +function readPkgJsonInDirectory(dir /*: string */) /*: $FlowFixMe */ { const pkgJsonPath = path.join(dir, 'package.json'); if (!fs.existsSync(pkgJsonPath)) { throw `[Codegen] Error: ${pkgJsonPath} does not exist.`; } - return JSON.parse(fs.readFileSync(pkgJsonPath)); + return JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')); } function buildCodegenIfNeeded() { @@ -69,7 +72,7 @@ function buildCodegenIfNeeded() { // we don't know whether they will be populated up until the end of the process. // // @parameter filepath: the root path from which we want to remove the empty files and folders. -function cleanupEmptyFilesAndFolders(filepath) { +function cleanupEmptyFilesAndFolders(filepath /*: string */) { const stats = fs.statSync(filepath); if (stats.isFile() && stats.size === 0) { @@ -94,20 +97,25 @@ function cleanupEmptyFilesAndFolders(filepath) { } } -function readReactNativeConfig(projectRoot) { +function readReactNativeConfig(projectRoot /*: string */) /*: $FlowFixMe */ { const rnConfigFilePath = path.resolve(projectRoot, 'react-native.config.js'); if (!fs.existsSync(rnConfigFilePath)) { return {}; } + // $FlowIgnore[unsupported-syntax] return require(rnConfigFilePath); } /** * Finding libraries! */ -function findCodegenEnabledLibraries(pkgJson, projectRoot, reactNativeConfig) { +function findCodegenEnabledLibraries( + pkgJson /*: $FlowFixMe */, + projectRoot /*: string */, + reactNativeConfig /*: $FlowFixMe */, +) /*: Array<$FlowFixMe> */ { const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot); if (pkgJsonIncludesGeneratedCode(pkgJson)) { return projectLibraries; @@ -120,7 +128,10 @@ function findCodegenEnabledLibraries(pkgJson, projectRoot, reactNativeConfig) { } } -function findProjectRootLibraries(pkgJson, projectRoot) { +function findProjectRootLibraries( + pkgJson /*: $FlowFixMe */, + projectRoot /*: string */, +) /*: Array<$FlowFixMe> */ { codegenLog('Searching for codegen-enabled libraries in the app.', true); if (pkgJson.codegenConfig == null) { @@ -138,7 +149,10 @@ function findProjectRootLibraries(pkgJson, projectRoot) { return extractLibrariesFromJSON(pkgJson, projectRoot); } -function findLibrariesFromReactNativeConfig(projectRoot, rnConfig) { +function findLibrariesFromReactNativeConfig( + projectRoot /*: string */, + rnConfig /*: $FlowFixMe */, +) /*: Array<$FlowFixMe> */ { codegenLog( `Searching for codegen-enabled libraries in react-native.config.js`, true, @@ -168,7 +182,10 @@ function findLibrariesFromReactNativeConfig(projectRoot, rnConfig) { }); } -function findExternalLibraries(pkgJson, projectRoot) { +function findExternalLibraries( + pkgJson /*: $FlowFixMe */, + projectRoot /*: string */, +) /*: Array<$FlowFixMe> */ { const dependencies = { ...pkgJson.dependencies, ...pkgJson.devDependencies, @@ -201,13 +218,16 @@ function findExternalLibraries(pkgJson, projectRoot) { return []; } } - const configFile = JSON.parse(fs.readFileSync(configFilePath)); + const configFile = JSON.parse(fs.readFileSync(configFilePath, 'utf8')); const codegenConfigFileDir = path.dirname(configFilePath); return extractLibrariesFromJSON(configFile, codegenConfigFileDir); }); } -function extractLibrariesFromJSON(configFile, dependencyPath) { +function extractLibrariesFromJSON( + configFile /*: $FlowFixMe */, + dependencyPath /*: string */, +) /*: Array<$FlowFixMe> */ { if (configFile.codegenConfig == null) { return []; } @@ -226,7 +246,7 @@ function extractLibrariesFromJSON(configFile, dependencyPath) { } } -function printDeprecationWarningIfNeeded(dependency) { +function printDeprecationWarningIfNeeded(dependency /*: string */) { if (dependency === REACT_NATIVE) { return; } @@ -264,7 +284,10 @@ function printDeprecationWarningIfNeeded(dependency) { `); } -function extractLibrariesFromConfigurationArray(configFile, dependencyPath) { +function extractLibrariesFromConfigurationArray( + configFile /*: $FlowFixMe */, + dependencyPath /*: string */, +) { return configFile.codegenConfig.libraries.map(config => { return { config, @@ -273,7 +296,7 @@ function extractLibrariesFromConfigurationArray(configFile, dependencyPath) { }); } -function isReactNativeCoreLibrary(libraryName) { +function isReactNativeCoreLibrary(libraryName /*: string */) /*: boolean */ { return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER; } @@ -299,9 +322,11 @@ function isReactNativeCoreLibrary(libraryName) { * Validates that modules are defined in at most one library. * Validates that components are defined in at most one library. */ -function parseiOSAnnotations(libraries) { - const mLibraryMap = {}; - const cLibraryMap = {}; +function parseiOSAnnotations( + libraries /*: $ReadOnlyArray<$FlowFixMe> */, +) /*: {[string]: $FlowFixMe} */ { + const mLibraryMap = {} /*:: as {[string]: $FlowFixMe} */; + const cLibraryMap = {} /*:: as {[string]: $FlowFixMe} */; const map = {}; for (const library of libraries) { @@ -351,7 +376,7 @@ function parseiOSAnnotations(libraries) { return ` Component { "${moduleName}" } => Libraries{ ${libraryNamesString} }\n`; }); - if (moduleConflicts.length > 0 || componentConflicts.legnth > 0) { + if (moduleConflicts.length > 0 || componentConflicts.length > 0) { throw new Error( 'Some components or modules are declared in more than one libraries: \n' + [...moduleConflicts, ...componentConflicts].join('\n'), @@ -361,9 +386,9 @@ function parseiOSAnnotations(libraries) { return map; } -function getLibraryName(library) { +function getLibraryName(library /*: $FlowFixMe */) { return JSON.parse( - fs.readFileSync(path.join(library.libraryPath, 'package.json')), + fs.readFileSync(path.join(library.libraryPath, 'package.json'), 'utf8'), ).name; } @@ -372,7 +397,10 @@ function getLibraryName(library) { * * This is needed when selectively disabling libraries in react-native.config.js since codegen should exclude those libraries as well. */ -function findDisabledLibrariesByPlatform(reactNativeConfig, platform) { +function findDisabledLibrariesByPlatform( + reactNativeConfig /*: $FlowFixMe */, + platform /*: string */, +) /*: Array<$FlowFixMe> */ { const dependencies = reactNativeConfig.dependencies ?? {}; return Object.keys(dependencies).filter( diff --git a/packages/react-native/scripts/codegen/generate-specs-cli-executor.js b/packages/react-native/scripts/codegen/generate-specs-cli-executor.js index ece43d63b21..a50afb5e673 100644 --- a/packages/react-native/scripts/codegen/generate-specs-cli-executor.js +++ b/packages/react-native/scripts/codegen/generate-specs-cli-executor.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -14,22 +15,26 @@ const fs = require('fs'); const path = require('path'); const GENERATORS = { - all: { - android: ['componentsAndroid', 'modulesAndroid', 'modulesCxx'], - ios: ['componentsIOS', 'modulesIOS', 'modulesCxx'], - }, - components: { - android: ['componentsAndroid'], - ios: ['componentsIOS'], - }, - modules: { - android: ['modulesAndroid', 'modulesCxx'], - ios: ['modulesIOS', 'modulesCxx'], - }, -}; + all: { + android: ['componentsAndroid', 'modulesAndroid', 'modulesCxx'], + ios: ['componentsIOS', 'modulesIOS', 'modulesCxx'], + }, + components: { + android: ['componentsAndroid'], + ios: ['componentsIOS'], + }, + modules: { + android: ['modulesAndroid', 'modulesCxx'], + ios: ['modulesIOS', 'modulesCxx'], + }, + } /*:: as {[string]: {[string]: $ReadOnlyArray}} */; -function createOutputDirectoryIfNeeded(outputDirectory, libraryName) { +function createOutputDirectoryIfNeeded( + outputDirectory /*: string */, + libraryName /*: string */, +) { if (!outputDirectory) { + // $FlowFixMe[reassign-const] outputDirectory = path.resolve(__dirname, '..', 'Libraries', libraryName); } fs.mkdirSync(outputDirectory, {recursive: true}); @@ -43,7 +48,7 @@ function createOutputDirectoryIfNeeded(outputDirectory, libraryName) { * @return a valid schema * @throw an Error if the schema doesn't exists in a given path or if it can't be parsed. */ -function readAndParseSchema(schemaPath) { +function readAndParseSchema(schemaPath /*: string */) { const schemaText = fs.readFileSync(schemaPath, 'utf-8'); if (schemaText == null) { @@ -57,20 +62,20 @@ function readAndParseSchema(schemaPath) { } } -function validateLibraryType(libraryType) { +function validateLibraryType(libraryType /*: string */) { if (GENERATORS[libraryType] == null) { throw new Error(`Invalid library type. ${libraryType}`); } } function generateSpecFromInMemorySchema( - platform, - schema, - outputDirectory, - libraryName, - packageName, - libraryType, - useLocalIncludePaths, + platform /*: string */, + schema /*: string */, + outputDirectory /*: string */, + libraryName /*: string */, + packageName /*: string */, + libraryType /*: string */, + useLocalIncludePaths /*: boolean */, ) { validateLibraryType(libraryType); createOutputDirectoryIfNeeded(outputDirectory, libraryName); @@ -105,13 +110,14 @@ function generateSpecFromInMemorySchema( } function generateSpec( - platform, - schemaPath, - outputDirectory, - libraryName, - packageName, - libraryType, + platform /*: string */, + schemaPath /*: string */, + outputDirectory /*: string */, + libraryName /*: string */, + packageName /*: string */, + libraryType /*: string */, ) { + // $FlowFixMe[incompatible-call] generateSpecFromInMemorySchema( platform, readAndParseSchema(schemaPath), @@ -124,5 +130,5 @@ function generateSpec( module.exports = { execute: generateSpec, - generateSpecFromInMemorySchema: generateSpecFromInMemorySchema, + generateSpecFromInMemorySchema, }; diff --git a/packages/react-native/scripts/compose-source-maps.js b/packages/react-native/scripts/compose-source-maps.js index db9ae1aa5ed..034b7165af1 100755 --- a/packages/react-native/scripts/compose-source-maps.js +++ b/packages/react-native/scripts/compose-source-maps.js @@ -5,6 +5,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -14,7 +15,7 @@ const fs = require('fs'); const {composeSourceMaps} = require('metro-source-map'); const argv = process.argv.slice(2); -let outputPath; +let outputPath /*: ?string */; for (let i = 0; i < argv.length; ) { if (argv[i] === '-o') { outputPath = argv[i + 1]; @@ -58,7 +59,7 @@ if (!argv.length) { const composedMapJSON = JSON.stringify( composeSourceMaps([packagerSourcemap, compilerSourcemap]), ); - if (outputPath) { + if (outputPath != null) { fs.writeFileSync(outputPath, composedMapJSON, 'utf8'); } else { process.stdout.write(composedMapJSON); diff --git a/packages/react-native/scripts/featureflags/index.js b/packages/react-native/scripts/featureflags/index.js index 413707af059..14b12078685 100644 --- a/packages/react-native/scripts/featureflags/index.js +++ b/packages/react-native/scripts/featureflags/index.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlags.kt-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlags.kt-template.js index 15c8ef7721b..878fddd757f 100644 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlags.kt-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlags.kt-template.js @@ -1,10 +1,3 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - /** * Copyright (c) Meta Platforms, Inc. and affiliates. * diff --git a/packages/react-native/scripts/generate-codegen-artifacts.js b/packages/react-native/scripts/generate-codegen-artifacts.js index b77bbad9e3d..30ef4de6538 100644 --- a/packages/react-native/scripts/generate-codegen-artifacts.js +++ b/packages/react-native/scripts/generate-codegen-artifacts.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -33,4 +34,5 @@ const argv = yargs .usage('Usage: $0 -p [path to app] -t [target platform] -o [output path]') .demandOption(['p', 't']).argv; +// $FlowFixMe[prop-missing] executor.execute(argv.path, argv.targetPlatform, argv.outputPath, argv.source); diff --git a/packages/react-native/scripts/generate-provider-cli.js b/packages/react-native/scripts/generate-provider-cli.js index 22141ce8b7e..aa9d4acd293 100644 --- a/packages/react-native/scripts/generate-provider-cli.js +++ b/packages/react-native/scripts/generate-provider-cli.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -34,11 +35,15 @@ const argv = yargs ).argv; const GENERATORS = { - android: [], - ios: ['providerIOS'], -}; + android: [], + ios: ['providerIOS'], + } /*:: as {[string]: $ReadOnlyArray} */; -function generateProvider(platform, schemaListPath, outputDirectory) { +function generateProvider( + platform /*: string */, + schemaListPath /*: string */, + outputDirectory /*: string */, +) { const schemaListText = fs.readFileSync(schemaListPath, 'utf-8'); if (schemaListText == null) { @@ -57,7 +62,7 @@ function generateProvider(platform, schemaListPath, outputDirectory) { throw new Error(`Can't parse schema to JSON. ${schemaListPath}`); } - const schemas = {}; + const schemas = {} /*:: as {[string]: $FlowFixMe} */; try { for (const libraryName of Object.keys(schemaPaths)) { const tmpSchemaText = fs.readFileSync(schemaPaths[libraryName], 'utf-8'); @@ -83,6 +88,7 @@ function generateProvider(platform, schemaListPath, outputDirectory) { } function main() { + // $FlowFixMe[prop-missing] generateProvider(argv.platform, argv.schemaListPath, argv.outputDir); } diff --git a/packages/react-native/scripts/generate-specs-cli.js b/packages/react-native/scripts/generate-specs-cli.js index 2c3a0eb78b1..f8cd1fa3de7 100644 --- a/packages/react-native/scripts/generate-specs-cli.js +++ b/packages/react-native/scripts/generate-specs-cli.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -49,11 +50,17 @@ const argv = yargs function main() { executor.execute( + // $FlowFixMe[prop-missing] argv.platform, + // $FlowFixMe[prop-missing] argv.schemaPath, + // $FlowFixMe[prop-missing] argv.outputDir, + // $FlowFixMe[prop-missing] argv.libraryName, + // $FlowFixMe[prop-missing] argv.javaPackageName, + // $FlowFixMe[prop-missing] argv.libraryType, ); } diff --git a/packages/react-native/scripts/hermes/__tests__/hermes-utils-test.js b/packages/react-native/scripts/hermes/__tests__/hermes-utils-test.js index 300d4e3b08f..d735445b071 100644 --- a/packages/react-native/scripts/hermes/__tests__/hermes-utils-test.js +++ b/packages/react-native/scripts/hermes/__tests__/hermes-utils-test.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -35,8 +36,9 @@ const hermesTagSha = '5244f819b2f3949ca94a3a1bf75d54a8ed59d94a'; const ROOT_DIR = path.normalize(path.join(__dirname, '../../..')); const SDKS_DIR = path.join(ROOT_DIR, 'sdks'); -let execCalls, spawnCalls; -let fs; +let execCalls: $FlowFixMe; +let spawnCalls: $FlowFixMe; +let fs: $FlowFixMe; jest.mock('child_process', () => ({ execSync: jest.fn((command, options) => { @@ -153,6 +155,7 @@ describe('hermes-utils', () => { }), ); fs = require('fs'); + // $FlowFixMe[prop-missing] fs.reset(); populateMockFilesystemWithHermesBuildScripts(); diff --git a/packages/react-native/scripts/hermes/bump-hermes-version.js b/packages/react-native/scripts/hermes/bump-hermes-version.js index 09f2c135f36..3ac8c9711b6 100755 --- a/packages/react-native/scripts/hermes/bump-hermes-version.js +++ b/packages/react-native/scripts/hermes/bump-hermes-version.js @@ -5,12 +5,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ 'use strict'; const {setHermesTag} = require('./hermes-utils'); +// $FlowFixMe[untyped-import] const inquirer = require('inquirer'); /** * This script walks a releaser through bumping the Hermes version for a release. @@ -27,6 +29,7 @@ let argv = yargs.option('t', { }).argv; async function main() { + // $FlowFixMe[prop-missing] const hermesTag = argv.tag; const {confirmHermesTag} = await inquirer.prompt({ type: 'confirm', @@ -42,6 +45,6 @@ async function main() { setHermesTag(hermesTag); } -main().then(() => { +void main().then(() => { exit(0); }); diff --git a/packages/react-native/scripts/hermes/create-tarball.js b/packages/react-native/scripts/hermes/create-tarball.js index 121d0a81397..7214d5639c4 100644 --- a/packages/react-native/scripts/hermes/create-tarball.js +++ b/packages/react-native/scripts/hermes/create-tarball.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -41,9 +42,13 @@ let argv = yargs }).argv; async function main() { + // $FlowFixMe[prop-missing] const hermesDir = argv.inputDir; + // $FlowFixMe[prop-missing] const buildType = argv.buildType; + // $FlowFixMe[prop-missing] const excludeDebugSymbols = argv.excludeDebugSymbols; + // $FlowFixMe[prop-missing] let tarballOutputDir = argv.outputDir; if (!tarballOutputDir) { @@ -68,6 +73,6 @@ async function main() { return tarballOutputPath; } -main().then(() => { +void main().then(() => { process.exit(0); }); diff --git a/packages/react-native/scripts/hermes/get-tarball-name.js b/packages/react-native/scripts/hermes/get-tarball-name.js index 6b9cafa789f..ace7543b5dd 100644 --- a/packages/react-native/scripts/hermes/get-tarball-name.js +++ b/packages/react-native/scripts/hermes/get-tarball-name.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -24,11 +25,12 @@ let argv = yargs.option('b', { }).argv; async function main() { + // $FlowFixMe[prop-missing] const tarballName = getHermesPrebuiltArtifactsTarballName(argv.buildType); console.log(tarballName); return tarballName; } -main().then(() => { +void main().then(() => { process.exit(0); }); diff --git a/packages/react-native/scripts/hermes/hermes-utils.js b/packages/react-native/scripts/hermes/hermes-utils.js index eb831e74044..d8e4d45e2f6 100644 --- a/packages/react-native/scripts/hermes/hermes-utils.js +++ b/packages/react-native/scripts/hermes/hermes-utils.js @@ -224,9 +224,9 @@ set_target_properties(native-hermesc PROPERTIES } function getHermesPrebuiltArtifactsTarballName( - buildType /*: string */, + buildType /*:: ?: string */, ) /*: string */ { - if (!buildType) { + if (buildType == null) { throw Error('Did not specify build type.'); } return `hermes-ios-${buildType.toLowerCase()}.tar.gz`; diff --git a/packages/react-native/scripts/hermes/prepare-hermes-for-build.js b/packages/react-native/scripts/hermes/prepare-hermes-for-build.js index acb35fe0ec7..fb9c95361f4 100644 --- a/packages/react-native/scripts/hermes/prepare-hermes-for-build.js +++ b/packages/react-native/scripts/hermes/prepare-hermes-for-build.js @@ -4,6 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ @@ -23,7 +24,7 @@ const { shouldUsePrebuiltHermesC, } = require('./hermes-utils'); -async function main(isInCI) { +async function main(isInCI /*: boolean */) { if (!shouldBuildHermesFromSource(isInCI)) { copyPodSpec(); return; @@ -41,6 +42,6 @@ async function main(isInCI) { const isInCI = process.env.CI === 'true'; -main(isInCI).then(() => { +void main(isInCI).then(() => { process.exit(0); }); diff --git a/packages/react-native/scripts/packager-reporter.js b/packages/react-native/scripts/packager-reporter.js index a3f5bd54619..f6ab6a9194f 100644 --- a/packages/react-native/scripts/packager-reporter.js +++ b/packages/react-native/scripts/packager-reporter.js @@ -4,17 +4,21 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format */ 'use strict'; +let reporter /*: $FlowFixMe */; + const logPath = process.env.RCT_PACKAGER_LOG_PATH; if (logPath != null && logPath !== '') { const JsonReporter = require('metro/src/lib/JsonReporter'); const fs = require('fs'); const path = require('path'); - module.exports = class extends JsonReporter { + // $FlowFixMe[missing-type-arg] + reporter = class extends JsonReporter { constructor() { fs.mkdirSync(path.dirname(logPath), { recursive: true, @@ -23,5 +27,7 @@ if (logPath != null && logPath !== '') { } }; } else { - module.exports = require('metro/src/lib/TerminalReporter'); + reporter = require('metro/src/lib/TerminalReporter'); } + +module.exports = reporter;