electron-incremental-update 1.0.3 → 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.
- package/README.md +549 -535
- package/dist/{chunk-OUZLSVQC.mjs → chunk-CXHA5TF7.js} +92 -4
- package/dist/{index.mjs → index.cjs} +172 -38
- package/dist/{index.d.mts → index.d.cts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +53 -157
- package/dist/utils.cjs +270 -0
- package/dist/{utils.d.mts → utils.d.cts} +9 -11
- package/dist/utils.d.ts +9 -11
- package/dist/utils.js +21 -253
- package/dist/vite.d.ts +31 -14
- package/dist/vite.js +121 -135
- package/package.json +24 -27
- package/utils.js +1 -1
- package/dist/chunk-GB6VLKJZ.mjs +0 -95
- package/dist/chunk-GXZSAUBR.mjs +0 -36
- package/dist/utils.mjs +0 -40
- package/dist/vite.d.mts +0 -329
- package/dist/vite.mjs +0 -404
- /package/dist/{noDep-TvZoKVF8.d.mts → pure-GoN_3MEj.d.cts} +0 -0
- /package/dist/{noDep-TvZoKVF8.d.ts → pure-GoN_3MEj.d.ts} +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
4
7
|
|
|
5
8
|
// src/utils/electron.ts
|
|
6
9
|
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
@@ -133,7 +136,86 @@ function getPaths(entryDirName = "dist-entry") {
|
|
|
133
136
|
};
|
|
134
137
|
}
|
|
135
138
|
|
|
139
|
+
// src/utils/zip.ts
|
|
140
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
|
|
141
|
+
import { gunzip, gzip } from "node:zlib";
|
|
142
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
143
|
+
if (!existsSync2(gzipPath)) {
|
|
144
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
145
|
+
}
|
|
146
|
+
const compressedBuffer = readFileSync2(gzipPath);
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
gunzip(compressedBuffer, (err, buffer) => {
|
|
149
|
+
rmSync(gzipPath);
|
|
150
|
+
if (err) {
|
|
151
|
+
reject(err);
|
|
152
|
+
}
|
|
153
|
+
writeFileSync(targetFilePath, buffer);
|
|
154
|
+
resolve(null);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
159
|
+
if (!existsSync2(filePath)) {
|
|
160
|
+
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
161
|
+
}
|
|
162
|
+
const buffer = readFileSync2(filePath);
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
gzip(buffer, (err, buffer2) => {
|
|
165
|
+
if (err) {
|
|
166
|
+
reject(err);
|
|
167
|
+
}
|
|
168
|
+
writeFileSync(targetFilePath, buffer2);
|
|
169
|
+
resolve(null);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/utils/pure.ts
|
|
175
|
+
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
176
|
+
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
177
|
+
throw new Error("origin url must start with https://github.com/");
|
|
178
|
+
}
|
|
179
|
+
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
180
|
+
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
181
|
+
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
182
|
+
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
183
|
+
}
|
|
184
|
+
function handleUnexpectedErrors(callback) {
|
|
185
|
+
process.on("uncaughtException", callback);
|
|
186
|
+
process.on("unhandledRejection", callback);
|
|
187
|
+
}
|
|
188
|
+
function parseVersion(version) {
|
|
189
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
|
|
190
|
+
const match = semver.exec(version);
|
|
191
|
+
if (!match) {
|
|
192
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
193
|
+
}
|
|
194
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
195
|
+
const ret = {
|
|
196
|
+
major,
|
|
197
|
+
minor,
|
|
198
|
+
patch,
|
|
199
|
+
stage: "",
|
|
200
|
+
stageVersion: -1
|
|
201
|
+
};
|
|
202
|
+
if (match[4]) {
|
|
203
|
+
let [stage, _v] = match[4].split(".");
|
|
204
|
+
ret.stage = stage;
|
|
205
|
+
ret.stageVersion = Number(_v) || -1;
|
|
206
|
+
}
|
|
207
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
208
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
209
|
+
}
|
|
210
|
+
return ret;
|
|
211
|
+
}
|
|
212
|
+
function isUpdateJSON(json) {
|
|
213
|
+
const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
214
|
+
return is2(json) && is2(json?.beta);
|
|
215
|
+
}
|
|
216
|
+
|
|
136
217
|
export {
|
|
218
|
+
__require,
|
|
137
219
|
is,
|
|
138
220
|
getPathFromAppNameAsar,
|
|
139
221
|
getVersions,
|
|
@@ -144,5 +226,11 @@ export {
|
|
|
144
226
|
singleInstance,
|
|
145
227
|
setPortableAppDataPath,
|
|
146
228
|
waitAppReady,
|
|
147
|
-
getPaths
|
|
229
|
+
getPaths,
|
|
230
|
+
unzipFile,
|
|
231
|
+
zipFile,
|
|
232
|
+
parseGithubCdnURL,
|
|
233
|
+
handleUnexpectedErrors,
|
|
234
|
+
parseVersion,
|
|
235
|
+
isUpdateJSON
|
|
148
236
|
};
|
|
@@ -1,29 +1,162 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
17
19
|
|
|
18
20
|
// src/index.ts
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
DownloadError: () => DownloadError,
|
|
24
|
+
MinimumVersionError: () => MinimumVersionError,
|
|
25
|
+
Updater: () => Updater,
|
|
26
|
+
VerifyFailedError: () => VerifyFailedError,
|
|
27
|
+
createUpdater: () => createUpdater,
|
|
28
|
+
initApp: () => initApp,
|
|
29
|
+
startupWithUpdater: () => startupWithUpdater
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
var import_node_path2 = require("path");
|
|
33
|
+
var import_node_fs4 = require("fs");
|
|
34
|
+
var import_electron4 = require("electron");
|
|
22
35
|
|
|
23
36
|
// src/updater/core.ts
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
var import_node_fs3 = require("fs");
|
|
38
|
+
var import_promises = require("fs/promises");
|
|
39
|
+
var import_electron3 = require("electron");
|
|
40
|
+
|
|
41
|
+
// src/utils/electron.ts
|
|
42
|
+
var import_node_fs = require("fs");
|
|
43
|
+
var import_node_path = require("path");
|
|
44
|
+
var import_node_os = require("os");
|
|
45
|
+
var import_electron = require("electron");
|
|
46
|
+
var is = {
|
|
47
|
+
dev: !import_electron.app.isPackaged,
|
|
48
|
+
win: process.platform === "win32",
|
|
49
|
+
mac: process.platform === "darwin",
|
|
50
|
+
linux: process.platform === "linux"
|
|
51
|
+
};
|
|
52
|
+
function getPathFromAppNameAsar(...path) {
|
|
53
|
+
return is.dev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
|
|
54
|
+
}
|
|
55
|
+
function getVersions() {
|
|
56
|
+
const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
|
|
57
|
+
return {
|
|
58
|
+
appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
|
|
59
|
+
entryVersion: import_electron.app.getVersion(),
|
|
60
|
+
electronVersion: process.versions.electron,
|
|
61
|
+
nodeVersion: process.versions.node,
|
|
62
|
+
systemVersion: `${platform} ${(0, import_node_os.release)()}`
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function restartApp() {
|
|
66
|
+
import_electron.app.relaunch();
|
|
67
|
+
import_electron.app.quit();
|
|
68
|
+
}
|
|
69
|
+
function waitAppReady(timeout = 1e3) {
|
|
70
|
+
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
|
|
71
|
+
const _ = setTimeout(() => {
|
|
72
|
+
reject(new Error("app is not ready"));
|
|
73
|
+
}, timeout);
|
|
74
|
+
import_electron.app.whenReady().then(() => {
|
|
75
|
+
clearTimeout(_);
|
|
76
|
+
resolve2();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/utils/zip.ts
|
|
82
|
+
var import_node_fs2 = require("fs");
|
|
83
|
+
var import_node_zlib = require("zlib");
|
|
84
|
+
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
85
|
+
if (!(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
86
|
+
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
87
|
+
}
|
|
88
|
+
const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
|
|
89
|
+
return new Promise((resolve2, reject) => {
|
|
90
|
+
(0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
|
|
91
|
+
(0, import_node_fs2.rmSync)(gzipPath);
|
|
92
|
+
if (err) {
|
|
93
|
+
reject(err);
|
|
94
|
+
}
|
|
95
|
+
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
|
|
96
|
+
resolve2(null);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/utils/pure.ts
|
|
102
|
+
function parseVersion(version) {
|
|
103
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
|
|
104
|
+
const match = semver.exec(version);
|
|
105
|
+
if (!match) {
|
|
106
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
107
|
+
}
|
|
108
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
109
|
+
const ret = {
|
|
110
|
+
major,
|
|
111
|
+
minor,
|
|
112
|
+
patch,
|
|
113
|
+
stage: "",
|
|
114
|
+
stageVersion: -1
|
|
115
|
+
};
|
|
116
|
+
if (match[4]) {
|
|
117
|
+
let [stage, _v] = match[4].split(".");
|
|
118
|
+
ret.stage = stage;
|
|
119
|
+
ret.stageVersion = Number(_v) || -1;
|
|
120
|
+
}
|
|
121
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
122
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
123
|
+
}
|
|
124
|
+
return ret;
|
|
125
|
+
}
|
|
126
|
+
function isUpdateJSON(json) {
|
|
127
|
+
const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
128
|
+
return is2(json) && is2(json?.beta);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/crypto/dec.ts
|
|
132
|
+
var import_node_crypto2 = require("crypto");
|
|
133
|
+
|
|
134
|
+
// src/crypto/utils.ts
|
|
135
|
+
var import_node_crypto = require("crypto");
|
|
136
|
+
function hashString(data, length) {
|
|
137
|
+
const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
|
|
138
|
+
return Buffer.from(hash).subarray(0, length);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/crypto/dec.ts
|
|
142
|
+
function decrypt(encryptedText, key, iv) {
|
|
143
|
+
const decipher = (0, import_node_crypto2.createDecipheriv)("aes-256-cbc", key, iv);
|
|
144
|
+
let decrypted = decipher.update(encryptedText, "base64url", "utf8");
|
|
145
|
+
decrypted += decipher.final("utf8");
|
|
146
|
+
return decrypted;
|
|
147
|
+
}
|
|
148
|
+
var verify = (buffer, signature, cert) => {
|
|
149
|
+
try {
|
|
150
|
+
const [sig, version] = decrypt(signature, hashString(cert, 32), hashString(buffer, 16)).split("%");
|
|
151
|
+
const result = (0, import_node_crypto2.createVerify)("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
152
|
+
return result ? version : false;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/crypto/enc.ts
|
|
159
|
+
var import_node_crypto3 = require("crypto");
|
|
27
160
|
|
|
28
161
|
// src/updater/types.ts
|
|
29
162
|
var MinimumVersionError = class extends Error {
|
|
@@ -51,11 +184,11 @@ var DownloadError = class extends Error {
|
|
|
51
184
|
};
|
|
52
185
|
|
|
53
186
|
// src/updater/defaultFunctions/download.ts
|
|
54
|
-
|
|
187
|
+
var import_electron2 = require("electron");
|
|
55
188
|
var downloadJSONDefault = async (url, headers) => {
|
|
56
189
|
await waitAppReady();
|
|
57
190
|
return new Promise((resolve2, reject) => {
|
|
58
|
-
const request = net.request({
|
|
191
|
+
const request = import_electron2.net.request({
|
|
59
192
|
url,
|
|
60
193
|
method: "GET",
|
|
61
194
|
redirect: "follow"
|
|
@@ -89,7 +222,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
|
|
|
89
222
|
await waitAppReady();
|
|
90
223
|
let current = 0;
|
|
91
224
|
return new Promise((resolve2, reject) => {
|
|
92
|
-
const request = net.request({
|
|
225
|
+
const request = import_electron2.net.request({
|
|
93
226
|
url,
|
|
94
227
|
method: "GET",
|
|
95
228
|
redirect: "follow"
|
|
@@ -189,13 +322,13 @@ var Updater = class {
|
|
|
189
322
|
return await compare(appVersion, version);
|
|
190
323
|
}
|
|
191
324
|
async parseData(format, data) {
|
|
192
|
-
if (existsSync(this.tmpFilePath)) {
|
|
325
|
+
if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
|
|
193
326
|
this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
|
|
194
|
-
await rm(this.tmpFilePath);
|
|
327
|
+
await (0, import_promises.rm)(this.tmpFilePath);
|
|
195
328
|
}
|
|
196
|
-
if (existsSync(this.gzipPath)) {
|
|
329
|
+
if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
|
|
197
330
|
this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
|
|
198
|
-
await rm(this.gzipPath);
|
|
331
|
+
await (0, import_promises.rm)(this.gzipPath);
|
|
199
332
|
}
|
|
200
333
|
if (!["string", "object", "undefined"].includes(typeof data)) {
|
|
201
334
|
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
@@ -221,7 +354,7 @@ var Updater = class {
|
|
|
221
354
|
} : {
|
|
222
355
|
name: "releaseAsarURL",
|
|
223
356
|
url: this.option.releaseAsarURL,
|
|
224
|
-
repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${app.name}-${this.info?.version}.asar.gz`,
|
|
357
|
+
repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${import_electron3.app.name}-${this.info?.version}.asar.gz`,
|
|
225
358
|
fn: this.option.overrideFunctions?.downloadBuffer ?? downloadBufferDefault
|
|
226
359
|
};
|
|
227
360
|
data ??= config.url;
|
|
@@ -307,7 +440,7 @@ var Updater = class {
|
|
|
307
440
|
}
|
|
308
441
|
this.logger?.info("verify success");
|
|
309
442
|
this.logger?.info(`write to ${this.gzipPath}`);
|
|
310
|
-
await writeFile(this.gzipPath, buffer);
|
|
443
|
+
await (0, import_promises.writeFile)(this.gzipPath, buffer);
|
|
311
444
|
this.logger?.info(`extract to ${this.tmpFilePath}`);
|
|
312
445
|
await unzipFile(this.gzipPath, this.tmpFilePath);
|
|
313
446
|
this.logger?.info(`download success, version: ${_ver}`);
|
|
@@ -354,21 +487,21 @@ function initApp(appOptions) {
|
|
|
354
487
|
function handleError(err, logger) {
|
|
355
488
|
console.error(err);
|
|
356
489
|
onStartError?.(err, logger);
|
|
357
|
-
|
|
490
|
+
import_electron4.app.quit();
|
|
358
491
|
}
|
|
359
492
|
async function startup(updater) {
|
|
360
493
|
const logger = updater.logger;
|
|
361
494
|
try {
|
|
362
495
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
363
496
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
364
|
-
if (
|
|
497
|
+
if ((0, import_node_fs4.existsSync)(tempAsarPath)) {
|
|
365
498
|
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
366
|
-
await onInstall(() => renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
499
|
+
await onInstall(() => (0, import_node_fs4.renameSync)(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
367
500
|
}
|
|
368
501
|
const mainDir = is.dev ? electronDevDistPath : appNameAsarPath;
|
|
369
|
-
const entry = resolve(__dirname, mainDir, mainPath);
|
|
502
|
+
const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
|
|
370
503
|
await beforeStart?.(entry, logger);
|
|
371
|
-
|
|
504
|
+
require(entry)(updater);
|
|
372
505
|
} catch (error) {
|
|
373
506
|
handleError(error, logger);
|
|
374
507
|
}
|
|
@@ -389,7 +522,8 @@ function initApp(appOptions) {
|
|
|
389
522
|
}
|
|
390
523
|
};
|
|
391
524
|
}
|
|
392
|
-
export
|
|
525
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
526
|
+
0 && (module.exports = {
|
|
393
527
|
DownloadError,
|
|
394
528
|
MinimumVersionError,
|
|
395
529
|
Updater,
|
|
@@ -397,4 +531,4 @@ export {
|
|
|
397
531
|
createUpdater,
|
|
398
532
|
initApp,
|
|
399
533
|
startupWithUpdater
|
|
400
|
-
};
|
|
534
|
+
});
|
package/dist/index.d.ts
CHANGED