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