electron-incremental-update 1.0.2 → 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 -301
- 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 +43 -23
- package/dist/vite.js +145 -146
- 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 -326
- package/dist/vite.mjs +0 -392
- /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,73 +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
|
-
var import_node_path3 = require("path");
|
|
38
|
-
var import_node_fs4 = require("fs");
|
|
39
|
-
var import_vite = require("vite");
|
|
40
|
-
var import_simple = __toESM(require("vite-plugin-electron/simple"));
|
|
41
|
-
var import_vite_plugin_electron = require("vite-plugin-electron");
|
|
42
|
-
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";
|
|
43
8
|
|
|
44
9
|
// src/build-plugins/build.ts
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}
|
|
50
22
|
|
|
51
|
-
// src/crypto.ts
|
|
52
|
-
|
|
53
|
-
function encrypt(plainText,
|
|
54
|
-
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);
|
|
55
27
|
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
56
28
|
encrypted += cipher.final("base64url");
|
|
57
29
|
return encrypted;
|
|
58
30
|
}
|
|
59
|
-
function key(data, length) {
|
|
60
|
-
const hash = (0, import_node_crypto.createHash)("SHA256").update(data).digest("binary");
|
|
61
|
-
return Buffer.from(hash).subarray(0, length);
|
|
62
|
-
}
|
|
63
31
|
var signature = (buffer, privateKey, cert, version) => {
|
|
64
|
-
const sig =
|
|
65
|
-
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));
|
|
66
34
|
};
|
|
67
35
|
|
|
68
|
-
// src/utils/
|
|
36
|
+
// src/utils/pure.ts
|
|
69
37
|
function parseVersion(version) {
|
|
70
|
-
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-
|
|
38
|
+
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i;
|
|
71
39
|
const match = semver.exec(version);
|
|
72
40
|
if (!match) {
|
|
73
41
|
throw new TypeError(`invalid version: ${version}`);
|
|
@@ -96,19 +64,19 @@ function isUpdateJSON(json) {
|
|
|
96
64
|
}
|
|
97
65
|
|
|
98
66
|
// src/utils/zip.ts
|
|
99
|
-
|
|
100
|
-
|
|
67
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
68
|
+
import { gunzip, gzip } from "node:zlib";
|
|
101
69
|
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
102
|
-
if (!
|
|
70
|
+
if (!existsSync(filePath)) {
|
|
103
71
|
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
104
72
|
}
|
|
105
|
-
const buffer =
|
|
73
|
+
const buffer = readFileSync(filePath);
|
|
106
74
|
return new Promise((resolve2, reject) => {
|
|
107
|
-
|
|
75
|
+
gzip(buffer, (err, buffer2) => {
|
|
108
76
|
if (err) {
|
|
109
77
|
reject(err);
|
|
110
78
|
}
|
|
111
|
-
|
|
79
|
+
writeFileSync(targetFilePath, buffer2);
|
|
112
80
|
resolve2(null);
|
|
113
81
|
});
|
|
114
82
|
});
|
|
@@ -122,9 +90,9 @@ async function buildAsar({
|
|
|
122
90
|
electronDistPath,
|
|
123
91
|
rendererDistPath
|
|
124
92
|
}) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
await
|
|
93
|
+
renameSync(rendererDistPath, join(electronDistPath, "renderer"));
|
|
94
|
+
writeFileSync2(join(electronDistPath, "version"), version);
|
|
95
|
+
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
128
96
|
await zipFile(asarOutputPath, gzipPath);
|
|
129
97
|
}
|
|
130
98
|
async function buildVersion({
|
|
@@ -149,18 +117,18 @@ async function buildVersion({
|
|
|
149
117
|
size: 0,
|
|
150
118
|
version
|
|
151
119
|
};
|
|
152
|
-
if ((
|
|
120
|
+
if (existsSync2(versionPath)) {
|
|
153
121
|
try {
|
|
154
|
-
const oldVersionJson = JSON.parse(
|
|
122
|
+
const oldVersionJson = JSON.parse(readFileSync2(versionPath, "utf-8"));
|
|
155
123
|
if (isUpdateJSON(oldVersionJson)) {
|
|
156
124
|
_json = oldVersionJson;
|
|
157
125
|
} else {
|
|
158
|
-
|
|
126
|
+
log.warn("old version json is invalid, ignore it");
|
|
159
127
|
}
|
|
160
128
|
} catch (error) {
|
|
161
129
|
}
|
|
162
130
|
}
|
|
163
|
-
const buffer =
|
|
131
|
+
const buffer = readFileSync2(gzipPath);
|
|
164
132
|
const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
|
|
165
133
|
if (generateVersionJson) {
|
|
166
134
|
_json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
|
|
@@ -181,7 +149,7 @@ async function buildVersion({
|
|
|
181
149
|
_json.size = buffer.length;
|
|
182
150
|
}
|
|
183
151
|
}
|
|
184
|
-
|
|
152
|
+
writeFileSync2(versionPath, JSON.stringify(_json, null, 2));
|
|
185
153
|
}
|
|
186
154
|
async function buildEntry({
|
|
187
155
|
sourcemap,
|
|
@@ -189,10 +157,9 @@ async function buildEntry({
|
|
|
189
157
|
appEntryPath,
|
|
190
158
|
entryOutputDirPath,
|
|
191
159
|
nativeModuleEntryMap,
|
|
192
|
-
overrideEsbuildOptions
|
|
193
|
-
postBuild
|
|
160
|
+
overrideEsbuildOptions
|
|
194
161
|
}) {
|
|
195
|
-
await
|
|
162
|
+
await build({
|
|
196
163
|
entryPoints: {
|
|
197
164
|
entry: appEntryPath,
|
|
198
165
|
...nativeModuleEntryMap
|
|
@@ -210,49 +177,36 @@ async function buildEntry({
|
|
|
210
177
|
},
|
|
211
178
|
...overrideEsbuildOptions
|
|
212
179
|
});
|
|
213
|
-
await postBuild?.({
|
|
214
|
-
getPathFromEntryOutputDir(...paths) {
|
|
215
|
-
return (0, import_node_path.join)(entryOutputDirPath, ...paths);
|
|
216
|
-
},
|
|
217
|
-
existsAndCopyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
218
|
-
if ((0, import_node_fs2.existsSync)(from)) {
|
|
219
|
-
const target = (0, import_node_path.join)(entryOutputDirPath, to ?? (0, import_node_path.basename)(from));
|
|
220
|
-
if (!skipIfExist || !(0, import_node_fs2.existsSync)(target)) {
|
|
221
|
-
(0, import_node_fs2.cpSync)(from, target);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
180
|
}
|
|
227
181
|
|
|
228
182
|
// src/build-plugins/key.ts
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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";
|
|
232
186
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
233
|
-
const privateKeyDir =
|
|
234
|
-
if (!(
|
|
235
|
-
|
|
187
|
+
const privateKeyDir = dirname(privateKeyPath);
|
|
188
|
+
if (!existsSync3(privateKeyDir)) {
|
|
189
|
+
mkdirSync(privateKeyDir, { recursive: true });
|
|
236
190
|
}
|
|
237
|
-
const certDir =
|
|
238
|
-
if (!(
|
|
239
|
-
|
|
191
|
+
const certDir = dirname(certPath);
|
|
192
|
+
if (!existsSync3(certDir)) {
|
|
193
|
+
mkdirSync(certDir, { recursive: true });
|
|
240
194
|
}
|
|
241
|
-
const { cert, private: privateKey } =
|
|
195
|
+
const { cert, private: privateKey } = generate(subject, {
|
|
242
196
|
keySize: keyLength,
|
|
243
197
|
algorithm: "sha256",
|
|
244
198
|
days
|
|
245
199
|
});
|
|
246
|
-
(
|
|
247
|
-
(
|
|
200
|
+
writeFileSync3(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
201
|
+
writeFileSync3(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
248
202
|
}
|
|
249
|
-
var noCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}
|
|
250
|
-
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['"])/;
|
|
251
205
|
function writeCertToEntry(entryPath, cert) {
|
|
252
|
-
if (!(
|
|
206
|
+
if (!existsSync3(entryPath)) {
|
|
253
207
|
throw new Error(`entry not exist: ${entryPath}`);
|
|
254
208
|
}
|
|
255
|
-
const file = (
|
|
209
|
+
const file = readFileSync3(entryPath, "utf-8");
|
|
256
210
|
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join("\n + ");
|
|
257
211
|
let replaced = file;
|
|
258
212
|
if (noCertRegex.test(file)) {
|
|
@@ -262,7 +216,7 @@ function writeCertToEntry(entryPath, cert) {
|
|
|
262
216
|
} else {
|
|
263
217
|
throw new Error("no `SIGNATURE_CERT` found in entry");
|
|
264
218
|
}
|
|
265
|
-
(
|
|
219
|
+
writeFileSync3(entryPath, replaced);
|
|
266
220
|
}
|
|
267
221
|
function parseKeys({
|
|
268
222
|
keyLength,
|
|
@@ -272,14 +226,14 @@ function parseKeys({
|
|
|
272
226
|
subject,
|
|
273
227
|
days
|
|
274
228
|
}) {
|
|
275
|
-
const keysDir =
|
|
276
|
-
!(
|
|
277
|
-
if (!(
|
|
278
|
-
|
|
229
|
+
const keysDir = dirname(privateKeyPath);
|
|
230
|
+
!existsSync3(keysDir) && mkdirSync(keysDir);
|
|
231
|
+
if (!existsSync3(privateKeyPath) || !existsSync3(certPath)) {
|
|
232
|
+
log.warn("no key pair found, generate new key pair");
|
|
279
233
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
280
234
|
}
|
|
281
|
-
const privateKey = process.env.UPDATER_PK || (
|
|
282
|
-
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");
|
|
283
237
|
writeCertToEntry(appEntryPath, cert);
|
|
284
238
|
return { privateKey, cert };
|
|
285
239
|
}
|
|
@@ -288,17 +242,17 @@ function parseSubjects(subject) {
|
|
|
288
242
|
}
|
|
289
243
|
|
|
290
244
|
// src/build-plugins/option.ts
|
|
291
|
-
function parseOptions(
|
|
245
|
+
function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
292
246
|
const {
|
|
293
247
|
minimumVersion = "0.0.0",
|
|
294
248
|
entry: {
|
|
295
|
-
minify
|
|
296
|
-
sourcemap
|
|
249
|
+
minify: entryMinify,
|
|
250
|
+
sourcemap: entrySourcemap,
|
|
297
251
|
entryOutputDirPath = "dist-entry",
|
|
298
252
|
appEntryPath = "electron/entry.ts",
|
|
299
253
|
nativeModuleEntryMap = {},
|
|
300
254
|
postBuild,
|
|
301
|
-
overrideEsbuildOptions
|
|
255
|
+
overrideEsbuildOptions = {}
|
|
302
256
|
} = {},
|
|
303
257
|
paths: {
|
|
304
258
|
asarOutputPath = `release/${pkg.name}.asar`,
|
|
@@ -331,12 +285,11 @@ function parseOptions(isBuild, pkg, options = {}) {
|
|
|
331
285
|
rendererDistPath
|
|
332
286
|
};
|
|
333
287
|
const buildEntryOption = {
|
|
334
|
-
minify,
|
|
335
|
-
sourcemap,
|
|
288
|
+
minify: entryMinify ?? minify,
|
|
289
|
+
sourcemap: entrySourcemap ?? sourcemap,
|
|
336
290
|
entryOutputDirPath,
|
|
337
291
|
appEntryPath,
|
|
338
292
|
nativeModuleEntryMap,
|
|
339
|
-
postBuild,
|
|
340
293
|
overrideEsbuildOptions
|
|
341
294
|
};
|
|
342
295
|
const { privateKey, cert } = parseKeys({
|
|
@@ -357,44 +310,81 @@ function parseOptions(isBuild, pkg, options = {}) {
|
|
|
357
310
|
generateSignature,
|
|
358
311
|
generateVersionJson
|
|
359
312
|
};
|
|
360
|
-
return { buildAsarOption, buildEntryOption, buildVersionOption };
|
|
313
|
+
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild };
|
|
361
314
|
}
|
|
362
315
|
|
|
316
|
+
// src/constant.ts
|
|
317
|
+
var id = "electron-incremental-updater";
|
|
318
|
+
var bytecodeId = `${id}-bytecode`;
|
|
319
|
+
var loaderId = `${id}-loader`;
|
|
320
|
+
|
|
363
321
|
// src/vite.ts
|
|
364
322
|
function debugStartup(args) {
|
|
365
323
|
process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
|
|
366
324
|
}
|
|
367
|
-
|
|
368
|
-
|
|
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}]` });
|
|
369
335
|
function electronWithUpdater(options) {
|
|
370
|
-
|
|
336
|
+
let {
|
|
371
337
|
isBuild,
|
|
372
|
-
pkg,
|
|
338
|
+
pkg = resolvePackageJson(),
|
|
373
339
|
main: _main,
|
|
374
340
|
preload: _preload,
|
|
341
|
+
sourcemap,
|
|
342
|
+
minify,
|
|
375
343
|
updater,
|
|
376
344
|
useNotBundle = true,
|
|
377
345
|
logParsedOptions
|
|
378
346
|
} = options;
|
|
379
|
-
|
|
347
|
+
if (!pkg) {
|
|
348
|
+
log.error(`package.json not found`, { timestamp: true });
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
const _options = parseOptions(pkg, sourcemap, minify, updater);
|
|
380
352
|
try {
|
|
381
|
-
(
|
|
382
|
-
(
|
|
353
|
+
rmSync2(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
354
|
+
rmSync2(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
383
355
|
} catch (ignore) {
|
|
384
356
|
}
|
|
385
357
|
log.info(`remove old files`, { timestamp: true });
|
|
386
|
-
const { buildAsarOption, buildEntryOption, buildVersionOption } = _options;
|
|
358
|
+
const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild } = _options;
|
|
387
359
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
388
|
-
|
|
389
|
-
const _appPath = (
|
|
390
|
-
if (
|
|
391
|
-
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}"`);
|
|
392
364
|
}
|
|
393
|
-
let isInit = false;
|
|
394
365
|
const _buildEntry = async () => {
|
|
395
366
|
await buildEntry(buildEntryOption);
|
|
396
|
-
log.info(`build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
367
|
+
log.info(`vite build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
397
368
|
};
|
|
369
|
+
const _postBuild = postBuild ? async () => await postBuild({
|
|
370
|
+
getPathFromEntryOutputDir(...paths) {
|
|
371
|
+
return join2(entryOutputDirPath, ...paths);
|
|
372
|
+
},
|
|
373
|
+
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
374
|
+
if (existsSync4(from)) {
|
|
375
|
+
const target = join2(entryOutputDirPath, to ?? basename2(from));
|
|
376
|
+
if (!skipIfExist || !existsSync4(target)) {
|
|
377
|
+
try {
|
|
378
|
+
cpSync(from, target);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
log.warn(`copy failed: ${error}`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}) : async () => {
|
|
386
|
+
};
|
|
387
|
+
let isInit = false;
|
|
398
388
|
const electronPluginOptions = {
|
|
399
389
|
main: {
|
|
400
390
|
entry: _main.files,
|
|
@@ -402,15 +392,16 @@ function electronWithUpdater(options) {
|
|
|
402
392
|
if (!isInit) {
|
|
403
393
|
isInit = true;
|
|
404
394
|
await _buildEntry();
|
|
395
|
+
await _postBuild();
|
|
405
396
|
}
|
|
406
397
|
_main.onstart ? _main.onstart(args) : args.startup();
|
|
407
398
|
},
|
|
408
|
-
vite:
|
|
399
|
+
vite: mergeConfig(
|
|
409
400
|
{
|
|
410
|
-
plugins: !isBuild && useNotBundle ?
|
|
401
|
+
plugins: [!isBuild && useNotBundle ? notBundle() : void 0],
|
|
411
402
|
build: {
|
|
412
403
|
sourcemap,
|
|
413
|
-
minify
|
|
404
|
+
minify,
|
|
414
405
|
outDir: `${buildAsarOption.electronDistPath}/main`,
|
|
415
406
|
rollupOptions: {
|
|
416
407
|
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
@@ -423,7 +414,7 @@ function electronWithUpdater(options) {
|
|
|
423
414
|
preload: {
|
|
424
415
|
input: _preload.files,
|
|
425
416
|
onstart: _preload.onstart,
|
|
426
|
-
vite:
|
|
417
|
+
vite: mergeConfig(
|
|
427
418
|
{
|
|
428
419
|
plugins: [
|
|
429
420
|
{
|
|
@@ -434,6 +425,7 @@ function electronWithUpdater(options) {
|
|
|
434
425
|
},
|
|
435
426
|
async closeBundle() {
|
|
436
427
|
await _buildEntry();
|
|
428
|
+
await _postBuild();
|
|
437
429
|
await buildAsar(buildAsarOption);
|
|
438
430
|
log.info(`build asar to '${buildAsarOption.asarOutputPath}'`, { timestamp: true });
|
|
439
431
|
await buildVersion(buildVersionOption);
|
|
@@ -443,7 +435,7 @@ function electronWithUpdater(options) {
|
|
|
443
435
|
],
|
|
444
436
|
build: {
|
|
445
437
|
sourcemap: sourcemap ? "inline" : void 0,
|
|
446
|
-
minify
|
|
438
|
+
minify,
|
|
447
439
|
outDir: `${buildAsarOption.electronDistPath}/preload`,
|
|
448
440
|
rollupOptions: {
|
|
449
441
|
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
@@ -460,28 +452,35 @@ function electronWithUpdater(options) {
|
|
|
460
452
|
...electronPluginOptions,
|
|
461
453
|
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
462
454
|
},
|
|
463
|
-
(
|
|
455
|
+
(key, value) => key === "privateKey" || key === "cert" ? "***" : value,
|
|
464
456
|
2
|
|
465
457
|
),
|
|
466
458
|
{ timestamp: true }
|
|
467
459
|
);
|
|
468
460
|
let extraHmrPlugin;
|
|
469
461
|
if (nativeModuleEntryMap) {
|
|
470
|
-
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) =>
|
|
462
|
+
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath2(file)));
|
|
471
463
|
extraHmrPlugin = {
|
|
472
464
|
name: `${id}-dev`,
|
|
473
465
|
apply() {
|
|
474
466
|
return !isBuild;
|
|
475
467
|
},
|
|
476
468
|
configureServer: (server) => {
|
|
477
|
-
server.watcher.add(files).on(
|
|
469
|
+
server.watcher.add(files).on(
|
|
470
|
+
"change",
|
|
471
|
+
(p) => files.includes(p) && _buildEntry().then(async () => {
|
|
472
|
+
await startup.exit();
|
|
473
|
+
await _postBuild();
|
|
474
|
+
await startup();
|
|
475
|
+
})
|
|
476
|
+
);
|
|
478
477
|
}
|
|
479
478
|
};
|
|
480
479
|
}
|
|
481
|
-
return [(
|
|
480
|
+
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
482
481
|
}
|
|
483
|
-
|
|
484
|
-
0 && (module.exports = {
|
|
482
|
+
export {
|
|
485
483
|
debugStartup,
|
|
486
|
-
electronWithUpdater
|
|
487
|
-
|
|
484
|
+
electronWithUpdater,
|
|
485
|
+
log
|
|
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')
|