@srcpush/react-native-code-push 1.0.3-beta → 1.0.3-feat-new-architecture.1

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.
package/CodePush.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk";
2
2
  import { Alert } from "./AlertAdapter";
3
3
  import requestFetchAdapter from "./request-fetch-adapter";
4
- import { AppState, Platform } from "react-native";
4
+ import { AppState, Platform, TurboModuleRegistry } from "react-native";
5
5
  import log from "./logging";
6
6
  import hoistStatics from 'hoist-non-react-statics';
7
7
 
8
- let NativeCodePush = require("react-native").NativeModules.CodePush;
8
+ let NativeCodePush = (TurboModuleRegistry?.get('CodePush')) || require("react-native").NativeModules.CodePush;
9
9
  const PackageMixins = require("./package-mixins")(NativeCodePush);
10
10
 
11
11
  async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchCallback = null) {
@@ -40,6 +40,16 @@ android {
40
40
  defaultConfig {
41
41
  consumerProguardFiles 'proguard-rules.pro'
42
42
  }
43
+
44
+ sourceSets {
45
+ main {
46
+ if (IS_NEW_ARCHITECTURE_ENABLED) {
47
+ java.srcDirs += ['src/newarch/java']
48
+ } else {
49
+ java.srcDirs += ['src/oldarch/java']
50
+ }
51
+ }
52
+ }
43
53
  }
44
54
 
45
55
  dependencies {
@@ -46,7 +46,7 @@ import java.util.Map;
46
46
  import java.util.UUID;
47
47
 
48
48
  @OptIn(markerClass = UnstableReactNativeAPI.class)
49
- public class CodePushNativeModule extends BaseJavaModule {
49
+ public class CodePushNativeModule extends CodePushNativeModuleSpec {
50
50
  private String mBinaryContentsHash = null;
51
51
  private String mClientUniqueId = null;
52
52
  private LifecycleEventListener mLifecycleEventListener = null;
@@ -82,6 +82,11 @@ public class CodePushNativeModule extends BaseJavaModule {
82
82
 
83
83
  @Override
84
84
  public Map<String, Object> getConstants() {
85
+ return getTypedExportedConstants();
86
+ }
87
+
88
+ @Override
89
+ public Map<String, Object> getTypedExportedConstants() {
85
90
  final Map<String, Object> constants = new HashMap<>();
86
91
 
87
92
  constants.put("codePushInstallModeImmediate", CodePushInstallMode.IMMEDIATE.getValue());
@@ -500,8 +505,9 @@ public class CodePushNativeModule extends BaseJavaModule {
500
505
  }
501
506
  }
502
507
 
508
+ @Override
503
509
  @ReactMethod
504
- public void getUpdateMetadata(final int updateState, final Promise promise) {
510
+ public void getUpdateMetadata(final double updateState, final Promise promise) {
505
511
  AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
506
512
  @Override
507
513
  protected Void doInBackground(Void... params) {
@@ -520,11 +526,11 @@ public class CodePushNativeModule extends BaseJavaModule {
520
526
  currentUpdateIsPending = mSettingsManager.isPendingUpdate(currentHash);
521
527
  }
522
528
 
523
- if (updateState == CodePushUpdateState.PENDING.getValue() && !currentUpdateIsPending) {
529
+ if ((int)updateState == CodePushUpdateState.PENDING.getValue() && !currentUpdateIsPending) {
524
530
  // The caller wanted a pending update
525
531
  // but there isn't currently one.
526
532
  promise.resolve(null);
527
- } else if (updateState == CodePushUpdateState.RUNNING.getValue() && currentUpdateIsPending) {
533
+ } else if ((int)updateState == CodePushUpdateState.RUNNING.getValue() && currentUpdateIsPending) {
528
534
  // The caller wants the running update, but the current
529
535
  // one is pending, so we need to grab the previous.
530
536
  JSONObject previousPackage = mUpdateManager.getPreviousPackage();
@@ -625,8 +631,9 @@ public class CodePushNativeModule extends BaseJavaModule {
625
631
  asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
626
632
  }
627
633
 
634
+ @Override
628
635
  @ReactMethod
629
- public void installUpdate(final ReadableMap updatePackage, final int installMode, final int minimumBackgroundDuration, final Promise promise) {
636
+ public void installUpdate(final ReadableMap updatePackage, final double installMode, final double minimumBackgroundDuration, final Promise promise) {
630
637
  AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
631
638
  @Override
632
639
  protected Void doInBackground(Void... params) {
@@ -640,17 +647,17 @@ public class CodePushNativeModule extends BaseJavaModule {
640
647
  mSettingsManager.savePendingUpdate(pendingHash, /* isLoading */false);
641
648
  }
642
649
 
643
- if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue() ||
650
+ if ((int)installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue() ||
644
651
  // We also add the resume listener if the installMode is IMMEDIATE, because
645
652
  // if the current activity is backgrounded, we want to reload the bundle when
646
653
  // it comes back into the foreground.
647
- installMode == CodePushInstallMode.IMMEDIATE.getValue() ||
648
- installMode == CodePushInstallMode.ON_NEXT_SUSPEND.getValue()) {
654
+ (int)installMode == CodePushInstallMode.IMMEDIATE.getValue() ||
655
+ (int)installMode == CodePushInstallMode.ON_NEXT_SUSPEND.getValue()) {
649
656
 
650
657
  // Store the minimum duration on the native module as an instance
651
658
  // variable instead of relying on a closure below, so that any
652
659
  // subsequent resume-based installs could override it.
653
- CodePushNativeModule.this.mMinimumBackgroundDuration = minimumBackgroundDuration;
660
+ CodePushNativeModule.this.mMinimumBackgroundDuration = (int)minimumBackgroundDuration;
654
661
 
655
662
  if (mLifecycleEventListener == null) {
656
663
  // Ensure we do not add the listener twice.
@@ -672,7 +679,7 @@ public class CodePushNativeModule extends BaseJavaModule {
672
679
  // the foreground, so explicitly wait for it to be backgrounded first
673
680
  if (lastPausedDate != null) {
674
681
  long durationInBackground = (new Date().getTime() - lastPausedDate.getTime()) / 1000;
675
- if (installMode == CodePushInstallMode.IMMEDIATE.getValue()
682
+ if ((int)installMode == CodePushInstallMode.IMMEDIATE.getValue()
676
683
  || durationInBackground >= CodePushNativeModule.this.mMinimumBackgroundDuration) {
677
684
  CodePushUtils.log("Loading bundle on resume");
678
685
  restartAppInternal(false);
@@ -686,8 +693,8 @@ public class CodePushNativeModule extends BaseJavaModule {
686
693
  // resumed, we can detect how long it was in the background.
687
694
  lastPausedDate = new Date();
688
695
 
689
- if (installMode == CodePushInstallMode.ON_NEXT_SUSPEND.getValue() && mSettingsManager.isPendingUpdate(null)) {
690
- appSuspendHandler.postDelayed(loadBundleRunnable, minimumBackgroundDuration * 1000);
696
+ if ((int)installMode == CodePushInstallMode.ON_NEXT_SUSPEND.getValue() && mSettingsManager.isPendingUpdate(null)) {
697
+ appSuspendHandler.postDelayed(loadBundleRunnable, (int)minimumBackgroundDuration * 1000);
691
698
  }
692
699
  }
693
700
 
@@ -700,7 +707,11 @@ public class CodePushNativeModule extends BaseJavaModule {
700
707
  }
701
708
  }
702
709
 
703
- promise.resolve("");
710
+ if ((int)installMode == CodePushInstallMode.IMMEDIATE.getValue()) {
711
+ loadBundle();
712
+ }
713
+
714
+ promise.resolve(null);
704
715
  } catch(CodePushUnknownException e) {
705
716
  CodePushUtils.log(e);
706
717
  promise.reject(e);
@@ -822,13 +833,15 @@ public class CodePushNativeModule extends BaseJavaModule {
822
833
  mCodePush.clearUpdates();
823
834
  }
824
835
 
836
+ @Override
825
837
  @ReactMethod
826
838
  public void addListener(String eventName) {
827
839
  // Set up any upstream listeners or background tasks as necessary
828
840
  }
829
841
 
842
+ @Override
830
843
  @ReactMethod
831
- public void removeListeners(Integer count) {
844
+ public void removeListeners(double count) {
832
845
  // Remove upstream listeners, stop unnecessary background tasks
833
846
  }
834
847
 
@@ -0,0 +1,9 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext;
4
+
5
+ public abstract class CodePushNativeModuleSpec extends NativeRNCodePushSpec {
6
+ public CodePushNativeModuleSpec(ReactApplicationContext reactContext) {
7
+ super(reactContext);
8
+ }
9
+ }
@@ -0,0 +1,34 @@
1
+ package com.microsoft.codepush.react;
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext;
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
+ import com.facebook.react.bridge.Promise;
6
+ import com.facebook.react.bridge.ReadableMap;
7
+
8
+ public abstract class CodePushNativeModuleSpec extends ReactContextBaseJavaModule {
9
+ public CodePushNativeModuleSpec(ReactApplicationContext reactContext) {
10
+ super(reactContext);
11
+ }
12
+
13
+ public abstract void allow(Promise promise);
14
+ public abstract void clearPendingRestart(Promise promise);
15
+ public abstract void disallow(Promise promise);
16
+ public abstract void restartApp(boolean onlyIfUpdateIsPending, Promise promise);
17
+ public abstract void downloadUpdate(ReadableMap updatePackage, boolean notifyProgress, Promise promise);
18
+ public abstract void getConfiguration(Promise promise);
19
+ public abstract void getUpdateMetadata(double updateState, Promise promise);
20
+ public abstract void getNewStatusReport(Promise promise);
21
+ public abstract void installUpdate(ReadableMap updatePackage, double installMode, double minimumBackgroundDuration, Promise promise);
22
+ public abstract void isFailedUpdate(String packageHash, Promise promise);
23
+ public abstract void isFirstRun(String packageHash, Promise promise);
24
+ public abstract void notifyApplicationReady(Promise promise);
25
+ public abstract void recordStatusReported(ReadableMap statusReport);
26
+ public abstract void saveStatusReportForRetry(ReadableMap statusReport);
27
+ public abstract void downloadAndReplaceCurrentBundle(String remoteBundleUrl);
28
+ public abstract void clearUpdates();
29
+ public abstract void getLatestRollbackInfo(Promise promise);
30
+ public abstract void setLatestRollbackInfo(String packageHash, Promise promise);
31
+ public abstract void addListener(String eventName);
32
+ public abstract void removeListeners(double count);
33
+ public abstract java.util.Map<String, Object> getTypedExportedConstants();
34
+ }
package/android/gradlew CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srcpush/react-native-code-push",
3
- "version": "1.0.3-beta",
3
+ "version": "1.0.3-feat-new-architecture.1",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "code-push": "4.2.3",
45
- "glob": "^7.1.7",
45
+ "glob": "^13.0.1",
46
46
  "hoist-non-react-statics": "^3.3.2",
47
47
  "inquirer": "^8.1.5",
48
48
  "plist": "^3.0.4",
@@ -58,7 +58,6 @@
58
58
  "archiver": "latest",
59
59
  "body-parser": "latest",
60
60
  "code-push-plugin-testing-framework": "file:./code-push-plugin-testing-framework",
61
- "del": "v6.0.0",
62
61
  "express": "^5.1.0",
63
62
  "mkdirp": "latest",
64
63
  "mocha": "^11.7.2",
@@ -82,5 +81,13 @@
82
81
  "postlink": "node node_modules/@srcpush/react-native-code-push/scripts/postlink/run",
83
82
  "postunlink": "node node_modules/@srcpush/react-native-code-push/scripts/postunlink/run"
84
83
  }
84
+ },
85
+ "codegenConfig": {
86
+ "name": "RNCodePush",
87
+ "type": "modules",
88
+ "jsSrcsDir": "src",
89
+ "android": {
90
+ "javaPackageName": "com.microsoft.codepush.react"
91
+ }
85
92
  }
86
- }
93
+ }
@@ -0,0 +1,43 @@
1
+ const { execSync } = require('child_process');
2
+ const packageJson = require('../package.json');
3
+
4
+ const branchName = process.argv[2];
5
+ if (!branchName) {
6
+ console.error('Branch name is required');
7
+ process.exit(1);
8
+ }
9
+
10
+ const sanitizedBranch = branchName.replace(/[^a-zA-Z0-9]/g, '-').replace(/^-+|-+$/g, '');
11
+ const baseVersion = packageJson.version;
12
+ const versionPrefix = `${baseVersion}-${sanitizedBranch}`;
13
+
14
+ console.error(`Prefix: ${versionPrefix}`);
15
+
16
+ let versions = [];
17
+ try {
18
+ const stdout = execSync(`npm view ${packageJson.name} versions --json`, { stdio: ['pipe', 'pipe', 'ignore'] }).toString();
19
+ versions = JSON.parse(stdout);
20
+ if (!Array.isArray(versions)) {
21
+ versions = [versions];
22
+ }
23
+ } catch (e) {
24
+ console.error('Package not found or no versions. Starting from 1.');
25
+ }
26
+
27
+ let maxIncrement = 0;
28
+
29
+ versions.forEach(v => {
30
+ if (v.startsWith(versionPrefix)) {
31
+ const suffix = v.slice(versionPrefix.length);
32
+ if (suffix.startsWith('.')) {
33
+ const numStr = suffix.substring(1);
34
+ const num = parseInt(numStr, 10);
35
+ if (!isNaN(num) && num > maxIncrement) {
36
+ maxIncrement = num;
37
+ }
38
+ }
39
+ }
40
+ });
41
+
42
+ const nextVersion = `${versionPrefix}.${maxIncrement + 1}`;
43
+ console.log(nextVersion);
@@ -52,6 +52,6 @@ function findMainApplication() {
52
52
  }
53
53
 
54
54
  var nameParts = appName.split('.');
55
- var searchPath = glob.sync("**/" + nameParts[nameParts.length - 1] + ".java", ignoreFolders)[0];
55
+ var searchPath = globSync("**/" + nameParts[nameParts.length - 1] + ".java", ignoreFolders)[0];
56
56
  return searchPath;
57
57
  }
@@ -5,7 +5,7 @@ var packageFile = require('../../../../package.json');
5
5
 
6
6
  var ignoreNodeModules = { ignore: "node_modules/**" };
7
7
  var ignoreNodeModulesAndPods = { ignore: ["node_modules/**", "ios/Pods/**"] };
8
- var appDelegatePaths = glob.sync("**/AppDelegate.+(mm|m)", ignoreNodeModules);
8
+ var appDelegatePaths = glob.globSync ? glob.globSync("**/AppDelegate.+(mm|m)", ignoreNodeModules) : glob.sync("**/AppDelegate.+(mm|m)", ignoreNodeModules);
9
9
 
10
10
  exports.codePushHeaderImportStatement = `#import <CodePush/CodePush.h>`;
11
11
  exports.codePushHeaderImportStatementFormatted = `\n${this.codePushHeaderImportStatement}`;
@@ -0,0 +1,39 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ getConstants(): {
6
+ codePushInstallModeImmediate: number;
7
+ codePushInstallModeOnNextRestart: number;
8
+ codePushInstallModeOnNextResume: number;
9
+ codePushInstallModeOnNextSuspend: number;
10
+ codePushUpdateStateRunning: number;
11
+ codePushUpdateStatePending: number;
12
+ codePushUpdateStateLatest: number;
13
+ };
14
+
15
+ allow(): Promise<void>;
16
+ clearPendingRestart(): Promise<void>;
17
+ disallow(): Promise<void>;
18
+ restartApp(onlyIfUpdateIsPending: boolean): Promise<void>;
19
+ downloadUpdate(updatePackage: Object, notifyProgress: boolean): Promise<Object>;
20
+ getConfiguration(): Promise<Object>;
21
+ getUpdateMetadata(updateState: number): Promise<Object>;
22
+ getNewStatusReport(): Promise<Object>;
23
+ installUpdate(updatePackage: Object, installMode: number, minimumBackgroundDuration: number): Promise<void>;
24
+ isFailedUpdate(packageHash: string): Promise<boolean>;
25
+ isFirstRun(packageHash: string): Promise<boolean>;
26
+ notifyApplicationReady(): Promise<void>;
27
+ recordStatusReported(statusReport: Object): void;
28
+ saveStatusReportForRetry(statusReport: Object): void;
29
+ downloadAndReplaceCurrentBundle(remoteBundleUrl: string): void;
30
+ clearUpdates(): void;
31
+ getLatestRollbackInfo(): Promise<Object>;
32
+ setLatestRollbackInfo(packageHash: string): Promise<void>;
33
+
34
+ // Events
35
+ addListener(eventName: string): void;
36
+ removeListeners(count: number): void;
37
+ }
38
+
39
+ export default TurboModuleRegistry.get<Spec>('CodePush');