Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Flow in feature flags scripts #42814

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions flow-typed/npm/signedsource_v1.x.x.js
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<<ad8bfca49acda85e56fea1c124b5bc8a>>
* @generated SignedSource<<ef51a5a7152e6f4fe0556b17aec2c0c2>>
*/

/**
Expand All @@ -18,9 +18,9 @@
*/

#include <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
#include <algorithm>
#include <sstream>
#include <stdexcept>
#include <string>
#include "ReactNativeFeatureFlags.h"

namespace facebook::react {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -181,16 +167,14 @@ void ReactNativeFeatureFlagsAccessor::markFlagAsAccessed(
}

void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() {
std::string accessedFeatureFlagNames;

std::ostringstream featureFlagListBuilder;
for (const auto& featureFlagName : accessedFeatureFlags_) {
if (featureFlagName != nullptr) {
featureFlagListBuilder << featureFlagName << ", ";
}
}

accessedFeatureFlagNames = featureFlagListBuilder.str();
std::string accessedFeatureFlagNames = featureFlagListBuilder.str();
if (!accessedFeatureFlagNames.empty()) {
accessedFeatureFlagNames =
accessedFeatureFlagNames.substr(0, accessedFeatureFlagNames.size() - 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<40315ae6cc418effd421dff2be6831c7>>
* @generated SignedSource<<b61bc487a077e9e1dc6ab2b176fd72cb>>
*/

/**
Expand All @@ -24,7 +24,6 @@
#include <atomic>
#include <memory>
#include <optional>
#include <vector>

namespace facebook::react {

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/scripts/featureflags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Example:
```

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,49 @@
* 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 ReactNativeFeatureFlagsProviderHolderCPP from './templates/android/ReactNativeFeatureFlagsProviderHolder.cpp-template';
import ReactNativeFeatureFlagsProviderHolderH from './templates/android/ReactNativeFeatureFlagsProviderHolder.h-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, 'ReactNativeFeatureFlagsProviderHolder.h')]:
ReactNativeFeatureFlagsProviderHolderH(featureFlagDefinitions),
[path.join(androidJniPath, 'ReactNativeFeatureFlagsProviderHolder.cpp')]:
ReactNativeFeatureFlagsProviderHolderCPP(featureFlagDefinitions),
[path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.h')]:
JReactNativeFeatureFlagsCxxInteropH(featureFlagDefinitions),
[path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.cpp')]:
JReactNativeFeatureFlagsCxxInteropCPP(featureFlagDefinitions),
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
};
}
Loading
Loading