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
package/dist/vite.js
CHANGED
|
@@ -1,74 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key2 of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
16
|
-
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
1
|
// src/vite.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
module.exports = __toCommonJS(vite_exports);
|
|
38
|
-
var import_node_path3 = require("path");
|
|
39
|
-
var import_node_fs4 = require("fs");
|
|
40
|
-
var import_vite3 = require("vite");
|
|
41
|
-
var import_simple = __toESM(require("vite-plugin-electron/simple"));
|
|
42
|
-
var import_vite_plugin_electron = require("vite-plugin-electron");
|
|
43
|
-
var import_plugin = require("vite-plugin-electron/plugin");
|
|
2
|
+
import { basename as basename2, join as join2, resolve } from "node:path";
|
|
3
|
+
import { cpSync, existsSync as existsSync4, readFileSync as readFileSync4, rmSync as rmSync2 } from "node:fs";
|
|
4
|
+
import { createLogger, mergeConfig, normalizePath as normalizePath2 } from "vite";
|
|
5
|
+
import ElectronSimple from "vite-plugin-electron/simple";
|
|
6
|
+
import { startup } from "vite-plugin-electron";
|
|
7
|
+
import { notBundle } from "vite-plugin-electron/plugin";
|
|
44
8
|
|
|
45
9
|
// src/build-plugins/build.ts
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
10
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import Asar from "@electron/asar";
|
|
13
|
+
import { build } from "esbuild";
|
|
14
|
+
import "vite";
|
|
15
|
+
|
|
16
|
+
// src/crypto/utils.ts
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
function hashString(data, length) {
|
|
19
|
+
const hash = createHash("SHA256").update(data).digest("binary");
|
|
20
|
+
return Buffer.from(hash).subarray(0, length);
|
|
21
|
+
}
|
|
51
22
|
|
|
52
|
-
// src/crypto.ts
|
|
53
|
-
|
|
54
|
-
function encrypt(plainText,
|
|
55
|
-
const cipher =
|
|
23
|
+
// src/crypto/enc.ts
|
|
24
|
+
import { createCipheriv, createPrivateKey, createSign } from "node:crypto";
|
|
25
|
+
function encrypt(plainText, key, iv) {
|
|
26
|
+
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
56
27
|
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
57
28
|
encrypted += cipher.final("base64url");
|
|
58
29
|
return encrypted;
|
|
59
30
|
}
|
|
60
|
-
function key(data, length) {
|
|
61
|
-
const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
|
|
62
|
-
return Buffer.from(hash).subarray(0, length);
|
|
63
|
-
}
|
|
64
31
|
var signature = (buffer, privateKey, cert, version) => {
|
|
65
|
-
const sig =
|
|
66
|
-
return encrypt(`${sig}%${version}`,
|
|
32
|
+
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
33
|
+
return encrypt(`${sig}%${version}`, hashString(cert, 32), hashString(buffer, 16));
|
|
67
34
|
};
|
|
68
35
|
|
|
69
|
-
// src/utils/
|
|
36
|
+
// src/utils/pure.ts
|
|
70
37
|
function parseVersion(version) {
|
|
71
|
-
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-
|
|
38
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
|
|
72
39
|
const match = semver.exec(version);
|
|
73
40
|
if (!match) {
|
|
74
41
|
throw new TypeError(`invalid version: ${version}`);
|
|
@@ -97,19 +64,19 @@ function isUpdateJSON(json) {
|
|
|
97
64
|
}
|
|
98
65
|
|
|
99
66
|
// src/utils/zip.ts
|
|
100
|
-
|
|
101
|
-
|
|
67
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
68
|
+
import { gunzip, gzip } from "node:zlib";
|
|
102
69
|
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
103
|
-
if (!
|
|
70
|
+
if (!existsSync(filePath)) {
|
|
104
71
|
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
105
72
|
}
|
|
106
|
-
const buffer =
|
|
73
|
+
const buffer = readFileSync(filePath);
|
|
107
74
|
return new Promise((resolve2, reject) => {
|
|
108
|
-
|
|
75
|
+
gzip(buffer, (err, buffer2) => {
|
|
109
76
|
if (err) {
|
|
110
77
|
reject(err);
|
|
111
78
|
}
|
|
112
|
-
|
|
79
|
+
writeFileSync(targetFilePath, buffer2);
|
|
113
80
|
resolve2(null);
|
|
114
81
|
});
|
|
115
82
|
});
|
|
@@ -123,9 +90,9 @@ async function buildAsar({
|
|
|
123
90
|
electronDistPath,
|
|
124
91
|
rendererDistPath
|
|
125
92
|
}) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
await
|
|
93
|
+
renameSync(rendererDistPath, join(electronDistPath, "renderer"));
|
|
94
|
+
writeFileSync2(join(electronDistPath, "version"), version);
|
|
95
|
+
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
129
96
|
await zipFile(asarOutputPath, gzipPath);
|
|
130
97
|
}
|
|
131
98
|
async function buildVersion({
|
|
@@ -150,9 +117,9 @@ async function buildVersion({
|
|
|
150
117
|
size: 0,
|
|
151
118
|
version
|
|
152
119
|
};
|
|
153
|
-
if ((
|
|
120
|
+
if (existsSync2(versionPath)) {
|
|
154
121
|
try {
|
|
155
|
-
const oldVersionJson = JSON.parse(
|
|
122
|
+
const oldVersionJson = JSON.parse(readFileSync2(versionPath, "utf-8"));
|
|
156
123
|
if (isUpdateJSON(oldVersionJson)) {
|
|
157
124
|
_json = oldVersionJson;
|
|
158
125
|
} else {
|
|
@@ -161,7 +128,7 @@ async function buildVersion({
|
|
|
161
128
|
} catch (error) {
|
|
162
129
|
}
|
|
163
130
|
}
|
|
164
|
-
const buffer =
|
|
131
|
+
const buffer = readFileSync2(gzipPath);
|
|
165
132
|
const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
|
|
166
133
|
if (generateVersionJson) {
|
|
167
134
|
_json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
|
|
@@ -182,7 +149,7 @@ async function buildVersion({
|
|
|
182
149
|
_json.size = buffer.length;
|
|
183
150
|
}
|
|
184
151
|
}
|
|
185
|
-
|
|
152
|
+
writeFileSync2(versionPath, JSON.stringify(_json, null, 2));
|
|
186
153
|
}
|
|
187
154
|
async function buildEntry({
|
|
188
155
|
sourcemap,
|
|
@@ -192,7 +159,7 @@ async function buildEntry({
|
|
|
192
159
|
nativeModuleEntryMap,
|
|
193
160
|
overrideEsbuildOptions
|
|
194
161
|
}) {
|
|
195
|
-
await
|
|
162
|
+
await build({
|
|
196
163
|
entryPoints: {
|
|
197
164
|
entry: appEntryPath,
|
|
198
165
|
...nativeModuleEntryMap
|
|
@@ -213,33 +180,33 @@ async function buildEntry({
|
|
|
213
180
|
}
|
|
214
181
|
|
|
215
182
|
// src/build-plugins/key.ts
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
183
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
184
|
+
import { dirname } from "node:path";
|
|
185
|
+
import { generate } from "selfsigned";
|
|
219
186
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
220
|
-
const privateKeyDir =
|
|
221
|
-
if (!(
|
|
222
|
-
|
|
187
|
+
const privateKeyDir = dirname(privateKeyPath);
|
|
188
|
+
if (!existsSync3(privateKeyDir)) {
|
|
189
|
+
mkdirSync(privateKeyDir, { recursive: true });
|
|
223
190
|
}
|
|
224
|
-
const certDir =
|
|
225
|
-
if (!(
|
|
226
|
-
|
|
191
|
+
const certDir = dirname(certPath);
|
|
192
|
+
if (!existsSync3(certDir)) {
|
|
193
|
+
mkdirSync(certDir, { recursive: true });
|
|
227
194
|
}
|
|
228
|
-
const { cert, private: privateKey } =
|
|
195
|
+
const { cert, private: privateKey } = generate(subject, {
|
|
229
196
|
keySize: keyLength,
|
|
230
197
|
algorithm: "sha256",
|
|
231
198
|
days
|
|
232
199
|
});
|
|
233
|
-
(
|
|
234
|
-
(
|
|
200
|
+
writeFileSync3(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
201
|
+
writeFileSync3(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
235
202
|
}
|
|
236
|
-
var noCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}
|
|
237
|
-
var existCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])
|
|
203
|
+
var noCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/;
|
|
204
|
+
var existCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/;
|
|
238
205
|
function writeCertToEntry(entryPath, cert) {
|
|
239
|
-
if (!(
|
|
206
|
+
if (!existsSync3(entryPath)) {
|
|
240
207
|
throw new Error(`entry not exist: ${entryPath}`);
|
|
241
208
|
}
|
|
242
|
-
const file = (
|
|
209
|
+
const file = readFileSync3(entryPath, "utf-8");
|
|
243
210
|
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join("\n + ");
|
|
244
211
|
let replaced = file;
|
|
245
212
|
if (noCertRegex.test(file)) {
|
|
@@ -249,7 +216,7 @@ function writeCertToEntry(entryPath, cert) {
|
|
|
249
216
|
} else {
|
|
250
217
|
throw new Error("no `SIGNATURE_CERT` found in entry");
|
|
251
218
|
}
|
|
252
|
-
(
|
|
219
|
+
writeFileSync3(entryPath, replaced);
|
|
253
220
|
}
|
|
254
221
|
function parseKeys({
|
|
255
222
|
keyLength,
|
|
@@ -259,14 +226,14 @@ function parseKeys({
|
|
|
259
226
|
subject,
|
|
260
227
|
days
|
|
261
228
|
}) {
|
|
262
|
-
const keysDir =
|
|
263
|
-
!(
|
|
264
|
-
if (!(
|
|
229
|
+
const keysDir = dirname(privateKeyPath);
|
|
230
|
+
!existsSync3(keysDir) && mkdirSync(keysDir);
|
|
231
|
+
if (!existsSync3(privateKeyPath) || !existsSync3(certPath)) {
|
|
265
232
|
log.warn("no key pair found, generate new key pair");
|
|
266
233
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
267
234
|
}
|
|
268
|
-
const privateKey = process.env.UPDATER_PK || (
|
|
269
|
-
const cert = process.env.UPDATER_CERT || (
|
|
235
|
+
const privateKey = process.env.UPDATER_PK || readFileSync3(privateKeyPath, "utf-8");
|
|
236
|
+
const cert = process.env.UPDATER_CERT || readFileSync3(certPath, "utf-8");
|
|
270
237
|
writeCertToEntry(appEntryPath, cert);
|
|
271
238
|
return { privateKey, cert };
|
|
272
239
|
}
|
|
@@ -275,12 +242,12 @@ function parseSubjects(subject) {
|
|
|
275
242
|
}
|
|
276
243
|
|
|
277
244
|
// src/build-plugins/option.ts
|
|
278
|
-
function parseOptions(
|
|
245
|
+
function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
279
246
|
const {
|
|
280
247
|
minimumVersion = "0.0.0",
|
|
281
248
|
entry: {
|
|
282
|
-
minify
|
|
283
|
-
sourcemap
|
|
249
|
+
minify: entryMinify,
|
|
250
|
+
sourcemap: entrySourcemap,
|
|
284
251
|
entryOutputDirPath = "dist-entry",
|
|
285
252
|
appEntryPath = "electron/entry.ts",
|
|
286
253
|
nativeModuleEntryMap = {},
|
|
@@ -318,8 +285,8 @@ function parseOptions(isBuild, pkg, options = {}) {
|
|
|
318
285
|
rendererDistPath
|
|
319
286
|
};
|
|
320
287
|
const buildEntryOption = {
|
|
321
|
-
minify,
|
|
322
|
-
sourcemap,
|
|
288
|
+
minify: entryMinify ?? minify,
|
|
289
|
+
sourcemap: entrySourcemap ?? sourcemap,
|
|
323
290
|
entryOutputDirPath,
|
|
324
291
|
appEntryPath,
|
|
325
292
|
nativeModuleEntryMap,
|
|
@@ -346,59 +313,78 @@ function parseOptions(isBuild, pkg, options = {}) {
|
|
|
346
313
|
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild };
|
|
347
314
|
}
|
|
348
315
|
|
|
316
|
+
// src/constant.ts
|
|
317
|
+
var id = "electron-incremental-updater";
|
|
318
|
+
var bytecodeId = `${id}-bytecode`;
|
|
319
|
+
var loaderId = `${id}-loader`;
|
|
320
|
+
|
|
349
321
|
// src/vite.ts
|
|
350
322
|
function debugStartup(args) {
|
|
351
323
|
process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
|
|
352
324
|
}
|
|
353
|
-
|
|
354
|
-
|
|
325
|
+
function resolvePackageJson(root = process.cwd()) {
|
|
326
|
+
const packageJsonPath = join2(root, "package.json");
|
|
327
|
+
const packageJsonStr = readFileSync4(packageJsonPath, "utf8");
|
|
328
|
+
try {
|
|
329
|
+
return JSON.parse(packageJsonStr);
|
|
330
|
+
} catch {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
var log = createLogger("info", { prefix: `[${id}]` });
|
|
355
335
|
function electronWithUpdater(options) {
|
|
356
|
-
|
|
336
|
+
let {
|
|
357
337
|
isBuild,
|
|
358
|
-
pkg,
|
|
338
|
+
pkg = resolvePackageJson(),
|
|
359
339
|
main: _main,
|
|
360
340
|
preload: _preload,
|
|
341
|
+
sourcemap,
|
|
342
|
+
minify,
|
|
361
343
|
updater,
|
|
362
344
|
useNotBundle = true,
|
|
363
345
|
logParsedOptions
|
|
364
346
|
} = options;
|
|
365
|
-
|
|
347
|
+
if (!pkg) {
|
|
348
|
+
log.error(`package.json not found`, { timestamp: true });
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
const _options = parseOptions(pkg, sourcemap, minify, updater);
|
|
366
352
|
try {
|
|
367
|
-
(
|
|
368
|
-
(
|
|
353
|
+
rmSync2(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
354
|
+
rmSync2(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
369
355
|
} catch (ignore) {
|
|
370
356
|
}
|
|
371
357
|
log.info(`remove old files`, { timestamp: true });
|
|
372
358
|
const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild } = _options;
|
|
373
359
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
374
|
-
|
|
375
|
-
const _appPath = (
|
|
376
|
-
if (
|
|
377
|
-
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${
|
|
360
|
+
sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
|
|
361
|
+
const _appPath = normalizePath2(join2(entryOutputDirPath, "entry.js"));
|
|
362
|
+
if (resolve(normalizePath2(pkg.main)) !== resolve(_appPath)) {
|
|
363
|
+
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
378
364
|
}
|
|
379
|
-
let isInit = false;
|
|
380
365
|
const _buildEntry = async () => {
|
|
381
366
|
await buildEntry(buildEntryOption);
|
|
382
|
-
log.info(`build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
367
|
+
log.info(`vite build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
383
368
|
};
|
|
384
|
-
const _postBuild = postBuild ? async () => postBuild({
|
|
369
|
+
const _postBuild = postBuild ? async () => await postBuild({
|
|
385
370
|
getPathFromEntryOutputDir(...paths) {
|
|
386
|
-
return (
|
|
371
|
+
return join2(entryOutputDirPath, ...paths);
|
|
387
372
|
},
|
|
388
|
-
|
|
389
|
-
if ((
|
|
390
|
-
const target = (
|
|
391
|
-
if (!skipIfExist || !(
|
|
373
|
+
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
374
|
+
if (existsSync4(from)) {
|
|
375
|
+
const target = join2(entryOutputDirPath, to ?? basename2(from));
|
|
376
|
+
if (!skipIfExist || !existsSync4(target)) {
|
|
392
377
|
try {
|
|
393
|
-
|
|
394
|
-
} catch (
|
|
395
|
-
log.warn(`copy failed: ${
|
|
378
|
+
cpSync(from, target);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
log.warn(`copy failed: ${error}`);
|
|
396
381
|
}
|
|
397
382
|
}
|
|
398
383
|
}
|
|
399
384
|
}
|
|
400
385
|
}) : async () => {
|
|
401
386
|
};
|
|
387
|
+
let isInit = false;
|
|
402
388
|
const electronPluginOptions = {
|
|
403
389
|
main: {
|
|
404
390
|
entry: _main.files,
|
|
@@ -410,12 +396,12 @@ function electronWithUpdater(options) {
|
|
|
410
396
|
}
|
|
411
397
|
_main.onstart ? _main.onstart(args) : args.startup();
|
|
412
398
|
},
|
|
413
|
-
vite:
|
|
399
|
+
vite: mergeConfig(
|
|
414
400
|
{
|
|
415
|
-
plugins: !isBuild && useNotBundle ?
|
|
401
|
+
plugins: [!isBuild && useNotBundle ? notBundle() : void 0],
|
|
416
402
|
build: {
|
|
417
403
|
sourcemap,
|
|
418
|
-
minify
|
|
404
|
+
minify,
|
|
419
405
|
outDir: `${buildAsarOption.electronDistPath}/main`,
|
|
420
406
|
rollupOptions: {
|
|
421
407
|
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
@@ -428,7 +414,7 @@ function electronWithUpdater(options) {
|
|
|
428
414
|
preload: {
|
|
429
415
|
input: _preload.files,
|
|
430
416
|
onstart: _preload.onstart,
|
|
431
|
-
vite:
|
|
417
|
+
vite: mergeConfig(
|
|
432
418
|
{
|
|
433
419
|
plugins: [
|
|
434
420
|
{
|
|
@@ -439,6 +425,7 @@ function electronWithUpdater(options) {
|
|
|
439
425
|
},
|
|
440
426
|
async closeBundle() {
|
|
441
427
|
await _buildEntry();
|
|
428
|
+
await _postBuild();
|
|
442
429
|
await buildAsar(buildAsarOption);
|
|
443
430
|
log.info(`build asar to '${buildAsarOption.asarOutputPath}'`, { timestamp: true });
|
|
444
431
|
await buildVersion(buildVersionOption);
|
|
@@ -448,7 +435,7 @@ function electronWithUpdater(options) {
|
|
|
448
435
|
],
|
|
449
436
|
build: {
|
|
450
437
|
sourcemap: sourcemap ? "inline" : void 0,
|
|
451
|
-
minify
|
|
438
|
+
minify,
|
|
452
439
|
outDir: `${buildAsarOption.electronDistPath}/preload`,
|
|
453
440
|
rollupOptions: {
|
|
454
441
|
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
@@ -465,14 +452,14 @@ function electronWithUpdater(options) {
|
|
|
465
452
|
...electronPluginOptions,
|
|
466
453
|
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
467
454
|
},
|
|
468
|
-
(
|
|
455
|
+
(key, value) => key === "privateKey" || key === "cert" ? "***" : value,
|
|
469
456
|
2
|
|
470
457
|
),
|
|
471
458
|
{ timestamp: true }
|
|
472
459
|
);
|
|
473
460
|
let extraHmrPlugin;
|
|
474
461
|
if (nativeModuleEntryMap) {
|
|
475
|
-
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) =>
|
|
462
|
+
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath2(file)));
|
|
476
463
|
extraHmrPlugin = {
|
|
477
464
|
name: `${id}-dev`,
|
|
478
465
|
apply() {
|
|
@@ -482,19 +469,18 @@ function electronWithUpdater(options) {
|
|
|
482
469
|
server.watcher.add(files).on(
|
|
483
470
|
"change",
|
|
484
471
|
(p) => files.includes(p) && _buildEntry().then(async () => {
|
|
485
|
-
await
|
|
472
|
+
await startup.exit();
|
|
486
473
|
await _postBuild();
|
|
487
|
-
await
|
|
474
|
+
await startup();
|
|
488
475
|
})
|
|
489
476
|
);
|
|
490
477
|
}
|
|
491
478
|
};
|
|
492
479
|
}
|
|
493
|
-
return [(
|
|
480
|
+
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
494
481
|
}
|
|
495
|
-
|
|
496
|
-
0 && (module.exports = {
|
|
482
|
+
export {
|
|
497
483
|
debugStartup,
|
|
498
484
|
electronWithUpdater,
|
|
499
485
|
log
|
|
500
|
-
}
|
|
486
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.1.0",
|
|
4
5
|
"description": "electron incremental update tools, powered by vite",
|
|
5
6
|
"author": "subframe7536",
|
|
6
7
|
"license": "MIT",
|
|
@@ -8,24 +9,24 @@
|
|
|
8
9
|
"keywords": [
|
|
9
10
|
"electron",
|
|
10
11
|
"incremental update",
|
|
11
|
-
"updater"
|
|
12
|
+
"updater",
|
|
13
|
+
"bytecode"
|
|
12
14
|
],
|
|
13
15
|
"exports": {
|
|
14
16
|
".": {
|
|
15
|
-
"import": "./dist/index.
|
|
16
|
-
"require": "./dist/index.
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
17
19
|
},
|
|
18
20
|
"./vite": {
|
|
19
|
-
"import": "./dist/vite.
|
|
20
|
-
"require": "./dist/vite.js"
|
|
21
|
+
"import": "./dist/vite.js"
|
|
21
22
|
},
|
|
22
23
|
"./utils": {
|
|
23
|
-
"import": "./dist/utils.
|
|
24
|
-
"require": "./dist/utils.
|
|
24
|
+
"import": "./dist/utils.js",
|
|
25
|
+
"require": "./dist/utils.cjs"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
|
-
"main": "dist/index.
|
|
28
|
-
"module": "dist/index.
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.js",
|
|
29
30
|
"files": [
|
|
30
31
|
"dist",
|
|
31
32
|
"utils.d.ts",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
],
|
|
36
37
|
"scripts": {
|
|
37
38
|
"dev": "tsup --watch",
|
|
38
|
-
"build": "tsup &&
|
|
39
|
+
"build": "tsup && esno fix-module.cjs",
|
|
39
40
|
"release": "pnpm test && pnpm run build && bumpp --all && npm publish",
|
|
40
41
|
"test": "vitest --run",
|
|
41
42
|
"lint": "eslint . --fix"
|
|
@@ -45,29 +46,25 @@
|
|
|
45
46
|
"registry": "https://registry.npmjs.org/"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
49
|
+
"@electron/asar": "*",
|
|
48
50
|
"esbuild": "*",
|
|
49
51
|
"vite-plugin-electron": "^0.15.6 || ^0.28"
|
|
50
52
|
},
|
|
51
53
|
"dependencies": {
|
|
52
|
-
"@electron/asar": "^3.2.9",
|
|
53
54
|
"@subframe7536/type-utils": "^0.1.6",
|
|
54
55
|
"selfsigned": "^2.4.1"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@subframe7536/eslint-config": "^0.6.
|
|
58
|
-
"@types/node": "^20.
|
|
59
|
-
"bumpp": "^9.4.
|
|
60
|
-
"electron": "28.
|
|
61
|
-
"eslint": "^
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"vite
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
"pnpm": {
|
|
69
|
-
"overrides": {
|
|
70
|
-
"has": "npm:@nolyfill/has@latest"
|
|
71
|
-
}
|
|
58
|
+
"@subframe7536/eslint-config": "^0.6.6",
|
|
59
|
+
"@types/node": "^20.14.7",
|
|
60
|
+
"bumpp": "^9.4.1",
|
|
61
|
+
"electron": "28.2.10",
|
|
62
|
+
"eslint": "^9.5.0",
|
|
63
|
+
"esno": "^4.7.0",
|
|
64
|
+
"tsup": "^8.1.0",
|
|
65
|
+
"typescript": "^5.5.2",
|
|
66
|
+
"vite": "^5.3.1",
|
|
67
|
+
"vite-plugin-electron": "^0.28.7",
|
|
68
|
+
"vitest": "^1.6.0"
|
|
72
69
|
}
|
|
73
70
|
}
|
package/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/utils.
|
|
1
|
+
module.exports = require('./dist/utils.cjs')
|
package/dist/chunk-GB6VLKJZ.mjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
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")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// src/utils/zip.ts
|
|
10
|
-
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
-
import { gunzip, gzip } from "node:zlib";
|
|
12
|
-
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
13
|
-
if (!existsSync(gzipPath)) {
|
|
14
|
-
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
15
|
-
}
|
|
16
|
-
const compressedBuffer = readFileSync(gzipPath);
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
gunzip(compressedBuffer, (err, buffer) => {
|
|
19
|
-
rmSync(gzipPath);
|
|
20
|
-
if (err) {
|
|
21
|
-
reject(err);
|
|
22
|
-
}
|
|
23
|
-
writeFileSync(targetFilePath, buffer);
|
|
24
|
-
resolve(null);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
29
|
-
if (!existsSync(filePath)) {
|
|
30
|
-
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
31
|
-
}
|
|
32
|
-
const buffer = readFileSync(filePath);
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
gzip(buffer, (err, buffer2) => {
|
|
35
|
-
if (err) {
|
|
36
|
-
reject(err);
|
|
37
|
-
}
|
|
38
|
-
writeFileSync(targetFilePath, buffer2);
|
|
39
|
-
resolve(null);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/utils/noDep.ts
|
|
45
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
46
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
47
|
-
throw new Error("origin url must start with https://github.com/");
|
|
48
|
-
}
|
|
49
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
50
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
51
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
52
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
53
|
-
}
|
|
54
|
-
function handleUnexpectedErrors(callback) {
|
|
55
|
-
process.on("uncaughtException", callback);
|
|
56
|
-
process.on("unhandledRejection", callback);
|
|
57
|
-
}
|
|
58
|
-
function parseVersion(version) {
|
|
59
|
-
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
60
|
-
const match = semver.exec(version);
|
|
61
|
-
if (!match) {
|
|
62
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
63
|
-
}
|
|
64
|
-
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
65
|
-
const ret = {
|
|
66
|
-
major,
|
|
67
|
-
minor,
|
|
68
|
-
patch,
|
|
69
|
-
stage: "",
|
|
70
|
-
stageVersion: -1
|
|
71
|
-
};
|
|
72
|
-
if (match[4]) {
|
|
73
|
-
let [stage, _v] = match[4].split(".");
|
|
74
|
-
ret.stage = stage;
|
|
75
|
-
ret.stageVersion = Number(_v) || -1;
|
|
76
|
-
}
|
|
77
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
78
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
79
|
-
}
|
|
80
|
-
return ret;
|
|
81
|
-
}
|
|
82
|
-
function isUpdateJSON(json) {
|
|
83
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
84
|
-
return is(json) && is(json?.beta);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export {
|
|
88
|
-
__require,
|
|
89
|
-
unzipFile,
|
|
90
|
-
zipFile,
|
|
91
|
-
parseGithubCdnURL,
|
|
92
|
-
handleUnexpectedErrors,
|
|
93
|
-
parseVersion,
|
|
94
|
-
isUpdateJSON
|
|
95
|
-
};
|