pear-runtime-updater 3.0.7 → 3.0.10
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.
- package/README.md +7 -0
- package/index.js +24 -5
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ const updater = new PearRuntimeUpdater({
|
|
|
41
41
|
|
|
42
42
|
await updater.ready()
|
|
43
43
|
|
|
44
|
+
updater.on('update-scheduled', (delay) => console.log('Update will start in', delay))
|
|
44
45
|
updater.on('updating', () => console.log('Update downloading…'))
|
|
45
46
|
updater.on('updated', async () => {
|
|
46
47
|
console.log('Update ready')
|
|
@@ -71,6 +72,7 @@ goodbye(async () => {
|
|
|
71
72
|
- Appends update content via [Hyperdrive](https://github.com/holepunchto/hyperdrive)
|
|
72
73
|
- Emits when an update is in progress, update diffs and when it’s ready
|
|
73
74
|
- `applyUpdate()` to atomic swap the new build (bundled apps; macOS/Linux)
|
|
75
|
+
- Default random update delay to avoid seeder overload on new releases
|
|
74
76
|
|
|
75
77
|
## API
|
|
76
78
|
|
|
@@ -84,6 +86,11 @@ goodbye(async () => {
|
|
|
84
86
|
- `opts.app` – (optional) Path to the app bundle (for bundled apps; used with `applyUpdate()`).
|
|
85
87
|
- `opts.bundled` – (optional) Whether the app is bundled. Defaults to `!!opts.app`.
|
|
86
88
|
- `opts.updates` – (optional) Set to false to opt out of updates.
|
|
89
|
+
- `opts.delay` – (optional) Upper bound (in ms) for the randomized update mirror delay. Defaults to 3_600_000 (60 minutes).
|
|
90
|
+
|
|
91
|
+
#### `updater.on('update-scheduled')`
|
|
92
|
+
|
|
93
|
+
Emitted when a new upgrade drive length is detected and the update has been scheduled with a random delay.
|
|
87
94
|
|
|
88
95
|
#### `updater.on('updating')`
|
|
89
96
|
|
package/index.js
CHANGED
|
@@ -40,6 +40,12 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
40
40
|
this.updating = false
|
|
41
41
|
this.updated = false
|
|
42
42
|
|
|
43
|
+
this._defaultDelay = 3_600_000 // defaults to 1h
|
|
44
|
+
this._delay = Math.floor(
|
|
45
|
+
Math.random() * (Number.isInteger(opts.delay) ? opts.delay : this._defaultDelay)
|
|
46
|
+
)
|
|
47
|
+
this._scheduledUpdate = null
|
|
48
|
+
|
|
43
49
|
this._debouncedUpdate = debounceify(this._update.bind(this))
|
|
44
50
|
|
|
45
51
|
this.ready().catch(noop)
|
|
@@ -56,9 +62,13 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
56
62
|
})
|
|
57
63
|
|
|
58
64
|
this._debouncedUpdate().catch((err) => this.emit('error', err))
|
|
59
|
-
this.drive.core.on('append', () =>
|
|
60
|
-
this.
|
|
61
|
-
|
|
65
|
+
this.drive.core.on('append', () => {
|
|
66
|
+
if (this._scheduledUpdate !== null) clearTimeout(this._scheduledUpdate) // cancel old pending updates before scheduling new one
|
|
67
|
+
this._scheduledUpdate = setTimeout(() => {
|
|
68
|
+
this._debouncedUpdate().catch((err) => this.emit('error', err))
|
|
69
|
+
}, this._delay)
|
|
70
|
+
this.emit('update-scheduled', this._delay)
|
|
71
|
+
})
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
|
|
@@ -67,6 +77,7 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
67
77
|
|
|
68
78
|
if (!this.updates) return
|
|
69
79
|
if (this.checkout !== null) await this.checkout.close()
|
|
80
|
+
if (this._scheduledUpdate) clearTimeout(this._scheduledUpdate)
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
async applyUpdate() {
|
|
@@ -118,8 +129,16 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
118
129
|
const local = new Localdrive(next)
|
|
119
130
|
|
|
120
131
|
const prefix = prefixFor(host, this.name)
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
// Binary may be a file or a directory bundle
|
|
133
|
+
// Entries exist only for files, so try exact path first, then iterate under it
|
|
134
|
+
let hasContent = (await co.entry(prefix)) !== null
|
|
135
|
+
if (!hasContent) {
|
|
136
|
+
for await (const _entry of co.list(prefix)) {
|
|
137
|
+
hasContent = true
|
|
138
|
+
break
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!hasContent) throw new Error('update not found')
|
|
123
142
|
this.updating = true
|
|
124
143
|
this.emit('updating')
|
|
125
144
|
for await (const data of co.mirror(local, { prefix })) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-runtime-updater",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10",
|
|
4
4
|
"description": "Listens for OTA Pear App updates",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Holepunch Inc",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"format": "prettier . --write",
|
|
22
22
|
"test": "npm run test:node && npm run test:bare",
|
|
23
|
-
"test:node": "brittle-node test/index.test.js",
|
|
24
|
-
"test:bare": "brittle-bare test/index.test.js",
|
|
23
|
+
"test:node": "brittle-node test/index.test.js test/e2e.test.js",
|
|
24
|
+
"test:bare": "brittle-bare test/index.test.js test/e2e.test.js",
|
|
25
25
|
"lint": "prettier --check . && lunte"
|
|
26
26
|
},
|
|
27
27
|
"imports": {
|
|
@@ -69,5 +69,19 @@
|
|
|
69
69
|
"prettier": "^3.8.1",
|
|
70
70
|
"prettier-config-holepunch": "^2.0.0",
|
|
71
71
|
"test-tmp": "^1.4.0"
|
|
72
|
-
}
|
|
72
|
+
},
|
|
73
|
+
"directories": {
|
|
74
|
+
"test": "test"
|
|
75
|
+
},
|
|
76
|
+
"repository": {
|
|
77
|
+
"type": "git",
|
|
78
|
+
"url": "git+https://github.com/holepunchto/pear-runtime-updater.git"
|
|
79
|
+
},
|
|
80
|
+
"keywords": [],
|
|
81
|
+
"type": "commonjs",
|
|
82
|
+
"types": "./index.d.ts",
|
|
83
|
+
"bugs": {
|
|
84
|
+
"url": "https://github.com/holepunchto/pear-runtime-updater/issues"
|
|
85
|
+
},
|
|
86
|
+
"homepage": "https://github.com/holepunchto/pear-runtime-updater#readme"
|
|
73
87
|
}
|