From 3d55f229cb540d0c5c57c0047c62a5cb515b4b08 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Wed, 4 Jun 2025 12:03:52 -0700 Subject: [PATCH] RN: Flowify `packages/react-native-fantom` (#51784) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51784 Adds `flow` to the remaining files that are lacking it in the `packages/react-native-fantom` directory. This also adds any necessary type annotations (using comment syntax). Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D75886119 fbshipit-source-id: 6045b4037da21791db2a8960fbdb83aa2fb5bbf2 --- jest.config.js | 12 +++- .../react-native-fantom/config/hasteImpl.js | 5 +- .../react-native-fantom/config/jest.config.js | 25 +++++--- .../config/metro-babel-transformer.js | 1 + .../config/metro.config.js | 58 ++++++++++--------- packages/react-native-fantom/runner/index.js | 1 + .../runner/warmup/index.js | 1 + 7 files changed, 63 insertions(+), 40 deletions(-) diff --git a/jest.config.js b/jest.config.js index 3fb2cd09000..9a6e58d9fb6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,11 +4,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 * @format */ 'use strict'; +// $FlowFixMe[cannot-resolve-module] +// $FlowFixMe[untyped-import] const {defaults} = require('jest-config'); const PODS_LOCATIONS = [ @@ -39,18 +42,21 @@ module.exports = { '/packages/react-native/Libraries/Renderer', '/packages/react-native/sdks/hermes/', ...PODS_LOCATIONS, - ], + ] /*:: as $ReadOnlyArray */, transformIgnorePatterns: ['node_modules/(?!@react-native/)'], haste: { defaultPlatform: 'ios', platforms: ['ios', 'android'], }, - moduleFileExtensions: ['fb.js'].concat(defaults.moduleFileExtensions), + moduleFileExtensions: [ + 'fb.js', + ...defaults.moduleFileExtensions, + ] /*:: as $ReadOnlyArray */, modulePathIgnorePatterns: [ 'scripts/.*/__fixtures__/', '/packages/react-native/sdks/hermes/', ...PODS_LOCATIONS, - ], + ] /*:: as $ReadOnlyArray */, unmockedModulePathPatterns: [ 'node_modules/react/', 'packages/react-native/Libraries/Renderer', diff --git a/packages/react-native-fantom/config/hasteImpl.js b/packages/react-native-fantom/config/hasteImpl.js index f3377970ef6..f027551d694 100644 --- a/packages/react-native-fantom/config/hasteImpl.js +++ b/packages/react-native-fantom/config/hasteImpl.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 * @format */ @@ -13,7 +14,7 @@ const crypto = require('crypto'); const fs = require('fs'); module.exports = { - getHasteName(filePath) { + getHasteName(filePath /*: string */) /*: ?string */ { if (filePath.endsWith('ReactNativeInternalFeatureFlags.js')) { return 'ReactNativeInternalFeatureFlags'; } @@ -21,7 +22,7 @@ module.exports = { return null; }, - getCacheKey() { + getCacheKey() /*: string */ { return crypto .createHash('sha1') .update(fs.readFileSync(__filename)) diff --git a/packages/react-native-fantom/config/jest.config.js b/packages/react-native-fantom/config/jest.config.js index 1d647a91793..c46a211b959 100644 --- a/packages/react-native-fantom/config/jest.config.js +++ b/packages/react-native-fantom/config/jest.config.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 * @format */ @@ -12,26 +13,32 @@ const baseConfig = require('../../../jest.config'); const path = require('path'); -const isCI = Boolean(process.env.SANDCASTLE || process.env.GITHUB_ACTIONS); +const isCI = + Boolean(process.env.SANDCASTLE) || Boolean(process.env.GITHUB_ACTIONS); + +// In CI, we want to prewarm the caches/builds before running the tests so +// that time isn't attributed to the first test that runs. +const globalSetup /*: ?string */ = isCI + ? '/packages/react-native-fantom/runner/warmup/index.js' + : null; module.exports = { - rootDir: path.resolve(__dirname, '../../..'), + rootDir: path.resolve(__dirname, '../../..') /*:: as string */, roots: [ '/packages/react-native', '/packages/react-native-fantom', '/packages/polyfills', ], - moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'cpp', 'h'], + moduleFileExtensions: [ + ...baseConfig.moduleFileExtensions, + 'cpp', + 'h', + ] /*:: as $ReadOnlyArray */, // This allows running Meta-internal tests with the `-test.fb.js` suffix. testRegex: '/__tests__/.*-itest(\\.fb)?\\.js$', testPathIgnorePatterns: baseConfig.testPathIgnorePatterns, transformIgnorePatterns: ['.*'], testRunner: '/packages/react-native-fantom/runner/index.js', watchPathIgnorePatterns: ['/packages/react-native-fantom/build/'], - - // In CI, we want to prewarm the caches/builds before running the tests so - // that time isn't attributed to the first test that runs. - globalSetup: isCI - ? '/packages/react-native-fantom/runner/warmup/index.js' - : null, + globalSetup, }; diff --git a/packages/react-native-fantom/config/metro-babel-transformer.js b/packages/react-native-fantom/config/metro-babel-transformer.js index 43db237cafe..9d6b82df66c 100644 --- a/packages/react-native-fantom/config/metro-babel-transformer.js +++ b/packages/react-native-fantom/config/metro-babel-transformer.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-fantom/config/metro.config.js b/packages/react-native-fantom/config/metro.config.js index daa11a3ac19..550757f280e 100644 --- a/packages/react-native-fantom/config/metro.config.js +++ b/packages/react-native-fantom/config/metro.config.js @@ -4,11 +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 strict-local * @format */ 'use strict'; +/*:: +import type {ConfigT, InputConfigT} from 'metro-config'; +*/ + const {getDefaultConfig} = require('@react-native/metro-config'); const {mergeConfig} = require('metro-config'); const path = require('path'); @@ -17,12 +22,12 @@ const rnTesterConfig = getDefaultConfig( path.resolve('../../../packages/rn-tester'), ); -const JS_DIR = process.env.JS_DIR - ? path.resolve(process.cwd(), process.env.JS_DIR) - : null; +const cwd = process.cwd(); +const JS_DIR = + process.env.JS_DIR != null ? path.resolve(cwd, process.env.JS_DIR) : null; const NODE_MODULES = path.sep + 'node_modules' + path.sep; -const config = { +const config /*: InputConfigT */ = { projectRoot: path.resolve(__dirname, '../../..'), reporter: { update: () => {}, @@ -30,21 +35,21 @@ const config = { resolver: { blockList: /\/RendererProxy\.fb\.js$/, // Disable dependency injection for the renderer sourceExts: ['fb.js', ...rnTesterConfig.resolver.sourceExts], - nodeModulesPaths: JS_DIR - ? [path.join(JS_DIR, 'public', 'node_modules')] - : [], + nodeModulesPaths: + JS_DIR != null ? [path.join(JS_DIR, 'public', 'node_modules')] : [], hasteImplModulePath: path.resolve(__dirname, 'hasteImpl.js'), - resolveRequest: JS_DIR - ? (ctx, dep, platform) => - ctx.originModulePath.includes(NODE_MODULES) - ? ctx.resolveRequest(ctx, dep, platform) - : // Disable hierarchical node_modules lookup from 1P code. - ctx.resolveRequest( - {...ctx, disableHierarchicalLookup: true}, - dep, - platform, - ) - : null, + resolveRequest: + JS_DIR != null + ? (ctx, dep, platform) => + ctx.originModulePath.includes(NODE_MODULES) + ? ctx.resolveRequest(ctx, dep, platform) + : // Disable hierarchical node_modules lookup from 1P code. + ctx.resolveRequest( + {...ctx, disableHierarchicalLookup: true}, + dep, + platform, + ) + : null, }, transformer: { // We need to wrap the default transformer so we can run it from source @@ -55,13 +60,14 @@ const config = { // Force an empty list so Metro doesn't inject InitializeCore in tests. getModulesRunBeforeMainModule: () => [], }, - watchFolders: JS_DIR - ? [ - path.join(JS_DIR, 'RKJSModules', 'vendor', 'react'), - path.join(JS_DIR, 'tools', 'metro', 'packages', 'metro-runtime'), - path.join(JS_DIR, 'public', 'node_modules'), - ] - : [], + watchFolders: + JS_DIR != null + ? [ + path.join(JS_DIR, 'RKJSModules', 'vendor', 'react'), + path.join(JS_DIR, 'tools', 'metro', 'packages', 'metro-runtime'), + path.join(JS_DIR, 'public', 'node_modules'), + ] + : [], }; -module.exports = mergeConfig(rnTesterConfig, config); +module.exports = mergeConfig(rnTesterConfig, config) /*:: as ConfigT */; diff --git a/packages/react-native-fantom/runner/index.js b/packages/react-native-fantom/runner/index.js index b794dd80af4..a4bf32ccd4c 100644 --- a/packages/react-native-fantom/runner/index.js +++ b/packages/react-native-fantom/runner/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-fantom/runner/warmup/index.js b/packages/react-native-fantom/runner/warmup/index.js index 964e62cb4de..ef652c3df5d 100644 --- a/packages/react-native-fantom/runner/warmup/index.js +++ b/packages/react-native-fantom/runner/warmup/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 */