pear-runtime-updater 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/index.js +19 -8
  2. package/package.json +22 -4
package/index.js CHANGED
@@ -8,7 +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 { platform, arch } = require('which-runtime')
11
+ const { platform, arch, isWindows } = require('which-runtime')
12
12
  const host = platform + '-' + arch
13
13
 
14
14
  module.exports = class PearRuntime extends ReadyResource {
@@ -22,7 +22,10 @@ module.exports = class PearRuntime extends ReadyResource {
22
22
  this.version = opts.version || 0
23
23
  this.app = opts.app
24
24
  this.name = opts.name ?? (this.app && path.basename(this.app))
25
+ if (isWindows) this.name = path.basename(this.name, path.extname(this.name)) + '.msix'
26
+ this.bootstrap = opts.bootstrap
25
27
  this.bundled = opts.bundled || !!this.app
28
+ this.win32RestartAfterUpdate = opts.win32 && opts.win32.restart
26
29
 
27
30
  if (this.updates) {
28
31
  const { drive: upgrade } = link.parse(opts.upgrade)
@@ -62,7 +65,7 @@ module.exports = class PearRuntime extends ReadyResource {
62
65
 
63
66
  if (!this.swarm) {
64
67
  const keyPair = await this.store.createKeyPair('pear-container')
65
- this.swarm = new Hyperswarm({ keyPair })
68
+ this.swarm = new Hyperswarm({ keyPair, bootstrap: this.bootstrap })
66
69
  }
67
70
 
68
71
  this.swarm.on('connection', (connection) => this.store.replicate(connection))
@@ -77,18 +80,26 @@ module.exports = class PearRuntime extends ReadyResource {
77
80
  }
78
81
 
79
82
  async _close() {
80
- await this.drive?.close()
81
- await this.checkout?.close()
82
- await this.store?.destroy()
83
- await this.swarm?.destroy()
83
+ if (!this.updates) return
84
+
85
+ await this.drive.close()
86
+ if (this.checkout !== null) await this.checkout.close()
87
+ await this.store.close()
88
+ await this.swarm.destroy()
84
89
  }
85
90
 
86
91
  async applyUpdate() {
87
92
  if (!this.updated || this.applied || !this.bundled) return
88
93
  this.applied = true
89
94
 
90
- // mac only for now, linux similar, windows, more pain
91
- await fsx.swap(path.join(this.next, 'by-arch', host, 'app', this.name), this.app)
95
+ const nextApp = path.join(this.next, 'by-arch', host, 'app', this.name)
96
+ if (isWindows) {
97
+ const MSIXManager = require('msix-manager') // require must be here for platform compatibility
98
+ const manager = new MSIXManager()
99
+ await manager.addPackage(nextApp, { restartOnUpdate: this.win32RestartAfterUpdate })
100
+ } else {
101
+ await fsx.swap(nextApp, this.app)
102
+ }
92
103
  await fs.promises.rm(this.next, { recursive: true, force: true })
93
104
  }
94
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-runtime-updater",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Listens for OTA Pear App updates",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc",
@@ -19,8 +19,10 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "format": "prettier . --write",
22
- "test": "prettier . --check && lunte",
23
- "lint": "lunte"
22
+ "test": "npm run test:node && npm run test:bare",
23
+ "test:node": "brittle-node test/updates.test.js",
24
+ "test:bare": "brittle-bare test/updates.test.js",
25
+ "lint": "prettier --check . && lunte"
24
26
  },
25
27
  "imports": {
26
28
  "fs": {
@@ -30,6 +32,14 @@
30
32
  "path": {
31
33
  "bare": "bare-path",
32
34
  "default": "path"
35
+ },
36
+ "os": {
37
+ "bare": "bare-os",
38
+ "default": "os"
39
+ },
40
+ "child_process": {
41
+ "bare": "bare-subprocess",
42
+ "default": "child_process"
33
43
  }
34
44
  },
35
45
  "dependencies": {
@@ -41,13 +51,21 @@
41
51
  "hyperdrive": "^13.2.1",
42
52
  "hyperswarm": "^4.16.0",
43
53
  "localdrive": "^2.2.0",
54
+ "msix-manager": "^0.1.2",
44
55
  "pear-link": "^4.2.1",
45
56
  "ready-resource": "^1.2.0",
46
57
  "which-runtime": "^1.3.2"
47
58
  },
48
59
  "devDependencies": {
60
+ "@hyperswarm/testnet": "^3.1.4",
61
+ "bare-env": "^3.0.0",
62
+ "bare-os": "^3.7.0",
63
+ "bare-subprocess": "^5.2.2",
64
+ "brittle": "^3.19.1",
49
65
  "lunte": "^1.6.0",
66
+ "pear-build": "^0.2.0",
50
67
  "prettier": "^3.8.1",
51
- "prettier-config-holepunch": "^2.0.0"
68
+ "prettier-config-holepunch": "^2.0.0",
69
+ "test-tmp": "^1.4.0"
52
70
  }
53
71
  }