npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@swyng/react-native-code-push

v1.0.2

Published

React Native plugin for SwyngPush over-the-air updates

Readme

Sign up with SwyngPush to use CodePush

React Native Module for SwyngPush

This plugin provides client-side integration for the SwyngPush service, allowing you to easily add over-the-air updates to your React Native app(s).

How does it work?

A React Native app is composed of JavaScript files and any accompanying images, which are bundled together by the metro bundler and distributed as part of a platform-specific binary (i.e. an .ipa or .apk file). Once the app is released, updating either the JavaScript code (e.g. making bug fixes, adding new features) or image assets, requires you to recompile and redistribute the entire binary, which of course, includes any review time associated with the store(s) you are publishing to.

The SwyngPush plugin helps get product improvements in front of your end users instantly, by keeping your JavaScript and images synchronized with updates you release to the SwyngPush server. This way, your app gets the benefits of an offline mobile experience, as well as the "web-like" agility of side-loading updates as soon as they are available.

In order to ensure that your end users always have a functioning version of your app, the SwyngPush plugin maintains a copy of the previous update, so that in the event that you accidentally push an update which includes a crash, it can automatically roll back. This way, you can rest assured that your newfound release agility won't result in users becoming blocked before you have a chance to roll back on the server.

Note: Any product changes which touch native code (e.g. modifying your AppDelegate.m/MainActivity.java file, adding a new plugin) cannot be distributed via CodePush, and therefore, must be updated via the appropriate store(s).

Supported React Native platforms

  • iOS (7+)
  • Android (4.1+) on TLS 1.2 compatible devices

We try our best to maintain backwards compatibility of our plugin with previous versions of React Native, but due to the nature of the platform, and the existence of breaking changes between releases, it is possible that you need to use a specific version of the CodePush plugin in order to support the exact version of React Native you are using. The following table outlines which CodePush plugin versions officially support the respective React Native versions:

| React Native version(s) | Supporting CodePush version(s) | | ------------------------ | ------------------------------------------------- | | v0.76, v0.77, 0.78, 0.79 | v1.0+ (Old/New Architecture) | | v0.80 | v1.0+ (Old/New Architecture) | | v0.81+ | v1.0+ (Old/New Architecture) | | v0.82+ | v1.0+ (New Architecture) |

Supported Components

When using the React Native assets system (i.e. using the require("./foo.png") syntax), the following list represents the set of core components (and props) that support having their referenced images and videos updated via CodePush:

| Component | Prop(s) | | ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------- | | Image | source | | MapView.Marker (Requires react-native-maps >=O.3.2) | image | | ProgressViewIOS | progressImage, trackImage | | TabBarIOS.Item | icon, selectedIcon | | ToolbarAndroid (React Native 0.21.0+) | actions[].icon, logo, overflowIcon | | Video | source |

Note: CodePush only works with Video components when using require in the source prop. For example:

<Video source={require("./foo.mp4")} />

Getting Started

Once you've followed the general-purpose "getting started" instructions for setting up your SwyngPush account, you can start CodePush-ifying your React Native app by running the following command from within your app's root directory:

yarn add @swyng/react-native-code-push

As with all other React Native plugins, the integration experience is different for iOS and Android, so perform the following setup steps depending on which platform(s) you are targeting. Note, if you are targeting both platforms it is recommended to create separate CodePush applications for each platform.

Then continue with installing the native module:

Plugin Usage

With the CodePush plugin downloaded and linked, and your app asking CodePush where to get the right JS bundle from, the only thing left is to add the necessary code to your app to control the following policies:

  1. When (and how often) to check for an update? (for example app start, in response to clicking a button in a settings page, periodically at some fixed interval)

  2. When an update is available, how to present it to the end user?

The simplest way to do this is to "CodePush-ify" your app's root component. To do so, you can choose one of the following two options:

  • Option 1: Wrap your root component with the codePush higher-order component:

    • For class component

      import codePush from "@swyng/react-native-code-push";
      
      class MyApp extends Component {}
      
      MyApp = codePush(MyApp);
    • For functional component

      import codePush from "@swyng/react-native-code-push";
      
      let MyApp: () => React$Node = () => {};
      
      MyApp = codePush(MyApp);
  • Option 2: Use the ES7 decorator syntax:

    NOTE: Decorators are not yet supported in Babel 6.x pending proposal update. You may need to enable it by installing and using babel-preset-react-native-stage-0.

    • For class component

      import codePush from "@swyng/react-native-code-push";
      
      @codePush
      class MyApp extends Component {}
    • For functional component

      import codePush from "@swyng/react-native-code-push";
      
      const MyApp: () => React$Node = () => {};
      
      export default codePush(MyApp);

By default, CodePush will check for updates on every app start. If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible.

If you would like your app to discover updates more quickly, you can also choose to sync up with the CodePush server every time the app resumes from the background.

let codePushOptions = {
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
};

let MyApp: () => React$Node = () => {};

MyApp = codePush(codePushOptions)(MyApp);

Alternatively, if you want fine-grained control over when the check happens (like a button press or timer interval), you can call CodePush.sync() at any time with your desired SyncOptions, and optionally turn off CodePush's automatic checking by specifying a manual checkFrequency:

let codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };

class MyApp extends Component {
  onButtonPress() {
    codePush.sync({
      updateDialog: true,
      installMode: codePush.InstallMode.IMMEDIATE,
    });
  }

  render() {
    return (
      <View>
        <TouchableOpacity onPress={this.onButtonPress}>
          <Text>Check for updates</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

MyApp = codePush(codePushOptions)(MyApp);

If you would like to display an update confirmation dialog (an "active install"), configure when an available update is installed (like force an immediate restart) or customize the update experience in any other way, refer to the codePush() API reference for information on how to tweak this default behavior.

For Expo users with CNG (Continuous Native Generation)

// app.json
{
  "expo": {
    "plugins": [
      [
        "@swyng/react-native-code-push/expo",
        {
          "ios": {
            "CodePushDeploymentKey": "your-deployment-key",
            "CodePushServerURL": "https://bl-prod-2-ap-south-1.swyng.site"
          },
          "android": {
            "CodePushDeploymentKey": "your-deployment-key",
            "CodePushServerURL": "https://bl-prod-2-ap-south-1.swyng.site"
          }
        }
      ]
    ]
  }
}

Currently, the SwyngPush CLI doesn't support expo-cli build. To make it work, you need to customize metro.config.js in the root directory:

npx expo customize metro.config.js

Store Guideline Compliance

Android Google Play and iOS App Store have corresponding guidelines that have rules you should be aware of before integrating the CodePush solution within your application.

Google Play

Third paragraph of Device and Network Abuse topic describes that updating source code by any method other than Google Play's update mechanism is restricted. But this restriction does not apply to updating JavaScript bundles.

This restriction does not apply to code that runs in a virtual machine and has limited access to Android APIs (such as JavaScript in a webview or browser).

That fully allows CodePush as it updates just JS bundles and can't update native code.

App Store

Paragraph 3.3.2 of the Apple Developer Program License Agreement fully allows performing over-the-air updates of JavaScript and assets:

Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS.

CodePush allows you to follow these rules in full compliance so long as the update you push does not significantly deviate your product from its original App Store approved intent.

To further remain in compliance with Apple's guidelines we suggest that App Store-distributed apps don't enable the updateDialog option when calling sync, since in the App Store Review Guidelines it is written that:

Apps must not force users to rate the app, review the app, download other apps, or other similar actions in order to access functionality, content, or use of the app.

This is not necessarily the case for updateDialog, since it won't force the user to download the new version, but at least you should be aware of that ruling if you decide to show it.

Releasing Updates

Once your app is configured and distributed to your users, and you have made some JS or asset changes, it's time to release them. The recommended way to release them is using the create_bundle command in the SwyngPush CLI, which will bundle your JavaScript files, asset files, and release the update to the SwyngPush server.

NOTE: Before you can start releasing updates, please log into SwyngPush by running the npx @swyng/cli login -u <username> -p <password> command.

In its most basic form, this command only requires some parameters:

npx @swyng/cli create_bundle -t <TargetVersion> -n <AppName> -d <deployment>

npx @swyng/cli create_bundle -t 1.0.0 -n Demo1 -d Staging

The create_bundle command enables such a simple workflow because it provides many sensible defaults (like generating a release bundle, assuming your app's entry file on iOS is either index.ios.js or index.js). However, all of these defaults can be customized to allow incremental flexibility as necessary, which makes it a good fit for most scenarios.

The CodePush client supports differential updates, so even though you are releasing your JS bundle and assets on every update, your end users will only actually download the files they need. The service handles this automatically so that you can focus on creating awesome apps and we can worry about optimizing end user downloads.

For more details about how the create_bundle command works, as well as the various parameters it exposes, refer to the CLI docs.

Dynamic Deployment Assignment

The above section illustrated how you can leverage multiple CodePush deployments in order to effectively test your updates before broadly releasing them to your end users. However, since that workflow statically embeds the deployment assignment into the actual binary, a staging or production build will only ever sync updates from that deployment. In many cases, this is sufficient, since you only want your team, customers, stakeholders, etc. to sync with your pre-production releases, and therefore, only they need a build that knows how to sync with staging. However, if you want to be able to perform A/B tests, or provide early access of your app to certain users, it can prove very useful to be able to dynamically place specific users (or audiences) into specific deployments at runtime.

In order to achieve this kind of workflow, all you need to do is specify the deployment key you want the current user to synchronize with when calling the codePush method. When specified, this key will override the "default" one that was provided in your app's Info.plist (iOS) or MainActivity.java (Android) files. This allows you to produce a build for staging or production, that is also capable of being dynamically "redirected" as needed.

// Imagine that "userProfile" is a prop that this component received
// which includes the deployment key that the current user should use.
codePush.sync({ deploymentKey: userProfile.CODEPUSH_KEY });

With that change in place, now it's just a matter of choosing how your app determines the right deployment key for the current user. In practice, there are typically two solutions for this:

  1. Expose a user-visible mechanism for changing deployments at any time. For example, your settings page could have a toggle for enabling "beta" access.

  2. Annotate the server-side profile of your users with an additional piece of metadata that indicates the deployment they should sync with. By default, your app could just use the binary-embedded key, but after a user has authenticated, your server can choose to "redirect" them to a different deployment.

// #1) Create your new deployment to hold releases of a specific app variant
npx @swyng/cli app create_deployment -n <AppName> -dn <DeploymentName>

// #2) Target any new releases at that custom deployment
npx @swyng/cli create_bundle -t <TargetVersion> -n <AppName> -d <deployment>

API Reference

Debugging / Troubleshooting

The sync method includes a lot of diagnostic logging out-of-the-box, so if you're encountering an issue when using it, the best thing to try first is examining the output logs of your app. This will tell you whether the app is configured correctly (like can the plugin find your deployment key?), if the app is able to reach the server, if an available update is being discovered, if the update is being successfully downloaded/installed, etc.

The simplest way to view these logs is to add the flag --debug for each command. This will output a log stream that is filtered to just CodePush messages. This makes it easy to identify issues, without needing to use a platform-specific tool, or wade through a potentially high volume of logs.

Additionally, you can also use any of the platform-specific tools to view the CodePush logs. Start up the Chrome DevTools Console, the Xcode Console (iOS), and/or ADB logcat (Android), and look for messages which are prefixed with [CodePush].

| Issue / Symptom | Possible Solution | |-----------------|-------------------| | Compilation Error | Double-check that your version of React Native is compatible with the CodePush version you are using. | | Network timeout / hang when calling sync or checkForUpdate in the iOS Simulator | Try resetting the simulator by selecting the Simulator -> Reset Content and Settings.. menu item, and then re-running your app. | | Server responds with a 404 when calling sync or checkForUpdate | Double-check that the deployment key you added to your Info.plist (iOS), build.gradle (Android) or that you're passing to sync/checkForUpdate, is in fact correct. You can run npx @swyng/cli app ls_deployment -n <AppName> -k to view the correct keys for your app deployments. | | Update not being discovered | Double-check that the version of your running app (like 1.0.0) matches the version you specified when releasing the update to CodePush. Additionally, make sure that you are releasing to the same deployment that your app is configured to sync with. | | Update not being displayed after restart | If you're not calling sync on app start (like within componentDidMount of your root component), then you need to explicitly call notifyApplicationReady on app start, otherwise, the plugin will think your update failed and roll it back. | | I've released an update for iOS but my Android app also shows an update and it breaks it | Be sure you have different deployment keys for each platform in order to receive updates correctly. | | I've released new update but changes are not reflected | Be sure that you are running app in modes other than Debug. In Debug mode, React Native app always downloads JS bundle generated by packager, so JS bundle downloaded by CodePush does not apply. |

TypeScript Consumption

This module ships its *.d.ts file as part of its NPM package, which allows you to simply import it, and receive intellisense in supporting editors (like Visual Studio Code), as well as compile-time type checking if you're using TypeScript. For the most part, this behavior should just work out of the box, however, if you've specified es6 as the value for either the target or module compiler option in your tsconfig.json file, then just make sure that you also set the moduleResolution option to node. This ensures that the TypeScript compiler will look within the node_modules for the type definitions of imported modules.


License

MIT - See LICENSE.md