pear-mobile 0.0.1 → 0.0.3

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.
Files changed (3) hide show
  1. package/README.md +58 -28
  2. package/index.js +14 -56
  3. package/package.json +12 -9
package/README.md CHANGED
@@ -6,63 +6,93 @@ Embeddable Pear runtime for mobile applications. Provides storage path and bare
6
6
  npm install pear-mobile
7
7
  ```
8
8
 
9
- ```sh
10
- npm install react-native-bare-kit --save
11
- ```
9
+ This module integrates Pear into React-Native-based Mobile applications.
12
10
 
13
- Requires `react-native-bare-kit` to be listed in project dependencies.
11
+ See [pear-runtime](https://github.com/holepunchto/pear-runtime) for Pear's embeddable runtime module for Desktop Devices.
14
12
 
15
13
  ## Usage
16
14
 
17
15
  ```js
18
- import PearRuntime from 'pear-mobile'
19
- import bundle from './worker.bundle.js'
16
+ const PearRuntime = require('pear-mobile')
17
+ const { version, upgrade } = require('./package.json')
20
18
 
21
- const runtime = new PearRuntime()
22
- const appStorage = runtime.storage
19
+ const dir = Bare.argv[0] // pass the /Documents storage dir
23
20
 
24
- const IPC = runtime.run('/worker.bundle', bundle, [appStorage])
21
+ const runtime = new PearRuntime({ version, upgrade, dir })
22
+ runtime.on('updated', async () => {
23
+ await runtime.applyUpdate()
24
+ conosle.log('restart for update')
25
+ })
25
26
  ```
26
27
 
28
+ ## Quick Starts
29
+
30
+ ### Expo
31
+
32
+ ```sh
33
+ git clone https://github.com/holepunchto/hello-pear-react-native
34
+ ```
35
+
36
+ For end-to-end instructions from building to deploying with [Pear](https://docs.pears.com) see [hello-pear-react-native](https://github.com/holepunchto/hello-pear-react-native) `README.md`.
37
+
38
+ ## Features
39
+
40
+ - Peer-to-Peer Over-the-Air (P2P OTA) updates (via [pear-runtime-updater](https://www.github.com/holepunchto/pear-runtime-updater))
41
+ - Application storage management
42
+
27
43
  ## API
28
44
 
29
- #### `const runtime = new PearRuntime()`
45
+ Inherits from [pear-runtime-updater]{https://www.github.com/holepunchto/pear-runtime-updater}
30
46
 
31
- Create a runtime.
47
+ #### `const runtime = new PearRuntime(opts)`
32
48
 
33
- #### `runtime.storage`
49
+ Create a runtime. `opts` may include:
34
50
 
35
- Absolute path to the runtime app storage directory.
51
+ - **`dir`** (required) Base directory for runtime data and app storage.
52
+ - **`version`** – Current app version (e.g. from `package.json`); used for update checks.
53
+ - **`upgrade`** – Pear link for OTA updates (e.g. from `package.json` `upgrade` field).
54
+ - **`app`** – Path to the native boot bundle override; required for `applyUpdate()` to swap in the new build. Defaults to `path/to/Documents/pear-runtime/upgrades`
55
+ - **`updates`** – Set to `false` to disable P2P OTA updates.
56
+ - **`storage`** – Saves the app storage path.
36
57
 
37
- #### `runtime.on(event, callback)`
58
+ #### `runtime.storage`
38
59
 
39
- Subscribe to an event. Returns `runtime` for chaining.
60
+ Suggested storage folder for app storage.
40
61
 
41
- #### `runtime.off(event, callback?)`
62
+ #### `await runtime.close()`
42
63
 
43
- Unsubscribe: remove `callback` for `event`, or remove all listeners for `event` if `callback` is omitted. Returns `runtime`.
64
+ Shut it down. You should do this when closing your app for best performance.
44
65
 
45
- #### `runtime.once(event, callback)`
66
+ ## Making updates
46
67
 
47
- Subscribe to an event once; listener is removed after the first emit. Returns `runtime`.
68
+ VERY EXPERIMENTAL, MOST DEFINITELY WILL CHANGE.
48
69
 
49
- #### `IPC = runtime.run(filename, bundle, argv)`
70
+ Update listening and apply logic lives in [pear-runtime-updater](https://www.github.com/holepunchto/pear-runtime-updater).
50
71
 
51
- Start a bare worker (worklet). Returns an IPC duplex stream. `filename` is a virtual path, `bundle` is the worklet bundle, `argv` is an array of string arguments.
72
+ First allocate a pear link if you haven't using [`pear`](https://github.com/holepunchto/pear):
52
73
 
53
- `Bare.argv` in worker to access `argv`.
74
+ ```sh
75
+ pear touch
76
+ ```
54
77
 
55
- #### `runtime.ready()`
78
+ Store this link in the `package.json` `upgrade` field of a project. See [example](./example/package.json).
56
79
 
57
- Returns a Promise. No-op on mobile; for API compatibility.
80
+ bundle your JS frontend. Take the distributable (e.g react-native bundle and assets) produced and make a deployment folder with the following structure:
58
81
 
59
- #### `runtime.close()`
82
+ ```
83
+ /package.json
84
+ /by-arch
85
+ /[...platform-arch]
86
+ /app
87
+ ```
60
88
 
61
- Returns a Promise. No-op on mobile; for API compatibility.
89
+ Now go to this folder and stage this onto the link with `pear stage`
62
90
 
63
- #### `runtime.applyUpdate()`
91
+ ```sh
92
+ pear stage {link-from-touch}
93
+ ```
64
94
 
65
- Returns a Promise. On mobile this is not supported and only logs a warning; for API compatibility.
95
+ Now seed it. Any build out there on a lower version will trigger the update flow.
66
96
 
67
97
  ## LICENSE
68
98
 
package/index.js CHANGED
@@ -1,59 +1,17 @@
1
- const { Worklet } = require('react-native-bare-kit')
2
- const RNFS = require('react-native-fs')
3
-
4
- module.exports = class PearRuntime {
5
- constructor(config = {}) {
6
- this._listeners = Object.create(null)
7
-
8
- this.version = config.version || 0
9
- this.storage = `${RNFS.DocumentDirectoryPath}/pear-runtime/storage`
10
- this.key = config.key
11
- this.length = config.length
12
- this.fork = config.fork || 0
13
- this.link = 'pear://' + this.fork + '.' + this.length + '.' + this.key
14
- }
15
-
16
- async ready() {}
17
- async close() {}
18
-
19
- on(event, callback) {
20
- if (!this._listeners[event]) this._listeners[event] = []
21
- this._listeners[event].push(callback)
22
- return this
23
- }
24
-
25
- off(event, callback) {
26
- if (!this._listeners[event]) return this
27
- if (callback) {
28
- this._listeners[event] = this._listeners[event].filter((fn) => fn !== callback)
29
- } else {
30
- this._listeners[event] = []
31
- }
32
- return this
33
- }
34
-
35
- once(event, fn) {
36
- const wrap = (...args) => {
37
- this.off(event, wrap)
38
- fn(...args)
1
+ const PearRuntimeUpdater = require('pear-runtime-updater')
2
+ const path = require('bare-path')
3
+ const fs = require('bare-fs')
4
+
5
+ module.exports = class PearRuntime extends PearRuntimeUpdater {
6
+ constructor(opts = {}) {
7
+ const appPath = opts.app || path.join(opts.dir, 'pear-runtime', 'upgrade')
8
+ if (!fs.existsSync(appPath)) fs.mkdirSync(appPath, { recursive: true, force: true })
9
+ if (fs.existsSync(path.join(appPath, 'package.json'))) {
10
+ const manifest = fs.readFileSync(path.join(appPath, 'package.json'))
11
+ opts.version = JSON.parse(manifest).version
39
12
  }
40
- return this.on(event, wrap)
41
- }
42
-
43
- emit(event, ...args) {
44
- const list = this._listeners[event]
45
- if (!list) return this
46
- for (const fn of list) fn(...args)
47
- return this
48
- }
49
-
50
- run(filename, bundle, argv) {
51
- const worklet = new Worklet()
52
- worklet.start(filename, bundle, argv)
53
- return worklet.IPC
54
- }
55
-
56
- async applyUpdate() {
57
- console.warn('PearRuntime: applyUpdate() not supported for mobile')
13
+ opts = { app: appPath, ...opts }
14
+ super(opts)
15
+ this.storage = opts.storage || path.join(this.dir, 'app-storage')
58
16
  }
59
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-mobile",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Embeddable Pear runtime for mobile applications",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -13,14 +13,9 @@
13
13
  "files": [
14
14
  "package.json",
15
15
  "index.js",
16
- "index.d.ts"
16
+ "index.d.ts",
17
+ "index.rn.js"
17
18
  ],
18
- "devDependencies": {
19
- "brittle": "^3.19.0",
20
- "lunte": "^1.2.0",
21
- "prettier": "^3.6.2",
22
- "prettier-config-holepunch": "^2.0.0"
23
- },
24
19
  "scripts": {
25
20
  "format": "prettier . --write",
26
21
  "test": "prettier . --check && lunte && brittle-bare test/index.js",
@@ -36,7 +31,15 @@
36
31
  "url": "https://github.com/holepunchto/pear-mobile/issues"
37
32
  },
38
33
  "homepage": "https://github.com/holepunchto/pear-mobile",
34
+ "devDependencies": {
35
+ "brittle": "^3.19.0",
36
+ "lunte": "^1.2.0",
37
+ "prettier": "^3.6.2",
38
+ "prettier-config-holepunch": "^2.0.0"
39
+ },
39
40
  "dependencies": {
40
- "react-native-fs": "^2.20.0"
41
+ "bare-fs": "^4.5.4",
42
+ "bare-path": "^3.0.0",
43
+ "pear-runtime-updater": "^0.0.10"
41
44
  }
42
45
  }