pear-runtime-updater 3.0.5 → 3.0.7

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 (2) hide show
  1. package/index.js +11 -11
  2. package/package.json +2 -1
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._updateBackground()
56
- this.drive.core.on('append', () => this._updateBackground())
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 (this.updating || !this.updates) return
88
+ if (!this.updates) return
88
89
 
89
90
  await this.drive.update()
90
91
 
@@ -111,15 +112,16 @@ 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
+ const prefix = prefixFor(host, this.name)
121
+ const exists = await co.get(prefix)
122
+ if (!exists) throw new Error('update not found')
120
123
  this.updating = true
121
124
  this.emit('updating')
122
- const prefix = prefixFor(host, this.name)
123
125
  for await (const data of co.mirror(local, { prefix })) {
124
126
  this.emit('updating-delta', data)
125
127
  }
@@ -134,8 +136,6 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
134
136
  this.updating = false
135
137
  this.updated = true
136
138
  this.emit('updated')
137
-
138
- if (this.drive.core.length > length) this._updateBackground()
139
139
  }
140
140
 
141
141
  async _prefetchLatest() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-runtime-updater",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Listens for OTA Pear App updates",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc",
@@ -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",