pear-runtime-updater 3.0.2 → 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 +43 -4
- package/package.json +6 -5
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const ReadyResource = require('ready-resource')
|
|
|
7
7
|
const link = require('pear-link')
|
|
8
8
|
const hid = require('hypercore-id-encoding')
|
|
9
9
|
const { platform, arch, isWindows } = require('which-runtime')
|
|
10
|
+
const semver = require('bare-semver')
|
|
10
11
|
const host = platform + '-' + arch
|
|
11
12
|
|
|
12
13
|
module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
@@ -20,7 +21,7 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
20
21
|
|
|
21
22
|
this.dir = opts.dir
|
|
22
23
|
this.store = opts.store
|
|
23
|
-
this.version = opts.version || 0
|
|
24
|
+
this.version = opts.version || '0.0.0-0'
|
|
24
25
|
this.app = opts.app
|
|
25
26
|
this.name = opts.name
|
|
26
27
|
this.bundled = opts.bundled || !!this.app
|
|
@@ -34,6 +35,7 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
34
35
|
|
|
35
36
|
this.next = null
|
|
36
37
|
this.checkout = null
|
|
38
|
+
this.prefetched = false
|
|
37
39
|
this.updating = false
|
|
38
40
|
this.updated = false
|
|
39
41
|
|
|
@@ -70,7 +72,7 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
70
72
|
if (isWindows) {
|
|
71
73
|
const MSIXManager = require('msix-manager') // require must be here for platform compatibility
|
|
72
74
|
const manager = new MSIXManager()
|
|
73
|
-
await manager.addPackage(nextApp)
|
|
75
|
+
await manager.addPackage(nextApp, { forceUpdateFromAnyVersion: true })
|
|
74
76
|
} else {
|
|
75
77
|
await fsx.swap(nextApp, this.app)
|
|
76
78
|
}
|
|
@@ -85,6 +87,8 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
85
87
|
if (this.updating || !this.updates) return
|
|
86
88
|
this.updating = true
|
|
87
89
|
|
|
90
|
+
await this.drive.update()
|
|
91
|
+
|
|
88
92
|
const length = this.drive.core.length
|
|
89
93
|
const id = length + '.' + this.drive.core.fork
|
|
90
94
|
const next = path.join(this.dir, 'pear-runtime/next', id)
|
|
@@ -93,17 +97,30 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
93
97
|
this.checkout = co
|
|
94
98
|
|
|
95
99
|
const manifest = await co.get('/package.json')
|
|
96
|
-
|
|
100
|
+
|
|
101
|
+
const current = semver.Version.parse(this.version)
|
|
102
|
+
const remote = manifest ? semver.Version.parse(JSON.parse(manifest).version) : null
|
|
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
|
+
|
|
112
|
+
if (!remote || current.compare(remote) >= 0) {
|
|
97
113
|
this.updating = false
|
|
98
114
|
this.checkout = null
|
|
99
115
|
await co.close()
|
|
116
|
+
if (this.drive.core.length > length) this._updateBackground()
|
|
100
117
|
return
|
|
101
118
|
}
|
|
102
119
|
|
|
103
120
|
const local = new Localdrive(next)
|
|
104
121
|
|
|
105
122
|
this.emit('updating')
|
|
106
|
-
const prefix =
|
|
123
|
+
const prefix = prefixFor(host, this.name)
|
|
107
124
|
for await (const data of co.mirror(local, { prefix })) {
|
|
108
125
|
this.emit('updating-delta', data)
|
|
109
126
|
}
|
|
@@ -121,6 +138,28 @@ module.exports = class PearRuntimeUpdater extends ReadyResource {
|
|
|
121
138
|
|
|
122
139
|
if (this.drive.core.length > length) this._updateBackground()
|
|
123
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}`
|
|
124
163
|
}
|
|
125
164
|
|
|
126
165
|
function noop() {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-runtime-updater",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
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/
|
|
24
|
-
"test:bare": "brittle-bare test/
|
|
23
|
+
"test:node": "brittle-node test/index.test.js",
|
|
24
|
+
"test:bare": "brittle-bare test/index.test.js",
|
|
25
25
|
"lint": "prettier --check . && lunte"
|
|
26
26
|
},
|
|
27
27
|
"imports": {
|
|
@@ -45,11 +45,12 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"bare-fs": "^4.5.3",
|
|
47
47
|
"bare-path": "^3.0.0",
|
|
48
|
+
"bare-semver": "^1.0.2",
|
|
48
49
|
"fs-native-extensions": "^1.4.5",
|
|
49
50
|
"hypercore-id-encoding": "^1.3.0",
|
|
50
51
|
"hyperdrive": "^13.2.1",
|
|
51
52
|
"localdrive": "^2.2.0",
|
|
52
|
-
"msix-manager": "^0.2.
|
|
53
|
+
"msix-manager": "^0.2.4",
|
|
53
54
|
"pear-link": "^4.2.1",
|
|
54
55
|
"ready-resource": "^1.2.0",
|
|
55
56
|
"which-runtime": "^1.3.2"
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"corestore": "^7.9.1",
|
|
64
65
|
"hyperswarm": "^4.17.0",
|
|
65
66
|
"lunte": "^1.6.0",
|
|
66
|
-
"pear-build": "^
|
|
67
|
+
"pear-build": "^1.1.0",
|
|
67
68
|
"prettier": "^3.8.1",
|
|
68
69
|
"prettier-config-holepunch": "^2.0.0",
|
|
69
70
|
"test-tmp": "^1.4.0"
|