pear-runtime-react-native
v2.0.1
Published
Enables OTA updates with pear-runtime in react-native mobile apps
Readme
pear-runtime-react-native
Pear runtime for React Native: storage path, bare workers (worklets), and OTA updates.
npm install pear-runtime-react-native react-native-bare-kitRequires react-native-bare-kit in your project.
MVP - EXPERIMENTAL
This boilerplate is MVP and Experimental.
Usage
import PearRuntime from 'pear-runtime-react-native'
import bundle from './worker.bundle.js'
const runtime = new PearRuntime()
const IPC = runtime.run('/worker.bundle', bundle)OTA updates
OTA works for Expo and plain React Native. Native setup differs; Metro and JS setup are the same.
Flow: Expo
Native — In
app.json/app.config.jsadd the plugin, then run prebuild:{ "expo": { "plugins": ["pear-runtime-react-native/plugin"] } }npx expo prebuildRelease builds load the OTA bundle from
pear-runtime/ota/app.bundlewhen present.Metro and App entry below.
Flow: Plain React Native
Apply the same native changes (iOS bundleURL, Android getJSBundleFile) to your ios/ and android/ projects manually so release builds load from pear-runtime/ota/app.bundle when present. Then do Metro and App entry below.
Metro
Create metro.config.js in the project root:
const { getMetroConfig } = require('pear-runtime-react-native/metro-config')
module.exports = getMetroConfig(__dirname, { useExpo: true, useSentry: false })Options (second argument): useExpo — merge in expo/metro-config when available (default true). useSentry — merge in @sentry/react-native/metro when available (default false).
Add @react-native/metro-config to your devDependencies. With Expo, expo/metro-config is merged in automatically. Then npx react-native bundle works for OTA payloads.
npm install @react-native/metro-config --save-devCreate OTA bundle (payload)
From the project root (entry file must match your app, e.g. index.js):
npx react-native bundle --platform ios --dev false --entry-file index.js --bundle-output dist/by-arch/<host-arch>/app/app.bundle --assets-dest dist/by-arch/<host-arch>/app
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output dist/by-arch/<host-arch>/app/app.bundle --assets-dest dist/by-arch/<host-arch>/app
cp -f package.json dist/package.jsonThen stage and seed with pear as in your OTA flow.
API
const pear = PearRuntime()
Create a pear runtime (currently doesnt do anything on its own).
IPC <stream.Duplex> = pear.run(filename, bundle, argv)
Start a Bare worklet. returns IPC duplex stream.
License
Apache-2.0
