electron-incremental-update 2.0.0-beta.7 → 2.0.0-beta.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-DFNDKSE6.js → chunk-4MH6ZXCY.js} +12 -12
- package/dist/{chunk-N77WQ5WB.js → chunk-KZSYEXLO.js} +9 -9
- package/dist/index.cjs +15 -10
- package/dist/index.js +9 -9
- package/dist/provider.cjs +9 -4
- package/dist/provider.js +1 -1
- package/dist/utils.cjs +24 -17
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -2
- package/dist/vite.d.ts +7 -4
- package/dist/vite.js +157 -112
- package/package.json +8 -6
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { __require } from './chunk-72ZAJ7AF.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { app } from 'electron';
|
|
5
5
|
|
|
6
6
|
var isDev = __EIU_IS_DEV__;
|
|
7
7
|
var isWin = process.platform === "win32";
|
|
8
8
|
var isMac = process.platform === "darwin";
|
|
9
9
|
var isLinux = process.platform === "linux";
|
|
10
|
-
function getPathFromAppNameAsar(...
|
|
11
|
-
return isDev ? "DEV.asar" : join(dirname(app.getAppPath()), `${app.name}.asar`, ...
|
|
10
|
+
function getPathFromAppNameAsar(...paths) {
|
|
11
|
+
return isDev ? "DEV.asar" : path.join(path.dirname(app.getAppPath()), `${app.name}.asar`, ...paths);
|
|
12
12
|
}
|
|
13
13
|
function getAppVersion() {
|
|
14
|
-
return isDev ? getEntryVersion() : readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
14
|
+
return isDev ? getEntryVersion() : fs.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
15
15
|
}
|
|
16
16
|
function getEntryVersion() {
|
|
17
17
|
return app.getVersion();
|
|
18
18
|
}
|
|
19
19
|
function requireNative(moduleName) {
|
|
20
|
-
return __require(join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
20
|
+
return __require(path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
21
21
|
}
|
|
22
22
|
function restartApp() {
|
|
23
23
|
app.relaunch();
|
|
@@ -51,9 +51,9 @@ function singleInstance(window) {
|
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
53
53
|
function setPortableAppDataPath(dirName = "data") {
|
|
54
|
-
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
55
|
-
if (!existsSync(portablePath)) {
|
|
56
|
-
mkdirSync(portablePath);
|
|
54
|
+
const portablePath = path.join(path.dirname(app.getPath("exe")), dirName);
|
|
55
|
+
if (!fs.existsSync(portablePath)) {
|
|
56
|
+
fs.mkdirSync(portablePath);
|
|
57
57
|
}
|
|
58
58
|
app.setPath("appData", portablePath);
|
|
59
59
|
}
|
|
@@ -65,13 +65,13 @@ function loadPage(win, htmlFilePath = "index.html") {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
function getPathFromPreload(...paths) {
|
|
68
|
-
return isDev ? join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
68
|
+
return isDev ? path.join(app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
69
69
|
}
|
|
70
70
|
function getPathFromPublic(...paths) {
|
|
71
|
-
return isDev ? join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
71
|
+
return isDev ? path.join(app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
72
72
|
}
|
|
73
73
|
function getPathFromEntryAsar(...paths) {
|
|
74
|
-
return join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
74
|
+
return path.join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
75
75
|
}
|
|
76
76
|
function handleUnexpectedErrors(callback) {
|
|
77
77
|
process.on("uncaughtException", callback);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
3
|
|
|
4
4
|
// src/utils/zip.ts
|
|
5
5
|
async function defaultZipFile(buffer) {
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
7
|
-
brotliCompress(buffer, (err, buffer2) => {
|
|
7
|
+
zlib.brotliCompress(buffer, (err, buffer2) => {
|
|
8
8
|
if (err) {
|
|
9
9
|
reject(err);
|
|
10
10
|
} else {
|
|
@@ -15,7 +15,7 @@ async function defaultZipFile(buffer) {
|
|
|
15
15
|
}
|
|
16
16
|
async function defaultUnzipFile(buffer) {
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
|
-
brotliDecompress(buffer, (err, buffer2) => {
|
|
18
|
+
zlib.brotliDecompress(buffer, (err, buffer2) => {
|
|
19
19
|
if (err) {
|
|
20
20
|
reject(err);
|
|
21
21
|
} else {
|
|
@@ -25,19 +25,19 @@ async function defaultUnzipFile(buffer) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function hashBuffer(data, length) {
|
|
28
|
-
const hash = createHash("SHA256").update(data).digest("binary");
|
|
28
|
+
const hash = crypto.createHash("SHA256").update(data).digest("binary");
|
|
29
29
|
return Buffer.from(hash).subarray(0, length);
|
|
30
30
|
}
|
|
31
31
|
function aesEncrypt(plainText, key, iv) {
|
|
32
|
-
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
32
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
|
|
33
33
|
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
34
34
|
}
|
|
35
35
|
function defaultSignature(buffer, privateKey, cert, version) {
|
|
36
|
-
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
36
|
+
const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
|
|
37
37
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
38
38
|
}
|
|
39
39
|
function aesDecrypt(encryptedText, key, iv) {
|
|
40
|
-
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
40
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
41
41
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
42
42
|
}
|
|
43
43
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -46,7 +46,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
46
46
|
if (ver !== version) {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
|
-
return createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
49
|
+
return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
50
50
|
} catch {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
|
-
var
|
|
4
|
+
var fs3 = require('fs');
|
|
5
5
|
var electron = require('electron');
|
|
6
6
|
var events = require('events');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
11
|
+
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
12
|
+
|
|
8
13
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
14
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
15
|
}) : x)(function(x) {
|
|
@@ -21,11 +26,11 @@ var isDev = __EIU_IS_DEV__;
|
|
|
21
26
|
process.platform === "win32";
|
|
22
27
|
process.platform === "darwin";
|
|
23
28
|
process.platform === "linux";
|
|
24
|
-
function getPathFromAppNameAsar(...
|
|
25
|
-
return isDev ? "DEV.asar" :
|
|
29
|
+
function getPathFromAppNameAsar(...paths) {
|
|
30
|
+
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
26
31
|
}
|
|
27
32
|
function getAppVersion() {
|
|
28
|
-
return isDev ? getEntryVersion() :
|
|
33
|
+
return isDev ? getEntryVersion() : fs3__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
29
34
|
}
|
|
30
35
|
function getEntryVersion() {
|
|
31
36
|
return electron.app.getVersion();
|
|
@@ -167,14 +172,14 @@ var Updater = class extends events.EventEmitter {
|
|
|
167
172
|
}
|
|
168
173
|
this.logger?.debug("verify start");
|
|
169
174
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
170
|
-
this.err("download failed", "validate", "invalid
|
|
175
|
+
this.err("download failed", "validate", "invalid update asar file");
|
|
171
176
|
return false;
|
|
172
177
|
}
|
|
173
178
|
this.logger?.debug("verify success");
|
|
174
179
|
try {
|
|
175
180
|
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
176
181
|
this.logger?.debug(`install to ${tmpFilePath}`);
|
|
177
|
-
|
|
182
|
+
fs3__default.default.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
178
183
|
this.logger?.info(`download success, version: ${_version}`);
|
|
179
184
|
this.info = void 0;
|
|
180
185
|
this.emit("update-downloaded");
|
|
@@ -241,12 +246,12 @@ async function initApp(appOptions) {
|
|
|
241
246
|
try {
|
|
242
247
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
243
248
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
244
|
-
if (
|
|
249
|
+
if (fs3__default.default.existsSync(tempAsarPath)) {
|
|
245
250
|
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
246
|
-
await onInstall(() =>
|
|
251
|
+
await onInstall(() => fs3__default.default.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
247
252
|
}
|
|
248
|
-
const mainFilePath =
|
|
249
|
-
isDev ?
|
|
253
|
+
const mainFilePath = path__default.default.join(
|
|
254
|
+
isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
250
255
|
"main",
|
|
251
256
|
__EIU_MAIN_FILE__
|
|
252
257
|
);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-
|
|
1
|
+
import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-4MH6ZXCY.js';
|
|
2
2
|
import { isUpdateJSON, __require } from './chunk-72ZAJ7AF.js';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs2 from 'node:fs';
|
|
5
5
|
import { app } from 'electron';
|
|
6
6
|
import { EventEmitter } from 'node:events';
|
|
7
7
|
|
|
@@ -137,14 +137,14 @@ var Updater = class extends EventEmitter {
|
|
|
137
137
|
}
|
|
138
138
|
this.logger?.debug("verify start");
|
|
139
139
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
140
|
-
this.err("download failed", "validate", "invalid
|
|
140
|
+
this.err("download failed", "validate", "invalid update asar file");
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
this.logger?.debug("verify success");
|
|
144
144
|
try {
|
|
145
145
|
const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
|
|
146
146
|
this.logger?.debug(`install to ${tmpFilePath}`);
|
|
147
|
-
writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
147
|
+
fs2.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
|
|
148
148
|
this.logger?.info(`download success, version: ${_version}`);
|
|
149
149
|
this.info = void 0;
|
|
150
150
|
this.emit("update-downloaded");
|
|
@@ -211,12 +211,12 @@ async function initApp(appOptions) {
|
|
|
211
211
|
try {
|
|
212
212
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
213
213
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
214
|
-
if (existsSync(tempAsarPath)) {
|
|
214
|
+
if (fs2.existsSync(tempAsarPath)) {
|
|
215
215
|
logger?.info(`installing new asar: ${tempAsarPath}`);
|
|
216
|
-
await onInstall(() => renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
216
|
+
await onInstall(() => fs2.renameSync(tempAsarPath, appNameAsarPath), tempAsarPath, appNameAsarPath, logger);
|
|
217
217
|
}
|
|
218
|
-
const mainFilePath = join(
|
|
219
|
-
isDev ? join(app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
218
|
+
const mainFilePath = path.join(
|
|
219
|
+
isDev ? path.join(app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
220
220
|
"main",
|
|
221
221
|
__EIU_MAIN_FILE__
|
|
222
222
|
);
|
package/dist/provider.cjs
CHANGED
|
@@ -5,6 +5,11 @@ var electron = require('electron');
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var zlib = require('zlib');
|
|
7
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
11
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
12
|
+
|
|
8
13
|
// src/provider/github.ts
|
|
9
14
|
|
|
10
15
|
// src/utils/version.ts
|
|
@@ -121,11 +126,11 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
|
|
|
121
126
|
});
|
|
122
127
|
}
|
|
123
128
|
function hashBuffer(data, length) {
|
|
124
|
-
const hash =
|
|
129
|
+
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
125
130
|
return Buffer.from(hash).subarray(0, length);
|
|
126
131
|
}
|
|
127
132
|
function aesDecrypt(encryptedText, key, iv) {
|
|
128
|
-
const decipher =
|
|
133
|
+
const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
129
134
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
130
135
|
}
|
|
131
136
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -134,14 +139,14 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
134
139
|
if (ver !== version) {
|
|
135
140
|
return false;
|
|
136
141
|
}
|
|
137
|
-
return
|
|
142
|
+
return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
138
143
|
} catch {
|
|
139
144
|
return false;
|
|
140
145
|
}
|
|
141
146
|
}
|
|
142
147
|
async function defaultUnzipFile(buffer) {
|
|
143
148
|
return new Promise((resolve, reject) => {
|
|
144
|
-
|
|
149
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
|
|
145
150
|
if (err) {
|
|
146
151
|
reject(err);
|
|
147
152
|
} else {
|
package/dist/provider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultVerifySignature, defaultUnzipFile } from './chunk-
|
|
1
|
+
import { defaultVerifySignature, defaultUnzipFile } from './chunk-KZSYEXLO.js';
|
|
2
2
|
import { defaultIsLowerVersion, isUpdateJSON } from './chunk-72ZAJ7AF.js';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
4
|
import { app, net } from 'electron';
|
package/dist/utils.cjs
CHANGED
|
@@ -6,6 +6,13 @@ var electron = require('electron');
|
|
|
6
6
|
var zlib = require('zlib');
|
|
7
7
|
var crypto = require('crypto');
|
|
8
8
|
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
+
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
14
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
15
|
+
|
|
9
16
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
17
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
18
|
}) : x)(function(x) {
|
|
@@ -16,17 +23,17 @@ var isDev = __EIU_IS_DEV__;
|
|
|
16
23
|
var isWin = process.platform === "win32";
|
|
17
24
|
var isMac = process.platform === "darwin";
|
|
18
25
|
var isLinux = process.platform === "linux";
|
|
19
|
-
function getPathFromAppNameAsar(...
|
|
20
|
-
return isDev ? "DEV.asar" :
|
|
26
|
+
function getPathFromAppNameAsar(...paths) {
|
|
27
|
+
return isDev ? "DEV.asar" : path__default.default.join(path__default.default.dirname(electron.app.getAppPath()), `${electron.app.name}.asar`, ...paths);
|
|
21
28
|
}
|
|
22
29
|
function getAppVersion() {
|
|
23
|
-
return isDev ? getEntryVersion() :
|
|
30
|
+
return isDev ? getEntryVersion() : fs__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
24
31
|
}
|
|
25
32
|
function getEntryVersion() {
|
|
26
33
|
return electron.app.getVersion();
|
|
27
34
|
}
|
|
28
35
|
function requireNative(moduleName) {
|
|
29
|
-
return __require(
|
|
36
|
+
return __require(path__default.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, moduleName));
|
|
30
37
|
}
|
|
31
38
|
function restartApp() {
|
|
32
39
|
electron.app.relaunch();
|
|
@@ -60,9 +67,9 @@ function singleInstance(window) {
|
|
|
60
67
|
return result;
|
|
61
68
|
}
|
|
62
69
|
function setPortableAppDataPath(dirName = "data") {
|
|
63
|
-
const portablePath =
|
|
64
|
-
if (!
|
|
65
|
-
|
|
70
|
+
const portablePath = path__default.default.join(path__default.default.dirname(electron.app.getPath("exe")), dirName);
|
|
71
|
+
if (!fs__default.default.existsSync(portablePath)) {
|
|
72
|
+
fs__default.default.mkdirSync(portablePath);
|
|
66
73
|
}
|
|
67
74
|
electron.app.setPath("appData", portablePath);
|
|
68
75
|
}
|
|
@@ -74,13 +81,13 @@ function loadPage(win, htmlFilePath = "index.html") {
|
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
function getPathFromPreload(...paths) {
|
|
77
|
-
return isDev ?
|
|
84
|
+
return isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "preload", ...paths) : getPathFromAppNameAsar("preload", ...paths);
|
|
78
85
|
}
|
|
79
86
|
function getPathFromPublic(...paths) {
|
|
80
|
-
return isDev ?
|
|
87
|
+
return isDev ? path__default.default.join(electron.app.getAppPath(), "public", ...paths) : getPathFromAppNameAsar("renderer", ...paths);
|
|
81
88
|
}
|
|
82
89
|
function getPathFromEntryAsar(...paths) {
|
|
83
|
-
return
|
|
90
|
+
return path__default.default.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
|
|
84
91
|
}
|
|
85
92
|
function handleUnexpectedErrors(callback) {
|
|
86
93
|
process.on("uncaughtException", callback);
|
|
@@ -88,7 +95,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
88
95
|
}
|
|
89
96
|
async function defaultZipFile(buffer) {
|
|
90
97
|
return new Promise((resolve, reject) => {
|
|
91
|
-
|
|
98
|
+
zlib__default.default.brotliCompress(buffer, (err, buffer2) => {
|
|
92
99
|
if (err) {
|
|
93
100
|
reject(err);
|
|
94
101
|
} else {
|
|
@@ -99,7 +106,7 @@ async function defaultZipFile(buffer) {
|
|
|
99
106
|
}
|
|
100
107
|
async function defaultUnzipFile(buffer) {
|
|
101
108
|
return new Promise((resolve, reject) => {
|
|
102
|
-
|
|
109
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => {
|
|
103
110
|
if (err) {
|
|
104
111
|
reject(err);
|
|
105
112
|
} else {
|
|
@@ -171,19 +178,19 @@ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVe
|
|
|
171
178
|
return existingJson;
|
|
172
179
|
}
|
|
173
180
|
function hashBuffer(data, length) {
|
|
174
|
-
const hash =
|
|
181
|
+
const hash = crypto__default.default.createHash("SHA256").update(data).digest("binary");
|
|
175
182
|
return Buffer.from(hash).subarray(0, length);
|
|
176
183
|
}
|
|
177
184
|
function aesEncrypt(plainText, key, iv) {
|
|
178
|
-
const cipher =
|
|
185
|
+
const cipher = crypto__default.default.createCipheriv("aes-256-cbc", key, iv);
|
|
179
186
|
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
180
187
|
}
|
|
181
188
|
function defaultSignature(buffer, privateKey, cert, version) {
|
|
182
|
-
const sig =
|
|
189
|
+
const sig = crypto__default.default.createSign("RSA-SHA256").update(buffer).sign(crypto__default.default.createPrivateKey(privateKey), "base64");
|
|
183
190
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
184
191
|
}
|
|
185
192
|
function aesDecrypt(encryptedText, key, iv) {
|
|
186
|
-
const decipher =
|
|
193
|
+
const decipher = crypto__default.default.createDecipheriv("aes-256-cbc", key, iv);
|
|
187
194
|
return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
|
|
188
195
|
}
|
|
189
196
|
function defaultVerifySignature(buffer, version, signature, cert) {
|
|
@@ -192,7 +199,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
192
199
|
if (ver !== version) {
|
|
193
200
|
return false;
|
|
194
201
|
}
|
|
195
|
-
return
|
|
202
|
+
return crypto__default.default.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
|
|
196
203
|
} catch {
|
|
197
204
|
return false;
|
|
198
205
|
}
|
package/dist/utils.d.cts
CHANGED
|
@@ -17,7 +17,7 @@ declare const isLinux: boolean;
|
|
|
17
17
|
*
|
|
18
18
|
* if is in dev, **always** return `'DEV.asar'`
|
|
19
19
|
*/
|
|
20
|
-
declare function getPathFromAppNameAsar(...
|
|
20
|
+
declare function getPathFromAppNameAsar(...paths: string[]): string;
|
|
21
21
|
/**
|
|
22
22
|
* get app version, if is in dev, return `getEntryVersion()`
|
|
23
23
|
*/
|
package/dist/utils.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const isLinux: boolean;
|
|
|
17
17
|
*
|
|
18
18
|
* if is in dev, **always** return `'DEV.asar'`
|
|
19
19
|
*/
|
|
20
|
-
declare function getPathFromAppNameAsar(...
|
|
20
|
+
declare function getPathFromAppNameAsar(...paths: string[]): string;
|
|
21
21
|
/**
|
|
22
22
|
* get app version, if is in dev, return `getEntryVersion()`
|
|
23
23
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-
|
|
2
|
-
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-
|
|
1
|
+
export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-4MH6ZXCY.js';
|
|
2
|
+
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-KZSYEXLO.js';
|
|
3
3
|
export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-72ZAJ7AF.js';
|
|
4
4
|
|
|
5
5
|
// src/utils/updater.ts
|
package/dist/vite.d.ts
CHANGED
|
@@ -234,14 +234,17 @@ interface ElectronUpdaterOptions {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
interface BytecodeOptions {
|
|
237
|
+
enable: boolean;
|
|
237
238
|
/**
|
|
238
|
-
*
|
|
239
|
+
* Remember to set `sandbox: false` when creating window
|
|
239
240
|
*/
|
|
240
|
-
|
|
241
|
+
preload?: boolean;
|
|
241
242
|
/**
|
|
242
|
-
*
|
|
243
|
+
* before transformed code compile callback, if return `null` or `undefined`, it will be ignored
|
|
244
|
+
* @param code transformed code
|
|
245
|
+
* @param id file path
|
|
243
246
|
*/
|
|
244
|
-
|
|
247
|
+
beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined>;
|
|
245
248
|
}
|
|
246
249
|
|
|
247
250
|
type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
|
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import path5 from 'node:path';
|
|
2
|
+
import fs3 from 'node:fs';
|
|
3
3
|
import { createLogger, normalizePath, mergeConfig, createFilter } from 'vite';
|
|
4
4
|
import ElectronSimple from 'vite-plugin-electron/simple';
|
|
5
5
|
import { startup } from 'vite-plugin-electron';
|
|
@@ -9,11 +9,11 @@ import { isCI } from 'ci-info';
|
|
|
9
9
|
export { isCI } from 'ci-info';
|
|
10
10
|
import Asar from '@electron/asar';
|
|
11
11
|
import { build } from 'esbuild';
|
|
12
|
-
import
|
|
12
|
+
import cp from 'node:child_process';
|
|
13
13
|
import * as babel from '@babel/core';
|
|
14
14
|
import MagicString from 'magic-string';
|
|
15
|
-
import
|
|
16
|
-
import
|
|
15
|
+
import zlib from 'node:zlib';
|
|
16
|
+
import crypto from 'node:crypto';
|
|
17
17
|
import { generate } from 'selfsigned';
|
|
18
18
|
|
|
19
19
|
// src/vite.ts
|
|
@@ -76,13 +76,13 @@ function getElectronPath() {
|
|
|
76
76
|
if (!electronModulePath) {
|
|
77
77
|
throw new Error("Electron is not installed");
|
|
78
78
|
}
|
|
79
|
-
const pathFile =
|
|
79
|
+
const pathFile = path5.join(electronModulePath, "path.txt");
|
|
80
80
|
let executablePath;
|
|
81
|
-
if (
|
|
82
|
-
executablePath =
|
|
81
|
+
if (fs3.existsSync(pathFile)) {
|
|
82
|
+
executablePath = fs3.readFileSync(pathFile, "utf-8");
|
|
83
83
|
}
|
|
84
84
|
if (executablePath) {
|
|
85
|
-
electronExecPath =
|
|
85
|
+
electronExecPath = path5.join(electronModulePath, "dist", executablePath);
|
|
86
86
|
process.env.ELECTRON_EXEC_PATH = electronExecPath;
|
|
87
87
|
} else {
|
|
88
88
|
throw new Error("Electron executable file is not existed");
|
|
@@ -91,14 +91,14 @@ function getElectronPath() {
|
|
|
91
91
|
return electronExecPath;
|
|
92
92
|
}
|
|
93
93
|
function getBytecodeCompilerPath() {
|
|
94
|
-
const scriptPath =
|
|
95
|
-
if (!
|
|
96
|
-
|
|
94
|
+
const scriptPath = path5.join(electronModulePath, "bytenode.cjs");
|
|
95
|
+
if (!fs3.existsSync(scriptPath)) {
|
|
96
|
+
fs3.writeFileSync(scriptPath, bytecodeGeneratorScript);
|
|
97
97
|
}
|
|
98
98
|
return scriptPath;
|
|
99
99
|
}
|
|
100
100
|
function toRelativePath(filename, importer) {
|
|
101
|
-
const relPath =
|
|
101
|
+
const relPath = path5.posix.relative(path5.dirname(importer), filename);
|
|
102
102
|
return relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
103
103
|
}
|
|
104
104
|
function compileToBytecode(code) {
|
|
@@ -106,8 +106,8 @@ function compileToBytecode(code) {
|
|
|
106
106
|
const logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
107
107
|
const electronPath = getElectronPath();
|
|
108
108
|
const bytecodePath = getBytecodeCompilerPath();
|
|
109
|
-
return new Promise((
|
|
110
|
-
const proc = spawn(electronPath, [bytecodePath], {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const proc = cp.spawn(electronPath, [bytecodePath], {
|
|
111
111
|
env: { ELECTRON_RUN_AS_NODE: "1" },
|
|
112
112
|
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
113
113
|
});
|
|
@@ -118,7 +118,7 @@ function compileToBytecode(code) {
|
|
|
118
118
|
if (proc.stdout) {
|
|
119
119
|
proc.stdout.on("data", (chunk) => data = Buffer.concat([data, chunk]));
|
|
120
120
|
proc.stdout.on("error", (err) => logErr(err));
|
|
121
|
-
proc.stdout.on("end", () =>
|
|
121
|
+
proc.stdout.on("end", () => resolve(data));
|
|
122
122
|
}
|
|
123
123
|
if (proc.stderr) {
|
|
124
124
|
proc.stderr.on("data", (chunk) => logErr("Error: ", chunk.toString()));
|
|
@@ -126,37 +126,77 @@ function compileToBytecode(code) {
|
|
|
126
126
|
}
|
|
127
127
|
proc.addListener("error", (err) => logErr(err));
|
|
128
128
|
proc.on("error", (err) => reject(err));
|
|
129
|
-
proc.on("exit", () =>
|
|
129
|
+
proc.on("exit", () => resolve(data));
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
function convertArrowToFunction(code) {
|
|
133
133
|
const result = babel.transform(code, {
|
|
134
|
-
plugins: ["@babel/plugin-transform-arrow-functions"]
|
|
134
|
+
plugins: ["@babel/plugin-transform-arrow-functions", "@babel/plugin-transform-template-literals"]
|
|
135
135
|
});
|
|
136
136
|
return {
|
|
137
137
|
code: result?.code || code,
|
|
138
138
|
map: result?.map
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
141
|
+
var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
|
|
142
|
+
function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
|
|
143
|
+
const hexArray = input.split("").map((c) => "0x" + (c.charCodeAt(0) + offset).toString(16));
|
|
144
|
+
return `_0xstr_([${hexArray.join(",")}],${offset})`;
|
|
143
145
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
function convertLiteral(code, sourcemap, offset) {
|
|
147
|
+
const s = new MagicString(code);
|
|
148
|
+
let hasTransformed = false;
|
|
149
|
+
const ast = babel.parse(code, { ast: true });
|
|
150
|
+
if (!ast) {
|
|
151
|
+
throw new Error("cannot parse code");
|
|
152
|
+
}
|
|
153
|
+
babel.traverse(ast, {
|
|
154
|
+
StringLiteral(path6) {
|
|
155
|
+
const parent = path6.parent;
|
|
156
|
+
const node = path6.node;
|
|
157
|
+
if (parent.type === "CallExpression") {
|
|
158
|
+
if (parent.callee.type === "Identifier" && parent.callee.name === "require") {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (parent.callee.type === "Import") {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (parent.type.startsWith("Export")) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (parent.type.startsWith("Import")) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (parent.type === "ObjectProperty" && parent.key === node) {
|
|
172
|
+
const result2 = `[${obfuscateString(node.value, offset)}]`;
|
|
173
|
+
const start2 = node.start;
|
|
174
|
+
const end2 = node.end;
|
|
175
|
+
if (start2 && end2) {
|
|
176
|
+
s.overwrite(start2, end2, result2);
|
|
177
|
+
hasTransformed = true;
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!node.value.trim()) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const result = obfuscateString(node.value, offset);
|
|
185
|
+
const start = node.start;
|
|
186
|
+
const end = node.end;
|
|
187
|
+
if (start && end) {
|
|
188
|
+
s.overwrite(start, end, result);
|
|
189
|
+
hasTransformed = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
if (hasTransformed) {
|
|
194
|
+
s.append("\n").append(decodeFn);
|
|
149
195
|
}
|
|
150
|
-
return
|
|
196
|
+
return {
|
|
151
197
|
code: s.toString(),
|
|
152
|
-
map: sourcemap ? s.generateMap({ hires:
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
var decodeFn = "function(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))}";
|
|
156
|
-
function obfuscateString(input) {
|
|
157
|
-
const offset = Math.random() << 4 | 0;
|
|
158
|
-
const hexArray = input.split("").map((c) => "0x" + (c.charCodeAt(0) + offset).toString(16));
|
|
159
|
-
return `(${decodeFn})(${JSON.stringify(hexArray)},${offset})`;
|
|
198
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
199
|
+
};
|
|
160
200
|
}
|
|
161
201
|
|
|
162
202
|
// src/build-plugins/utils.ts
|
|
@@ -179,11 +219,11 @@ async function buildAsar({
|
|
|
179
219
|
rendererDistPath,
|
|
180
220
|
generateGzipFile
|
|
181
221
|
}) {
|
|
182
|
-
renameSync(rendererDistPath, join(electronDistPath, "renderer"));
|
|
183
|
-
writeFileSync(join(electronDistPath, "version"), version);
|
|
222
|
+
fs3.renameSync(rendererDistPath, path5.join(electronDistPath, "renderer"));
|
|
223
|
+
fs3.writeFileSync(path5.join(electronDistPath, "version"), version);
|
|
184
224
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
185
|
-
const buf = await generateGzipFile(readFileSync(asarOutputPath));
|
|
186
|
-
writeFileSync(gzipPath, buf);
|
|
225
|
+
const buf = await generateGzipFile(fs3.readFileSync(asarOutputPath));
|
|
226
|
+
fs3.writeFileSync(gzipPath, buf);
|
|
187
227
|
log.info(`build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
|
|
188
228
|
return buf;
|
|
189
229
|
}
|
|
@@ -206,9 +246,9 @@ async function buildVersion({
|
|
|
206
246
|
signature: "",
|
|
207
247
|
version
|
|
208
248
|
};
|
|
209
|
-
if (existsSync(versionPath)) {
|
|
249
|
+
if (fs3.existsSync(versionPath)) {
|
|
210
250
|
try {
|
|
211
|
-
const oldVersionJson = JSON.parse(readFileSync(versionPath, "utf-8"));
|
|
251
|
+
const oldVersionJson = JSON.parse(fs3.readFileSync(versionPath, "utf-8"));
|
|
212
252
|
if (isUpdateJSON(oldVersionJson)) {
|
|
213
253
|
_json = oldVersionJson;
|
|
214
254
|
} else {
|
|
@@ -222,7 +262,7 @@ async function buildVersion({
|
|
|
222
262
|
if (!isUpdateJSON(_json)) {
|
|
223
263
|
throw new Error("invalid version info");
|
|
224
264
|
}
|
|
225
|
-
writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
265
|
+
fs3.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
226
266
|
log.info(`build version info to '${versionPath}'`, { timestamp: true });
|
|
227
267
|
}
|
|
228
268
|
async function buildEntry({
|
|
@@ -232,7 +272,7 @@ async function buildEntry({
|
|
|
232
272
|
entryOutputDirPath,
|
|
233
273
|
nativeModuleEntryMap,
|
|
234
274
|
overrideEsbuildOptions
|
|
235
|
-
}, define,
|
|
275
|
+
}, define, bytecodeOptions) {
|
|
236
276
|
const option = mergeConfig(
|
|
237
277
|
{
|
|
238
278
|
entryPoints: {
|
|
@@ -257,13 +297,13 @@ async function buildEntry({
|
|
|
257
297
|
overrideEsbuildOptions ?? {}
|
|
258
298
|
);
|
|
259
299
|
const { metafile } = await build(option);
|
|
260
|
-
if (
|
|
300
|
+
if (!bytecodeOptions || !bytecodeOptions.enable) {
|
|
261
301
|
return;
|
|
262
302
|
}
|
|
263
303
|
const filePaths = Object.keys(metafile?.outputs ?? []);
|
|
264
304
|
for (const filePath of filePaths) {
|
|
265
|
-
let code = readFileSync(filePath, "utf-8");
|
|
266
|
-
const fileName = basename(filePath);
|
|
305
|
+
let code = fs3.readFileSync(filePath, "utf-8");
|
|
306
|
+
const fileName = path5.basename(filePath);
|
|
267
307
|
const isEntry = fileName.endsWith("entry.js");
|
|
268
308
|
if (isEntry) {
|
|
269
309
|
code = code.replace(
|
|
@@ -271,16 +311,19 @@ async function buildEntry({
|
|
|
271
311
|
(_, cert) => `"${cert.slice(1, -1).replace(/\n/g, "\\n")}"`
|
|
272
312
|
);
|
|
273
313
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
314
|
+
let transformedCode = convertLiteral(convertArrowToFunction(code).code).code;
|
|
315
|
+
if (bytecodeOptions.beforeCompile) {
|
|
316
|
+
const result = await bytecodeOptions.beforeCompile(transformedCode, filePath);
|
|
317
|
+
if (result) {
|
|
318
|
+
transformedCode = result;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
278
321
|
const buffer = await compileToBytecode(transformedCode);
|
|
279
|
-
writeFileSync(
|
|
280
|
-
writeFileSync(
|
|
322
|
+
fs3.writeFileSync(
|
|
281
323
|
filePath,
|
|
282
324
|
`${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
|
|
283
325
|
);
|
|
326
|
+
fs3.writeFileSync(`${filePath}c`, buffer);
|
|
284
327
|
bytecodeLog.info(
|
|
285
328
|
`${filePath} [${(buffer.byteLength / 1e3).toFixed(2)} kB]`,
|
|
286
329
|
{ timestamp: true }
|
|
@@ -288,49 +331,45 @@ async function buildEntry({
|
|
|
288
331
|
}
|
|
289
332
|
bytecodeLog.info(`${filePaths.length} file${filePaths.length > 1 ? "s" : ""} compiled into bytecode`, { timestamp: true });
|
|
290
333
|
}
|
|
291
|
-
function getCert(code) {
|
|
292
|
-
const cert = code.match(/-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n/)?.[0];
|
|
293
|
-
return cert ? [cert] : [];
|
|
294
|
-
}
|
|
295
334
|
async function defaultZipFile(buffer) {
|
|
296
|
-
return new Promise((
|
|
297
|
-
brotliCompress(buffer, (err, buffer2) => {
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
zlib.brotliCompress(buffer, (err, buffer2) => {
|
|
298
337
|
if (err) {
|
|
299
338
|
reject(err);
|
|
300
339
|
} else {
|
|
301
|
-
|
|
340
|
+
resolve(buffer2);
|
|
302
341
|
}
|
|
303
342
|
});
|
|
304
343
|
});
|
|
305
344
|
}
|
|
306
345
|
function hashBuffer(data, length) {
|
|
307
|
-
const hash = createHash("SHA256").update(data).digest("binary");
|
|
346
|
+
const hash = crypto.createHash("SHA256").update(data).digest("binary");
|
|
308
347
|
return Buffer.from(hash).subarray(0, length);
|
|
309
348
|
}
|
|
310
349
|
function aesEncrypt(plainText, key, iv) {
|
|
311
|
-
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
350
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
|
|
312
351
|
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
313
352
|
}
|
|
314
353
|
function defaultSignature(buffer, privateKey, cert, version) {
|
|
315
|
-
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
354
|
+
const sig = crypto.createSign("RSA-SHA256").update(buffer).sign(crypto.createPrivateKey(privateKey), "base64");
|
|
316
355
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
317
356
|
}
|
|
318
357
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
319
|
-
const privateKeyDir = dirname(privateKeyPath);
|
|
320
|
-
if (!existsSync(privateKeyDir)) {
|
|
321
|
-
mkdirSync(privateKeyDir, { recursive: true });
|
|
358
|
+
const privateKeyDir = path5.dirname(privateKeyPath);
|
|
359
|
+
if (!fs3.existsSync(privateKeyDir)) {
|
|
360
|
+
fs3.mkdirSync(privateKeyDir, { recursive: true });
|
|
322
361
|
}
|
|
323
|
-
const certDir = dirname(certPath);
|
|
324
|
-
if (!existsSync(certDir)) {
|
|
325
|
-
mkdirSync(certDir, { recursive: true });
|
|
362
|
+
const certDir = path5.dirname(certPath);
|
|
363
|
+
if (!fs3.existsSync(certDir)) {
|
|
364
|
+
fs3.mkdirSync(certDir, { recursive: true });
|
|
326
365
|
}
|
|
327
366
|
const { cert, private: privateKey } = generate(subject, {
|
|
328
367
|
keySize: keyLength,
|
|
329
368
|
algorithm: "sha256",
|
|
330
369
|
days
|
|
331
370
|
});
|
|
332
|
-
writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
333
|
-
writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
371
|
+
fs3.writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
372
|
+
fs3.writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
334
373
|
}
|
|
335
374
|
function parseKeys({
|
|
336
375
|
keyLength,
|
|
@@ -339,22 +378,22 @@ function parseKeys({
|
|
|
339
378
|
subject,
|
|
340
379
|
days
|
|
341
380
|
}) {
|
|
342
|
-
const keysDir = dirname(privateKeyPath);
|
|
381
|
+
const keysDir = path5.dirname(privateKeyPath);
|
|
343
382
|
let privateKey = process.env.UPDATER_PK;
|
|
344
383
|
let cert = process.env.UPDATER_CERT;
|
|
345
384
|
if (privateKey && cert) {
|
|
346
385
|
log.info("use UPDATER_PK and UPDATER_CERT from environment variables", { timestamp: true });
|
|
347
386
|
return { privateKey, cert };
|
|
348
387
|
}
|
|
349
|
-
if (!existsSync(keysDir)) {
|
|
350
|
-
mkdirSync(keysDir);
|
|
388
|
+
if (!fs3.existsSync(keysDir)) {
|
|
389
|
+
fs3.mkdirSync(keysDir);
|
|
351
390
|
}
|
|
352
|
-
if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
|
|
391
|
+
if (!fs3.existsSync(privateKeyPath) || !fs3.existsSync(certPath)) {
|
|
353
392
|
log.info("no key pair found, generate new key pair", { timestamp: true });
|
|
354
393
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
355
394
|
}
|
|
356
|
-
privateKey = readFileSync(privateKeyPath, "utf-8");
|
|
357
|
-
cert = readFileSync(certPath, "utf-8");
|
|
395
|
+
privateKey = fs3.readFileSync(privateKeyPath, "utf-8");
|
|
396
|
+
cert = fs3.readFileSync(certPath, "utf-8");
|
|
358
397
|
return { privateKey, cert };
|
|
359
398
|
}
|
|
360
399
|
function parseSubjects(subject) {
|
|
@@ -433,15 +472,16 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
433
472
|
};
|
|
434
473
|
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
|
|
435
474
|
}
|
|
436
|
-
function bytecodePlugin(
|
|
475
|
+
function bytecodePlugin(env, options) {
|
|
476
|
+
const {
|
|
477
|
+
enable,
|
|
478
|
+
preload = false,
|
|
479
|
+
beforeCompile
|
|
480
|
+
} = options;
|
|
437
481
|
if (!enable) {
|
|
438
482
|
return null;
|
|
439
483
|
}
|
|
440
|
-
|
|
441
|
-
protectedStrings = [],
|
|
442
|
-
enablePreload = false
|
|
443
|
-
} = options;
|
|
444
|
-
if (!enablePreload && env === "preload") {
|
|
484
|
+
if (!preload && env === "preload") {
|
|
445
485
|
bytecodeLog.warn('bytecodePlugin is skiped in preload. To enable in preload, please manually set the "enablePreload" option to true and set `sandbox: false` when creating the window', { timestamp: true });
|
|
446
486
|
return null;
|
|
447
487
|
}
|
|
@@ -457,10 +497,9 @@ function bytecodePlugin(enable, env, options = {}) {
|
|
|
457
497
|
config = resolvedConfig;
|
|
458
498
|
},
|
|
459
499
|
transform(code, id2) {
|
|
460
|
-
if (
|
|
461
|
-
return;
|
|
500
|
+
if (!filter(id2)) {
|
|
501
|
+
return convertLiteral(code, !!config.build.sourcemap);
|
|
462
502
|
}
|
|
463
|
-
return convertString(code, protectedStrings, !!config.build.sourcemap);
|
|
464
503
|
},
|
|
465
504
|
generateBundle(options2) {
|
|
466
505
|
if (options2.format !== "es" && bytecodeRequired) {
|
|
@@ -497,7 +536,7 @@ function bytecodePlugin(enable, env, options = {}) {
|
|
|
497
536
|
(chunk) => chunk.type === "chunk" && chunk.fileName !== bytecodeModuleLoader
|
|
498
537
|
);
|
|
499
538
|
const bytecodeChunks = chunks.map((chunk) => chunk.fileName);
|
|
500
|
-
const nonEntryChunks = chunks.filter((chunk) => !chunk.isEntry).map((chunk) =>
|
|
539
|
+
const nonEntryChunks = chunks.filter((chunk) => !chunk.isEntry).map((chunk) => path5.basename(chunk.fileName));
|
|
501
540
|
const pattern = nonEntryChunks.map((chunk) => `(${chunk})`).join("|");
|
|
502
541
|
const bytecodeRE = pattern ? new RegExp(`require\\(\\S*(?=(${pattern})\\S*\\))`, "g") : null;
|
|
503
542
|
const getBytecodeLoaderBlock = (chunkFileName) => {
|
|
@@ -508,6 +547,12 @@ function bytecodePlugin(enable, env, options = {}) {
|
|
|
508
547
|
const chunk = output[name];
|
|
509
548
|
if (chunk.type === "chunk") {
|
|
510
549
|
let _code = chunk.code;
|
|
550
|
+
if (beforeCompile) {
|
|
551
|
+
const cbResult = await beforeCompile(_code, chunk.fileName);
|
|
552
|
+
if (cbResult) {
|
|
553
|
+
_code = cbResult;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
511
556
|
if (bytecodeRE && _code.match(bytecodeRE)) {
|
|
512
557
|
let match;
|
|
513
558
|
const s = new MagicString(_code);
|
|
@@ -520,20 +565,20 @@ function bytecodePlugin(enable, env, options = {}) {
|
|
|
520
565
|
}
|
|
521
566
|
_code = s.toString();
|
|
522
567
|
}
|
|
523
|
-
const chunkFilePath =
|
|
568
|
+
const chunkFilePath = path5.resolve(outDir, name);
|
|
524
569
|
if (bytecodeChunks.includes(name)) {
|
|
525
570
|
const bytecodeBuffer = await compileToBytecode(_code);
|
|
526
|
-
|
|
571
|
+
fs3.writeFileSync(chunkFilePath + "c", bytecodeBuffer);
|
|
527
572
|
if (chunk.isEntry) {
|
|
528
573
|
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
529
|
-
const bytecodeModuleBlock = `require("./${
|
|
574
|
+
const bytecodeModuleBlock = `require("./${path5.basename(name) + "c"}");`;
|
|
530
575
|
const code = `${useStrict}
|
|
531
576
|
${bytecodeLoaderBlock}
|
|
532
577
|
module.exports=${bytecodeModuleBlock}
|
|
533
578
|
`;
|
|
534
|
-
|
|
579
|
+
fs3.writeFileSync(chunkFilePath, code);
|
|
535
580
|
} else {
|
|
536
|
-
|
|
581
|
+
fs3.unlinkSync(chunkFilePath);
|
|
537
582
|
}
|
|
538
583
|
bytecodeFiles.push({ name: name + "c", size: bytecodeBuffer.length });
|
|
539
584
|
} else {
|
|
@@ -560,14 +605,14 @@ module.exports=${bytecodeModuleBlock}
|
|
|
560
605
|
_code = hasBytecodeMoudle ? _code.replace(useStrict, `${useStrict}
|
|
561
606
|
${bytecodeLoaderBlock}`) : _code;
|
|
562
607
|
}
|
|
563
|
-
|
|
608
|
+
fs3.writeFileSync(chunkFilePath, _code);
|
|
564
609
|
}
|
|
565
610
|
}
|
|
566
611
|
})
|
|
567
612
|
);
|
|
568
613
|
},
|
|
569
614
|
closeBundle() {
|
|
570
|
-
const outDir = `${normalizePath(
|
|
615
|
+
const outDir = `${normalizePath(path5.relative(config.root, path5.resolve(config.root, config.build.outDir)))}/`;
|
|
571
616
|
bytecodeFiles.forEach((file) => {
|
|
572
617
|
bytecodeLog.info(
|
|
573
618
|
`${outDir}${file.name} [${readableSize(file.size)}]`,
|
|
@@ -589,9 +634,9 @@ function debugStartup(args) {
|
|
|
589
634
|
function getMainFilePath(options) {
|
|
590
635
|
let mainFilePath;
|
|
591
636
|
if (typeof options === "string") {
|
|
592
|
-
mainFilePath = basename(options);
|
|
637
|
+
mainFilePath = path5.basename(options);
|
|
593
638
|
} else if (Array.isArray(options)) {
|
|
594
|
-
mainFilePath = basename(options[0]);
|
|
639
|
+
mainFilePath = path5.basename(options[0]);
|
|
595
640
|
} else {
|
|
596
641
|
const name = options?.index ?? options?.main;
|
|
597
642
|
if (!name) {
|
|
@@ -631,21 +676,18 @@ async function electronWithUpdater(options) {
|
|
|
631
676
|
return void 0;
|
|
632
677
|
}
|
|
633
678
|
const _options = parseOptions(pkg, sourcemap, minify, updater);
|
|
634
|
-
const bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? {
|
|
635
|
-
if (bytecodeOptions) {
|
|
636
|
-
minify = false;
|
|
637
|
-
}
|
|
679
|
+
const bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { enable: true } : void 0;
|
|
638
680
|
try {
|
|
639
|
-
rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
640
|
-
rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
681
|
+
fs3.rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
682
|
+
fs3.rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
641
683
|
} catch {
|
|
642
684
|
}
|
|
643
685
|
log.info(`remove old files`, { timestamp: true });
|
|
644
686
|
const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert } = _options;
|
|
645
687
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
646
688
|
sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
|
|
647
|
-
const _appPath = normalizePath(join(entryOutputDirPath, "entry.js"));
|
|
648
|
-
if (resolve(normalizePath(pkg.main)) !== resolve(_appPath)) {
|
|
689
|
+
const _appPath = normalizePath(path5.join(entryOutputDirPath, "entry.js"));
|
|
690
|
+
if (path5.resolve(normalizePath(pkg.main)) !== path5.resolve(_appPath)) {
|
|
649
691
|
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
650
692
|
}
|
|
651
693
|
const define = {
|
|
@@ -661,20 +703,20 @@ async function electronWithUpdater(options) {
|
|
|
661
703
|
await buildEntry(
|
|
662
704
|
buildEntryOption,
|
|
663
705
|
define,
|
|
664
|
-
|
|
706
|
+
bytecodeOptions
|
|
665
707
|
);
|
|
666
708
|
log.info(`vite build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
667
709
|
};
|
|
668
710
|
const _postBuild = postBuild ? async () => await postBuild({
|
|
669
711
|
getPathFromEntryOutputDir(...paths) {
|
|
670
|
-
return join(entryOutputDirPath, ...paths);
|
|
712
|
+
return path5.join(entryOutputDirPath, ...paths);
|
|
671
713
|
},
|
|
672
714
|
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
673
|
-
if (existsSync(from)) {
|
|
674
|
-
const target = join(entryOutputDirPath, to ?? basename(from));
|
|
675
|
-
if (!skipIfExist || !existsSync(target)) {
|
|
715
|
+
if (fs3.existsSync(from)) {
|
|
716
|
+
const target = path5.join(entryOutputDirPath, to ?? path5.basename(from));
|
|
717
|
+
if (!skipIfExist || !fs3.existsSync(target)) {
|
|
676
718
|
try {
|
|
677
|
-
cpSync(from, target);
|
|
719
|
+
fs3.cpSync(from, target);
|
|
678
720
|
} catch (error) {
|
|
679
721
|
log.warn(`copy failed: ${error}`);
|
|
680
722
|
}
|
|
@@ -685,7 +727,7 @@ async function electronWithUpdater(options) {
|
|
|
685
727
|
};
|
|
686
728
|
let isInit = false;
|
|
687
729
|
const rollupOptions = {
|
|
688
|
-
external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src),
|
|
730
|
+
external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src) || src === "original-fs",
|
|
689
731
|
treeshake: true
|
|
690
732
|
};
|
|
691
733
|
const electronPluginOptions = {
|
|
@@ -707,7 +749,7 @@ async function electronWithUpdater(options) {
|
|
|
707
749
|
{
|
|
708
750
|
plugins: [
|
|
709
751
|
!isBuild && useNotBundle ? notBundle() : void 0,
|
|
710
|
-
bytecodeOptions && bytecodePlugin(
|
|
752
|
+
bytecodeOptions && bytecodePlugin("main", bytecodeOptions)
|
|
711
753
|
],
|
|
712
754
|
build: {
|
|
713
755
|
sourcemap,
|
|
@@ -726,7 +768,7 @@ async function electronWithUpdater(options) {
|
|
|
726
768
|
vite: mergeConfig(
|
|
727
769
|
{
|
|
728
770
|
plugins: [
|
|
729
|
-
bytecodeOptions && bytecodePlugin(
|
|
771
|
+
bytecodeOptions && bytecodePlugin("preload", bytecodeOptions),
|
|
730
772
|
{
|
|
731
773
|
name: `${id}-build`,
|
|
732
774
|
enforce: "post",
|
|
@@ -772,7 +814,10 @@ async function electronWithUpdater(options) {
|
|
|
772
814
|
}
|
|
773
815
|
let extraHmrPlugin;
|
|
774
816
|
if (nativeModuleEntryMap) {
|
|
775
|
-
const files = [
|
|
817
|
+
const files = [
|
|
818
|
+
...Object.values(nativeModuleEntryMap),
|
|
819
|
+
appEntryPath
|
|
820
|
+
].map((file) => path5.resolve(normalizePath(file)));
|
|
776
821
|
extraHmrPlugin = {
|
|
777
822
|
name: `${id}-dev`,
|
|
778
823
|
apply() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.8",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"author": "subframe7536",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"build": "tsup && esno fix-module.cjs",
|
|
46
46
|
"release": "pnpm test && pnpm run build && bumpp --all && npm publish",
|
|
47
47
|
"test": "vitest --run",
|
|
48
|
+
"test:dev": "vitest",
|
|
48
49
|
"format": "eslint . --fix"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
@@ -53,27 +54,28 @@
|
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"@electron/asar": "*",
|
|
56
|
-
"esbuild": "*"
|
|
57
|
-
"magic-string": "*"
|
|
57
|
+
"esbuild": "*"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@babel/core": "^7.24.
|
|
60
|
+
"@babel/core": "^7.24.9",
|
|
61
61
|
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
|
62
|
+
"@babel/plugin-transform-template-literals": "^7.24.7",
|
|
62
63
|
"@subframe7536/type-utils": "^0.1.6",
|
|
63
64
|
"ci-info": "^4.0.0",
|
|
64
65
|
"local-pkg": "^0.5.0",
|
|
66
|
+
"magic-string": "^0.30.10",
|
|
65
67
|
"selfsigned": "^2.4.1",
|
|
66
68
|
"vite-plugin-electron": "^0.28.7"
|
|
67
69
|
},
|
|
68
70
|
"devDependencies": {
|
|
69
|
-
"@subframe7536/eslint-config": "^0.7.
|
|
71
|
+
"@subframe7536/eslint-config": "^0.7.3",
|
|
70
72
|
"@types/babel__core": "^7.20.5",
|
|
71
73
|
"@types/node": "^20.14.11",
|
|
72
74
|
"bumpp": "^9.4.1",
|
|
73
75
|
"electron": "28.2.10",
|
|
74
76
|
"eslint": "^9.7.0",
|
|
75
77
|
"esno": "^4.7.0",
|
|
76
|
-
"tsup": "^8.1
|
|
78
|
+
"tsup": "^8.2.1",
|
|
77
79
|
"typescript": "^5.5.3",
|
|
78
80
|
"vite": "^5.3.4",
|
|
79
81
|
"vite-plugin-electron": "^0.28.7",
|