electron-incremental-update 0.7.6 → 0.7.8
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/dist/{chunk-Q2K52LOG.mjs → chunk-2XHZMWRR.mjs} +8 -1
- package/dist/{chunk-67MCNA7W.mjs → chunk-SWXNCK6H.mjs} +27 -2
- package/dist/index.d.mts +90 -72
- package/dist/index.d.ts +90 -72
- package/dist/index.js +78 -41
- package/dist/index.mjs +61 -44
- package/dist/updateJson-7e45d9e1.d.ts +11 -0
- package/dist/utils.d.mts +12 -1
- package/dist/utils.d.ts +12 -1
- package/dist/utils.js +28 -1
- package/dist/utils.mjs +5 -1
- package/dist/vite.d.mts +20 -6
- package/dist/vite.d.ts +20 -6
- package/dist/vite.js +79 -47
- package/dist/vite.mjs +60 -34
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -20,20 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
MinimumVersionError: () => MinimumVersionError,
|
|
24
|
+
VerifyFailedError: () => VerifyFailedError,
|
|
23
25
|
createUpdater: () => createUpdater,
|
|
24
26
|
initApp: () => initApp
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(src_exports);
|
|
27
29
|
var import_node_path2 = require("path");
|
|
28
30
|
var import_node_fs3 = require("fs");
|
|
29
|
-
var
|
|
31
|
+
var import_electron3 = require("electron");
|
|
30
32
|
|
|
31
33
|
// src/updater/index.ts
|
|
32
34
|
var import_node_events = require("events");
|
|
33
35
|
var import_node_buffer3 = require("buffer");
|
|
34
36
|
var import_node_fs2 = require("fs");
|
|
35
37
|
var import_promises = require("fs/promises");
|
|
36
|
-
var import_electron3 = require("electron");
|
|
37
38
|
|
|
38
39
|
// src/crypto.ts
|
|
39
40
|
var import_node_crypto = require("crypto");
|
|
@@ -69,6 +70,9 @@ function getProductAsarPath(name) {
|
|
|
69
70
|
function getEntryVersion() {
|
|
70
71
|
return import_electron.app.getVersion();
|
|
71
72
|
}
|
|
73
|
+
function getProductVersion(name) {
|
|
74
|
+
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
75
|
+
}
|
|
72
76
|
function waitAppReady(duration = 1e3) {
|
|
73
77
|
return new Promise((resolve2, reject) => {
|
|
74
78
|
const timeout = setTimeout(() => {
|
|
@@ -96,17 +100,28 @@ async function unzipFile(gzipPath, targetFilePath) {
|
|
|
96
100
|
});
|
|
97
101
|
});
|
|
98
102
|
}
|
|
103
|
+
function parseVersion(version) {
|
|
104
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
105
|
+
const match = semver.exec(version);
|
|
106
|
+
if (!match) {
|
|
107
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
108
|
+
}
|
|
109
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
110
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
111
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
112
|
+
}
|
|
113
|
+
return { major, minor, patch, stage: match[4] };
|
|
114
|
+
}
|
|
99
115
|
|
|
100
|
-
// src/
|
|
101
|
-
var import_node_buffer2 = require("buffer");
|
|
102
|
-
var import_electron2 = require("electron");
|
|
103
|
-
|
|
104
|
-
// src/updater/types.ts
|
|
116
|
+
// src/updateJson.ts
|
|
105
117
|
function isUpdateJSON(json) {
|
|
106
|
-
|
|
118
|
+
const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
|
|
119
|
+
return is(json) && "beta" in json && is(json.beta);
|
|
107
120
|
}
|
|
108
121
|
|
|
109
122
|
// src/updater/defaultFunctions.ts
|
|
123
|
+
var import_node_buffer2 = require("buffer");
|
|
124
|
+
var import_electron2 = require("electron");
|
|
110
125
|
async function downloadJSONDefault(url, updater, headers) {
|
|
111
126
|
await waitAppReady();
|
|
112
127
|
return new Promise((resolve2, reject) => {
|
|
@@ -169,20 +184,6 @@ async function downloadBufferDefault(url, updater, headers) {
|
|
|
169
184
|
});
|
|
170
185
|
}
|
|
171
186
|
var compareVersionDefault = (oldVersion, newVersion) => {
|
|
172
|
-
if (!oldVersion || !newVersion || typeof oldVersion !== "string" || typeof newVersion !== "string") {
|
|
173
|
-
throw new TypeError("invalid version");
|
|
174
|
-
}
|
|
175
|
-
const parseVersion = (version) => {
|
|
176
|
-
const [versionNumber, stage] = version.split("-", 2);
|
|
177
|
-
if (!versionNumber || !versionNumber.includes(".")) {
|
|
178
|
-
throw new TypeError("invalid version");
|
|
179
|
-
}
|
|
180
|
-
const [major, minor, patch] = versionNumber.split(".").map(Number);
|
|
181
|
-
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
182
|
-
throw new TypeError("invalid version");
|
|
183
|
-
}
|
|
184
|
-
return { major, minor, patch, stage };
|
|
185
|
-
};
|
|
186
187
|
const oldV = parseVersion(oldVersion);
|
|
187
188
|
const newV = parseVersion(newVersion);
|
|
188
189
|
if (oldV.major < newV.major || oldV.major === newV.major && oldV.minor < newV.minor || oldV.major === newV.major && oldV.minor === newV.minor && oldV.patch < newV.patch) {
|
|
@@ -195,6 +196,24 @@ var compareVersionDefault = (oldVersion, newVersion) => {
|
|
|
195
196
|
};
|
|
196
197
|
|
|
197
198
|
// src/updater/index.ts
|
|
199
|
+
var MinimumVersionError = class extends Error {
|
|
200
|
+
currentVersion;
|
|
201
|
+
minVersion;
|
|
202
|
+
constructor(version, minimumVersion) {
|
|
203
|
+
super(`current entry version is ${version}, less than the minimumVersion ${minimumVersion}`);
|
|
204
|
+
this.currentVersion = version;
|
|
205
|
+
this.minVersion = minimumVersion;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var VerifyFailedError = class extends Error {
|
|
209
|
+
signature;
|
|
210
|
+
cert;
|
|
211
|
+
constructor(signature, cert) {
|
|
212
|
+
super("verify failed, invalid signature or certificate");
|
|
213
|
+
this.signature = signature;
|
|
214
|
+
this.cert = cert;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
198
217
|
function createUpdater(updaterOptions) {
|
|
199
218
|
const {
|
|
200
219
|
SIGNATURE_CERT,
|
|
@@ -203,6 +222,7 @@ function createUpdater(updaterOptions) {
|
|
|
203
222
|
releaseAsarURL: _release,
|
|
204
223
|
updateJsonURL: _update,
|
|
205
224
|
debug = false,
|
|
225
|
+
receiveBeta = false,
|
|
206
226
|
downloadConfig: { extraHeader, userAgent } = {},
|
|
207
227
|
overrideFunctions: {
|
|
208
228
|
compareVersion,
|
|
@@ -214,22 +234,21 @@ function createUpdater(updaterOptions) {
|
|
|
214
234
|
const updater = new import_node_events.EventEmitter();
|
|
215
235
|
let signature;
|
|
216
236
|
let version;
|
|
217
|
-
let _debug = debug;
|
|
218
237
|
const asarPath = getProductAsarPath(productName);
|
|
219
238
|
const gzipPath = `${asarPath}.gz`;
|
|
220
239
|
const tmpFilePath = `${asarPath}.tmp`;
|
|
221
240
|
function log(msg) {
|
|
222
|
-
|
|
241
|
+
debug && updater.emit("debug", msg);
|
|
223
242
|
}
|
|
224
|
-
function needUpdate(version2) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
243
|
+
async function needUpdate(version2, minVersion) {
|
|
244
|
+
const compare = compareVersion ?? compareVersionDefault;
|
|
245
|
+
const productVersion = getProductVersion(productName);
|
|
246
|
+
const entryVersion = getEntryVersion();
|
|
247
|
+
if (await compare(entryVersion, minVersion)) {
|
|
248
|
+
throw new MinimumVersionError(entryVersion, minVersion);
|
|
228
249
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const _compare = compareVersion ?? compareVersionDefault;
|
|
232
|
-
return _compare(currentVersion, version2);
|
|
250
|
+
log(`check update: current version is ${productVersion}, new version is ${version2}`);
|
|
251
|
+
return await compare(productVersion, version2);
|
|
233
252
|
}
|
|
234
253
|
async function parseData(format, data, version2) {
|
|
235
254
|
if ((0, import_node_fs2.existsSync)(tmpFilePath)) {
|
|
@@ -244,7 +263,7 @@ function createUpdater(updaterOptions) {
|
|
|
244
263
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && import_node_buffer3.Buffer.isBuffer(data)) {
|
|
245
264
|
return data;
|
|
246
265
|
} else {
|
|
247
|
-
throw new
|
|
266
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
248
267
|
}
|
|
249
268
|
} else if (["string", "undefined"].includes(typeof data)) {
|
|
250
269
|
const ua = userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
@@ -279,18 +298,34 @@ function createUpdater(updaterOptions) {
|
|
|
279
298
|
log(`download ${format} from ${data}`);
|
|
280
299
|
const ret = await info.fn(data, updater, headers);
|
|
281
300
|
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
301
|
+
if (format === "buffer") {
|
|
302
|
+
updater.emit("downloadBuffer", ret);
|
|
303
|
+
}
|
|
282
304
|
return ret;
|
|
283
305
|
} else {
|
|
284
|
-
throw new
|
|
306
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
285
307
|
}
|
|
286
308
|
}
|
|
287
309
|
updater.productName = productName;
|
|
288
|
-
updater.
|
|
310
|
+
updater.debug = debug;
|
|
311
|
+
updater.receiveBeta = receiveBeta;
|
|
289
312
|
updater.checkUpdate = async (data) => {
|
|
290
313
|
try {
|
|
291
|
-
|
|
314
|
+
let {
|
|
315
|
+
signature: _sig,
|
|
316
|
+
size,
|
|
317
|
+
version: _ver,
|
|
318
|
+
minimumVersion,
|
|
319
|
+
beta
|
|
320
|
+
} = await parseData("json", data);
|
|
321
|
+
if (receiveBeta) {
|
|
322
|
+
_ver = beta.version;
|
|
323
|
+
_sig = beta.signature;
|
|
324
|
+
minimumVersion = beta.minimumVersion;
|
|
325
|
+
size = beta.size;
|
|
326
|
+
}
|
|
292
327
|
log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
|
|
293
|
-
if (!needUpdate(_ver)) {
|
|
328
|
+
if (!await needUpdate(_ver, minimumVersion)) {
|
|
294
329
|
log(`update unavailable: ${_ver}`);
|
|
295
330
|
return void 0;
|
|
296
331
|
} else {
|
|
@@ -313,9 +348,9 @@ function createUpdater(updaterOptions) {
|
|
|
313
348
|
const buffer = await parseData("buffer", data, version);
|
|
314
349
|
log("verify start");
|
|
315
350
|
const _verify = verifySignaure ?? verify;
|
|
316
|
-
const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
|
|
351
|
+
const _ver = await _verify(buffer, _sig, SIGNATURE_CERT);
|
|
317
352
|
if (!_ver) {
|
|
318
|
-
throw new
|
|
353
|
+
throw new VerifyFailedError(_sig, SIGNATURE_CERT);
|
|
319
354
|
}
|
|
320
355
|
log("verify success");
|
|
321
356
|
log(`write to ${gzipPath}`);
|
|
@@ -343,7 +378,7 @@ function initApp(appOptions) {
|
|
|
343
378
|
} = appOptions || {};
|
|
344
379
|
function handleError(msg) {
|
|
345
380
|
onStartError?.(new Error(msg));
|
|
346
|
-
|
|
381
|
+
import_electron3.app.quit();
|
|
347
382
|
}
|
|
348
383
|
function startup(updater) {
|
|
349
384
|
try {
|
|
@@ -351,7 +386,7 @@ function initApp(appOptions) {
|
|
|
351
386
|
if ((0, import_node_fs3.existsSync)(`${asarPath}.tmp`)) {
|
|
352
387
|
(0, import_node_fs3.renameSync)(`${asarPath}.tmp`, asarPath);
|
|
353
388
|
}
|
|
354
|
-
const mainDir =
|
|
389
|
+
const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
|
|
355
390
|
const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
|
|
356
391
|
onStart?.(entry);
|
|
357
392
|
require(entry)(updater);
|
|
@@ -377,6 +412,8 @@ function initApp(appOptions) {
|
|
|
377
412
|
}
|
|
378
413
|
// Annotate the CommonJS export names for ESM import in node:
|
|
379
414
|
0 && (module.exports = {
|
|
415
|
+
MinimumVersionError,
|
|
416
|
+
VerifyFailedError,
|
|
380
417
|
createUpdater,
|
|
381
418
|
initApp
|
|
382
419
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isUpdateJSON,
|
|
2
3
|
verify
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2XHZMWRR.mjs";
|
|
4
5
|
import {
|
|
5
6
|
__require,
|
|
6
7
|
getEntryVersion,
|
|
7
8
|
getProductAsarPath,
|
|
9
|
+
getProductVersion,
|
|
10
|
+
parseVersion,
|
|
8
11
|
unzipFile,
|
|
9
12
|
waitAppReady
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-SWXNCK6H.mjs";
|
|
11
14
|
|
|
12
15
|
// src/index.ts
|
|
13
16
|
import { resolve } from "node:path";
|
|
14
17
|
import { existsSync as existsSync2, renameSync } from "node:fs";
|
|
15
|
-
import { app
|
|
18
|
+
import { app } from "electron";
|
|
16
19
|
|
|
17
20
|
// src/updater/index.ts
|
|
18
21
|
import { EventEmitter } from "node:events";
|
|
19
22
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
20
23
|
import { existsSync } from "node:fs";
|
|
21
24
|
import { rm, writeFile } from "node:fs/promises";
|
|
22
|
-
import { app } from "electron";
|
|
23
25
|
|
|
24
26
|
// src/updater/defaultFunctions.ts
|
|
25
27
|
import { Buffer } from "node:buffer";
|
|
26
28
|
import { net } from "electron";
|
|
27
|
-
|
|
28
|
-
// src/updater/types.ts
|
|
29
|
-
function isUpdateJSON(json) {
|
|
30
|
-
return "signature" in json && "version" in json && "size" in json;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/updater/defaultFunctions.ts
|
|
34
29
|
async function downloadJSONDefault(url, updater, headers) {
|
|
35
30
|
await waitAppReady();
|
|
36
31
|
return new Promise((resolve2, reject) => {
|
|
@@ -93,20 +88,6 @@ async function downloadBufferDefault(url, updater, headers) {
|
|
|
93
88
|
});
|
|
94
89
|
}
|
|
95
90
|
var compareVersionDefault = (oldVersion, newVersion) => {
|
|
96
|
-
if (!oldVersion || !newVersion || typeof oldVersion !== "string" || typeof newVersion !== "string") {
|
|
97
|
-
throw new TypeError("invalid version");
|
|
98
|
-
}
|
|
99
|
-
const parseVersion = (version) => {
|
|
100
|
-
const [versionNumber, stage] = version.split("-", 2);
|
|
101
|
-
if (!versionNumber || !versionNumber.includes(".")) {
|
|
102
|
-
throw new TypeError("invalid version");
|
|
103
|
-
}
|
|
104
|
-
const [major, minor, patch] = versionNumber.split(".").map(Number);
|
|
105
|
-
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
106
|
-
throw new TypeError("invalid version");
|
|
107
|
-
}
|
|
108
|
-
return { major, minor, patch, stage };
|
|
109
|
-
};
|
|
110
91
|
const oldV = parseVersion(oldVersion);
|
|
111
92
|
const newV = parseVersion(newVersion);
|
|
112
93
|
if (oldV.major < newV.major || oldV.major === newV.major && oldV.minor < newV.minor || oldV.major === newV.major && oldV.minor === newV.minor && oldV.patch < newV.patch) {
|
|
@@ -119,6 +100,24 @@ var compareVersionDefault = (oldVersion, newVersion) => {
|
|
|
119
100
|
};
|
|
120
101
|
|
|
121
102
|
// src/updater/index.ts
|
|
103
|
+
var MinimumVersionError = class extends Error {
|
|
104
|
+
currentVersion;
|
|
105
|
+
minVersion;
|
|
106
|
+
constructor(version, minimumVersion) {
|
|
107
|
+
super(`current entry version is ${version}, less than the minimumVersion ${minimumVersion}`);
|
|
108
|
+
this.currentVersion = version;
|
|
109
|
+
this.minVersion = minimumVersion;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var VerifyFailedError = class extends Error {
|
|
113
|
+
signature;
|
|
114
|
+
cert;
|
|
115
|
+
constructor(signature, cert) {
|
|
116
|
+
super("verify failed, invalid signature or certificate");
|
|
117
|
+
this.signature = signature;
|
|
118
|
+
this.cert = cert;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
122
121
|
function createUpdater(updaterOptions) {
|
|
123
122
|
const {
|
|
124
123
|
SIGNATURE_CERT,
|
|
@@ -127,6 +126,7 @@ function createUpdater(updaterOptions) {
|
|
|
127
126
|
releaseAsarURL: _release,
|
|
128
127
|
updateJsonURL: _update,
|
|
129
128
|
debug = false,
|
|
129
|
+
receiveBeta = false,
|
|
130
130
|
downloadConfig: { extraHeader, userAgent } = {},
|
|
131
131
|
overrideFunctions: {
|
|
132
132
|
compareVersion,
|
|
@@ -138,22 +138,21 @@ function createUpdater(updaterOptions) {
|
|
|
138
138
|
const updater = new EventEmitter();
|
|
139
139
|
let signature;
|
|
140
140
|
let version;
|
|
141
|
-
let _debug = debug;
|
|
142
141
|
const asarPath = getProductAsarPath(productName);
|
|
143
142
|
const gzipPath = `${asarPath}.gz`;
|
|
144
143
|
const tmpFilePath = `${asarPath}.tmp`;
|
|
145
144
|
function log(msg) {
|
|
146
|
-
|
|
145
|
+
debug && updater.emit("debug", msg);
|
|
147
146
|
}
|
|
148
|
-
function needUpdate(version2) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
147
|
+
async function needUpdate(version2, minVersion) {
|
|
148
|
+
const compare = compareVersion ?? compareVersionDefault;
|
|
149
|
+
const productVersion = getProductVersion(productName);
|
|
150
|
+
const entryVersion = getEntryVersion();
|
|
151
|
+
if (await compare(entryVersion, minVersion)) {
|
|
152
|
+
throw new MinimumVersionError(entryVersion, minVersion);
|
|
152
153
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const _compare = compareVersion ?? compareVersionDefault;
|
|
156
|
-
return _compare(currentVersion, version2);
|
|
154
|
+
log(`check update: current version is ${productVersion}, new version is ${version2}`);
|
|
155
|
+
return await compare(productVersion, version2);
|
|
157
156
|
}
|
|
158
157
|
async function parseData(format, data, version2) {
|
|
159
158
|
if (existsSync(tmpFilePath)) {
|
|
@@ -168,7 +167,7 @@ function createUpdater(updaterOptions) {
|
|
|
168
167
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer2.isBuffer(data)) {
|
|
169
168
|
return data;
|
|
170
169
|
} else {
|
|
171
|
-
throw new
|
|
170
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
172
171
|
}
|
|
173
172
|
} else if (["string", "undefined"].includes(typeof data)) {
|
|
174
173
|
const ua = userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
@@ -203,18 +202,34 @@ function createUpdater(updaterOptions) {
|
|
|
203
202
|
log(`download ${format} from ${data}`);
|
|
204
203
|
const ret = await info.fn(data, updater, headers);
|
|
205
204
|
log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
|
|
205
|
+
if (format === "buffer") {
|
|
206
|
+
updater.emit("downloadBuffer", ret);
|
|
207
|
+
}
|
|
206
208
|
return ret;
|
|
207
209
|
} else {
|
|
208
|
-
throw new
|
|
210
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
updater.productName = productName;
|
|
212
|
-
updater.
|
|
214
|
+
updater.debug = debug;
|
|
215
|
+
updater.receiveBeta = receiveBeta;
|
|
213
216
|
updater.checkUpdate = async (data) => {
|
|
214
217
|
try {
|
|
215
|
-
|
|
218
|
+
let {
|
|
219
|
+
signature: _sig,
|
|
220
|
+
size,
|
|
221
|
+
version: _ver,
|
|
222
|
+
minimumVersion,
|
|
223
|
+
beta
|
|
224
|
+
} = await parseData("json", data);
|
|
225
|
+
if (receiveBeta) {
|
|
226
|
+
_ver = beta.version;
|
|
227
|
+
_sig = beta.signature;
|
|
228
|
+
minimumVersion = beta.minimumVersion;
|
|
229
|
+
size = beta.size;
|
|
230
|
+
}
|
|
216
231
|
log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
|
|
217
|
-
if (!needUpdate(_ver)) {
|
|
232
|
+
if (!await needUpdate(_ver, minimumVersion)) {
|
|
218
233
|
log(`update unavailable: ${_ver}`);
|
|
219
234
|
return void 0;
|
|
220
235
|
} else {
|
|
@@ -237,9 +252,9 @@ function createUpdater(updaterOptions) {
|
|
|
237
252
|
const buffer = await parseData("buffer", data, version);
|
|
238
253
|
log("verify start");
|
|
239
254
|
const _verify = verifySignaure ?? verify;
|
|
240
|
-
const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
|
|
255
|
+
const _ver = await _verify(buffer, _sig, SIGNATURE_CERT);
|
|
241
256
|
if (!_ver) {
|
|
242
|
-
throw new
|
|
257
|
+
throw new VerifyFailedError(_sig, SIGNATURE_CERT);
|
|
243
258
|
}
|
|
244
259
|
log("verify success");
|
|
245
260
|
log(`write to ${gzipPath}`);
|
|
@@ -267,7 +282,7 @@ function initApp(appOptions) {
|
|
|
267
282
|
} = appOptions || {};
|
|
268
283
|
function handleError(msg) {
|
|
269
284
|
onStartError?.(new Error(msg));
|
|
270
|
-
|
|
285
|
+
app.quit();
|
|
271
286
|
}
|
|
272
287
|
function startup(updater) {
|
|
273
288
|
try {
|
|
@@ -275,7 +290,7 @@ function initApp(appOptions) {
|
|
|
275
290
|
if (existsSync2(`${asarPath}.tmp`)) {
|
|
276
291
|
renameSync(`${asarPath}.tmp`, asarPath);
|
|
277
292
|
}
|
|
278
|
-
const mainDir =
|
|
293
|
+
const mainDir = app.isPackaged ? asarPath : electronDevDistPath;
|
|
279
294
|
const entry = resolve(__dirname, mainDir, mainPath);
|
|
280
295
|
onStart?.(entry);
|
|
281
296
|
__require(entry)(updater);
|
|
@@ -300,6 +315,8 @@ function initApp(appOptions) {
|
|
|
300
315
|
};
|
|
301
316
|
}
|
|
302
317
|
export {
|
|
318
|
+
MinimumVersionError,
|
|
319
|
+
VerifyFailedError,
|
|
303
320
|
createUpdater,
|
|
304
321
|
initApp
|
|
305
322
|
};
|
package/dist/utils.d.mts
CHANGED
|
@@ -12,9 +12,14 @@ declare function getEntryVersion(): string;
|
|
|
12
12
|
* @param name - The name of the application
|
|
13
13
|
*/
|
|
14
14
|
declare function getProductVersion(name: string): string;
|
|
15
|
+
declare class NoSuchNativeModuleError extends Error {
|
|
16
|
+
moduleName: string;
|
|
17
|
+
constructor(moduleName: string);
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* require native package from app.asar
|
|
17
21
|
* @param packageName native package name
|
|
22
|
+
* @throws error: {@link NoSuchNativeModuleError}
|
|
18
23
|
*/
|
|
19
24
|
declare function requireNative<T = any>(packageName: string): T;
|
|
20
25
|
/**
|
|
@@ -40,5 +45,11 @@ declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
|
40
45
|
declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
|
|
41
46
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
42
47
|
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
48
|
+
declare function parseVersion(version: string): {
|
|
49
|
+
major: number;
|
|
50
|
+
minor: number;
|
|
51
|
+
patch: number;
|
|
52
|
+
stage: string;
|
|
53
|
+
};
|
|
43
54
|
|
|
44
|
-
export { getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
|
55
|
+
export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.d.ts
CHANGED
|
@@ -12,9 +12,14 @@ declare function getEntryVersion(): string;
|
|
|
12
12
|
* @param name - The name of the application
|
|
13
13
|
*/
|
|
14
14
|
declare function getProductVersion(name: string): string;
|
|
15
|
+
declare class NoSuchNativeModuleError extends Error {
|
|
16
|
+
moduleName: string;
|
|
17
|
+
constructor(moduleName: string);
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* require native package from app.asar
|
|
17
21
|
* @param packageName native package name
|
|
22
|
+
* @throws error: {@link NoSuchNativeModuleError}
|
|
18
23
|
*/
|
|
19
24
|
declare function requireNative<T = any>(packageName: string): T;
|
|
20
25
|
/**
|
|
@@ -40,5 +45,11 @@ declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
|
40
45
|
declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
|
|
41
46
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
42
47
|
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
48
|
+
declare function parseVersion(version: string): {
|
|
49
|
+
major: number;
|
|
50
|
+
minor: number;
|
|
51
|
+
patch: number;
|
|
52
|
+
stage: string;
|
|
53
|
+
};
|
|
43
54
|
|
|
44
|
-
export { getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
|
55
|
+
export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
+
NoSuchNativeModuleError: () => NoSuchNativeModuleError,
|
|
23
24
|
getEntryVersion: () => getEntryVersion,
|
|
24
25
|
getGithubFileCdnGroup: () => getGithubFileCdnGroup,
|
|
25
26
|
getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
|
|
@@ -27,6 +28,7 @@ __export(utils_exports, {
|
|
|
27
28
|
getProductVersion: () => getProductVersion,
|
|
28
29
|
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
29
30
|
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
31
|
+
parseVersion: () => parseVersion,
|
|
30
32
|
requireNative: () => requireNative,
|
|
31
33
|
restartApp: () => restartApp,
|
|
32
34
|
unzipFile: () => unzipFile,
|
|
@@ -47,9 +49,20 @@ function getEntryVersion() {
|
|
|
47
49
|
function getProductVersion(name) {
|
|
48
50
|
return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
|
|
49
51
|
}
|
|
52
|
+
var NoSuchNativeModuleError = class extends Error {
|
|
53
|
+
moduleName;
|
|
54
|
+
constructor(moduleName) {
|
|
55
|
+
super(`no such native module: ${moduleName}`);
|
|
56
|
+
this.moduleName = moduleName;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
50
59
|
function requireNative(packageName) {
|
|
51
60
|
const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
|
|
52
|
-
|
|
61
|
+
try {
|
|
62
|
+
return require(path);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new NoSuchNativeModuleError(packageName);
|
|
65
|
+
}
|
|
53
66
|
}
|
|
54
67
|
function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
|
|
55
68
|
if (!repository.startsWith("https://github.com/")) {
|
|
@@ -141,8 +154,21 @@ function handleUnexpectedErrors(callback) {
|
|
|
141
154
|
process.on("uncaughtException", listener);
|
|
142
155
|
process.on("unhandledRejection", listener);
|
|
143
156
|
}
|
|
157
|
+
function parseVersion(version) {
|
|
158
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
159
|
+
const match = semver.exec(version);
|
|
160
|
+
if (!match) {
|
|
161
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
162
|
+
}
|
|
163
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
164
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
165
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
166
|
+
}
|
|
167
|
+
return { major, minor, patch, stage: match[4] };
|
|
168
|
+
}
|
|
144
169
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
170
|
0 && (module.exports = {
|
|
171
|
+
NoSuchNativeModuleError,
|
|
146
172
|
getEntryVersion,
|
|
147
173
|
getGithubFileCdnGroup,
|
|
148
174
|
getGithubReleaseCdnGroup,
|
|
@@ -150,6 +176,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
150
176
|
getProductVersion,
|
|
151
177
|
handleUnexpectedErrors,
|
|
152
178
|
parseGithubCdnURL,
|
|
179
|
+
parseVersion,
|
|
153
180
|
requireNative,
|
|
154
181
|
restartApp,
|
|
155
182
|
unzipFile,
|
package/dist/utils.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
NoSuchNativeModuleError,
|
|
2
3
|
getEntryVersion,
|
|
3
4
|
getGithubFileCdnGroup,
|
|
4
5
|
getGithubReleaseCdnGroup,
|
|
@@ -6,13 +7,15 @@ import {
|
|
|
6
7
|
getProductVersion,
|
|
7
8
|
handleUnexpectedErrors,
|
|
8
9
|
parseGithubCdnURL,
|
|
10
|
+
parseVersion,
|
|
9
11
|
requireNative,
|
|
10
12
|
restartApp,
|
|
11
13
|
unzipFile,
|
|
12
14
|
waitAppReady,
|
|
13
15
|
zipFile
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-SWXNCK6H.mjs";
|
|
15
17
|
export {
|
|
18
|
+
NoSuchNativeModuleError,
|
|
16
19
|
getEntryVersion,
|
|
17
20
|
getGithubFileCdnGroup,
|
|
18
21
|
getGithubReleaseCdnGroup,
|
|
@@ -20,6 +23,7 @@ export {
|
|
|
20
23
|
getProductVersion,
|
|
21
24
|
handleUnexpectedErrors,
|
|
22
25
|
parseGithubCdnURL,
|
|
26
|
+
parseVersion,
|
|
23
27
|
requireNative,
|
|
24
28
|
restartApp,
|
|
25
29
|
unzipFile,
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
+
import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
|
|
3
4
|
|
|
4
5
|
type DistinguishedName = {
|
|
5
6
|
countryName?: string;
|
|
@@ -14,7 +15,8 @@ type DistinguishedName = {
|
|
|
14
15
|
businessCategory?: string;
|
|
15
16
|
emailAddress?: string;
|
|
16
17
|
};
|
|
17
|
-
type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string
|
|
18
|
+
type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
|
|
19
|
+
type FunctionGenerateVersionJson = (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
|
|
18
20
|
type Options = {
|
|
19
21
|
/**
|
|
20
22
|
* whether is in build mode
|
|
@@ -32,6 +34,11 @@ type Options = {
|
|
|
32
34
|
* you can set as 'version' in `package.json`
|
|
33
35
|
*/
|
|
34
36
|
version: string;
|
|
37
|
+
/**
|
|
38
|
+
* mini version of entry
|
|
39
|
+
* @default version
|
|
40
|
+
*/
|
|
41
|
+
minimumVersion?: string;
|
|
35
42
|
/**
|
|
36
43
|
* Whether to minify entry file
|
|
37
44
|
*/
|
|
@@ -55,6 +62,11 @@ type Options = {
|
|
|
55
62
|
* @default `release/${productName}.asar`
|
|
56
63
|
*/
|
|
57
64
|
asarOutputPath?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Path to version info output, content is {@link UpdateJSON}
|
|
67
|
+
* @default `version.json`
|
|
68
|
+
*/
|
|
69
|
+
versionPath?: string;
|
|
58
70
|
/**
|
|
59
71
|
* Path to gzipped asar file
|
|
60
72
|
* @default `release/${productName}-${version}.asar.gz`
|
|
@@ -70,11 +82,6 @@ type Options = {
|
|
|
70
82
|
* @default `dist`
|
|
71
83
|
*/
|
|
72
84
|
rendererDistPath?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Path to version info output
|
|
75
|
-
* @default `version.json`
|
|
76
|
-
*/
|
|
77
|
-
versionPath?: string;
|
|
78
85
|
};
|
|
79
86
|
/**
|
|
80
87
|
* signature config
|
|
@@ -124,6 +131,13 @@ type Options = {
|
|
|
124
131
|
* @param cert certificate
|
|
125
132
|
*/
|
|
126
133
|
generateSignature?: FunctionGenerateSignature;
|
|
134
|
+
/**
|
|
135
|
+
* custom signature generate function {@link FunctionGenerateVersionJson}
|
|
136
|
+
* @param signature generated signature
|
|
137
|
+
* @param version currentVersion
|
|
138
|
+
* @param cert certificate
|
|
139
|
+
*/
|
|
140
|
+
generateVersionJson?: FunctionGenerateVersionJson;
|
|
127
141
|
};
|
|
128
142
|
};
|
|
129
143
|
};
|