forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 126
/
RCTBundleURLProvider.h
184 lines (157 loc) · 7.47 KB
/
RCTBundleURLProvider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* 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.
*/
#import <Foundation/Foundation.h>
#import "RCTDefines.h"
RCT_EXTERN NSString *const RCTBundleURLProviderUpdatedNotification;
RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort;
#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
* by calling this function before initializing React Native (RCTBridge etc).
* By default the access is enabled.
*/
RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
#endif
#if !TARGET_OS_OSX // [macOS]
static NSString *const kRCTPlatformName = @"ios";
#else // [macOS
static NSString *const kRCTPlatformName = @"macos";
#endif // macOS] // [macOS]
@interface RCTBundleURLProvider : NSObject
/**
* Reset every settings to default.
*/
- (void)resetToDefaults;
/**
* Return the server host. If its a development build and there's no jsLocation defined,
* it will return the server host IP address
*/
- (NSString *)packagerServerHost;
/**
* Return the server host with optional port. If its a development build and there's no jsLocation defined,
* it will return the server host IP address
*/
- (NSString *)packagerServerHostPort;
/**
* Returns if there's a packager running at the given host port.
* The port is optional, if not specified, kRCTBundleURLProviderDefaultPort will be used
*/
+ (BOOL)isPackagerRunning:(NSString *)hostPort;
/**
* Returns if there's a packager running at the given scheme://host:port.
* The port is optional, if not specified, kRCTBundleURLProviderDefaultPort will be used
* The scheme is also optional, if not specified, a default http protocol will be used
*/
+ (BOOL)isPackagerRunning:(NSString *)hostPort scheme:(NSString *)scheme;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(NSURL * (^)(void))fallbackURLProvider;
/**
* Returns the jsBundleURL for a given split bundle entrypoint in development
*/
- (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
* if extension is nil, "jsbundle" will be used.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *)extension;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle. If extension is nil,
* "jsbundle" will be used.
*/
- (NSURL *)jsBundleURLForFallbackExtension:(NSString *)extension;
/**
* Returns the resourceURL for a given bundle entrypoint and
* the fallback offline resource file if the packager is not running.
*/
- (NSURL *)resourceURLForResourceRoot:(NSString *)root
resourceName:(NSString *)name
resourceExtension:(NSString *)extension
offlineBundle:(NSBundle *)offlineBundle;
/**
* The IP address or hostname of the packager.
*/
@property (nonatomic, copy) NSString *jsLocation;
@property (nonatomic, assign) BOOL enableMinification;
@property (nonatomic, assign) BOOL enableDev;
@property (nonatomic, assign) BOOL inlineSourceMap;
/**
* The scheme/protocol used of the packager, the default is the http protocol
*/
@property (nonatomic, copy) NSString *packagerScheme;
+ (instancetype)sharedSettings;
/**
* Given a hostname for the packager and a bundle root, returns the URL to the js bundle. Generally you should use the
* instance method -jsBundleURLForBundleRoot:fallbackResource: which includes logic to guess if the packager is running
* and fall back to a pre-packaged bundle if it is not.
*
* The options here mirror some of Metro's Bundling Options:
* - enableDev: Whether to keep or remove `__DEV__` blocks from the bundle.
* - enableMinification: Enables or disables minification. Usually production bundles are minified and development
* bundles are not.
* - modulesOnly: When true, will only send module definitions without polyfills and without the require-runtime.
* - runModule: When true, will run the main module after defining all modules. This is used in the main bundle but not
* in split bundles.
*/
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
__deprecated_msg(
"Use `jsBundleURLForBundleRoot:packagerHost:enableDev:enableMinification:inlineSourceMap:` instead");
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
packagerScheme:(NSString *)scheme
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
modulesOnly:(BOOL)modulesOnly
runModule:(BOOL)runModule
__deprecated_msg(
"Use jsBundleURLForBundleRoot:packagerHost:enableDev:enableMinification:inlineSourceMap:modulesOnly:runModule:` instead");
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
inlineSourceMap:(BOOL)inlineSourceMap;
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
packagerScheme:(NSString *)scheme
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
inlineSourceMap:(BOOL)inlineSourceMap
modulesOnly:(BOOL)modulesOnly
runModule:(BOOL)runModule;
/**
* Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
* In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged
* resource if it is not: -resourceURLForResourceRoot:resourceName:resourceExtension:offlineBundle:
*/
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
packagerHost:(NSString *)packagerHost
scheme:(NSString *)scheme
query:(NSString *)query
__deprecated_msg("Use version with queryItems parameter instead");
/**
* Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
* In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged
* resource if it is not: -resourceURLForResourceRoot:resourceName:resourceExtension:offlineBundle:
*/
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
packagerHost:(NSString *)packagerHost
scheme:(NSString *)scheme
queryItems:(NSArray<NSURLQueryItem *> *)queryItems;
@end