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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cryptoticket/react-native-hot-patching

v1.2.4

Published

Dynamic bundle update for React Native

Downloads

11

Readme

React Native Hot Patching

React Native package that in background downloads bundles from the remote server and reloads bundles dynamically. App review process may take a long time so it might be useful to have the ability to update the app immediately in case of hot fixes. Should be used together with rn-version-admin. The primary goal of this package is to provide a mechanism for app hot patching(when there's a critical bug in your app and app review takes a long time then hot patching can help) not constant app updating.

NOTICE: only JS code can be updated via hot patching. So if you have any native changes in your code they won't be applied in JS bundle.

How to install

  1. Install npm package
npm i @cryptoticket/react-native-hot-patching --save
  1. Add react-native-fs to your app. Used as a peer dependency for bundle downloading.
  2. Add react-native-zip-archive to your app. Used as a peer dependency for unzipping bundle(to get JS bundle file and app assets).
  3. Add react-native-dynamic-bundle to your app. Used as a peer dependency for bundle management. NOTICE: use latest version from github, not from npm.
  4. Deploy rn-version-admin service where you should upload zipped bundles.
  5. Init package on app start
import RNHotPatching from '@cryptoticket/react-native-hot-patching';
import { version } from './package.json';

try {
  await RNHotPatching.init({
    url: 'https://bundle-update.com', // rn-version-admin address 
    appVersion: version // app version from package.json
  });
} catch(err) {
    console.log('Error on RNHotPatching.init()');
    console.log(err);
}

What is going on in background

Case 1

If current app version (from package.json) is 1.0.0 and there is an active bundle(on the server side) with version 1.0.1, is_update_required field set to true and apply_from_version is set to 1.0.0 then:

  • bundle with version 1.0.1 will be downloaded and saved on the device
  • bundle with version 1.0.1 will be set as active
  • when user opens app the next time then version 1.0.1 will be opened

Case 2

If current app version (from package.json) is 1.0.0 and there is an active bundle(on the server side) with version 1.0.2, is_update_required field set to true and apply_from_version is set to 1.0.1 then:

  • bundle is NOT downloaded because current app version 1.0.0 < minimum required version 1.0.1 from apply_from_version field

Case 3

If current app version is 1.0.1(updated via hot patching) and app is updated to version 1.0.2 via app store then:

  • hotpatched version 1.0.1 is deleted from the device
  • active bundle is set to null (which tells the plugin to use version from the app store)
  • when user opens app the next time then version 1.0.2 from the app store will be opened

Methods

getCurrentAppVersion(appVersion: string)

appVersion: app version from package.json

Returns current app version(from package.json or from bundle that was previously downloaded via hot patching). In most cases you should not use this method directly as init() handles everything out-of-the-box.

Example:

import RNHotPatching from '@cryptoticket/react-native-hot-patching';
import { version } from './package.json';

const appVersion = RNHotPatching.getCurrentAppVersion(version);
console.log(appVersion); // version from package.json or currently active bundle

init(options: Object)

options: init options. You should set url param of the deployed rn-version-admin service and appVersion param with the app version from package.json.

Initializes bundle plugin. This method MUST be called on app start.

Example:

import RNHotPatching from '@cryptoticket/react-native-hot-patching';
import { version } from './package.json';

try {
  await RNHotPatching.init({
    url: 'https://bundle-update.com', // rn-version-admin address 
    appVersion: version // app version from package.json
  });
} catch(err) {
  console.log('Error on RNHotPatching.init()');
  console.log(err);
}

isActivationRequired(currentAppVersion: string, remoteBundleData: Object)

currentAppVersion: current app version (from package.json or previously downloaded bundle)

remoteBundleData: remote bundle data object from rn-version-admin. Example:

{
    "_id": "5e599743ee4d7e37ed0d0254",
    "platform": "android",
    "storage": "file",
    "version": "1.0.1", // required
    "is_update_required": false, // required
    "apply_from_version": "1.0.0", // required
    "url": "http://localhost:3000/static/bundles/1.0.0/android.bundle.zip",
    "desc": "test",
    "created_at": "2020-02-28T22:42:12.005Z",
    "updated_at": "2020-02-28T22:42:12.005Z"
}

Checks whether bundle should be downloaded from the remote server and set as active. Returns true only when:

  • remoteBundleData.is_update_required is true
  • remoteBundleData.apply_from_version <= current app version < remoteBundleData.version

In most cases you should not use this method directly as init() handles everything out-of-the-box.

Example:

import RNHotPatching from '@cryptoticket/react-native-hot-patching';
import { version } from './package.json';

const appVersion = RNHotPatching.getCurrentAppVersion(version);
const isActivationRequired = RNHotPatching.isActivationRequired(appVersion, {is_update_required: true, version: '1.0.1', apply_from_version: '1.0.0'});
console.log(isActivationRequired); // whether bundle should be downloaded and set as active

removeStaleBundles(appVersion: string)

appVersion: app version from package.json

Removes stale bundles. If your app version from package.json is 1.0.1 and there is a previously downloaded bundle with version 1.0.0 then 1.0.0 will be removed from the file system. In most cases you should not use this method directly as init() handles everything out-of-the-box.

Example:

import RNHotPatching from '@cryptoticket/react-native-hot-patching';
import { version } from './package.json';

RNHotPatching.removeStaleBundles(version);

reset()

Removes all downloaded bundles, resets default bundle to the one from the app store and immediately reloads the app.

Example:

import RNHotPatching from '@cryptoticket/react-native-hot-patching';
import { version } from './package.json';

RNHotPatching.reset();

How to run tests

npm run test