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.mjs
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
signature
|
|
3
|
-
} from "./chunk-GXZSAUBR.mjs";
|
|
4
|
-
import {
|
|
5
|
-
isUpdateJSON,
|
|
6
|
-
parseVersion,
|
|
7
|
-
zipFile
|
|
8
|
-
} from "./chunk-GB6VLKJZ.mjs";
|
|
9
|
-
|
|
10
|
-
// src/vite.ts
|
|
11
|
-
import { join as join2, resolve } from "node:path";
|
|
12
|
-
import { rmSync } from "node:fs";
|
|
13
|
-
import { createLogger, mergeConfig, normalizePath } from "vite";
|
|
14
|
-
import ElectronSimple from "vite-plugin-electron/simple";
|
|
15
|
-
import { startup } from "vite-plugin-electron";
|
|
16
|
-
import { notBundle } from "vite-plugin-electron/plugin";
|
|
17
|
-
|
|
18
|
-
// src/build-plugins/build.ts
|
|
19
|
-
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
20
|
-
import { cpSync, existsSync } from "node:fs";
|
|
21
|
-
import { basename, join } from "node:path";
|
|
22
|
-
import Asar from "@electron/asar";
|
|
23
|
-
import { build } from "esbuild";
|
|
24
|
-
async function buildAsar({
|
|
25
|
-
version,
|
|
26
|
-
asarOutputPath,
|
|
27
|
-
gzipPath,
|
|
28
|
-
electronDistPath,
|
|
29
|
-
rendererDistPath
|
|
30
|
-
}) {
|
|
31
|
-
await rename(rendererDistPath, join(electronDistPath, "renderer"));
|
|
32
|
-
await writeFile(join(electronDistPath, "version"), version);
|
|
33
|
-
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
34
|
-
await zipFile(asarOutputPath, gzipPath);
|
|
35
|
-
}
|
|
36
|
-
async function buildVersion({
|
|
37
|
-
gzipPath,
|
|
38
|
-
versionPath,
|
|
39
|
-
privateKey,
|
|
40
|
-
cert,
|
|
41
|
-
version,
|
|
42
|
-
minimumVersion,
|
|
43
|
-
generateSignature,
|
|
44
|
-
generateVersionJson
|
|
45
|
-
}) {
|
|
46
|
-
let _json = {
|
|
47
|
-
beta: {
|
|
48
|
-
minimumVersion: version,
|
|
49
|
-
signature: "",
|
|
50
|
-
size: 0,
|
|
51
|
-
version
|
|
52
|
-
},
|
|
53
|
-
minimumVersion: version,
|
|
54
|
-
signature: "",
|
|
55
|
-
size: 0,
|
|
56
|
-
version
|
|
57
|
-
};
|
|
58
|
-
if (existsSync(versionPath)) {
|
|
59
|
-
try {
|
|
60
|
-
const oldVersionJson = JSON.parse(await readFile(versionPath, "utf-8"));
|
|
61
|
-
if (isUpdateJSON(oldVersionJson)) {
|
|
62
|
-
_json = oldVersionJson;
|
|
63
|
-
} else {
|
|
64
|
-
console.warn("old version json is invalid, ignore it");
|
|
65
|
-
}
|
|
66
|
-
} catch (error) {
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const buffer = await readFile(gzipPath);
|
|
70
|
-
const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
|
|
71
|
-
if (generateVersionJson) {
|
|
72
|
-
_json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
|
|
73
|
-
if (!isUpdateJSON(_json)) {
|
|
74
|
-
throw new Error("invalid version info");
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
_json.beta = {
|
|
78
|
-
version,
|
|
79
|
-
minimumVersion,
|
|
80
|
-
signature: sig,
|
|
81
|
-
size: buffer.length
|
|
82
|
-
};
|
|
83
|
-
if (!parseVersion(version).stage) {
|
|
84
|
-
_json.version = version;
|
|
85
|
-
_json.minimumVersion = minimumVersion;
|
|
86
|
-
_json.signature = sig;
|
|
87
|
-
_json.size = buffer.length;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
await writeFile(versionPath, JSON.stringify(_json, null, 2));
|
|
91
|
-
}
|
|
92
|
-
async function buildEntry({
|
|
93
|
-
sourcemap,
|
|
94
|
-
minify,
|
|
95
|
-
appEntryPath,
|
|
96
|
-
entryOutputDirPath,
|
|
97
|
-
nativeModuleEntryMap,
|
|
98
|
-
overrideEsbuildOptions,
|
|
99
|
-
postBuild
|
|
100
|
-
}) {
|
|
101
|
-
await build({
|
|
102
|
-
entryPoints: {
|
|
103
|
-
entry: appEntryPath,
|
|
104
|
-
...nativeModuleEntryMap
|
|
105
|
-
},
|
|
106
|
-
bundle: true,
|
|
107
|
-
platform: "node",
|
|
108
|
-
outdir: entryOutputDirPath,
|
|
109
|
-
minify,
|
|
110
|
-
sourcemap,
|
|
111
|
-
entryNames: "[dir]/[name]",
|
|
112
|
-
assetNames: "[dir]/[name]",
|
|
113
|
-
external: ["electron", "original-fs"],
|
|
114
|
-
loader: {
|
|
115
|
-
".node": "empty"
|
|
116
|
-
},
|
|
117
|
-
...overrideEsbuildOptions
|
|
118
|
-
});
|
|
119
|
-
await postBuild?.({
|
|
120
|
-
getPathFromEntryOutputDir(...paths) {
|
|
121
|
-
return join(entryOutputDirPath, ...paths);
|
|
122
|
-
},
|
|
123
|
-
existsAndCopyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
124
|
-
if (existsSync(from)) {
|
|
125
|
-
const target = join(entryOutputDirPath, to ?? basename(from));
|
|
126
|
-
if (!skipIfExist || !existsSync(target)) {
|
|
127
|
-
cpSync(from, target);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/build-plugins/key.ts
|
|
135
|
-
import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
136
|
-
import { dirname } from "node:path";
|
|
137
|
-
import { generate } from "selfsigned";
|
|
138
|
-
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
139
|
-
const privateKeyDir = dirname(privateKeyPath);
|
|
140
|
-
if (!existsSync2(privateKeyDir)) {
|
|
141
|
-
mkdirSync(privateKeyDir, { recursive: true });
|
|
142
|
-
}
|
|
143
|
-
const certDir = dirname(certPath);
|
|
144
|
-
if (!existsSync2(certDir)) {
|
|
145
|
-
mkdirSync(certDir, { recursive: true });
|
|
146
|
-
}
|
|
147
|
-
const { cert, private: privateKey } = generate(subject, {
|
|
148
|
-
keySize: keyLength,
|
|
149
|
-
algorithm: "sha256",
|
|
150
|
-
days
|
|
151
|
-
});
|
|
152
|
-
writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
153
|
-
writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
154
|
-
}
|
|
155
|
-
var noCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
156
|
-
var existCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
157
|
-
function writeCertToEntry(entryPath, cert) {
|
|
158
|
-
if (!existsSync2(entryPath)) {
|
|
159
|
-
throw new Error(`entry not exist: ${entryPath}`);
|
|
160
|
-
}
|
|
161
|
-
const file = readFileSync(entryPath, "utf-8");
|
|
162
|
-
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join("\n + ");
|
|
163
|
-
let replaced = file;
|
|
164
|
-
if (noCertRegex.test(file)) {
|
|
165
|
-
replaced = file.replace(noCertRegex, replacement);
|
|
166
|
-
} else if (existCertRegex.test(file)) {
|
|
167
|
-
replaced = file.replace(existCertRegex, replacement);
|
|
168
|
-
} else {
|
|
169
|
-
throw new Error("no `SIGNATURE_CERT` found in entry");
|
|
170
|
-
}
|
|
171
|
-
writeFileSync(entryPath, replaced);
|
|
172
|
-
}
|
|
173
|
-
function parseKeys({
|
|
174
|
-
keyLength,
|
|
175
|
-
privateKeyPath,
|
|
176
|
-
certPath,
|
|
177
|
-
appEntryPath,
|
|
178
|
-
subject,
|
|
179
|
-
days
|
|
180
|
-
}) {
|
|
181
|
-
const keysDir = dirname(privateKeyPath);
|
|
182
|
-
!existsSync2(keysDir) && mkdirSync(keysDir);
|
|
183
|
-
if (!existsSync2(privateKeyPath) || !existsSync2(certPath)) {
|
|
184
|
-
console.warn("no key pair found, generate new key pair");
|
|
185
|
-
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
186
|
-
}
|
|
187
|
-
const privateKey = process.env.UPDATER_PK || readFileSync(privateKeyPath, "utf-8");
|
|
188
|
-
const cert = process.env.UPDATER_CERT || readFileSync(certPath, "utf-8");
|
|
189
|
-
writeCertToEntry(appEntryPath, cert);
|
|
190
|
-
return { privateKey, cert };
|
|
191
|
-
}
|
|
192
|
-
function parseSubjects(subject) {
|
|
193
|
-
return Object.entries(subject).filter(([_, value]) => !!value).map(([name, value]) => ({ name, value }));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// src/build-plugins/option.ts
|
|
197
|
-
function parseOptions(isBuild, pkg, options = {}) {
|
|
198
|
-
const {
|
|
199
|
-
minimumVersion = "0.0.0",
|
|
200
|
-
entry: {
|
|
201
|
-
minify = isBuild,
|
|
202
|
-
sourcemap = isBuild,
|
|
203
|
-
entryOutputDirPath = "dist-entry",
|
|
204
|
-
appEntryPath = "electron/entry.ts",
|
|
205
|
-
nativeModuleEntryMap = {},
|
|
206
|
-
postBuild,
|
|
207
|
-
overrideEsbuildOptions
|
|
208
|
-
} = {},
|
|
209
|
-
paths: {
|
|
210
|
-
asarOutputPath = `release/${pkg.name}.asar`,
|
|
211
|
-
gzipPath = `release/${pkg.name}-${pkg.version}.asar.gz`,
|
|
212
|
-
electronDistPath = "dist-electron",
|
|
213
|
-
rendererDistPath = "dist",
|
|
214
|
-
versionPath = "version.json"
|
|
215
|
-
} = {},
|
|
216
|
-
keys: {
|
|
217
|
-
privateKeyPath = "keys/private.pem",
|
|
218
|
-
certPath = "keys/cert.pem",
|
|
219
|
-
keyLength = 2048,
|
|
220
|
-
certInfo = {},
|
|
221
|
-
overrideGenerator = {}
|
|
222
|
-
} = {}
|
|
223
|
-
} = options;
|
|
224
|
-
const { generateSignature, generateVersionJson } = overrideGenerator;
|
|
225
|
-
let {
|
|
226
|
-
subject = {
|
|
227
|
-
commonName: pkg.name,
|
|
228
|
-
organizationName: `org.${pkg.name}`
|
|
229
|
-
},
|
|
230
|
-
days = 3650
|
|
231
|
-
} = certInfo;
|
|
232
|
-
const buildAsarOption = {
|
|
233
|
-
version: pkg.version,
|
|
234
|
-
asarOutputPath,
|
|
235
|
-
gzipPath,
|
|
236
|
-
electronDistPath,
|
|
237
|
-
rendererDistPath
|
|
238
|
-
};
|
|
239
|
-
const buildEntryOption = {
|
|
240
|
-
minify,
|
|
241
|
-
sourcemap,
|
|
242
|
-
entryOutputDirPath,
|
|
243
|
-
appEntryPath,
|
|
244
|
-
nativeModuleEntryMap,
|
|
245
|
-
postBuild,
|
|
246
|
-
overrideEsbuildOptions
|
|
247
|
-
};
|
|
248
|
-
const { privateKey, cert } = parseKeys({
|
|
249
|
-
keyLength,
|
|
250
|
-
privateKeyPath,
|
|
251
|
-
certPath,
|
|
252
|
-
appEntryPath,
|
|
253
|
-
subject,
|
|
254
|
-
days
|
|
255
|
-
});
|
|
256
|
-
const buildVersionOption = {
|
|
257
|
-
version: pkg.version,
|
|
258
|
-
minimumVersion,
|
|
259
|
-
gzipPath,
|
|
260
|
-
privateKey,
|
|
261
|
-
cert,
|
|
262
|
-
versionPath,
|
|
263
|
-
generateSignature,
|
|
264
|
-
generateVersionJson
|
|
265
|
-
};
|
|
266
|
-
return { buildAsarOption, buildEntryOption, buildVersionOption };
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// src/vite.ts
|
|
270
|
-
function debugStartup(args) {
|
|
271
|
-
process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
|
|
272
|
-
}
|
|
273
|
-
var id = "electron-incremental-updater";
|
|
274
|
-
var log = createLogger("info", { prefix: `[${id}]` });
|
|
275
|
-
function electronWithUpdater(options) {
|
|
276
|
-
const {
|
|
277
|
-
isBuild,
|
|
278
|
-
pkg,
|
|
279
|
-
main: _main,
|
|
280
|
-
preload: _preload,
|
|
281
|
-
updater,
|
|
282
|
-
useNotBundle = true,
|
|
283
|
-
logParsedOptions
|
|
284
|
-
} = options;
|
|
285
|
-
const _options = parseOptions(isBuild, pkg, updater);
|
|
286
|
-
try {
|
|
287
|
-
rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
288
|
-
rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
289
|
-
} catch (ignore) {
|
|
290
|
-
}
|
|
291
|
-
log.info(`remove old files`, { timestamp: true });
|
|
292
|
-
const { buildAsarOption, buildEntryOption, buildVersionOption } = _options;
|
|
293
|
-
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
294
|
-
const sourcemap = isBuild || !!process.env.VSCODE_DEBUG;
|
|
295
|
-
const _appPath = join2(entryOutputDirPath, "entry.js");
|
|
296
|
-
if (resolve(normalizePath(pkg.main)) !== resolve(normalizePath(_appPath))) {
|
|
297
|
-
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${normalizePath(_appPath)}"`);
|
|
298
|
-
}
|
|
299
|
-
let isInit = false;
|
|
300
|
-
const _buildEntry = async () => {
|
|
301
|
-
await buildEntry(buildEntryOption);
|
|
302
|
-
log.info(`build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
303
|
-
};
|
|
304
|
-
const electronPluginOptions = {
|
|
305
|
-
main: {
|
|
306
|
-
entry: _main.files,
|
|
307
|
-
onstart: async (args) => {
|
|
308
|
-
if (!isInit) {
|
|
309
|
-
isInit = true;
|
|
310
|
-
await _buildEntry();
|
|
311
|
-
}
|
|
312
|
-
_main.onstart ? _main.onstart(args) : args.startup();
|
|
313
|
-
},
|
|
314
|
-
vite: mergeConfig(
|
|
315
|
-
{
|
|
316
|
-
plugins: !isBuild && useNotBundle ? [notBundle()] : void 0,
|
|
317
|
-
build: {
|
|
318
|
-
sourcemap,
|
|
319
|
-
minify: isBuild,
|
|
320
|
-
outDir: `${buildAsarOption.electronDistPath}/main`,
|
|
321
|
-
rollupOptions: {
|
|
322
|
-
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
_main.vite ?? {}
|
|
327
|
-
)
|
|
328
|
-
},
|
|
329
|
-
preload: {
|
|
330
|
-
input: _preload.files,
|
|
331
|
-
onstart: _preload.onstart,
|
|
332
|
-
vite: mergeConfig(
|
|
333
|
-
{
|
|
334
|
-
plugins: [
|
|
335
|
-
{
|
|
336
|
-
name: `${id}-build`,
|
|
337
|
-
enforce: "post",
|
|
338
|
-
apply() {
|
|
339
|
-
return isBuild;
|
|
340
|
-
},
|
|
341
|
-
async closeBundle() {
|
|
342
|
-
await _buildEntry();
|
|
343
|
-
await buildAsar(buildAsarOption);
|
|
344
|
-
log.info(`build asar to '${buildAsarOption.asarOutputPath}'`, { timestamp: true });
|
|
345
|
-
await buildVersion(buildVersionOption);
|
|
346
|
-
log.info(`build version info to '${buildVersionOption.versionPath}'`, { timestamp: true });
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
],
|
|
350
|
-
build: {
|
|
351
|
-
sourcemap: sourcemap ? "inline" : void 0,
|
|
352
|
-
minify: isBuild,
|
|
353
|
-
outDir: `${buildAsarOption.electronDistPath}/preload`,
|
|
354
|
-
rollupOptions: {
|
|
355
|
-
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
},
|
|
359
|
-
_preload.vite ?? {}
|
|
360
|
-
)
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
logParsedOptions && log.info(
|
|
364
|
-
JSON.stringify(
|
|
365
|
-
{
|
|
366
|
-
...electronPluginOptions,
|
|
367
|
-
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
368
|
-
},
|
|
369
|
-
(key, value) => key === "privateKey" || key === "cert" ? "***" : value,
|
|
370
|
-
2
|
|
371
|
-
),
|
|
372
|
-
{ timestamp: true }
|
|
373
|
-
);
|
|
374
|
-
let extraHmrPlugin;
|
|
375
|
-
if (nativeModuleEntryMap) {
|
|
376
|
-
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath(file)));
|
|
377
|
-
extraHmrPlugin = {
|
|
378
|
-
name: `${id}-dev`,
|
|
379
|
-
apply() {
|
|
380
|
-
return !isBuild;
|
|
381
|
-
},
|
|
382
|
-
configureServer: (server) => {
|
|
383
|
-
server.watcher.add(files).on("change", (p) => files.includes(p) && _buildEntry().then(() => startup()));
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
388
|
-
}
|
|
389
|
-
export {
|
|
390
|
-
debugStartup,
|
|
391
|
-
electronWithUpdater
|
|
392
|
-
};
|
|
File without changes
|
|
File without changes
|