pear-runtime-updater 0.0.13 → 1.0.0
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 +8 -21
- package/package.json +1 -2
package/index.js
CHANGED
|
@@ -8,9 +8,7 @@ const fsx = require('fs-native-extensions')
|
|
|
8
8
|
const ReadyResource = require('ready-resource')
|
|
9
9
|
const link = require('pear-link')
|
|
10
10
|
const hid = require('hypercore-id-encoding')
|
|
11
|
-
const
|
|
12
|
-
const { platform, arch, isWindows } = require('which-runtime')
|
|
13
|
-
const isMobile = platform === 'ios' || platform === 'android'
|
|
11
|
+
const { platform, arch } = require('which-runtime')
|
|
14
12
|
const host = platform + '-' + arch
|
|
15
13
|
|
|
16
14
|
module.exports = class PearRuntime extends ReadyResource {
|
|
@@ -23,7 +21,7 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
23
21
|
this.dir = opts.dir
|
|
24
22
|
this.version = opts.version || 0
|
|
25
23
|
this.app = opts.app
|
|
26
|
-
this.name = this.app && path.basename(this.app)
|
|
24
|
+
this.name = opts.name ?? (this.app && path.basename(this.app))
|
|
27
25
|
this.bundled = opts.bundled || !!this.app
|
|
28
26
|
|
|
29
27
|
if (this.updates) {
|
|
@@ -32,15 +30,17 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
32
30
|
this.length = upgrade.length || 0
|
|
33
31
|
this.fork = upgrade.fork || 0
|
|
34
32
|
this.link = link.serialize({ drive: { fork: this.fork, length: this.length, key: this.key } })
|
|
33
|
+
this.store = new Corestore(path.join(this.dir, 'pear-runtime/corestore'))
|
|
34
|
+
this.drive = new Hyperdrive(this.store, this.key)
|
|
35
35
|
} else {
|
|
36
36
|
this.key = null
|
|
37
37
|
this.length = null
|
|
38
38
|
this.fork = null
|
|
39
39
|
this.link = null
|
|
40
|
+
this.store = null
|
|
41
|
+
this.drive = null
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
this.store = null
|
|
43
|
-
this.drive = null
|
|
44
44
|
this.swarm = null
|
|
45
45
|
this.next = null
|
|
46
46
|
this.checkout = null
|
|
@@ -52,10 +52,6 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
52
52
|
|
|
53
53
|
async _open() {
|
|
54
54
|
if (!this.updates) return
|
|
55
|
-
if (this.store === null) {
|
|
56
|
-
this.store = new Corestore(path.join(this.dir, 'pear-runtime/corestore'))
|
|
57
|
-
}
|
|
58
|
-
if (this.drive === null) this.drive = new Hyperdrive(this.store, this.key)
|
|
59
55
|
await this.drive.ready()
|
|
60
56
|
|
|
61
57
|
if (this.bundled) {
|
|
@@ -92,15 +88,7 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
92
88
|
this.applied = true
|
|
93
89
|
|
|
94
90
|
// mac only for now, linux similar, windows, more pain
|
|
95
|
-
|
|
96
|
-
if (!isMobile && !isWindows) segments.push(this.name)
|
|
97
|
-
if (isWindows) {
|
|
98
|
-
const manager = new MSIXManager()
|
|
99
|
-
const msix = this.name.slice(0, -3) + 'msix'
|
|
100
|
-
await manager.addPackage(...segments, msix)
|
|
101
|
-
} else {
|
|
102
|
-
await fsx.swap(path.join(...segments), this.app)
|
|
103
|
-
}
|
|
91
|
+
await fsx.swap(path.join(this.next, 'by-arch', host, 'app', this.name), this.app)
|
|
104
92
|
await fs.promises.rm(this.next, { recursive: true, force: true })
|
|
105
93
|
}
|
|
106
94
|
|
|
@@ -130,11 +118,10 @@ module.exports = class PearRuntime extends ReadyResource {
|
|
|
130
118
|
const local = new Localdrive(next)
|
|
131
119
|
|
|
132
120
|
this.emit('updating')
|
|
133
|
-
const prefix = `/by-arch/${host}/app
|
|
121
|
+
const prefix = `/by-arch/${host}/app/${this.name}`
|
|
134
122
|
for await (const data of co.mirror(local, { prefix })) {
|
|
135
123
|
this.emit('updating-delta', data)
|
|
136
124
|
}
|
|
137
|
-
if (isMobile) await local.put(`${prefix}/package.json`, manifest)
|
|
138
125
|
|
|
139
126
|
await co.close()
|
|
140
127
|
await local.close()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-runtime-updater",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Listens for OTA Pear App updates",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Holepunch Inc",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"hyperdrive": "^13.2.1",
|
|
42
42
|
"hyperswarm": "^4.16.0",
|
|
43
43
|
"localdrive": "^2.2.0",
|
|
44
|
-
"msix-manager": "^0.1.1",
|
|
45
44
|
"pear-link": "^4.2.1",
|
|
46
45
|
"ready-resource": "^1.2.0",
|
|
47
46
|
"which-runtime": "^1.3.2"
|