@bravemobile/react-native-code-push 12.4.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@
4
4
  import childProcess from "child_process";
5
5
  import fs from "fs";
6
6
  import path from "path";
7
+ import { createRequire } from "node:module";
7
8
  import shell from "shelljs";
8
9
  /**
9
10
  * Run Hermes compile CLI command
@@ -12,9 +13,10 @@ import shell from "shelljs";
12
13
  * @param outputPath {string} Path to output .hbc file
13
14
  * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
14
15
  * @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
16
+ * @param projectRoot {string} Root directory of the target app project used to resolve the app's React Native module and locate the matching Hermes compiler. Defaults to the current working directory.
15
17
  * @return {Promise<void>}
16
18
  */
17
- export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcemapOutput, extraHermesFlags = []) {
19
+ export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcemapOutput, extraHermesFlags = [], projectRoot = process.cwd()) {
18
20
  const hermesArgs = [
19
21
  '-emit-binary',
20
22
  '-out',
@@ -28,7 +30,7 @@ export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcem
28
30
  console.log('Converting JS bundle to byte code via Hermes, running command:\n');
29
31
  return new Promise((resolve, reject) => {
30
32
  try {
31
- const hermesCommand = getHermesCommand();
33
+ const hermesCommand = getHermesCommand(projectRoot);
32
34
  const disableAllWarningsArg = '-w';
33
35
  shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
34
36
  // Copy HBC bundle to overwrite JS bundle
@@ -47,7 +49,7 @@ export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcem
47
49
  return;
48
50
  }
49
51
  // compose-source-maps.js file path
50
- const composeSourceMapsPath = getComposeSourceMapsPath();
52
+ const composeSourceMapsPath = getComposeSourceMapsPath(projectRoot);
51
53
  if (composeSourceMapsPath === null) {
52
54
  throw new Error('react-native compose-source-maps.js scripts is not found');
53
55
  }
@@ -87,7 +89,7 @@ export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcem
87
89
  });
88
90
  });
89
91
  }
90
- function getHermesCommand() {
92
+ function getHermesCommand(projectRoot) {
91
93
  const fileExists = (file) => {
92
94
  try {
93
95
  return fs.statSync(file).isFile();
@@ -96,7 +98,7 @@ function getHermesCommand() {
96
98
  return false;
97
99
  }
98
100
  };
99
- const hermescExecutable = path.join(getHermesCompilerPath(), getHermesOSBin(), getHermesOSExe());
101
+ const hermescExecutable = path.join(getHermesCompilerPath(projectRoot), getHermesOSBin(), getHermesOSExe());
100
102
  if (fileExists(hermescExecutable)) {
101
103
  return hermescExecutable;
102
104
  }
@@ -124,45 +126,67 @@ function getHermesOSExe() {
124
126
  return hermesExecutableName;
125
127
  }
126
128
  }
127
- function getComposeSourceMapsPath() {
129
+ function getComposeSourceMapsPath(projectRoot) {
128
130
  // detect if compose-source-maps.js script exists
129
- const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
131
+ const composeSourceMaps = path.join(getReactNativePackagePath(projectRoot), 'scripts', 'compose-source-maps.js');
130
132
  if (fs.existsSync(composeSourceMaps)) {
131
133
  return composeSourceMaps;
132
134
  }
133
135
  return null;
134
136
  }
135
- function getReactNativePackagePath() {
136
- const result = childProcess.spawnSync('node', [
137
- '--print',
138
- "require.resolve('react-native/package.json')",
139
- ]);
140
- const packagePath = path.dirname(result.stdout.toString());
141
- if (result.status === 0 && directoryExistsSync(packagePath)) {
137
+ function getReactNativePackagePath(projectRoot) {
138
+ const packagePath = resolvePackageRoot(projectRoot, 'react-native');
139
+ if (packagePath !== null) {
142
140
  return packagePath;
143
141
  }
144
- return path.join('node_modules', 'react-native');
142
+ return path.join(projectRoot, 'node_modules', 'react-native');
145
143
  }
146
- function getHermescDirPathInHermesCompilerPackage() {
147
- const result = childProcess.spawnSync('node', [
148
- '--print',
149
- "require.resolve('hermes-compiler/package.json')",
150
- ]);
151
- const packagePath = path.dirname(result.stdout.toString());
152
- const hermescDirPath = path.join(packagePath, 'hermesc');
153
- if (result.status === 0 && directoryExistsSync(hermescDirPath)) {
144
+ function getHermescDirPathInHermesCompilerPackage(projectRoot) {
145
+ const reactNativePackagePath = getReactNativePackagePath(projectRoot);
146
+ const hermescDirPath = path.join(path.dirname(reactNativePackagePath), 'hermes-compiler', 'hermesc');
147
+ if (directoryExistsSync(hermescDirPath)) {
154
148
  return hermescDirPath;
155
149
  }
156
150
  return null;
157
151
  }
158
- function getHermesCompilerPath() {
159
- const hermescDirPath = getHermescDirPathInHermesCompilerPackage();
152
+ function getHermesCompilerPath(projectRoot) {
153
+ const hermescDirPath = getHermescDirPathInHermesCompilerPackage(projectRoot);
160
154
  if (hermescDirPath) {
161
155
  // Since react-native 0.83, Hermes compiler executables are in 'hermes-compiler' package
162
156
  return hermescDirPath;
163
157
  }
164
158
  else {
165
- return path.join(getReactNativePackagePath(), 'sdks', 'hermesc');
159
+ return path.join(getReactNativePackagePath(projectRoot), 'sdks', 'hermesc');
160
+ }
161
+ }
162
+ function resolvePackageRoot(projectRoot, packageName) {
163
+ try {
164
+ const projectRequire = createRequire(path.join(projectRoot, 'package.json'));
165
+ const resolvedPath = projectRequire.resolve(packageName);
166
+ return findPackageRoot(packageName, resolvedPath);
167
+ }
168
+ catch {
169
+ return null;
170
+ }
171
+ }
172
+ function findPackageRoot(packageName, resolvedPath) {
173
+ let currentPath = path.dirname(resolvedPath);
174
+ while (true) {
175
+ const packageJsonPath = path.join(currentPath, 'package.json');
176
+ try {
177
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
178
+ if (packageJson.name === packageName) {
179
+ return currentPath;
180
+ }
181
+ }
182
+ catch {
183
+ // Continue traversing upward until the package root is found.
184
+ }
185
+ const parentPath = path.dirname(currentPath);
186
+ if (parentPath === currentPath) {
187
+ return null;
188
+ }
189
+ currentPath = parentPath;
166
190
  }
167
191
  }
168
192
  function directoryExistsSync(dirname) {
@@ -5,6 +5,7 @@
5
5
  import childProcess from "child_process";
6
6
  import fs from "fs";
7
7
  import path from "path";
8
+ import { createRequire } from "node:module";
8
9
  import shell from "shelljs";
9
10
 
10
11
  /**
@@ -14,6 +15,7 @@ import shell from "shelljs";
14
15
  * @param outputPath {string} Path to output .hbc file
15
16
  * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
16
17
  * @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
18
+ * @param projectRoot {string} Root directory of the target app project used to resolve the app's React Native module and locate the matching Hermes compiler. Defaults to the current working directory.
17
19
  * @return {Promise<void>}
18
20
  */
19
21
  export async function runHermesEmitBinaryCommand(
@@ -21,6 +23,7 @@ export async function runHermesEmitBinaryCommand(
21
23
  outputPath: string,
22
24
  sourcemapOutput: string,
23
25
  extraHermesFlags: string[] = [],
26
+ projectRoot: string = process.cwd(),
24
27
  ): Promise<void> {
25
28
  const hermesArgs: string[] = [
26
29
  '-emit-binary',
@@ -37,7 +40,7 @@ export async function runHermesEmitBinaryCommand(
37
40
 
38
41
  return new Promise<void>((resolve, reject) => {
39
42
  try {
40
- const hermesCommand = getHermesCommand();
43
+ const hermesCommand = getHermesCommand(projectRoot);
41
44
 
42
45
  const disableAllWarningsArg = '-w';
43
46
  shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
@@ -58,7 +61,7 @@ export async function runHermesEmitBinaryCommand(
58
61
  }
59
62
 
60
63
  // compose-source-maps.js file path
61
- const composeSourceMapsPath = getComposeSourceMapsPath();
64
+ const composeSourceMapsPath = getComposeSourceMapsPath(projectRoot);
62
65
  if (composeSourceMapsPath === null) {
63
66
  throw new Error('react-native compose-source-maps.js scripts is not found');
64
67
  }
@@ -106,7 +109,7 @@ export async function runHermesEmitBinaryCommand(
106
109
  });
107
110
  }
108
111
 
109
- function getHermesCommand(): string {
112
+ function getHermesCommand(projectRoot: string): string {
110
113
  const fileExists = (file: string): boolean => {
111
114
  try {
112
115
  return fs.statSync(file).isFile();
@@ -115,7 +118,7 @@ function getHermesCommand(): string {
115
118
  }
116
119
  };
117
120
 
118
- const hermescExecutable = path.join(getHermesCompilerPath(), getHermesOSBin(), getHermesOSExe());
121
+ const hermescExecutable = path.join(getHermesCompilerPath(projectRoot), getHermesOSBin(), getHermesOSExe());
119
122
  if (fileExists(hermescExecutable)) {
120
123
  return hermescExecutable;
121
124
  }
@@ -146,48 +149,75 @@ function getHermesOSExe(): string {
146
149
  }
147
150
  }
148
151
 
149
- function getComposeSourceMapsPath(): string | null {
152
+ function getComposeSourceMapsPath(projectRoot: string): string | null {
150
153
  // detect if compose-source-maps.js script exists
151
- const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
154
+ const composeSourceMaps = path.join(getReactNativePackagePath(projectRoot), 'scripts', 'compose-source-maps.js');
152
155
  if (fs.existsSync(composeSourceMaps)) {
153
156
  return composeSourceMaps;
154
157
  }
155
158
  return null;
156
159
  }
157
160
 
158
- function getReactNativePackagePath(): string {
159
- const result = childProcess.spawnSync('node', [
160
- '--print',
161
- "require.resolve('react-native/package.json')",
162
- ]);
163
- const packagePath = path.dirname(result.stdout.toString());
164
- if (result.status === 0 && directoryExistsSync(packagePath)) {
161
+ function getReactNativePackagePath(projectRoot: string): string {
162
+ const packagePath = resolvePackageRoot(projectRoot, 'react-native');
163
+ if (packagePath !== null) {
165
164
  return packagePath;
166
165
  }
167
166
 
168
- return path.join('node_modules', 'react-native');
167
+ return path.join(projectRoot, 'node_modules', 'react-native');
169
168
  }
170
169
 
171
- function getHermescDirPathInHermesCompilerPackage() {
172
- const result = childProcess.spawnSync('node', [
173
- '--print',
174
- "require.resolve('hermes-compiler/package.json')",
175
- ]);
176
- const packagePath = path.dirname(result.stdout.toString());
177
- const hermescDirPath = path.join(packagePath, 'hermesc');
178
- if (result.status === 0 && directoryExistsSync(hermescDirPath)) {
170
+ function getHermescDirPathInHermesCompilerPackage(projectRoot: string) {
171
+ const reactNativePackagePath = getReactNativePackagePath(projectRoot);
172
+ const hermescDirPath = path.join(path.dirname(reactNativePackagePath), 'hermes-compiler', 'hermesc');
173
+
174
+ if (directoryExistsSync(hermescDirPath)) {
179
175
  return hermescDirPath;
180
176
  }
177
+
181
178
  return null;
182
179
  }
183
180
 
184
- function getHermesCompilerPath() {
185
- const hermescDirPath = getHermescDirPathInHermesCompilerPackage();
181
+ function getHermesCompilerPath(projectRoot: string) {
182
+ const hermescDirPath = getHermescDirPathInHermesCompilerPackage(projectRoot);
186
183
  if (hermescDirPath) {
187
184
  // Since react-native 0.83, Hermes compiler executables are in 'hermes-compiler' package
188
185
  return hermescDirPath
189
186
  } else {
190
- return path.join(getReactNativePackagePath(), 'sdks', 'hermesc');
187
+ return path.join(getReactNativePackagePath(projectRoot), 'sdks', 'hermesc');
188
+ }
189
+ }
190
+
191
+ function resolvePackageRoot(projectRoot: string, packageName: string): string | null {
192
+ try {
193
+ const projectRequire = createRequire(path.join(projectRoot, 'package.json'));
194
+ const resolvedPath = projectRequire.resolve(packageName);
195
+ return findPackageRoot(packageName, resolvedPath);
196
+ } catch {
197
+ return null;
198
+ }
199
+ }
200
+
201
+ function findPackageRoot(packageName: string, resolvedPath: string): string | null {
202
+ let currentPath = path.dirname(resolvedPath);
203
+
204
+ while (true) {
205
+ const packageJsonPath = path.join(currentPath, 'package.json');
206
+
207
+ try {
208
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { name?: string };
209
+ if (packageJson.name === packageName) {
210
+ return currentPath;
211
+ }
212
+ } catch {
213
+ // Continue traversing upward until the package root is found.
214
+ }
215
+
216
+ const parentPath = path.dirname(currentPath);
217
+ if (parentPath === currentPath) {
218
+ return null;
219
+ }
220
+ currentPath = parentPath;
191
221
  }
192
222
  }
193
223
 
@@ -1,14 +1,40 @@
1
- #if __has_include(<React/RCTEventEmitter.h>)
2
- #import <React/RCTEventEmitter.h>
3
- #elif __has_include("RCTEventEmitter.h")
4
- #import "RCTEventEmitter.h"
1
+ #import <Foundation/Foundation.h>
2
+
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+ #if defined(__cplusplus)
5
+ #if __has_include(<RNCodePushSpec/RNCodePushSpec.h>)
6
+ #import <RNCodePushSpec/RNCodePushSpec.h>
7
+ #elif __has_include("RNCodePushSpec.h")
8
+ #import "RNCodePushSpec.h"
9
+ #endif
10
+ #else
11
+ #if __has_include(<React/RCTBridgeModule.h>)
12
+ #import <React/RCTBridgeModule.h>
13
+ #elif __has_include("RCTBridgeModule.h")
14
+ #import "RCTBridgeModule.h"
15
+ #else
16
+ #import "React/RCTBridgeModule.h"
17
+ #endif
18
+ #endif
5
19
  #else
6
- #import "React/RCTEventEmitter.h" // Required when used as a Pod in a Swift project
20
+ #if __has_include(<React/RCTEventEmitter.h>)
21
+ #import <React/RCTEventEmitter.h>
22
+ #elif __has_include("RCTEventEmitter.h")
23
+ #import "RCTEventEmitter.h"
24
+ #else
25
+ #import "React/RCTEventEmitter.h" // Required when used as a Pod in a Swift project
26
+ #endif
7
27
  #endif
8
28
 
9
- #import <Foundation/Foundation.h>
10
-
29
+ #ifdef RCT_NEW_ARCH_ENABLED
30
+ #if defined(__cplusplus)
31
+ @interface CodePush : NativeCodePushSpecBase
32
+ #else
33
+ @interface CodePush : NSObject <RCTBridgeModule>
34
+ #endif
35
+ #else
11
36
  @interface CodePush : RCTEventEmitter
37
+ #endif
12
38
 
13
39
  + (NSURL *)binaryBundleURL;
14
40
  /*
@@ -68,7 +94,7 @@
68
94
  * This information will be used to decide whether the application
69
95
  * should ignore the update or not.
70
96
  */
71
- + (NSDictionary*)getRollbackInfo;
97
+ + (NSDictionary*)getLatestRollbackInfo;
72
98
  /*
73
99
  * This method is used to save information about the latest rollback.
74
100
  * This information will be used to decide whether the application
@@ -203,7 +229,13 @@ failCallback:(void (^)(NSError *err))failCallback;
203
229
 
204
230
  @end
205
231
 
232
+ #if defined(__cplusplus)
233
+ extern "C" {
234
+ #endif
206
235
  void CPLog(NSString *formatString, ...);
236
+ #if defined(__cplusplus)
237
+ }
238
+ #endif
207
239
 
208
240
  typedef NS_ENUM(NSInteger, CodePushInstallMode) {
209
241
  CodePushInstallModeImmediate,
@@ -8,7 +8,11 @@
8
8
 
9
9
  #import "CodePush.h"
10
10
 
11
- @interface CodePush () <RCTBridgeModule, RCTFrameUpdateObserver>
11
+ @interface CodePush () <RCTFrameUpdateObserver
12
+ #ifdef RCT_NEW_ARCH_ENABLED
13
+ , NativeCodePushSpec
14
+ #endif
15
+ >
12
16
  @end
13
17
 
14
18
  @implementation CodePush {
@@ -62,6 +66,7 @@ static NSString *const PackageIsPendingKey = @"isPending";
62
66
  static BOOL isRunningBinaryVersion = NO;
63
67
  static BOOL needToReportRollback = NO;
64
68
  static BOOL testConfigurationFlag = NO;
69
+ static BOOL hasInitializedUpdateAfterRestartForCurrentLoad = NO;
65
70
 
66
71
  // These values are used to save the NS bundle, name, extension and subdirectory
67
72
  // for the JS bundle in the binary.
@@ -246,6 +251,9 @@ static NSString *const LatestRollbackCountKey = @"count";
246
251
 
247
252
  #pragma mark - Private API methods
248
253
 
254
+ #ifdef RCT_NEW_ARCH_ENABLED
255
+ @synthesize bridge = _bridge;
256
+ #endif
249
257
  @synthesize methodQueue = _methodQueue;
250
258
  @synthesize pauseCallback = _pauseCallback;
251
259
  @synthesize paused = _paused;
@@ -269,7 +277,7 @@ static NSString *const LatestRollbackCountKey = @"count";
269
277
  - (void)clearDebugUpdates
270
278
  {
271
279
  dispatch_async(dispatch_get_main_queue(), ^{
272
- if ([super.bridge.bundleURL.scheme hasPrefix:@"http"]) {
280
+ if ([self.bridge.bundleURL.scheme hasPrefix:@"http"]) {
273
281
  NSError *error;
274
282
  NSString *binaryAppVersion = [[CodePushConfig current] appVersion];
275
283
  NSDictionary *currentPackageMetadata = [CodePushPackage getCurrentPackage:&error];
@@ -283,28 +291,6 @@ static NSString *const LatestRollbackCountKey = @"count";
283
291
  });
284
292
  }
285
293
 
286
- /*
287
- * This method is used by the React Native bridge to allow
288
- * our plugin to expose constants to the JS-side. In our case
289
- * we're simply exporting enum values so that the JS and Native
290
- * sides of the plugin can be in sync.
291
- */
292
- - (NSDictionary *)constantsToExport
293
- {
294
- // Export the values of the CodePushInstallMode and CodePushUpdateState
295
- // enums so that the script-side can easily stay in sync
296
- return @{
297
- @"codePushInstallModeOnNextRestart":@(CodePushInstallModeOnNextRestart),
298
- @"codePushInstallModeImmediate": @(CodePushInstallModeImmediate),
299
- @"codePushInstallModeOnNextResume": @(CodePushInstallModeOnNextResume),
300
- @"codePushInstallModeOnNextSuspend": @(CodePushInstallModeOnNextSuspend),
301
-
302
- @"codePushUpdateStateRunning": @(CodePushUpdateStateRunning),
303
- @"codePushUpdateStatePending": @(CodePushUpdateStatePending),
304
- @"codePushUpdateStateLatest": @(CodePushUpdateStateLatest)
305
- };
306
- };
307
-
308
294
  + (BOOL)requiresMainQueueSetup
309
295
  {
310
296
  return YES;
@@ -319,13 +305,16 @@ static NSString *const LatestRollbackCountKey = @"count";
319
305
 
320
306
  - (void)dispatchDownloadProgressEvent {
321
307
  // Notify the script-side about the progress
322
- [self sendEventWithName:DownloadProgressEvent
323
- body:@{
324
- @"totalBytes" : [NSNumber
325
- numberWithLongLong:_latestExpectedContentLength],
326
- @"receivedBytes" : [NSNumber
327
- numberWithLongLong:_latestReceivedConentLength]
328
- }];
308
+ NSDictionary *progress = @{
309
+ @"totalBytes" : [NSNumber numberWithLongLong:_latestExpectedContentLength],
310
+ @"receivedBytes" : [NSNumber numberWithLongLong:_latestReceivedConentLength]
311
+ };
312
+
313
+ #ifndef RCT_NEW_ARCH_ENABLED
314
+ [self sendEventWithName:DownloadProgressEvent body:progress];
315
+ #else
316
+ [self emitOnDownloadProgress:progress];
317
+ #endif
329
318
  }
330
319
 
331
320
  - (void)dispatchThrottledDownloadProgressEventWithForce:(BOOL)force
@@ -385,7 +374,12 @@ static NSString *const LatestRollbackCountKey = @"count";
385
374
 
386
375
  self = [super init];
387
376
  if (self) {
388
- [self initializeUpdateAfterRestart];
377
+ @synchronized([CodePush class]) {
378
+ if (!hasInitializedUpdateAfterRestartForCurrentLoad) {
379
+ hasInitializedUpdateAfterRestartForCurrentLoad = YES;
380
+ [self initializeUpdateAfterRestart];
381
+ }
382
+ }
389
383
  }
390
384
 
391
385
  return self;
@@ -535,6 +529,10 @@ static NSString *const LatestRollbackCountKey = @"count";
535
529
  */
536
530
  - (void)loadBundle
537
531
  {
532
+ @synchronized([CodePush class]) {
533
+ hasInitializedUpdateAfterRestartForCurrentLoad = NO;
534
+ }
535
+
538
536
  // This needs to be async dispatched because the bridge is not set on init
539
537
  // when the app first starts, therefore rollbacks will not take effect.
540
538
  dispatch_async(dispatch_get_main_queue(), ^{
@@ -542,8 +540,8 @@ static NSString *const LatestRollbackCountKey = @"count";
542
540
  // is debugging and therefore, shouldn't be redirected to a local
543
541
  // file (since Chrome wouldn't support it). Otherwise, update
544
542
  // the current bundle URL to point at the latest update
545
- if ([CodePush isUsingTestConfiguration] || ![super.bridge.bundleURL.scheme hasPrefix:@"http"]) {
546
- [super.bridge setValue:[CodePush bundleURL] forKey:@"bundleURL"];
543
+ if ([CodePush isUsingTestConfiguration] || ![self.bridge.bundleURL.scheme hasPrefix:@"http"]) {
544
+ [self.bridge setValue:[CodePush bundleURL] forKey:@"bundleURL"];
547
545
  }
548
546
 
549
547
  RCTTriggerReloadCommandListeners(@"CodePush reload");
@@ -713,8 +711,8 @@ static NSString *const LatestRollbackCountKey = @"count";
713
711
  */
714
712
  RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
715
713
  notifyProgress:(BOOL)notifyProgress
716
- resolver:(RCTPromiseResolveBlock)resolve
717
- rejecter:(RCTPromiseRejectBlock)reject)
714
+ resolve:(RCTPromiseResolveBlock)resolve
715
+ reject:(RCTPromiseRejectBlock)reject)
718
716
  {
719
717
  NSDictionary *mutableUpdatePackage = [updatePackage mutableCopy];
720
718
  NSURL *binaryBundleURL = [CodePush binaryBundleURL];
@@ -813,7 +811,7 @@ RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
813
811
  * app version, as well as the deployment key that was configured in the Info.plist file.
814
812
  */
815
813
  RCT_EXPORT_METHOD(getConfiguration:(RCTPromiseResolveBlock)resolve
816
- rejecter:(RCTPromiseRejectBlock)reject)
814
+ reject:(RCTPromiseRejectBlock)reject)
817
815
  {
818
816
  NSDictionary *configuration = [[CodePushConfig current] configuration];
819
817
  NSError *error;
@@ -846,10 +844,11 @@ RCT_EXPORT_METHOD(getConfiguration:(RCTPromiseResolveBlock)resolve
846
844
  /*
847
845
  * This method is the native side of the CodePush.getUpdateMetadata method.
848
846
  */
849
- RCT_EXPORT_METHOD(getUpdateMetadata:(CodePushUpdateState)updateState
850
- resolver:(RCTPromiseResolveBlock)resolve
851
- rejecter:(RCTPromiseRejectBlock)reject)
847
+ RCT_EXPORT_METHOD(getUpdateMetadata:(double)updateStateValue
848
+ resolve:(RCTPromiseResolveBlock)resolve
849
+ reject:(RCTPromiseRejectBlock)reject)
852
850
  {
851
+ CodePushUpdateState updateState = (CodePushUpdateState)updateStateValue;
853
852
  NSError *error;
854
853
  NSMutableDictionary *package = [[CodePushPackage getCurrentPackage:&error] mutableCopy];
855
854
 
@@ -895,11 +894,13 @@ RCT_EXPORT_METHOD(getUpdateMetadata:(CodePushUpdateState)updateState
895
894
  * This method is the native side of the LocalPackage.install method.
896
895
  */
897
896
  RCT_EXPORT_METHOD(installUpdate:(NSDictionary*)updatePackage
898
- installMode:(CodePushInstallMode)installMode
899
- minimumBackgroundDuration:(int)minimumBackgroundDuration
900
- resolver:(RCTPromiseResolveBlock)resolve
901
- rejecter:(RCTPromiseRejectBlock)reject)
897
+ installMode:(double)installModeValue
898
+ minimumBackgroundDuration:(double)minimumBackgroundDurationValue
899
+ resolve:(RCTPromiseResolveBlock)resolve
900
+ reject:(RCTPromiseRejectBlock)reject)
902
901
  {
902
+ CodePushInstallMode installMode = (CodePushInstallMode)installModeValue;
903
+ int minimumBackgroundDuration = (int)minimumBackgroundDurationValue;
903
904
  NSError *error;
904
905
  [CodePushPackage installPackage:updatePackage
905
906
  removePendingUpdate:[[self class] isPendingUpdate:nil]
@@ -965,7 +966,7 @@ RCT_EXPORT_METHOD(setLatestRollbackInfo:(NSString *)packageHash
965
966
 
966
967
 
967
968
  RCT_EXPORT_METHOD(getLatestRollbackInfo:(RCTPromiseResolveBlock)resolve
968
- rejecter:(RCTPromiseRejectBlock)reject)
969
+ reject:(RCTPromiseRejectBlock)reject)
969
970
  {
970
971
  NSDictionary *latestRollbackInfo = [[self class] getLatestRollbackInfo];
971
972
  resolve(latestRollbackInfo);
@@ -977,7 +978,7 @@ RCT_EXPORT_METHOD(getLatestRollbackInfo:(RCTPromiseResolveBlock)resolve
977
978
  */
978
979
  RCT_EXPORT_METHOD(isFirstRun:(NSString *)packageHash
979
980
  resolve:(RCTPromiseResolveBlock)resolve
980
- rejecter:(RCTPromiseRejectBlock)reject)
981
+ reject:(RCTPromiseRejectBlock)reject)
981
982
  {
982
983
  NSError *error;
983
984
  BOOL isFirstRun = _isFirstRunAfterUpdate
@@ -992,14 +993,13 @@ RCT_EXPORT_METHOD(isFirstRun:(NSString *)packageHash
992
993
  * This method is the native side of the CodePush.notifyApplicationReady() method.
993
994
  */
994
995
  RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve
995
- rejecter:(RCTPromiseRejectBlock)reject)
996
+ reject:(RCTPromiseRejectBlock)reject)
996
997
  {
997
998
  [CodePush removePendingUpdate];
998
999
  resolve(nil);
999
1000
  }
1000
1001
 
1001
- RCT_EXPORT_METHOD(allow:(RCTPromiseResolveBlock)resolve
1002
- rejecter:(RCTPromiseRejectBlock)reject)
1002
+ RCT_EXPORT_METHOD(allow)
1003
1003
  {
1004
1004
  CPLog(@"Re-allowing restarts.");
1005
1005
  _allowed = YES;
@@ -1010,34 +1010,25 @@ RCT_EXPORT_METHOD(allow:(RCTPromiseResolveBlock)resolve
1010
1010
  [_restartQueue removeObjectAtIndex:0];
1011
1011
  [self restartAppInternal:buf];
1012
1012
  }
1013
-
1014
- resolve(nil);
1015
1013
  }
1016
1014
 
1017
- RCT_EXPORT_METHOD(clearPendingRestart:(RCTPromiseResolveBlock)resolve
1018
- rejecter:(RCTPromiseRejectBlock)reject)
1015
+ RCT_EXPORT_METHOD(clearPendingRestart)
1019
1016
  {
1020
1017
  [_restartQueue removeAllObjects];
1021
- resolve(nil);
1022
1018
  }
1023
1019
 
1024
- RCT_EXPORT_METHOD(disallow:(RCTPromiseResolveBlock)resolve
1025
- rejecter:(RCTPromiseRejectBlock)reject)
1020
+ RCT_EXPORT_METHOD(disallow)
1026
1021
  {
1027
1022
  CPLog(@"Disallowing restarts.");
1028
1023
  _allowed = NO;
1029
- resolve(nil);
1030
1024
  }
1031
1025
 
1032
1026
  /*
1033
1027
  * This method is the native side of the CodePush.restartApp() method.
1034
1028
  */
1035
- RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending
1036
- resolve:(RCTPromiseResolveBlock)resolve
1037
- rejecter:(RCTPromiseRejectBlock)reject)
1029
+ RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending)
1038
1030
  {
1039
1031
  [self restartAppInternal:onlyIfUpdateIsPending];
1040
- resolve(nil);
1041
1032
  }
1042
1033
 
1043
1034
  /*
@@ -1071,7 +1062,7 @@ RCT_EXPORT_METHOD(downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl)
1071
1062
  * or an update failed) and return its details (version label, status).
1072
1063
  */
1073
1064
  RCT_EXPORT_METHOD(getNewStatusReport:(RCTPromiseResolveBlock)resolve
1074
- rejecter:(RCTPromiseRejectBlock)reject)
1065
+ reject:(RCTPromiseRejectBlock)reject)
1075
1066
  {
1076
1067
  if (needToReportRollback) {
1077
1068
  needToReportRollback = NO;
@@ -1128,4 +1119,12 @@ RCT_EXPORT_METHOD(saveStatusReportForRetry:(NSDictionary *)statusReport)
1128
1119
  _didUpdateProgress = NO;
1129
1120
  }
1130
1121
 
1122
+ #ifdef RCT_NEW_ARCH_ENABLED
1123
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
1124
+ (const facebook::react::ObjCTurboModule::InitParams &)params
1125
+ {
1126
+ return std::make_shared<facebook::react::NativeCodePushSpecJSI>(params);
1127
+ }
1128
+ #endif
1129
+
1131
1130
  @end