pear-runtime-updater 3.0.6 → 3.0.8
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/index.js +18 -12
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const link = require('pear-link')
|
|
|
8
8
|
const hid = require('hypercore-id-encoding')
|
|
9
9
|
const { platform, arch, isWindows } = require('which-runtime')
|
|
10
10
|
const semver = require('bare-semver')
|
|
11
|
+
const debounceify = require('debounceify')
|
|
11
12
|
const host = platform + '-' + arch
|
|
12
13
|
|
|
13
14
|
module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
@@ -39,6 +40,8 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
39
40
|
this.updating = false
|
|
40
41
|
this.updated = false
|
|
41
42
|
|
|
43
|
+
this._debouncedUpdate = debounceify(this._update.bind(this))
|
|
44
|
+
|
|
42
45
|
this.ready().catch(noop)
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -52,8 +55,10 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
52
55
|
force: true
|
|
53
56
|
})
|
|
54
57
|
|
|
55
|
-
this.
|
|
56
|
-
this.drive.core.on('append', () =>
|
|
58
|
+
this._debouncedUpdate().catch((err) => this.emit('error', err))
|
|
59
|
+
this.drive.core.on('append', () =>
|
|
60
|
+
this._debouncedUpdate().catch((err) => this.emit('error', err))
|
|
61
|
+
)
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
|
|
@@ -79,12 +84,8 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
79
84
|
await fs.promises.rm(this.next, { recursive: true, force: true })
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
_updateBackground() {
|
|
83
|
-
this._update().catch((err) => this.emit('error', err))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
87
|
async _update() {
|
|
87
|
-
if (
|
|
88
|
+
if (!this.updates) return
|
|
88
89
|
|
|
89
90
|
await this.drive.update()
|
|
90
91
|
|
|
@@ -111,15 +112,22 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
111
112
|
if (!remote || current.compare(remote) >= 0) {
|
|
112
113
|
this.checkout = null
|
|
113
114
|
await co.close()
|
|
114
|
-
if (this.drive.core.length > length) this._updateBackground()
|
|
115
115
|
return
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
const local = new Localdrive(next)
|
|
119
119
|
|
|
120
120
|
const prefix = prefixFor(host, this.name)
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
// Binary may be a file or a directory bundle
|
|
122
|
+
// Entries exist only for files, so try exact path first, then iterate under it
|
|
123
|
+
let hasContent = (await co.entry(prefix)) !== null
|
|
124
|
+
if (!hasContent) {
|
|
125
|
+
for await (const _entry of co.list(prefix)) {
|
|
126
|
+
hasContent = true
|
|
127
|
+
break
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!hasContent) throw new Error('update not found')
|
|
123
131
|
this.updating = true
|
|
124
132
|
this.emit('updating')
|
|
125
133
|
for await (const data of co.mirror(local, { prefix })) {
|
|
@@ -136,8 +144,6 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
136
144
|
this.updating = false
|
|
137
145
|
this.updated = true
|
|
138
146
|
this.emit('updated')
|
|
139
|
-
|
|
140
|
-
if (this.drive.core.length > length) this._updateBackground()
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
async _prefetchLatest() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-runtime-updater",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
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": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"bare-fs": "^4.5.3",
|
|
47
47
|
"bare-path": "^3.0.0",
|
|
48
48
|
"bare-semver": "^1.0.2",
|
|
49
|
+
"debounceify": "^1.1.0",
|
|
49
50
|
"fs-native-extensions": "^1.4.5",
|
|
50
51
|
"hypercore-id-encoding": "^1.3.0",
|
|
51
52
|
"hyperdrive": "^13.2.1",
|