Skip to content

Commit

Permalink
Setup a new macro to gate the core packager functionality
Browse files Browse the repository at this point in the history
Summary:
Changelog:
* Rename `ENABLE_PACKAGER_CONNECTION` macro to a more appropriate name `RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION` to reflect this is only used in RCT_DEV_SETTINGS

* Introduce `RCT_PACKAGER_LOADING_FUNCTIONALITY` that can be separate from `RCT_DEV_MENU`, by default, it equals to `RCT_DEV_MENU`

Reviewed By: fkgozali

Differential Revision: D30546025

fbshipit-source-id: f409c02dc1486041d7db5abdbf7eb482520fa171
  • Loading branch information
jimmy623 authored and facebook-github-bot committed Sep 13, 2021
1 parent 8d4fe82 commit a8cd8f7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion React/Base/RCTBundleURLProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RCT_EXTERN NSString *const RCTBundleURLProviderUpdatedNotification;
RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort;

#if RCT_DEV_MENU
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
/**
* Allow/disallow accessing the packager server for various runtime scenario.
* For instance, if a test run should never access the packager, disable it
Expand Down
4 changes: 2 additions & 2 deletions React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_METRO_PORT;

#if RCT_DEV_MENU
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
static BOOL kRCTAllowPackagerAccess = YES;
void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ - (NSString *)packagerServerHost

- (NSString *)packagerServerHostPort
{
#if RCT_DEV_MENU
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
if (!kRCTAllowPackagerAccess) {
RCTLogInfo(@"Packager server access is disabled in this environment");
return nil;
Expand Down
15 changes: 12 additions & 3 deletions React/Base/RCTDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
#define RCT_DEV_MENU RCT_DEV
#endif

/**
* Controls for the core packgaer loading functionality
* By default, this inherits from RCT_DEV_MENU but it also gives the capability to
* enable the packager functionality without the rest of the dev tools from RCT_DEV_MENU
*/
#ifndef RCT_ENABLE_LOADING_FROM_PACKAGER
#define RCT_ENABLE_LOADING_FROM_PACKAGER RCT_DEV_MENU
#endif

#ifndef RCT_ENABLE_INSPECTOR
#if RCT_DEV && __has_include(<React/RCTInspectorDevServerHelper.h>)
#define RCT_ENABLE_INSPECTOR 1
Expand All @@ -62,11 +71,11 @@
#endif
#endif

#ifndef ENABLE_PACKAGER_CONNECTION
#ifndef RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
#if RCT_DEV && (__has_include("RCTPackagerConnection.h") || __has_include(<React/RCTPackagerConnection.h>))
#define ENABLE_PACKAGER_CONNECTION 1
#define RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION 1
#else
#define ENABLE_PACKAGER_CONNECTION 0
#define RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION 0
#endif
#endif

Expand Down
12 changes: 6 additions & 6 deletions React/CoreModules/RCTDevSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

static NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu";

#if ENABLE_PACKAGER_CONNECTION
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
#import <React/RCTPackagerClient.h>
#import <React/RCTPackagerConnection.h>
#endif
Expand Down Expand Up @@ -114,14 +114,14 @@ - (void)_reloadWithDefaults:(NSDictionary *)defaultValues

@end

#if ENABLE_PACKAGER_CONNECTION
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
static RCTHandlerToken reloadToken;
static std::atomic<int> numInitializedModules{0};
#endif

@interface RCTDevSettings () <RCTBridgeModule, RCTInvalidating, NativeDevSettingsSpec, RCTDevSettingsInspectable> {
BOOL _isJSLoaded;
#if ENABLE_PACKAGER_CONNECTION
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
RCTHandlerToken _bridgeExecutorOverrideToken;
#endif
}
Expand Down Expand Up @@ -174,7 +174,7 @@ - (instancetype)initWithDataSource:(id<RCTDevSettingsDataSource>)dataSource

- (void)initialize
{
#if ENABLE_PACKAGER_CONNECTION
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
if (self.bridge) {
RCTBridge *__weak weakBridge = self.bridge;
_bridgeExecutorOverrideToken = [[RCTPackagerConnection sharedPackagerConnection]
Expand Down Expand Up @@ -227,7 +227,7 @@ - (dispatch_queue_t)methodQueue
- (void)invalidate
{
[super invalidate];
#if ENABLE_PACKAGER_CONNECTION
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
if (self.bridge) {
[[RCTPackagerConnection sharedPackagerConnection] removeHandler:_bridgeExecutorOverrideToken];
}
Expand Down Expand Up @@ -440,7 +440,7 @@ - (void)setExecutorClass:(Class)executorClass

- (void)addHandler:(id<RCTPackagerClientMethod>)handler forPackagerMethod:(NSString *)name
{
#if ENABLE_PACKAGER_CONNECTION
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
[[RCTPackagerConnection sharedPackagerConnection] addHandler:handler forMethod:name];
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion React/CoreModules/RCTDevSplitBundleLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@interface RCTDevSplitBundleLoader () <NativeDevSplitBundleLoaderSpec>
@end

#if RCT_DEV_MENU
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY

@implementation RCTDevSplitBundleLoader

Expand Down
2 changes: 1 addition & 1 deletion React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ - (void)executeSourceCode:(NSData *)sourceCode sync:(BOOL)sync
[self.devSettings setupHMRClientWithBundleURL:self.bundleURL];
}

#if RCT_DEV_MENU
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
- (void)loadAndExecuteSplitBundleURL:(NSURL *)bundleURL
onError:(RCTLoadAndExecuteErrorBlock)onError
onComplete:(dispatch_block_t)onComplete
Expand Down

0 comments on commit a8cd8f7

Please sign in to comment.