electron-incremental-update 0.8.3 → 0.8.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/README.md +233 -234
- package/dist/{chunk-7R4GHFED.mjs → chunk-CR6HTU6P.mjs} +3 -3
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/utils.js +3 -3
- package/dist/utils.mjs +1 -1
- package/dist/vite.js +23 -28
- package/dist/vite.mjs +21 -26
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -1,234 +1,233 @@
|
|
|
1
|
-
## electron incremental updater
|
|
2
|
-
|
|
3
|
-
This project provide a vite plugin, `Updater` class and some useful functions to generate incremental update.
|
|
4
|
-
|
|
5
|
-
There will be two asar in production, `app.asar` and `main.asar` (if "main" is your app's name).
|
|
6
|
-
|
|
7
|
-
The `app.asar` is used to load `main.asar` and initialize the `updater`. Also, all the **native modules**, which are set as `dependencies` in `package.json`, will be packaged into `app.asar` by `electron-builder`, [see usage](#use-native-modules).
|
|
8
|
-
|
|
9
|
-
The new `main.asar` downloaded from remote will be verified by presigned RSA + Signature. When pass the check and restart, the old `main.asar` will be replaced by the new one. Hooks like `beforeDoUpdate` are provided.
|
|
10
|
-
|
|
11
|
-
- inspired by Obsidian's update strategy
|
|
12
|
-
|
|
13
|
-
### notice
|
|
14
|
-
|
|
15
|
-
- this plugin is developed with [vite-plugin-electron](https://github.com/electron-vite/vite-plugin-electron), and may be effect in other electron vite frameworks
|
|
16
|
-
- **all options are documented in the jsdoc**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
├──
|
|
41
|
-
├──
|
|
42
|
-
├──
|
|
43
|
-
│ ├──
|
|
44
|
-
|
|
45
|
-
└──
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
import {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const { cdnPrefix:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
repository,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
'app.
|
|
143
|
-
'!**/{.
|
|
144
|
-
'
|
|
145
|
-
'
|
|
146
|
-
'!**/*.{
|
|
147
|
-
'
|
|
148
|
-
'
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
import
|
|
178
|
-
import {
|
|
179
|
-
import {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
console.log(
|
|
185
|
-
console.log(`\
|
|
186
|
-
console.log(`\
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
updater.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
```
|
|
1
|
+
## electron incremental updater
|
|
2
|
+
|
|
3
|
+
This project provide a vite plugin, `Updater` class and some useful functions to generate incremental update.
|
|
4
|
+
|
|
5
|
+
There will be two asar in production, `app.asar` and `main.asar` (if "main" is your app's name).
|
|
6
|
+
|
|
7
|
+
The `app.asar` is used to load `main.asar` and initialize the `updater`. Also, all the **native modules**, which are set as `dependencies` in `package.json`, will be packaged into `app.asar` by `electron-builder`, [see usage](#use-native-modules).
|
|
8
|
+
|
|
9
|
+
The new `main.asar` downloaded from remote will be verified by presigned RSA + Signature. When pass the check and restart, the old `main.asar` will be replaced by the new one. Hooks like `beforeDoUpdate` are provided.
|
|
10
|
+
|
|
11
|
+
- inspired by Obsidian's update strategy
|
|
12
|
+
|
|
13
|
+
### notice
|
|
14
|
+
|
|
15
|
+
- this plugin is developed with [vite-plugin-electron](https://github.com/electron-vite/vite-plugin-electron), and may be effect in other electron vite frameworks
|
|
16
|
+
- **all options are documented in the jsdoc**
|
|
17
|
+
|
|
18
|
+
## install
|
|
19
|
+
|
|
20
|
+
### npm
|
|
21
|
+
```bash
|
|
22
|
+
npm install electron-incremental-update
|
|
23
|
+
```
|
|
24
|
+
### yarn
|
|
25
|
+
```bash
|
|
26
|
+
yarn add electron-incremental-update
|
|
27
|
+
```
|
|
28
|
+
### pnpm
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add electron-incremental-update
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## setup
|
|
34
|
+
|
|
35
|
+
base on [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue)
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
electron
|
|
39
|
+
├── app.ts // <- add app entry file
|
|
40
|
+
├── electron-env.d.ts
|
|
41
|
+
├── main
|
|
42
|
+
│ ├── db.ts
|
|
43
|
+
│ ├── index.ts
|
|
44
|
+
└── preload
|
|
45
|
+
└── index.ts
|
|
46
|
+
src
|
|
47
|
+
└── ...
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### setup app
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// electron/app.ts
|
|
54
|
+
import { getGithubReleaseCdnGroup, initApp, parseGithubCdnURL } from 'electron-incremental-update'
|
|
55
|
+
import { name, repository } from '../package.json'
|
|
56
|
+
|
|
57
|
+
const SIGNATURE_CERT = '' // auto generate certificate when start app
|
|
58
|
+
|
|
59
|
+
const { cdnPrefix: asarPrefix } = getGithubReleaseCdnGroup()[0]
|
|
60
|
+
const { cdnPrefix: jsonPrefix } = getGithubFileCdnGroup()[0]
|
|
61
|
+
initApp({ onStart: console.log })
|
|
62
|
+
// can be updater option or function that return updater
|
|
63
|
+
.setUpdater({
|
|
64
|
+
SIGNATURE_CERT,
|
|
65
|
+
productName: name,
|
|
66
|
+
repository,
|
|
67
|
+
updateJsonURL: parseGithubCdnURL(repository, jsonPrefix, 'version.json'),
|
|
68
|
+
releaseAsarURL: parseGithubCdnURL(repository, asarPrefix, `download/latest/${name}.asar.gz`),
|
|
69
|
+
receiveBeta: true
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### setup vite.config.ts
|
|
74
|
+
|
|
75
|
+
make sure the plugin is set in the **last** build task
|
|
76
|
+
|
|
77
|
+
- for `vite-plugin-electron`, set it to `preload` (the second object in the plugin option array)
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// vite.config.ts
|
|
81
|
+
export default defineConfig(({ command }) => {
|
|
82
|
+
|
|
83
|
+
const isBuild = command === 'build'
|
|
84
|
+
// ...
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
plugins: [
|
|
88
|
+
electron([
|
|
89
|
+
// main
|
|
90
|
+
{
|
|
91
|
+
// ...
|
|
92
|
+
},
|
|
93
|
+
// preload
|
|
94
|
+
{
|
|
95
|
+
// ...
|
|
96
|
+
vite: {
|
|
97
|
+
plugins: [
|
|
98
|
+
updater({
|
|
99
|
+
productName: pkg.name,
|
|
100
|
+
version: pkg.version,
|
|
101
|
+
isBuild,
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
// ...
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
// when using vite-plugin-electron-renderer
|
|
108
|
+
{
|
|
109
|
+
// ...
|
|
110
|
+
}
|
|
111
|
+
]),
|
|
112
|
+
// ...
|
|
113
|
+
],
|
|
114
|
+
// ...
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### modify package.json
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
// ...
|
|
124
|
+
"main": "app.js" // <- app entry file
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### config electron-builder
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
const { name } = require('./package.json')
|
|
132
|
+
|
|
133
|
+
const target = `${name}.asar`
|
|
134
|
+
/**
|
|
135
|
+
* @type {import('electron-builder').Configuration}
|
|
136
|
+
*/
|
|
137
|
+
module.exports = {
|
|
138
|
+
appId: 'YourAppID',
|
|
139
|
+
productName: name,
|
|
140
|
+
files: [
|
|
141
|
+
'app.js', // <- app entry file
|
|
142
|
+
'!**/{.eslintignore,.eslintrc.cjs,.editorconfig,.prettierignore,.prettierrc.yaml,dev-app-update.yml,LICENSE,.nvmrc,.npmrc}',
|
|
143
|
+
'!**/{tsconfig.json,tsconfig.node.json,tsconfig.web.json}',
|
|
144
|
+
'!**/*debug*.*',
|
|
145
|
+
'!**/*.{md,zip,map}',
|
|
146
|
+
'!**/*.{c,cpp,h,hpp,cc,hh,cxx,hxx,gypi,gyp,sh}',
|
|
147
|
+
'!**/.{github,vscode}',
|
|
148
|
+
'!node_modules/**/better-sqlite3/deps/**',
|
|
149
|
+
],
|
|
150
|
+
asarUnpack: [
|
|
151
|
+
'**/*.{node,dll}',
|
|
152
|
+
],
|
|
153
|
+
directories: {
|
|
154
|
+
output: 'release',
|
|
155
|
+
},
|
|
156
|
+
extraResources: [
|
|
157
|
+
{ from: `release/${target}`, to: target }, // <- asar file
|
|
158
|
+
],
|
|
159
|
+
publish: null, // <- disable publish
|
|
160
|
+
// ...
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Usage
|
|
165
|
+
|
|
166
|
+
### use in main process
|
|
167
|
+
|
|
168
|
+
To use electron's `net` module for updating, the `checkUpdate` and `download` functions must be called after the app is ready by default.
|
|
169
|
+
|
|
170
|
+
However, you have the option to customize the download function when creating the updater.
|
|
171
|
+
|
|
172
|
+
**NOTE: There can only be one function and should be default export in the entry file**
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// electron/main/index.ts
|
|
176
|
+
import type { StartupWithUpdater, Updater } from 'electron-incremental-update'
|
|
177
|
+
import { getEntryVersion, getProductAsarPath, getProductVersion } from 'electron-incremental-update'
|
|
178
|
+
import { app } from 'electron'
|
|
179
|
+
import { name } from '../../package.json'
|
|
180
|
+
|
|
181
|
+
const startup: StartupWithUpdater = (updater: Updater) => {
|
|
182
|
+
await app.whenReady()
|
|
183
|
+
console.log('\ncurrent:')
|
|
184
|
+
console.log(`\tasar path: ${getProductAsarPath(name)}`)
|
|
185
|
+
console.log(`\tentry: ${getEntryVersion()}`)
|
|
186
|
+
console.log(`\tapp: ${getProductVersion(name)}`)
|
|
187
|
+
updater.onDownloading = ({ percent }) => {
|
|
188
|
+
console.log(percent)
|
|
189
|
+
}
|
|
190
|
+
updater.logger = console
|
|
191
|
+
updater.checkUpdate().then(async (result) => {
|
|
192
|
+
if (result === undefined) {
|
|
193
|
+
console.log('Update Unavailable')
|
|
194
|
+
} else if (result instanceof Error) {
|
|
195
|
+
console.error(result)
|
|
196
|
+
} else {
|
|
197
|
+
console.log('new version: ', result.version)
|
|
198
|
+
const { response } = await dialog.showMessageBox({
|
|
199
|
+
type: 'info',
|
|
200
|
+
buttons: ['Download', 'Later'],
|
|
201
|
+
message: 'Application update available!',
|
|
202
|
+
})
|
|
203
|
+
response === 0 && console.log(await updater.download())
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
export default startup
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### use native modules
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
// db.ts
|
|
214
|
+
import { requireNative } from 'electron-incremental-update'
|
|
215
|
+
|
|
216
|
+
const Database = requireNative<typeof import('better-sqlite3')>('better-sqlite3')
|
|
217
|
+
const db = new Database(':memory:')
|
|
218
|
+
db.exec(
|
|
219
|
+
'DROP TABLE IF EXISTS employees; '
|
|
220
|
+
+ 'CREATE TABLE IF NOT EXISTS employees (name TEXT, salary INTEGER)',
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
db.prepare('INSERT INTO employees VALUES (:n, :s)').run({
|
|
224
|
+
n: 'James',
|
|
225
|
+
s: 50000,
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const r = db.prepare('SELECT * from employees').all()
|
|
229
|
+
console.log(r)
|
|
230
|
+
// [ { name: 'James', salary: 50000 } ]
|
|
231
|
+
|
|
232
|
+
db.close()
|
|
233
|
+
```
|
|
@@ -13,13 +13,13 @@ var info = {
|
|
|
13
13
|
appPath: Electron.app?.getAppPath()
|
|
14
14
|
};
|
|
15
15
|
function getProductAsarPath(name) {
|
|
16
|
-
return info.dev ? join(dirname(info.appPath), `${name}.asar`)
|
|
16
|
+
return info.dev ? "dev.asar" : join(dirname(info.appPath), `${name}.asar`);
|
|
17
17
|
}
|
|
18
18
|
function getEntryVersion() {
|
|
19
19
|
return Electron.app.getVersion();
|
|
20
20
|
}
|
|
21
21
|
function getProductVersion(name) {
|
|
22
|
-
return info.dev ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8")
|
|
22
|
+
return info.dev ? getEntryVersion() : readFileSync(join(getProductAsarPath(name), "version"), "utf-8");
|
|
23
23
|
}
|
|
24
24
|
var NoSuchNativeModuleError = class extends Error {
|
|
25
25
|
moduleName;
|
|
@@ -29,7 +29,7 @@ var NoSuchNativeModuleError = class extends Error {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
function requireNative(packageName) {
|
|
32
|
-
const path = info.dev ? join(info.appPath, "node_modules", packageName)
|
|
32
|
+
const path = info.dev ? packageName : join(info.appPath, "node_modules", packageName);
|
|
33
33
|
try {
|
|
34
34
|
return __require(path);
|
|
35
35
|
} catch (error) {
|
package/dist/index.js
CHANGED
|
@@ -54,13 +54,13 @@ var info = {
|
|
|
54
54
|
appPath: import_electron.default.app?.getAppPath()
|
|
55
55
|
};
|
|
56
56
|
function getProductAsarPath(name) {
|
|
57
|
-
return info.dev ? (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`)
|
|
57
|
+
return info.dev ? "dev.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`);
|
|
58
58
|
}
|
|
59
59
|
function getEntryVersion() {
|
|
60
60
|
return import_electron.default.app.getVersion();
|
|
61
61
|
}
|
|
62
62
|
function getProductVersion(name) {
|
|
63
|
-
return info.dev ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8")
|
|
63
|
+
return info.dev ? getEntryVersion() : (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8");
|
|
64
64
|
}
|
|
65
65
|
function waitAppReady(duration = 1e3) {
|
|
66
66
|
return new Promise((resolve2, reject) => {
|
package/dist/index.mjs
CHANGED
package/dist/utils.js
CHANGED
|
@@ -57,13 +57,13 @@ var info = {
|
|
|
57
57
|
appPath: import_electron.default.app?.getAppPath()
|
|
58
58
|
};
|
|
59
59
|
function getProductAsarPath(name) {
|
|
60
|
-
return info.dev ? (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`)
|
|
60
|
+
return info.dev ? "dev.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`);
|
|
61
61
|
}
|
|
62
62
|
function getEntryVersion() {
|
|
63
63
|
return import_electron.default.app.getVersion();
|
|
64
64
|
}
|
|
65
65
|
function getProductVersion(name) {
|
|
66
|
-
return info.dev ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8")
|
|
66
|
+
return info.dev ? getEntryVersion() : (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8");
|
|
67
67
|
}
|
|
68
68
|
var NoSuchNativeModuleError = class extends Error {
|
|
69
69
|
moduleName;
|
|
@@ -73,7 +73,7 @@ var NoSuchNativeModuleError = class extends Error {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
function requireNative(packageName) {
|
|
76
|
-
const path = info.dev ? (0, import_node_path.join)(info.appPath, "node_modules", packageName)
|
|
76
|
+
const path = info.dev ? packageName : (0, import_node_path.join)(info.appPath, "node_modules", packageName);
|
|
77
77
|
try {
|
|
78
78
|
return require(path);
|
|
79
79
|
} catch (error) {
|
package/dist/utils.mjs
CHANGED
package/dist/vite.js
CHANGED
|
@@ -33,13 +33,13 @@ __export(vite_exports, {
|
|
|
33
33
|
ElectronUpdater: () => ElectronUpdater
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(vite_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_vite = require("vite");
|
|
37
37
|
|
|
38
38
|
// src/build-plugins/build.ts
|
|
39
39
|
var import_promises = require("fs/promises");
|
|
40
40
|
var import_node_fs2 = require("fs");
|
|
41
41
|
var import_asar = __toESM(require("@electron/asar"));
|
|
42
|
-
var
|
|
42
|
+
var import_esbuild = require("esbuild");
|
|
43
43
|
|
|
44
44
|
// src/crypto.ts
|
|
45
45
|
var import_node_crypto = require("crypto");
|
|
@@ -184,21 +184,13 @@ async function buildEntry({
|
|
|
184
184
|
entryOutputPath: outfile,
|
|
185
185
|
minify
|
|
186
186
|
}) {
|
|
187
|
-
await (0,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
rollupOptions: {
|
|
195
|
-
treeshake: true,
|
|
196
|
-
external: ["electron", "original-fs"],
|
|
197
|
-
output: {
|
|
198
|
-
file: outfile
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
187
|
+
await (0, import_esbuild.build)({
|
|
188
|
+
entryPoints: [entryPath],
|
|
189
|
+
bundle: true,
|
|
190
|
+
platform: "node",
|
|
191
|
+
outfile,
|
|
192
|
+
minify,
|
|
193
|
+
external: ["electron", "original-fs"]
|
|
202
194
|
});
|
|
203
195
|
}
|
|
204
196
|
|
|
@@ -208,7 +200,6 @@ var import_ci_info = require("ci-info");
|
|
|
208
200
|
// src/build-plugins/key.ts
|
|
209
201
|
var import_node_fs3 = require("fs");
|
|
210
202
|
var import_node_path2 = require("path");
|
|
211
|
-
var import_node_os = require("os");
|
|
212
203
|
var import_selfsigned = require("selfsigned");
|
|
213
204
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
214
205
|
const privateKeyDir = (0, import_node_path2.dirname)(privateKeyPath);
|
|
@@ -225,15 +216,18 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
|
225
216
|
}
|
|
226
217
|
function writeCertToMain(entryPath, cert) {
|
|
227
218
|
const file = (0, import_node_fs3.readFileSync)(entryPath, "utf-8");
|
|
228
|
-
const
|
|
229
|
-
const
|
|
219
|
+
const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
220
|
+
const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
221
|
+
const eol = file.includes("\r") ? "\r\n" : "\n";
|
|
222
|
+
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
|
|
230
223
|
let replaced = file;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
224
|
+
if (initRegex.test(file)) {
|
|
225
|
+
replaced = file.replace(initRegex, replacement);
|
|
226
|
+
} else if (existRegex.test(file)) {
|
|
227
|
+
replaced = file.replace(existRegex, replacement);
|
|
234
228
|
} else {
|
|
235
|
-
const lines = file.split(
|
|
236
|
-
const r = `${
|
|
229
|
+
const lines = file.split(eol);
|
|
230
|
+
const r = `${eol}const SIGNATURE_CERT = ${replacement}${eol}`;
|
|
237
231
|
let isMatched = false;
|
|
238
232
|
for (let i = 0; i < lines.length; i++) {
|
|
239
233
|
const line = lines[i];
|
|
@@ -244,9 +238,10 @@ function writeCertToMain(entryPath, cert) {
|
|
|
244
238
|
}
|
|
245
239
|
}
|
|
246
240
|
!isMatched && lines.push(r);
|
|
247
|
-
replaced = lines.join(
|
|
241
|
+
replaced = lines.join(eol);
|
|
248
242
|
}
|
|
249
|
-
(
|
|
243
|
+
console.log(JSON.stringify(replaced));
|
|
244
|
+
(0, import_node_fs3.writeFileSync)(entryPath, replaced);
|
|
250
245
|
}
|
|
251
246
|
function parseKeys({
|
|
252
247
|
keyLength,
|
|
@@ -353,7 +348,7 @@ function ElectronUpdater(options) {
|
|
|
353
348
|
const { entryPath, entryOutputPath } = buildEntryOption;
|
|
354
349
|
const { asarOutputPath } = buildAsarOption;
|
|
355
350
|
const id = "electron-incremental-updater";
|
|
356
|
-
const log = (0,
|
|
351
|
+
const log = (0, import_vite.createLogger)("info", { prefix: `[${id}]` });
|
|
357
352
|
return {
|
|
358
353
|
name: `vite-plugin-${id}`,
|
|
359
354
|
enforce: "post",
|
package/dist/vite.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
parseVersion,
|
|
6
6
|
zipFile
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CR6HTU6P.mjs";
|
|
8
8
|
import {
|
|
9
9
|
isUpdateJSON
|
|
10
10
|
} from "./chunk-2JVXVTC5.mjs";
|
|
@@ -17,7 +17,7 @@ import { createLogger } from "vite";
|
|
|
17
17
|
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
18
18
|
import { existsSync } from "node:fs";
|
|
19
19
|
import Asar from "@electron/asar";
|
|
20
|
-
import { build } from "
|
|
20
|
+
import { build } from "esbuild";
|
|
21
21
|
async function buildAsar({
|
|
22
22
|
version,
|
|
23
23
|
asarOutputPath,
|
|
@@ -88,20 +88,12 @@ async function buildEntry({
|
|
|
88
88
|
minify
|
|
89
89
|
}) {
|
|
90
90
|
await build({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
rollupOptions: {
|
|
98
|
-
treeshake: true,
|
|
99
|
-
external: ["electron", "original-fs"],
|
|
100
|
-
output: {
|
|
101
|
-
file: outfile
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
91
|
+
entryPoints: [entryPath],
|
|
92
|
+
bundle: true,
|
|
93
|
+
platform: "node",
|
|
94
|
+
outfile,
|
|
95
|
+
minify,
|
|
96
|
+
external: ["electron", "original-fs"]
|
|
105
97
|
});
|
|
106
98
|
}
|
|
107
99
|
|
|
@@ -111,7 +103,6 @@ import { isCI } from "ci-info";
|
|
|
111
103
|
// src/build-plugins/key.ts
|
|
112
104
|
import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
113
105
|
import { dirname } from "node:path";
|
|
114
|
-
import { EOL } from "node:os";
|
|
115
106
|
import { generate } from "selfsigned";
|
|
116
107
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
117
108
|
const privateKeyDir = dirname(privateKeyPath);
|
|
@@ -128,15 +119,18 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
|
128
119
|
}
|
|
129
120
|
function writeCertToMain(entryPath, cert) {
|
|
130
121
|
const file = readFileSync(entryPath, "utf-8");
|
|
131
|
-
const
|
|
132
|
-
const
|
|
122
|
+
const initRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
123
|
+
const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
124
|
+
const eol = file.includes("\r") ? "\r\n" : "\n";
|
|
125
|
+
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol}+ `);
|
|
133
126
|
let replaced = file;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
if (initRegex.test(file)) {
|
|
128
|
+
replaced = file.replace(initRegex, replacement);
|
|
129
|
+
} else if (existRegex.test(file)) {
|
|
130
|
+
replaced = file.replace(existRegex, replacement);
|
|
137
131
|
} else {
|
|
138
|
-
const lines = file.split(
|
|
139
|
-
const r = `${
|
|
132
|
+
const lines = file.split(eol);
|
|
133
|
+
const r = `${eol}const SIGNATURE_CERT = ${replacement}${eol}`;
|
|
140
134
|
let isMatched = false;
|
|
141
135
|
for (let i = 0; i < lines.length; i++) {
|
|
142
136
|
const line = lines[i];
|
|
@@ -147,9 +141,10 @@ function writeCertToMain(entryPath, cert) {
|
|
|
147
141
|
}
|
|
148
142
|
}
|
|
149
143
|
!isMatched && lines.push(r);
|
|
150
|
-
replaced = lines.join(
|
|
144
|
+
replaced = lines.join(eol);
|
|
151
145
|
}
|
|
152
|
-
|
|
146
|
+
console.log(JSON.stringify(replaced));
|
|
147
|
+
writeFileSync(entryPath, replaced);
|
|
153
148
|
}
|
|
154
149
|
function parseKeys({
|
|
155
150
|
keyLength,
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"author": "subframe7536",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.5",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup && node fix-module.js",
|
|
8
8
|
"release": "pnpm test && pnpm run build && bumpp --all && npm publish",
|
|
9
|
-
"test": "vitest --run"
|
|
9
|
+
"test": "vitest --run",
|
|
10
|
+
"lint": "eslint . --fix"
|
|
10
11
|
},
|
|
11
12
|
"publishConfig": {
|
|
12
13
|
"access": "public",
|
|
@@ -43,14 +44,14 @@
|
|
|
43
44
|
"updater"
|
|
44
45
|
],
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@subframe7536/eslint-config": "^0.2.
|
|
47
|
-
"@types/node": "^20.
|
|
48
|
-
"bumpp": "^9.
|
|
49
|
-
"electron": "^26.
|
|
50
|
-
"eslint": "^8.
|
|
47
|
+
"@subframe7536/eslint-config": "^0.2.9",
|
|
48
|
+
"@types/node": "^20.6.0",
|
|
49
|
+
"bumpp": "^9.2.0",
|
|
50
|
+
"electron": "^26.2.0",
|
|
51
|
+
"eslint": "^8.49.0",
|
|
51
52
|
"tsup": "^7.2.0",
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"vitest": "^0.34.
|
|
53
|
+
"typescript": "^5.2.2",
|
|
54
|
+
"vitest": "^0.34.4"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"@electron/asar": "^3.2.4",
|