diff --git a/flow-typed/npm/signedsource_v1.x.x.js b/flow-typed/npm/signedsource_v1.x.x.js new file mode 100644 index 000000000000..2bebd077442d --- /dev/null +++ b/flow-typed/npm/signedsource_v1.x.x.js @@ -0,0 +1,19 @@ +/** + * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + * + * @format + * @flow strict + */ + +declare module 'signedsource' { + declare type SignedSource = { + TokenNotFoundError: Error, + getSigningToken(): string, + isSigned(data: string): boolean, + signFile(data: string): string, + verifySignature(data: string): boolean, + [key: string]: mixed, + }; + + declare module.exports: SignedSource; +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt index 8c356cb7eec4..fed18a18fc76 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt index ca5c8ff1d077..65c786512eb1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<5b653e8a53f557ffc0f46b3e81e99bed>> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt index f90ae279e352..83deb2d4a179 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<47be3dbe5558f720a6c61742f2c63bf8>> + * @generated SignedSource<<41a2646126f7f448be8c8397b1698a4a>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index cbb9dcdabe8b..ab793abe3fa5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<70c19d5bb1e0c09f52b89b4bb3645b9d>> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt index 15639b90d14e..0db667939239 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<7ba0cb94c10989838250252fa06768a0>> + * @generated SignedSource<<77fc4d6577fc0e2e9a0500cc762bba77>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt index 8b477054ea8e..7d64ca81414f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<49a63388fa661d81b9cec735ac705bd0>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp index 7419a24d36d6..2af8ae426593 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<18e31d0833fda8cfb3f31b449479297a>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update @@ -19,10 +19,72 @@ #include "JReactNativeFeatureFlagsCxxInterop.h" #include -#include namespace facebook::react { +static jni::alias_ref getReactNativeFeatureFlagsProviderJavaClass() { + static const auto jClass = facebook::jni::findClassStatic( + "com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider"); + return jClass; +} + +/** + * Implementation of ReactNativeFeatureFlagsProvider that wraps a + * ReactNativeFeatureFlagsProvider Java object. + */ +class ReactNativeFeatureFlagsProviderHolder + : public ReactNativeFeatureFlagsProvider { + public: + explicit ReactNativeFeatureFlagsProviderHolder( + jni::alias_ref javaProvider) + : javaProvider_(make_global(javaProvider)){}; + + bool commonTestFlag() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("commonTestFlag"); + return method(javaProvider_); + } + + bool useModernRuntimeScheduler() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("useModernRuntimeScheduler"); + return method(javaProvider_); + } + + bool enableMicrotasks() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableMicrotasks"); + return method(javaProvider_); + } + + bool batchRenderingUpdatesInEventLoop() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("batchRenderingUpdatesInEventLoop"); + return method(javaProvider_); + } + + bool enableSpannableBuildingUnification() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableSpannableBuildingUnification"); + return method(javaProvider_); + } + + bool enableCustomDrawOrderFabric() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableCustomDrawOrderFabric"); + return method(javaProvider_); + } + + bool enableFixForClippedSubviewsCrash() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableFixForClippedSubviewsCrash"); + return method(javaProvider_); + } + + private: + jni::global_ref javaProvider_; +}; + bool JReactNativeFeatureFlagsCxxInterop::commonTestFlag( facebook::jni::alias_ref /*unused*/) { return ReactNativeFeatureFlags::commonTestFlag(); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h index b03aba4b813c..11976df07f67 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<356873b4021fcfe9a2afa79417813975>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.cpp deleted file mode 100644 index eac87db03ee9..000000000000 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - * - * @generated SignedSource<> - */ - -/** - * IMPORTANT: Do NOT modify this file directly. - * - * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. - * - * To regenerate this code, run the following script from the repo root: - * yarn featureflags-update - */ - -#include "ReactNativeFeatureFlagsProviderHolder.h" - -namespace facebook::react { - -static jni::alias_ref getJClass() { - static const auto jClass = facebook::jni::findClassStatic( - "com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider"); - return jClass; -} - -bool ReactNativeFeatureFlagsProviderHolder::commonTestFlag() { - static const auto method = - getJClass()->getMethod("commonTestFlag"); - return method(javaProvider_); -} - -bool ReactNativeFeatureFlagsProviderHolder::useModernRuntimeScheduler() { - static const auto method = - getJClass()->getMethod("useModernRuntimeScheduler"); - return method(javaProvider_); -} - -bool ReactNativeFeatureFlagsProviderHolder::enableMicrotasks() { - static const auto method = - getJClass()->getMethod("enableMicrotasks"); - return method(javaProvider_); -} - -bool ReactNativeFeatureFlagsProviderHolder::batchRenderingUpdatesInEventLoop() { - static const auto method = - getJClass()->getMethod("batchRenderingUpdatesInEventLoop"); - return method(javaProvider_); -} - -bool ReactNativeFeatureFlagsProviderHolder::enableSpannableBuildingUnification() { - static const auto method = - getJClass()->getMethod("enableSpannableBuildingUnification"); - return method(javaProvider_); -} - -bool ReactNativeFeatureFlagsProviderHolder::enableCustomDrawOrderFabric() { - static const auto method = - getJClass()->getMethod("enableCustomDrawOrderFabric"); - return method(javaProvider_); -} - -bool ReactNativeFeatureFlagsProviderHolder::enableFixForClippedSubviewsCrash() { - static const auto method = - getJClass()->getMethod("enableFixForClippedSubviewsCrash"); - return method(javaProvider_); -} - -} // namespace facebook::react diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.h deleted file mode 100644 index 2f01f8ad159f..000000000000 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - * - * @generated SignedSource<<879b0c096c4a2e9692a5e133bdfd8809>> - */ - -/** - * IMPORTANT: Do NOT modify this file directly. - * - * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. - * - * To regenerate this code, run the following script from the repo root: - * yarn featureflags-update - */ - -#pragma once - -#include -#include - -namespace facebook::react { - -/** - * Implementation of ReactNativeFeatureFlagsProvider that wraps a - * ReactNativeFeatureFlagsProvider Java object. - */ -class ReactNativeFeatureFlagsProviderHolder - : public ReactNativeFeatureFlagsProvider { - public: - explicit ReactNativeFeatureFlagsProviderHolder( - jni::alias_ref javaProvider) - : javaProvider_(make_global(javaProvider)){}; - - bool commonTestFlag() override; - bool useModernRuntimeScheduler() override; - bool enableMicrotasks() override; - bool batchRenderingUpdatesInEventLoop() override; - bool enableSpannableBuildingUnification() override; - bool enableCustomDrawOrderFabric() override; - bool enableFixForClippedSubviewsCrash() override; - - private: - jni::global_ref javaProvider_; -}; - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp index 9d4b4c50bb0c..981a5dfe54e8 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<6ccf42209dea35cd5c6ac9eb882c2ef7>> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h index af9c3fa5270e..f823ef82f3d7 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<252f46e2c95e08d1180f656c870087b7>> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp index 16c358b2ad12..7dbeca63453b 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp @@ -4,23 +4,23 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<0f2ef778c97b1928fde0245008015227>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update */ #include -#include #include #include +#include #include "ReactNativeFeatureFlags.h" namespace facebook::react { @@ -37,9 +37,7 @@ bool ReactNativeFeatureFlagsAccessor::commonTestFlag() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "commonTestFlag"; - markFlagAsAccessed(0, flagName); + markFlagAsAccessed(0, "commonTestFlag"); flagValue = currentProvider_->commonTestFlag(); commonTestFlag_ = flagValue; @@ -57,9 +55,7 @@ bool ReactNativeFeatureFlagsAccessor::useModernRuntimeScheduler() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "useModernRuntimeScheduler"; - markFlagAsAccessed(1, flagName); + markFlagAsAccessed(1, "useModernRuntimeScheduler"); flagValue = currentProvider_->useModernRuntimeScheduler(); useModernRuntimeScheduler_ = flagValue; @@ -77,9 +73,7 @@ bool ReactNativeFeatureFlagsAccessor::enableMicrotasks() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "enableMicrotasks"; - markFlagAsAccessed(2, flagName); + markFlagAsAccessed(2, "enableMicrotasks"); flagValue = currentProvider_->enableMicrotasks(); enableMicrotasks_ = flagValue; @@ -97,9 +91,7 @@ bool ReactNativeFeatureFlagsAccessor::batchRenderingUpdatesInEventLoop() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "batchRenderingUpdatesInEventLoop"; - markFlagAsAccessed(3, flagName); + markFlagAsAccessed(3, "batchRenderingUpdatesInEventLoop"); flagValue = currentProvider_->batchRenderingUpdatesInEventLoop(); batchRenderingUpdatesInEventLoop_ = flagValue; @@ -117,9 +109,7 @@ bool ReactNativeFeatureFlagsAccessor::enableSpannableBuildingUnification() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "enableSpannableBuildingUnification"; - markFlagAsAccessed(4, flagName); + markFlagAsAccessed(4, "enableSpannableBuildingUnification"); flagValue = currentProvider_->enableSpannableBuildingUnification(); enableSpannableBuildingUnification_ = flagValue; @@ -137,9 +127,7 @@ bool ReactNativeFeatureFlagsAccessor::enableCustomDrawOrderFabric() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "enableCustomDrawOrderFabric"; - markFlagAsAccessed(5, flagName); + markFlagAsAccessed(5, "enableCustomDrawOrderFabric"); flagValue = currentProvider_->enableCustomDrawOrderFabric(); enableCustomDrawOrderFabric_ = flagValue; @@ -157,9 +145,7 @@ bool ReactNativeFeatureFlagsAccessor::enableFixForClippedSubviewsCrash() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "enableFixForClippedSubviewsCrash"; - markFlagAsAccessed(6, flagName); + markFlagAsAccessed(6, "enableFixForClippedSubviewsCrash"); flagValue = currentProvider_->enableFixForClippedSubviewsCrash(); enableFixForClippedSubviewsCrash_ = flagValue; @@ -181,8 +167,6 @@ void ReactNativeFeatureFlagsAccessor::markFlagAsAccessed( } void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() { - std::string accessedFeatureFlagNames; - std::ostringstream featureFlagListBuilder; for (const auto& featureFlagName : accessedFeatureFlags_) { if (featureFlagName != nullptr) { @@ -190,7 +174,7 @@ void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() { } } - accessedFeatureFlagNames = featureFlagListBuilder.str(); + std::string accessedFeatureFlagNames = featureFlagListBuilder.str(); if (!accessedFeatureFlagNames.empty()) { accessedFeatureFlagNames = accessedFeatureFlagNames.substr(0, accessedFeatureFlagNames.size() - 2); diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h index 48d7c4f43e4c..6d6474bec1de 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<40315ae6cc418effd421dff2be6831c7>> + * @generated SignedSource<<4de1ed8503548f440c1a0e4f903c80c7>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update @@ -24,7 +24,6 @@ #include #include #include -#include namespace facebook::react { diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index 28f5b0d55bd1..5b3d40907528 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h index 7a252cfa02ff..cc0eede94bde 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<72abac7cc75e65bf1ded596033637050>> + * @generated SignedSource<> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index 2a381896ace5..49350b33e85f 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<64ea070fb82bd703eb617dcf64c6a7d1>> + * @generated SignedSource<<19dba0cacd4599408a2adeeeb1dce6f2>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index 9a419a94a245..bdacf6ffd269 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -4,14 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<994628655312f57c8ab774e9f119eb18>> + * @generated SignedSource<<4ce1b29660d13ea8dfe09777d9907f3f>> */ /** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 86db951b093f..cdaf0dcb1a3b 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -90,8 +90,8 @@ ], "scripts": { "prepack": "cp ../../README.md .", - "featureflags-check": "node ./scripts/featureflags/update.js --verify-unchanged", - "featureflags-update": "node ./scripts/featureflags/update.js" + "featureflags-check": "node ./scripts/featureflags/index.js --verify-unchanged", + "featureflags-update": "node ./scripts/featureflags/index.js" }, "peerDependencies": { "react": "18.2.0" diff --git a/packages/react-native/scripts/featureflags/README.md b/packages/react-native/scripts/featureflags/README.md index 42e18adba8e7..7cb68fec0811 100644 --- a/packages/react-native/scripts/featureflags/README.md +++ b/packages/react-native/scripts/featureflags/README.md @@ -11,46 +11,43 @@ everywhere. ## Definition -The source of truth for the definition of the flags is the file `ReactNativeFeatureFlags.json` -in this directory. That JSON file should have the following structure: +The source of truth for the definition of the flags is the file +`ReactNativeFeatureFlags.config.js` in this directory. -```flow -type Config = { - common: FeatureFlagsList, - jsOnly: FeatureFlagsList, -}; - -type FeatureFlagsList = { - [flagName: string]: { - description: string, - defaultValue: boolean | number | string, - }, -}; -``` - -Example: -```json -{ - "common": { - "enableMicrotasks": { - "description": "Enable the use of microtasks in the JS runtime.", - "defaultValue": false +Example contents: +```javascript +module.exports = { + common: { + enableMicrotasks: { + description: 'Enable the use of microtasks in the JS runtime.', + defaultValue: false } }, - "jsOnly": { - "enableAccessToHostTreeInFabric": { - "description": "Enables access to the host tree in Fabric using DOM-compatible APIs.", - "defaultValue": false + jsOnly: { + enableAccessToHostTreeInFabric: { + description: 'Enables access to the host tree in Fabric using DOM-compatible APIs.', + defaultValue: false } } -} +}; ``` After any changes to this definitions, the code that provides access to them -must be regenerated executing the `update` script in this directory. +must be regenerated running `yarn featureflags-update` from the `react-native` +repository. ## Access +You can access the common feature flags from anywhere in your application using +the `ReactNativeFeatureFlags` interface (available in C++/Objective-C++, +Kotlin/Java and JavaScript). JS-only feature flags can only be accessed from +JavaScript. + +**Accessing feature flags should be considered fast for all use cases**. +Feature flags are cached at every layer, which prevents having to go through JNI +when accessing the values from Kotlin and through JSI when accessing the values +from JavaScript. + ### C++ / Objective-C ```c++ @@ -89,6 +86,15 @@ if (ReactNativeFeatureFlags.enableAccessToHostTreeInFabric()) { ## Customization +Feature flags provide the default values defined in the configuration unless +overrides are applied at the application level. Overrides for common feature +flags can only be defined in native, while overrides for JS-ony flags can only +be defined in JavaScript. + +Overrides must be applied before any of the available feature flags has been +accessed. This prevents having inconsistent behavior during the lifecycle of the +application. + ### C++/Objective-C ```c++ diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js new file mode 100644 index 000000000000..ab2874123dc5 --- /dev/null +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -0,0 +1,97 @@ +/** + * 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. + * + * @flow strict + * @format + */ + +import type {FeatureFlagDefinitions} from './types'; + +const definitions: FeatureFlagDefinitions = { + common: { + // This is only used in unit tests for the feature flags system. + commonTestFlag: { + description: 'Common flag for testing. Do NOT modify.', + defaultValue: false, + }, + + useModernRuntimeScheduler: { + description: + 'When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.', + defaultValue: false, + }, + enableMicrotasks: { + description: + 'Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).', + defaultValue: false, + }, + batchRenderingUpdatesInEventLoop: { + description: + 'When enabled, the RuntimeScheduler processing the event loop will batch all rendering updates and dispatch them together at the end of each iteration of the loop.', + defaultValue: false, + }, + enableSpannableBuildingUnification: { + description: + 'Uses new, deduplicated logic for constructing Android Spannables from text fragments', + defaultValue: false, + }, + enableCustomDrawOrderFabric: { + description: + 'When enabled, Fabric will use customDrawOrder in ReactViewGroup (similar to old architecture).', + defaultValue: false, + }, + enableFixForClippedSubviewsCrash: { + description: + 'Attempt at fixing a crash related to subview clipping on Android. This is a kill switch for the fix', + defaultValue: false, + }, + }, + + jsOnly: { + // This is only used in unit tests for the feature flags system. + jsOnlyTestFlag: { + description: 'JS-only flag for testing. Do NOT modify.', + defaultValue: false, + }, + + isLayoutAnimationEnabled: { + description: + 'Function used to enable / disabled Layout Animations in React Native.', + defaultValue: true, + }, + animatedShouldDebounceQueueFlush: { + description: + 'Enables an experimental flush-queue debouncing in Animated.js.', + defaultValue: false, + }, + animatedShouldUseSingleOp: { + description: + 'Enables an experimental mega-operation for Animated.js that replaces many calls to native with a single call into native, to reduce JSI/JNI traffic.', + defaultValue: false, + }, + enableAccessToHostTreeInFabric: { + description: + 'Enables access to the host tree in Fabric using DOM-compatible APIs.', + defaultValue: false, + }, + shouldUseAnimatedObjectForTransform: { + description: + 'Enables use of AnimatedObject for animating transform values.', + defaultValue: false, + }, + shouldUseSetNativePropsInFabric: { + description: 'Enables use of setNativeProps in JS driven animations.', + defaultValue: true, + }, + shouldUseRemoveClippedSubviewsAsDefaultOnIOS: { + description: + 'removeClippedSubviews prop will be used as the default in FlatList on iOS to match Android', + defaultValue: false, + }, + }, +}; + +export default definitions; diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json deleted file mode 100644 index 95a4df931b47..000000000000 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "common": { - "commonTestFlag": { - "description": "Common flag for testing. Do NOT modify.", - "defaultValue": false - }, - "useModernRuntimeScheduler": { - "description": "When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.", - "defaultValue": false - }, - "enableMicrotasks": { - "description": "Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).", - "defaultValue": false - }, - "batchRenderingUpdatesInEventLoop": { - "description": "When enabled, the RuntimeScheduler processing the event loop will batch all rendering updates and dispatch them together at the end of each iteration of the loop.", - "defaultValue": false - }, - "enableSpannableBuildingUnification": { - "description": "Uses new, deduplicated logic for constructing Android Spannables from text fragments", - "defaultValue": false - }, - "enableCustomDrawOrderFabric": { - "description": "When enabled, Fabric will use customDrawOrder in ReactViewGroup (similar to old architecture).", - "defaultValue": false - }, - "enableFixForClippedSubviewsCrash": { - "description": "Attempt at fixing a crash related to subview clipping on Android. This is a kill switch for the fix", - "defaultValue": false - } - }, - "jsOnly": { - "jsOnlyTestFlag": { - "description": "JS-only flag for testing. Do NOT modify.", - "defaultValue": false - }, - "isLayoutAnimationEnabled": { - "description": "Function used to enable / disabled Layout Animations in React Native.", - "defaultValue": true - }, - "animatedShouldDebounceQueueFlush": { - "description": "Enables an experimental flush-queue debouncing in Animated.js.", - "defaultValue": false - }, - "animatedShouldUseSingleOp": { - "description": "Enables an experimental mega-operation for Animated.js that replaces many calls to native with a single call into native, to reduce JSI/JNI traffic.", - "defaultValue": false - }, - "enableAccessToHostTreeInFabric": { - "description": "Enables access to the host tree in Fabric using DOM-compatible APIs.", - "defaultValue": false - }, - "shouldUseAnimatedObjectForTransform": { - "description": "Enables use of AnimatedObject for animating transform values.", - "defaultValue": false - }, - "shouldUseSetNativePropsInFabric": { - "description": "Enables use of setNativeProps in JS driven animations.", - "defaultValue": true - }, - "shouldUseRemoveClippedSubviewsAsDefaultOnIOS": { - "description": "removeClippedSubviews prop will be used as the default in FlatList on iOS to match Android", - "defaultValue": false - } - } -} diff --git a/packages/react-native/scripts/featureflags/generateAndroidModules.js b/packages/react-native/scripts/featureflags/generateAndroidModules.js index edf0ce966a2e..4631fbfa366d 100644 --- a/packages/react-native/scripts/featureflags/generateAndroidModules.js +++ b/packages/react-native/scripts/featureflags/generateAndroidModules.js @@ -4,65 +4,43 @@ * 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'; +import type {GeneratorConfig, GeneratorResult} from './types'; -const JReactNativeFeatureFlagsCxxInteropCPP = require('./templates/android/JReactNativeFeatureFlagsCxxInterop.cpp-template'); -const JReactNativeFeatureFlagsCxxInteropH = require('./templates/android/JReactNativeFeatureFlagsCxxInterop.h-template'); -const ReactNativeFeatureFlagsKt = require('./templates/android/ReactNativeFeatureFlags.kt-template'); -const ReactNativeFeatureFlagsCxxAccessorKt = require('./templates/android/ReactNativeFeatureFlagsCxxAccessor.kt-template'); -const ReactNativeFeatureFlagsCxxInteropKt = require('./templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template'); -const ReactNativeFeatureFlagsDefaultsKt = require('./templates/android/ReactNativeFeatureFlagsDefaults.kt-template'); -const ReactNativeFeatureFlagsLocalAccessorKt = require('./templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template'); -const ReactNativeFeatureFlagsProviderKt = require('./templates/android/ReactNativeFeatureFlagsProvider.kt-template'); -const ReactNativeFeatureFlagsProviderHolderCPP = require('./templates/android/ReactNativeFeatureFlagsProviderHolder.cpp-template'); -const ReactNativeFeatureFlagsProviderHolderH = require('./templates/android/ReactNativeFeatureFlagsProviderHolder.h-template'); -const path = require('path'); +import JReactNativeFeatureFlagsCxxInteropCPP from './templates/android/JReactNativeFeatureFlagsCxxInterop.cpp-template'; +import JReactNativeFeatureFlagsCxxInteropH from './templates/android/JReactNativeFeatureFlagsCxxInterop.h-template'; +import ReactNativeFeatureFlagsKt from './templates/android/ReactNativeFeatureFlags.kt-template'; +import ReactNativeFeatureFlagsCxxAccessorKt from './templates/android/ReactNativeFeatureFlagsCxxAccessor.kt-template'; +import ReactNativeFeatureFlagsCxxInteropKt from './templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template'; +import ReactNativeFeatureFlagsDefaultsKt from './templates/android/ReactNativeFeatureFlagsDefaults.kt-template'; +import ReactNativeFeatureFlagsLocalAccessorKt from './templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template'; +import ReactNativeFeatureFlagsProviderKt from './templates/android/ReactNativeFeatureFlagsProvider.kt-template'; +import path from 'path'; + +export default function generateAndroidModules( + generatorConfig: GeneratorConfig, +): GeneratorResult { + const {androidPath, androidJniPath, featureFlagDefinitions} = generatorConfig; -module.exports = function generateandroidModules( - generatorConfig, - featureFlagsConfig, -) { return { - [path.join(generatorConfig.androidPath, 'ReactNativeFeatureFlags.kt')]: - ReactNativeFeatureFlagsKt(featureFlagsConfig), - [path.join( - generatorConfig.androidPath, - 'ReactNativeFeatureFlagsCxxAccessor.kt', - )]: ReactNativeFeatureFlagsCxxAccessorKt(featureFlagsConfig), - [path.join( - generatorConfig.androidPath, - 'ReactNativeFeatureFlagsLocalAccessor.kt', - )]: ReactNativeFeatureFlagsLocalAccessorKt(featureFlagsConfig), - [path.join( - generatorConfig.androidPath, - 'ReactNativeFeatureFlagsCxxInterop.kt', - )]: ReactNativeFeatureFlagsCxxInteropKt(featureFlagsConfig), - [path.join( - generatorConfig.androidPath, - 'ReactNativeFeatureFlagsDefaults.kt', - )]: ReactNativeFeatureFlagsDefaultsKt(featureFlagsConfig), - [path.join( - generatorConfig.androidPath, - 'ReactNativeFeatureFlagsProvider.kt', - )]: ReactNativeFeatureFlagsProviderKt(featureFlagsConfig), - [path.join( - generatorConfig.androidJniPath, - 'ReactNativeFeatureFlagsProviderHolder.h', - )]: ReactNativeFeatureFlagsProviderHolderH(featureFlagsConfig), - [path.join( - generatorConfig.androidJniPath, - 'ReactNativeFeatureFlagsProviderHolder.cpp', - )]: ReactNativeFeatureFlagsProviderHolderCPP(featureFlagsConfig), - [path.join( - generatorConfig.androidJniPath, - 'JReactNativeFeatureFlagsCxxInterop.h', - )]: JReactNativeFeatureFlagsCxxInteropH(featureFlagsConfig), - [path.join( - generatorConfig.androidJniPath, - 'JReactNativeFeatureFlagsCxxInterop.cpp', - )]: JReactNativeFeatureFlagsCxxInteropCPP(featureFlagsConfig), + [path.join(androidPath, 'ReactNativeFeatureFlags.kt')]: + ReactNativeFeatureFlagsKt(featureFlagDefinitions), + [path.join(androidPath, 'ReactNativeFeatureFlagsCxxAccessor.kt')]: + ReactNativeFeatureFlagsCxxAccessorKt(featureFlagDefinitions), + [path.join(androidPath, 'ReactNativeFeatureFlagsLocalAccessor.kt')]: + ReactNativeFeatureFlagsLocalAccessorKt(featureFlagDefinitions), + [path.join(androidPath, 'ReactNativeFeatureFlagsCxxInterop.kt')]: + ReactNativeFeatureFlagsCxxInteropKt(featureFlagDefinitions), + [path.join(androidPath, 'ReactNativeFeatureFlagsDefaults.kt')]: + ReactNativeFeatureFlagsDefaultsKt(featureFlagDefinitions), + [path.join(androidPath, 'ReactNativeFeatureFlagsProvider.kt')]: + ReactNativeFeatureFlagsProviderKt(featureFlagDefinitions), + [path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.h')]: + JReactNativeFeatureFlagsCxxInteropH(featureFlagDefinitions), + [path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.cpp')]: + JReactNativeFeatureFlagsCxxInteropCPP(featureFlagDefinitions), }; -}; +} diff --git a/packages/react-native/scripts/featureflags/generateCommonCxxModules.js b/packages/react-native/scripts/featureflags/generateCommonCxxModules.js index 4c021fc1d644..7329bf8abbd0 100644 --- a/packages/react-native/scripts/featureflags/generateCommonCxxModules.js +++ b/packages/react-native/scripts/featureflags/generateCommonCxxModules.js @@ -4,43 +4,37 @@ * 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'; +import type {GeneratorConfig, GeneratorResult} from './types'; -const ReactNativeFeatureFlagsCPP = require('./templates/common-cxx/ReactNativeFeatureFlags.cpp-template'); -const ReactNativeFeatureFlagsH = require('./templates/common-cxx/ReactNativeFeatureFlags.h-template'); -const ReactNativeFeatureFlagsAccessorCPP = require('./templates/common-cxx/ReactNativeFeatureFlagsAccessor.cpp-template'); -const ReactNativeFeatureFlagsAccessorH = require('./templates/common-cxx/ReactNativeFeatureFlagsAccessor.h-template'); -const ReactNativeFeatureFlagsDefaultsH = require('./templates/common-cxx/ReactNativeFeatureFlagsDefaults.h-template'); -const ReactNativeFeatureFlagsProviderH = require('./templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template'); -const path = require('path'); +import ReactNativeFeatureFlagsCPP from './templates/common-cxx/ReactNativeFeatureFlags.cpp-template'; +import ReactNativeFeatureFlagsH from './templates/common-cxx/ReactNativeFeatureFlags.h-template'; +import ReactNativeFeatureFlagsAccessorCPP from './templates/common-cxx/ReactNativeFeatureFlagsAccessor.cpp-template'; +import ReactNativeFeatureFlagsAccessorH from './templates/common-cxx/ReactNativeFeatureFlagsAccessor.h-template'; +import ReactNativeFeatureFlagsDefaultsH from './templates/common-cxx/ReactNativeFeatureFlagsDefaults.h-template'; +import ReactNativeFeatureFlagsProviderH from './templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template'; +import path from 'path'; + +export default function generateCommonCxxModules( + generatorConfig: GeneratorConfig, +): GeneratorResult { + const {commonCxxPath, featureFlagDefinitions} = generatorConfig; -module.exports = function generateCommonCxxModules( - generatorConfig, - featureFlagsConfig, -) { return { - [path.join(generatorConfig.commonCxxPath, 'ReactNativeFeatureFlags.h')]: - ReactNativeFeatureFlagsH(featureFlagsConfig), - [path.join(generatorConfig.commonCxxPath, 'ReactNativeFeatureFlags.cpp')]: - ReactNativeFeatureFlagsCPP(featureFlagsConfig), - [path.join( - generatorConfig.commonCxxPath, - 'ReactNativeFeatureFlagsAccessor.h', - )]: ReactNativeFeatureFlagsAccessorH(featureFlagsConfig), - [path.join( - generatorConfig.commonCxxPath, - 'ReactNativeFeatureFlagsAccessor.cpp', - )]: ReactNativeFeatureFlagsAccessorCPP(featureFlagsConfig), - [path.join( - generatorConfig.commonCxxPath, - 'ReactNativeFeatureFlagsDefaults.h', - )]: ReactNativeFeatureFlagsDefaultsH(featureFlagsConfig), - [path.join( - generatorConfig.commonCxxPath, - 'ReactNativeFeatureFlagsProvider.h', - )]: ReactNativeFeatureFlagsProviderH(featureFlagsConfig), + [path.join(commonCxxPath, 'ReactNativeFeatureFlags.h')]: + ReactNativeFeatureFlagsH(featureFlagDefinitions), + [path.join(commonCxxPath, 'ReactNativeFeatureFlags.cpp')]: + ReactNativeFeatureFlagsCPP(featureFlagDefinitions), + [path.join(commonCxxPath, 'ReactNativeFeatureFlagsAccessor.h')]: + ReactNativeFeatureFlagsAccessorH(featureFlagDefinitions), + [path.join(commonCxxPath, 'ReactNativeFeatureFlagsAccessor.cpp')]: + ReactNativeFeatureFlagsAccessorCPP(featureFlagDefinitions), + [path.join(commonCxxPath, 'ReactNativeFeatureFlagsDefaults.h')]: + ReactNativeFeatureFlagsDefaultsH(featureFlagDefinitions), + [path.join(commonCxxPath, 'ReactNativeFeatureFlagsProvider.h')]: + ReactNativeFeatureFlagsProviderH(featureFlagDefinitions), }; -}; +} diff --git a/packages/react-native/scripts/featureflags/generateFiles.js b/packages/react-native/scripts/featureflags/generateFiles.js index 91a974354931..f03df2163e64 100644 --- a/packages/react-native/scripts/featureflags/generateFiles.js +++ b/packages/react-native/scripts/featureflags/generateFiles.js @@ -4,49 +4,37 @@ * 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 */ -const generateAndroidModules = require('./generateAndroidModules'); -const generateCommonCxxModules = require('./generateCommonCxxModules'); -const generateJavaScriptModules = require('./generateJavaScriptModules'); -const fs = require('fs'); +import type {GeneratorConfig, GeneratorOptions} from './types'; -module.exports = function generateFiles(generatorConfig, generatorOptions) { - const userDefinedFeatureFlagsConfig = JSON.parse( - fs.readFileSync(generatorConfig.configPath, 'utf8'), - ); - - const featureFlagsConfig = Object.assign( - {jsOnly: {}, common: {}}, - userDefinedFeatureFlagsConfig, - ); +import generateAndroidModules from './generateAndroidModules'; +import generateCommonCxxModules from './generateCommonCxxModules'; +import generateJavaScriptModules from './generateJavaScriptModules'; +import fs from 'fs'; +export default function generateFiles( + generatorConfig: GeneratorConfig, + generatorOptions: GeneratorOptions, +): void { fs.mkdirSync(generatorConfig.jsPath, {recursive: true}); fs.mkdirSync(generatorConfig.commonCxxPath, {recursive: true}); fs.mkdirSync(generatorConfig.commonNativeModuleCxxPath, {recursive: true}); fs.mkdirSync(generatorConfig.androidPath, {recursive: true}); fs.mkdirSync(generatorConfig.androidJniPath, {recursive: true}); - const jsModules = generateJavaScriptModules( - generatorConfig, - featureFlagsConfig, - ); + const jsModules = generateJavaScriptModules(generatorConfig); - const commonCxxModules = generateCommonCxxModules( - generatorConfig, - featureFlagsConfig, - ); + const commonCxxModules = generateCommonCxxModules(generatorConfig); - const androidModules = generateAndroidModules( - generatorConfig, - featureFlagsConfig, - ); + const androidModules = generateAndroidModules(generatorConfig); const generatedFiles = {...jsModules, ...commonCxxModules, ...androidModules}; if (generatorOptions.verifyUnchanged) { - const existingModules = {}; + const existingModules: {[string]: string} = {}; for (const moduleName of Object.keys(generatedFiles)) { const existingModule = fs.readFileSync(moduleName, 'utf8'); existingModules[moduleName] = existingModule; @@ -79,4 +67,4 @@ module.exports = function generateFiles(generatorConfig, generatorOptions) { for (const [modulePath, moduleContents] of Object.entries(generatedFiles)) { fs.writeFileSync(modulePath, moduleContents, 'utf8'); } -}; +} diff --git a/packages/react-native/scripts/featureflags/generateJavaScriptModules.js b/packages/react-native/scripts/featureflags/generateJavaScriptModules.js index 63b11b912eb0..4fc7d30e1553 100644 --- a/packages/react-native/scripts/featureflags/generateJavaScriptModules.js +++ b/packages/react-native/scripts/featureflags/generateJavaScriptModules.js @@ -4,33 +4,32 @@ * 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'; +import type {GeneratorConfig, GeneratorResult} from './types'; -const NativeReactNativeFeatureFlagsCPP = require('./templates/js/NativeReactNativeFeatureFlags.cpp-template'); -const NativeReactNativeFeatureFlagsH = require('./templates/js/NativeReactNativeFeatureFlags.h-template'); -const NativeReactNativeFeatureFlagsJS = require('./templates/js/NativeReactNativeFeatureFlags.js-template'); -const ReactNativeFeatureFlagsJS = require('./templates/js/ReactNativeFeatureFlags.js-template'); -const path = require('path'); +import NativeReactNativeFeatureFlagsCPP from './templates/js/NativeReactNativeFeatureFlags.cpp-template'; +import NativeReactNativeFeatureFlagsH from './templates/js/NativeReactNativeFeatureFlags.h-template'; +import NativeReactNativeFeatureFlagsJS from './templates/js/NativeReactNativeFeatureFlags.js-template'; +import ReactNativeFeatureFlagsJS from './templates/js/ReactNativeFeatureFlags.js-template'; +import path from 'path'; + +export default function generateCommonCxxModules( + generatorConfig: GeneratorConfig, +): GeneratorResult { + const {jsPath, commonNativeModuleCxxPath, featureFlagDefinitions} = + generatorConfig; -module.exports = function generateCommonCxxModules( - generatorConfig, - featureFlagsConfig, -) { return { - [path.join(generatorConfig.jsPath, 'ReactNativeFeatureFlags.js')]: - ReactNativeFeatureFlagsJS(featureFlagsConfig), - [path.join(generatorConfig.jsPath, 'NativeReactNativeFeatureFlags.js')]: - NativeReactNativeFeatureFlagsJS(featureFlagsConfig), - [path.join( - generatorConfig.commonNativeModuleCxxPath, - 'NativeReactNativeFeatureFlags.h', - )]: NativeReactNativeFeatureFlagsH(featureFlagsConfig), - [path.join( - generatorConfig.commonNativeModuleCxxPath, - 'NativeReactNativeFeatureFlags.cpp', - )]: NativeReactNativeFeatureFlagsCPP(featureFlagsConfig), + [path.join(jsPath, 'ReactNativeFeatureFlags.js')]: + ReactNativeFeatureFlagsJS(featureFlagDefinitions), + [path.join(jsPath, 'NativeReactNativeFeatureFlags.js')]: + NativeReactNativeFeatureFlagsJS(featureFlagDefinitions), + [path.join(commonNativeModuleCxxPath, 'NativeReactNativeFeatureFlags.h')]: + NativeReactNativeFeatureFlagsH(featureFlagDefinitions), + [path.join(commonNativeModuleCxxPath, 'NativeReactNativeFeatureFlags.cpp')]: + NativeReactNativeFeatureFlagsCPP(featureFlagDefinitions), }; -}; +} diff --git a/packages/react-native/scripts/featureflags/index.js b/packages/react-native/scripts/featureflags/index.js new file mode 100644 index 000000000000..38e991437f20 --- /dev/null +++ b/packages/react-native/scripts/featureflags/index.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +if (require.main === module) { + require('../../../../scripts/build/babel-register').registerForMonorepo(); + const update = require('./update').default; + update(process.argv.includes('--verify-unchanged')); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.cpp-template.js b/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.cpp-template.js index 35e95e17fbf2..223a0e272153 100644 --- a/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.cpp-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.cpp-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -29,11 +27,44 @@ ${DO_NOT_MODIFY_COMMENT} #include "JReactNativeFeatureFlagsCxxInterop.h" #include -#include namespace facebook::react { -${Object.entries(config.common) +static jni::alias_ref getReactNativeFeatureFlagsProviderJavaClass() { + static const auto jClass = facebook::jni::findClassStatic( + "com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider"); + return jClass; +} + +/** + * Implementation of ReactNativeFeatureFlagsProvider that wraps a + * ReactNativeFeatureFlagsProvider Java object. + */ +class ReactNativeFeatureFlagsProviderHolder + : public ReactNativeFeatureFlagsProvider { + public: + explicit ReactNativeFeatureFlagsProviderHolder( + jni::alias_ref javaProvider) + : javaProvider_(make_global(javaProvider)){}; + +${Object.entries(definitions.common) + .map( + ([flagName, flagConfig]) => + ` ${getCxxTypeFromDefaultValue( + flagConfig.defaultValue, + )} ${flagName}() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("${flagName}"); + return method(javaProvider_); + }`, + ) + .join('\n\n')} + + private: + jni::global_ref javaProvider_; +}; + +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => `${getCxxTypeFromDefaultValue( @@ -62,7 +93,7 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() { makeNativeMethod( "override", JReactNativeFeatureFlagsCxxInterop::override), makeNativeMethod("dangerouslyReset", JReactNativeFeatureFlagsCxxInterop::dangerouslyReset), -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` makeNativeMethod( @@ -75,3 +106,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.h-template.js b/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.h-template.js index 580e47fcaab3..72995b1f714a 100644 --- a/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/JReactNativeFeatureFlagsCxxInterop.h-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -40,7 +38,7 @@ class JReactNativeFeatureFlagsCxxInterop constexpr static auto kJavaDescriptor = "Lcom/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop;"; -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` static ${getCxxTypeFromDefaultValue( @@ -62,3 +60,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} 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 148e6c364aff..520dc13456c0 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 @@ -4,16 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const {DO_NOT_MODIFY_COMMENT} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -35,7 +36,7 @@ object ReactNativeFeatureFlags { private var accessorProvider: () -> ReactNativeFeatureFlagsAccessor = { ReactNativeFeatureFlagsCxxAccessor() } private var accessor: ReactNativeFeatureFlagsAccessor = accessorProvider() -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` /** @@ -90,3 +91,4 @@ ${Object.entries(config.common) } } `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxAccessor.kt-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxAccessor.kt-template.js index a5fe55b8579d..9f63cbca9cc5 100644 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxAccessor.kt-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxAccessor.kt-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { +import { DO_NOT_MODIFY_COMMENT, getKotlinTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -30,7 +31,7 @@ ${DO_NOT_MODIFY_COMMENT} package com.facebook.react.internal.featureflags class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor { -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` private var ${flagName}Cache: ${getKotlinTypeFromDefaultValue( @@ -39,7 +40,7 @@ ${Object.entries(config.common) ) .join('\n')} -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` override fun ${flagName}(): Boolean { var cached = ${flagName}Cache @@ -58,3 +59,4 @@ ${Object.entries(config.common) override fun dangerouslyReset() = ReactNativeFeatureFlagsCxxInterop.dangerouslyReset() } `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template.js index 813f010d2126..3007b06913bb 100644 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { +import { DO_NOT_MODIFY_COMMENT, getKotlinTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -38,7 +39,7 @@ object ReactNativeFeatureFlagsCxxInterop { SoLoader.loadLibrary("react_featureflagsjni") } -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` @DoNotStrip @JvmStatic external fun ${flagName}(): ${getKotlinTypeFromDefaultValue( @@ -52,3 +53,4 @@ ${Object.entries(config.common) @DoNotStrip @JvmStatic external fun dangerouslyReset() } `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsDefaults.kt-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsDefaults.kt-template.js index d20df80a87b5..9707a32cb3b8 100644 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsDefaults.kt-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsDefaults.kt-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { +import { DO_NOT_MODIFY_COMMENT, getKotlinTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -33,7 +34,7 @@ open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvider { // We could use JNI to get the defaults from C++, // but that is more expensive than just duplicating the defaults here. -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` override fun ${flagName}(): ${getKotlinTypeFromDefaultValue( @@ -43,3 +44,4 @@ ${Object.entries(config.common) .join('\n\n')} } `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template.js index 3271ac929315..8c87853ca003 100644 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { +import { DO_NOT_MODIFY_COMMENT, getKotlinTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -34,7 +35,7 @@ class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAccessor { private val accessedFeatureFlags = mutableSetOf() -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` private var ${flagName}Cache: ${getKotlinTypeFromDefaultValue( @@ -43,7 +44,7 @@ ${Object.entries(config.common) ) .join('\n')} -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` override fun ${flagName}(): Boolean { var cached = ${flagName}Cache @@ -72,3 +73,4 @@ ${Object.entries(config.common) } } `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProvider.kt-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProvider.kt-template.js index 57eea78a02e2..558f86a5af3b 100644 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProvider.kt-template.js +++ b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProvider.kt-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { +import { DO_NOT_MODIFY_COMMENT, getKotlinTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -33,7 +34,7 @@ import com.facebook.proguard.annotations.DoNotStrip @DoNotStrip interface ReactNativeFeatureFlagsProvider { -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` @DoNotStrip fun ${flagName}(): ${getKotlinTypeFromDefaultValue( @@ -43,3 +44,4 @@ ${Object.entries(config.common) .join('\n\n')} } `); +} diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProviderHolder.cpp-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProviderHolder.cpp-template.js deleted file mode 100644 index 4bd3b3da43ce..000000000000 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProviderHolder.cpp-template.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -'use strict'; - -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); - -module.exports = config => - signedsource.signFile(`/* - * 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. - * - * ${signedsource.getSigningToken()} - */ - -${DO_NOT_MODIFY_COMMENT} - -#include "ReactNativeFeatureFlagsProviderHolder.h" - -namespace facebook::react { - -static jni::alias_ref getJClass() { - static const auto jClass = facebook::jni::findClassStatic( - "com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider"); - return jClass; -} - -${Object.entries(config.common) - .map( - ([flagName, flagConfig]) => - `${getCxxTypeFromDefaultValue( - flagConfig.defaultValue, - )} ReactNativeFeatureFlagsProviderHolder::${flagName}() { - static const auto method = - getJClass()->getMethod("${flagName}"); - return method(javaProvider_); -}`, - ) - .join('\n\n')} - -} // namespace facebook::react -`); diff --git a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProviderHolder.h-template.js b/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProviderHolder.h-template.js deleted file mode 100644 index 60e3272c9036..000000000000 --- a/packages/react-native/scripts/featureflags/templates/android/ReactNativeFeatureFlagsProviderHolder.h-template.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -'use strict'; - -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); - -module.exports = config => - signedsource.signFile(`/* - * 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. - * - * ${signedsource.getSigningToken()} - */ - -${DO_NOT_MODIFY_COMMENT} - -#pragma once - -#include -#include - -namespace facebook::react { - -/** - * Implementation of ReactNativeFeatureFlagsProvider that wraps a - * ReactNativeFeatureFlagsProvider Java object. - */ -class ReactNativeFeatureFlagsProviderHolder - : public ReactNativeFeatureFlagsProvider { - public: - explicit ReactNativeFeatureFlagsProviderHolder( - jni::alias_ref javaProvider) - : javaProvider_(make_global(javaProvider)){}; - -${Object.entries(config.common) - .map( - ([flagName, flagConfig]) => - ` ${getCxxTypeFromDefaultValue( - flagConfig.defaultValue, - )} ${flagName}() override;`, - ) - .join('\n')} - - private: - jni::global_ref javaProvider_; -}; - -} // namespace facebook::react -`); diff --git a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.cpp-template.js b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.cpp-template.js index 3bd2d55eddc9..bef6fbb8c20e 100644 --- a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.cpp-template.js +++ b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.cpp-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -31,7 +29,7 @@ ${DO_NOT_MODIFY_COMMENT} namespace facebook::react { -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => `${getCxxTypeFromDefaultValue( @@ -62,3 +60,4 @@ ReactNativeFeatureFlagsAccessor& ReactNativeFeatureFlags::getAccessor( } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.h-template.js b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.h-template.js index ed4e5faf47ec..5e6e896560e6 100644 --- a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlags.h-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -43,7 +41,7 @@ namespace facebook::react { */ class ReactNativeFeatureFlags { public: -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` /** @@ -95,3 +93,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.cpp-template.js b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.cpp-template.js index de6e313bc929..9a1340d0d5e5 100644 --- a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.cpp-template.js +++ b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.cpp-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -28,9 +26,9 @@ module.exports = config => ${DO_NOT_MODIFY_COMMENT} #include -#include #include #include +#include #include "ReactNativeFeatureFlags.h" namespace facebook::react { @@ -38,7 +36,7 @@ namespace facebook::react { ReactNativeFeatureFlagsAccessor::ReactNativeFeatureFlagsAccessor() : currentProvider_(std::make_unique()) {} -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig], flagPosition) => `${getCxxTypeFromDefaultValue( @@ -52,9 +50,7 @@ ${Object.entries(config.common) // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - // Mark the flag as accessed. - static const char* flagName = "${flagName}"; - markFlagAsAccessed(${flagPosition}, flagName); + markFlagAsAccessed(${flagPosition}, "${flagName}"); flagValue = currentProvider_->${flagName}(); ${flagName}_ = flagValue; @@ -78,8 +74,6 @@ void ReactNativeFeatureFlagsAccessor::markFlagAsAccessed( } void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() { - std::string accessedFeatureFlagNames; - std::ostringstream featureFlagListBuilder; for (const auto& featureFlagName : accessedFeatureFlags_) { if (featureFlagName != nullptr) { @@ -87,7 +81,7 @@ void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() { } } - accessedFeatureFlagNames = featureFlagListBuilder.str(); + std::string accessedFeatureFlagNames = featureFlagListBuilder.str(); if (!accessedFeatureFlagNames.empty()) { accessedFeatureFlagNames = accessedFeatureFlagNames.substr(0, accessedFeatureFlagNames.size() - 2); @@ -102,3 +96,4 @@ void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() { } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.h-template.js b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.h-template.js index 5478b3b0fab5..65ba094af2d6 100644 --- a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsAccessor.h-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -34,7 +32,6 @@ ${DO_NOT_MODIFY_COMMENT} #include #include #include -#include namespace facebook::react { @@ -42,7 +39,7 @@ class ReactNativeFeatureFlagsAccessor { public: ReactNativeFeatureFlagsAccessor(); -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` ${getCxxTypeFromDefaultValue(flagConfig.defaultValue)} ${flagName}();`, @@ -57,10 +54,10 @@ ${Object.entries(config.common) std::unique_ptr currentProvider_; std::array, ${ - Object.keys(config.common).length + Object.keys(definitions.common).length }> accessedFeatureFlags_; -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` std::atomic - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -37,7 +35,7 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { public: ReactNativeFeatureFlagsDefaults() = default; -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` ${getCxxTypeFromDefaultValue( @@ -51,3 +49,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template.js b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template.js index 1f01590b07b3..68689f927faa 100644 --- a/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -35,7 +33,7 @@ class ReactNativeFeatureFlagsProvider { public: virtual ~ReactNativeFeatureFlagsProvider() = default; -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` virtual ${getCxxTypeFromDefaultValue( @@ -47,3 +45,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js index 9844c5a5b4a7..13a28a72cecb 100644 --- a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -45,7 +43,7 @@ NativeReactNativeFeatureFlags::NativeReactNativeFeatureFlags( std::shared_ptr jsInvoker) : NativeReactNativeFeatureFlagsCxxSpec(std::move(jsInvoker)) {} -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => `${getCxxTypeFromDefaultValue( @@ -59,3 +57,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js index 0bf7a9b28dc1..492639ed9d3d 100644 --- a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js @@ -4,19 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const { - DO_NOT_MODIFY_COMMENT, - getCxxTypeFromDefaultValue, -} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/* +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -40,7 +38,7 @@ class NativeReactNativeFeatureFlags public: NativeReactNativeFeatureFlags(std::shared_ptr jsInvoker); -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` ${getCxxTypeFromDefaultValue( @@ -52,3 +50,4 @@ ${Object.entries(config.common) } // namespace facebook::react `); +} diff --git a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.js-template.js b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.js-template.js index 3bd1b05daac1..9c9e557879db 100644 --- a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.js-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.js-template.js @@ -4,16 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const {DO_NOT_MODIFY_COMMENT} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/** +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -30,7 +31,7 @@ import type {TurboModule} from '../../../Libraries/TurboModule/RCTExport'; import * as TurboModuleRegistry from '../../../Libraries/TurboModule/TurboModuleRegistry'; export interface Spec extends TurboModule { -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => ` +${flagName}?: () => ${typeof flagConfig.defaultValue};`, @@ -44,3 +45,4 @@ const NativeReactNativeFeatureFlags: ?Spec = TurboModuleRegistry.get( export default NativeReactNativeFeatureFlags; `); +} diff --git a/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js b/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js index 3d6251d3e7cd..90872bd5e58a 100644 --- a/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js @@ -4,16 +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 strict * @format */ -'use strict'; +import type {FeatureFlagDefinitions} from '../../types'; -const {DO_NOT_MODIFY_COMMENT} = require('../../utils'); -const signedsource = require('signedsource'); +import {DO_NOT_MODIFY_COMMENT} from '../../utils'; +import signedsource from 'signedsource'; -module.exports = config => - signedsource.signFile(`/** +export default function (definitions: FeatureFlagDefinitions): string { + return signedsource.signFile(`/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -33,7 +34,7 @@ import { } from './ReactNativeFeatureFlagsBase'; export type ReactNativeFeatureFlagsJsOnly = { -${Object.entries(config.jsOnly) +${Object.entries(definitions.jsOnly) .map( ([flagName, flagConfig]) => ` ${flagName}: Getter<${typeof flagConfig.defaultValue}>,`, @@ -45,7 +46,7 @@ export type ReactNativeFeatureFlagsJsOnlyOverrides = Partial ` ${flagName}: Getter<${typeof flagConfig.defaultValue}>,`, @@ -53,7 +54,7 @@ ${Object.entries(config.common) .join('\n')} } -${Object.entries(config.jsOnly) +${Object.entries(definitions.jsOnly) .map( ([flagName, flagConfig]) => `/** @@ -65,7 +66,7 @@ export const ${flagName}: Getter<${typeof flagConfig.defaultValue}> = createJava ) .join('\n\n')} -${Object.entries(config.common) +${Object.entries(definitions.common) .map( ([flagName, flagConfig]) => `/** @@ -83,3 +84,4 @@ export const ${flagName}: Getter<${typeof flagConfig.defaultValue}> = createNati */ export const override = setOverrides; `); +} diff --git a/packages/react-native/scripts/featureflags/types.js b/packages/react-native/scripts/featureflags/types.js new file mode 100644 index 000000000000..688a081d5b9a --- /dev/null +++ b/packages/react-native/scripts/featureflags/types.js @@ -0,0 +1,40 @@ +/** + * 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. + * + * @flow strict + * @format + */ + +export type FeatureFlagValue = boolean | number | string; + +export type FeatureFlagDefinitions = { + common: FeatureFlagList, + jsOnly: FeatureFlagList, +}; + +type FeatureFlagList = { + [flagName: string]: { + description: string, + defaultValue: FeatureFlagValue, + }, +}; + +export type GeneratorConfig = { + featureFlagDefinitions: FeatureFlagDefinitions, + jsPath: string, + commonCxxPath: string, + commonNativeModuleCxxPath: string, + androidPath: string, + androidJniPath: string, +}; + +export type GeneratorOptions = { + verifyUnchanged: boolean, +}; + +export type GeneratorResult = { + [path: string]: string /* content */, +}; diff --git a/packages/react-native/scripts/featureflags/update.js b/packages/react-native/scripts/featureflags/update.js index dff625d3e8d2..46ce9493f145 100644 --- a/packages/react-native/scripts/featureflags/update.js +++ b/packages/react-native/scripts/featureflags/update.js @@ -4,18 +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 strict * @format */ -const generateFiles = require('./generateFiles'); -const path = require('path'); +import generateFiles from './generateFiles'; +import featureFlagDefinitions from './ReactNativeFeatureFlags.config'; +import path from 'path'; const REACT_NATIVE_PACKAGE_ROOT = path.join(__dirname, '..', '..'); -function update() { +export default function update(verifyUnchanged: boolean): void { generateFiles( { - configPath: path.join(__dirname, 'ReactNativeFeatureFlags.json'), + featureFlagDefinitions, jsPath: path.join( REACT_NATIVE_PACKAGE_ROOT, 'src', @@ -58,11 +60,7 @@ function update() { ), }, { - verifyUnchanged: process.argv.includes('--verify-unchanged'), + verifyUnchanged, }, ); } - -if (require.main === module) { - update(); -} diff --git a/packages/react-native/scripts/featureflags/utils.js b/packages/react-native/scripts/featureflags/utils.js index a551227a6cb2..1634f3c73ff8 100644 --- a/packages/react-native/scripts/featureflags/utils.js +++ b/packages/react-native/scripts/featureflags/utils.js @@ -4,47 +4,48 @@ * 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 */ -module.exports = { - getCxxTypeFromDefaultValue: defaultValue => { - switch (typeof defaultValue) { - case 'boolean': - return 'bool'; - case 'number': - return 'int'; - case 'string': - return 'std::string'; - default: - throw new Error( - `Unsupported default value type: ${typeof defaultValue}`, - ); - } - }, +import type {FeatureFlagValue} from './types'; - getKotlinTypeFromDefaultValue: defaultValue => { - switch (typeof defaultValue) { - case 'boolean': - return 'Boolean'; - case 'number': - return 'Int'; - case 'string': - return 'String'; - default: - throw new Error( - `Unsupported default value type: ${typeof defaultValue}`, - ); - } - }, +export function getCxxTypeFromDefaultValue( + defaultValue: FeatureFlagValue, +): string { + switch (typeof defaultValue) { + case 'boolean': + return 'bool'; + case 'number': + return 'int'; + case 'string': + return 'std::string'; + default: + throw new Error(`Unsupported default value type: ${typeof defaultValue}`); + } +} - DO_NOT_MODIFY_COMMENT: `/** +export function getKotlinTypeFromDefaultValue( + defaultValue: FeatureFlagValue, +): string { + switch (typeof defaultValue) { + case 'boolean': + return 'Boolean'; + case 'number': + return 'Int'; + case 'string': + return 'String'; + default: + throw new Error(`Unsupported default value type: ${typeof defaultValue}`); + } +} + +export const DO_NOT_MODIFY_COMMENT = `/** * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update - */`, -}; + */`; diff --git a/packages/react-native/src/private/featureflags/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/NativeReactNativeFeatureFlags.js index 22050a3f31be..78bc969baebc 100644 --- a/packages/react-native/src/private/featureflags/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/NativeReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<2ca87dc970592f66d83f4799c4047c9b>> + * @generated SignedSource<> * @flow strict-local */ @@ -12,7 +12,7 @@ * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index dc612641d200..32c632c8b153 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<52b25f675aa8d5ae45941f0ee951358a>> * @flow strict-local */ @@ -12,7 +12,7 @@ * IMPORTANT: Do NOT modify this file directly. * * To change the definition of the flags, edit - * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. + * packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js. * * To regenerate this code, run the following script from the repo root: * yarn featureflags-update