pear-mobile 0.0.1 → 0.0.2

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 +17 -4
  2. package/index.js +13 -56
  3. package/package.json +12 -9
package/README.md CHANGED
@@ -15,18 +15,30 @@ Requires `react-native-bare-kit` to be listed in project dependencies.
15
15
  ## Usage
16
16
 
17
17
  ```js
18
+ /* React Native */
18
19
  import PearRuntime from 'pear-mobile'
19
20
  import bundle from './worker.bundle.js'
21
+ import { version, upgrade } from './package.json'
20
22
 
21
23
  const runtime = new PearRuntime()
22
- const appStorage = runtime.storage
24
+ const IPC = runtime.run('/worker.bundle', bundle, [runtime.dir])
23
25
 
24
- const IPC = runtime.run('/worker.bundle', bundle, [appStorage])
26
+ /* Bare Worklet */
27
+ const PearRuntime = require('pear-runtime')
28
+ const { version, upgrade } = require('./package.json')
29
+
30
+ const dir = Bare.argv[0]
31
+
32
+ const runtime = new PearRuntime({ version, upgrade, dir })
33
+ runtime.on('updated', () => {
34
+ runtime.applyUpdate()
35
+ conosle.log('restart for update')
36
+ })
25
37
  ```
26
38
 
27
39
  ## API
28
40
 
29
- #### `const runtime = new PearRuntime()`
41
+ #### `const runtime = new PearRuntime(...)`
30
42
 
31
43
  Create a runtime.
32
44
 
@@ -46,11 +58,12 @@ Unsubscribe: remove `callback` for `event`, or remove all listeners for `event`
46
58
 
47
59
  Subscribe to an event once; listener is removed after the first emit. Returns `runtime`.
48
60
 
49
- #### `IPC = runtime.run(filename, bundle, argv)`
61
+ #### `const IPC <stream.Duplex> = runtime.run(filename, bundle, argv)`
50
62
 
51
63
  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.
52
64
 
53
65
  `Bare.argv` in worker to access `argv`.
66
+ `Bare.IPC` in worker to access stream.
54
67
 
55
68
  #### `runtime.ready()`
56
69
 
package/index.js CHANGED
@@ -1,59 +1,16 @@
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)
58
15
  }
59
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-mobile",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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
  }