
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@bravemobile/react-native-code-push
Advanced tools
microsoft/react-native-code-push, ensuring compatibility and stability.Supports React Native 0.74 ~ 0.84.
[!NOTE] If you are using React Native 0.76 or lower, please use version
12.0.2of this library.
(Tested on the React Native CLI template apps)
If you have been using react-native-code-push, replace the NPM package first.
npm remove react-native-code-push
npm install @bravemobile/react-native-code-push
Edit android/app/build.gradle file to remove the apply from: "../../node_modules/..../codepush.gradle" line.
The following changes are optional but recommended for cleaning up the old configuration:
Info.plist, strings.xml, or JavaScript code.react-native-code-push module settings from settings.gradle.Follow the installation guide starting from '4. "CodePush-ify" your app'.
npm install @bravemobile/react-native-code-push
For React Native CLI projects, you can use the automatic setup command to configure your project for CodePush.
This command will automatically edit your AppDelegate and MainApplication files to integrate CodePush.
npx code-push init
And run the following command to install CocoaPods dependencies for iOS:
cd ios && pod install && cd ..
(or npx pod-install, bundle exec pod install --project-directory=./ios, ..)
If you prefer manual setup or if the automatic configuration fails, you can follow the manual setup instructions below.
Run cd ios && pod install && cd ..
(npx pod-install, bundle exec pod install --project-directory=./ios, ..)
AppDelegate CodeIf you have AppDelegate.swift (>= RN 0.77)
Add the following line to the bridging header file. (e.g. CodePushDemoApp-Bridging-Header.h)
+ #import <CodePush/CodePush.h>
Then, edit AppDelegate.swift like below.
@main
class AppDelegate: RCTAppDelegate {
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// ...
override func bundleURL() -> URL? {
#if DEBUG
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
- Bundle.main.url(forResource: "main", withExtension: "jsbundle")
+ CodePush.bundleURL()
#endif
}
}
Or if you have AppDelegate.mm
+ #import <CodePush/CodePush.h>
// ...
- (NSURL *)bundleURL
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
- return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
+ return [CodePush bundleURL];
#endif
}
@end
MainApplication Code(RN 0.82+) If you have MainApplication.kt
+ import com.microsoft.codepush.react.CodePush
class MainApplication : Application(), ReactApplication {
override val reactHost: ReactHost by lazy {
getDefaultReactHost(
context = applicationContext,
packageList =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
},
+ jsBundleFilePath = CodePush.getJSBundleFile(),
)
}
// ...
}
(RN 0.73+) If you have MainApplication.kt
+ import com.microsoft.codepush.react.CodePush
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
// ...
+ override fun getJSBundleFile(): String = CodePush.getJSBundleFile()
}
// ...
}
Or if you have MainApplication.java
// ...
+ import com.microsoft.codepush.react.CodePush
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost =
new DefaultReactNativeHost(this) {
// ...
+ @Override
+ override fun getJSBundleFile(): String {
+ return CodePush.getJSBundleFile()
+ }
};
// ...
}
For Expo projects, you can use the automated config plugin instead of manual setup.
Add plugin to your Expo configuration:
// app.config.js
export default {
expo: {
plugins: ["@bravemobile/react-native-code-push"],
},
};
Run prebuild to apply changes:
npx expo prebuild
[!NOTE] The plugin automatically handles all native iOS and Android code modifications. No manual editing of AppDelegate, MainApplication, or gradle files is required.
Requirements Expo SDK: 50.0.0 or higher
The root component of your app should be wrapped with a higher-order component.
You should also pass configuration options, including the implementation of the releaseHistoryFetcher function.
This function is used to find the latest CodePush update within the ReleaseHistoryInterface data.
To enable this, you need to create a release history using the CLI tool and upload it to the remote. (The following steps explain more about the CLI.)
At runtime, the library fetches this information to keep the app up to date.
import CodePush, {
ReleaseHistoryInterface,
UpdateCheckRequest,
} from "@bravemobile/react-native-code-push";
// ... MyApp Component
async function releaseHistoryFetcher(
updateRequest: UpdateCheckRequest,
): Promise<ReleaseHistoryInterface> {
// Fetch release history for current binary app version.
// You can implement how to fetch the release history freely. (Refer to the example app if you need a guide)
const {data: releaseHistory} = await axios.get<ReleaseHistoryInterface>(
`https://your.cdn.com/histories/${platform}/${identifier}/${updateRequest.app_version}.json`,
);
return releaseHistory;
}
export default CodePush({
checkFrequency: CodePush.CheckFrequency.MANUAL, // or something else
releaseHistoryFetcher: releaseHistoryFetcher,
})(MyApp);
[!NOTE] The URL for fetching the release history should point to the resource location generated by the CLI tool.
Please refer to the CodePushOptions type for more details.
CodePush.SyncStatus.UNKNOWN_ERROR status)[!TIP] For a more detailed and practical example, refer to the
CodePushDemoAppinexampledirectory. (link)
(1) Create a code-push.config.ts file in the root directory of your project.
Then, implement three functions to upload the bundle file and create/update the release history. The CLI tool uses these functions to release CodePush updates and manage releases. (These functions are not used at runtime by the library.)
You can copy and paste the following code and modify it as needed.
import {
CliConfigInterface,
ReleaseHistoryInterface,
} from "@bravemobile/react-native-code-push";
const Config: CliConfigInterface = {
bundleUploader: async (
source: string,
platform: "ios" | "android",
identifier,
): Promise<{downloadUrl: string}> => {
// ...
},
getReleaseHistory: async (
targetBinaryVersion: string,
platform: "ios" | "android",
identifier,
): Promise<ReleaseHistoryInterface> => {
// ...
},
setReleaseHistory: async (
targetBinaryVersion: string,
jsonFilePath: string,
releaseInfo: ReleaseHistoryInterface,
platform: "ios" | "android",
identifier,
): Promise<void> => {
// ...
},
};
module.exports = Config;
bundleUploader
downloadUrl returned by this function is recorded in ReleaseHistoryInterface data
and is used by the library runtime to download the bundle file from this URL.release command.getReleaseHistory
show-history command.release command.update-history command.(Similar to the releaseHistoryFetcher function in the library runtime options.)
setReleaseHistory
jsonFilePath or calls an API using releaseInfo metadata.create-history command.release command.update-history command.(2) For code-push.config.ts (TypeScript) to work properly, you may need to update your tsconfig.json.
{
"extends": "@react-native/typescript-config/tsconfig.json",
// ...
"include": [
// ...
+ "code-push.config.ts"
],
+ "ts-node": {
+ "compilerOptions": {
+ "module": "CommonJS",
+ "types": ["node"]
+ }
+ }
}
[!TIP] You can use
--helpcommand to see the available commands and options.
(interactive mode not supported yet)
create-historyCreate a new release history for a specific binary app version.
Example:
1.0.0.npx code-push create-history --binary-version 1.0.0 --platform ios --identifier staging
show-historyDisplay the release history for a specific binary app version.
Example:
1.0.0.npx code-push show-history --binary-version 1.0.0 --platform ios --identifier staging
releaseRelease a CodePush update for a specific binary app version.
Example:
1.0.1 targeting the binary app version 1.0.0.npx code-push release --binary-version 1.0.0 --app-version 1.0.1 \
--platform ios --identifier staging --entry-file index.js \
--mandatory true
# Expo project
npx code-push release --framework expo --binary-version 1.0.0 --app-version 1.0.1 --platform ios
--framework(-f) : Framework type (expo)--binary-version: The version of the binary app that the CodePush update is targeting.--app-version: The version of the CodePush update itself.[!IMPORTANT]
--app-versionshould be greater than--binary-version(SemVer comparison).
--rollout: The rollout percentage for the update. (0~100, inclusive)update-historyUpdate the release history for a specific CodePush update.
--enable option to disable a specific release for rollback. (or enable it)--mandatory option to make the update as mandatory or optional.--rollout option to change the rollout percentage of the update. (0~100, inclusive)
Example:
1.0.1 (targeting the binary app version 1.0.0).npx code-push update-history --binary-version 1.0.0 --app-version 1.0.1 \
--platform ios --identifier staging \
--enable false
bundleCreate a CodePush bundle file.
Example:
npx code-push bundle --platform android --entry-file index.js
# Expo project
npx code-push bundle --framework expo --platform android --entry-file index.js
--framework(-f): Framework type (expo)By default, the bundle file is created in the /build/bundleOutput directory.
[!NOTE] For Expo projects, the CLI uses
expo export:embedcommand for bundling instead of React Native's bundle command.
(The file name represents a hash value of the bundle content.)
FAQs
React Native plugin for the CodePush service
The npm package @bravemobile/react-native-code-push receives a total of 3,420 weekly downloads. As such, @bravemobile/react-native-code-push popularity was classified as popular.
We found that @bravemobile/react-native-code-push demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.