pear-runtime-updater 3.0.3 → 3.0.5
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 +35 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -35,6 +35,7 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
35
35
|
|
|
36
36
|
this.next = null
|
|
37
37
|
this.checkout = null
|
|
38
|
+
this.prefetched = false
|
|
38
39
|
this.updating = false
|
|
39
40
|
this.updated = false
|
|
40
41
|
|
|
@@ -84,7 +85,8 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
84
85
|
|
|
85
86
|
async _update() {
|
|
86
87
|
if (this.updating || !this.updates) return
|
|
87
|
-
|
|
88
|
+
|
|
89
|
+
await this.drive.update()
|
|
88
90
|
|
|
89
91
|
const length = this.drive.core.length
|
|
90
92
|
const id = length + '.' + this.drive.core.fork
|
|
@@ -98,8 +100,15 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
98
100
|
const current = semver.Version.parse(this.version)
|
|
99
101
|
const remote = manifest ? semver.Version.parse(JSON.parse(manifest).version) : null
|
|
100
102
|
|
|
103
|
+
if (remote && current.compare(remote) === 0 && this.bundled && !this.prefetched) {
|
|
104
|
+
try {
|
|
105
|
+
await this._prefetchLatest()
|
|
106
|
+
} catch (err) {
|
|
107
|
+
this.emit('error', err)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
if (!remote || current.compare(remote) >= 0) {
|
|
102
|
-
this.updating = false
|
|
103
112
|
this.checkout = null
|
|
104
113
|
await co.close()
|
|
105
114
|
if (this.drive.core.length > length) this._updateBackground()
|
|
@@ -108,8 +117,9 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
108
117
|
|
|
109
118
|
const local = new Localdrive(next)
|
|
110
119
|
|
|
120
|
+
this.updating = true
|
|
111
121
|
this.emit('updating')
|
|
112
|
-
const prefix =
|
|
122
|
+
const prefix = prefixFor(host, this.name)
|
|
113
123
|
for await (const data of co.mirror(local, { prefix })) {
|
|
114
124
|
this.emit('updating-delta', data)
|
|
115
125
|
}
|
|
@@ -127,6 +137,28 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
127
137
|
|
|
128
138
|
if (this.drive.core.length > length) this._updateBackground()
|
|
129
139
|
}
|
|
140
|
+
|
|
141
|
+
async _prefetchLatest() {
|
|
142
|
+
const length = this.drive.core.length
|
|
143
|
+
if (!length) return
|
|
144
|
+
|
|
145
|
+
const co = this.drive.checkout(length)
|
|
146
|
+
const prefix = prefixFor(host, this.name)
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
if (!(await co.has(prefix))) {
|
|
150
|
+
await co.download(prefix).done()
|
|
151
|
+
}
|
|
152
|
+
} finally {
|
|
153
|
+
await co.close()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.prefetched = true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function prefixFor(host, name) {
|
|
161
|
+
return `/by-arch/${host}/app/${name}`
|
|
130
162
|
}
|
|
131
163
|
|
|
132
164
|
function noop() {}
|