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.
@@ -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
- };
@@ -1,36 +0,0 @@
1
- // src/crypto.ts
2
- import { createCipheriv, createDecipheriv, createHash, createPrivateKey, createSign, createVerify } from "node:crypto";
3
- function encrypt(plainText, key2, iv) {
4
- const cipher = createCipheriv("aes-256-cbc", key2, iv);
5
- let encrypted = cipher.update(plainText, "utf8", "base64url");
6
- encrypted += cipher.final("base64url");
7
- return encrypted;
8
- }
9
- function decrypt(encryptedText, key2, iv) {
10
- const decipher = createDecipheriv("aes-256-cbc", key2, iv);
11
- let decrypted = decipher.update(encryptedText, "base64url", "utf8");
12
- decrypted += decipher.final("utf8");
13
- return decrypted;
14
- }
15
- function key(data, length) {
16
- const hash = createHash("SHA256").update(data).digest("binary");
17
- return Buffer.from(hash).subarray(0, length);
18
- }
19
- var signature = (buffer, privateKey, cert, version) => {
20
- const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
21
- return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
22
- };
23
- var verify = (buffer, signature2, cert) => {
24
- try {
25
- const [sig, version] = decrypt(signature2, key(cert, 32), key(buffer, 16)).split("%");
26
- const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
27
- return result ? version : false;
28
- } catch (error) {
29
- return false;
30
- }
31
- };
32
-
33
- export {
34
- signature,
35
- verify
36
- };
package/dist/utils.mjs DELETED
@@ -1,40 +0,0 @@
1
- import {
2
- disableHWAccForWin7,
3
- getPathFromAppNameAsar,
4
- getPaths,
5
- getVersions,
6
- is,
7
- loadNativeModuleFromEntry,
8
- restartApp,
9
- setAppUserModelId,
10
- setPortableAppDataPath,
11
- singleInstance,
12
- waitAppReady
13
- } from "./chunk-OUZLSVQC.mjs";
14
- import {
15
- handleUnexpectedErrors,
16
- isUpdateJSON,
17
- parseGithubCdnURL,
18
- parseVersion,
19
- unzipFile,
20
- zipFile
21
- } from "./chunk-GB6VLKJZ.mjs";
22
- export {
23
- disableHWAccForWin7,
24
- getPathFromAppNameAsar,
25
- getPaths,
26
- getVersions,
27
- handleUnexpectedErrors,
28
- is,
29
- isUpdateJSON,
30
- loadNativeModuleFromEntry,
31
- parseGithubCdnURL,
32
- parseVersion,
33
- restartApp,
34
- setAppUserModelId,
35
- setPortableAppDataPath,
36
- singleInstance,
37
- unzipFile,
38
- waitAppReady,
39
- zipFile
40
- };
package/dist/vite.d.mts DELETED
@@ -1,326 +0,0 @@
1
- import { Plugin } from 'vite';
2
- import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
3
- import { Promisable, Prettify } from '@subframe7536/type-utils';
4
- import { BuildOptions } from 'esbuild';
5
- import { a as UpdateJSON } from './noDep-TvZoKVF8.mjs';
6
-
7
- type PKG = {
8
- name: string;
9
- version: string;
10
- main: string;
11
- };
12
- type DistinguishedName = {
13
- countryName?: string;
14
- stateOrProvinceName?: string;
15
- localityName?: string;
16
- organizationName?: string;
17
- organizationalUnitName?: string;
18
- commonName?: string;
19
- serialNumber?: string;
20
- title?: string;
21
- description?: string;
22
- businessCategory?: string;
23
- emailAddress?: string;
24
- };
25
- type BuildEntryOption = {
26
- /**
27
- * whether to minify
28
- * @default isBuild
29
- */
30
- minify: boolean;
31
- /**
32
- * Whether to generate sourcemap
33
- * @default isBuild
34
- */
35
- sourcemap: boolean;
36
- /**
37
- * path to app entry output file
38
- * @default 'dist-entry'
39
- */
40
- entryOutputDirPath: string;
41
- /**
42
- * path to app entry file
43
- * @default 'electron/entry.ts'
44
- */
45
- appEntryPath: string;
46
- /**
47
- * esbuild path map of native modules in entry directory
48
- *
49
- * @default {}
50
- * @example
51
- * { db: './electron/native/db.ts' }
52
- */
53
- nativeModuleEntryMap?: Record<string, string>;
54
- /**
55
- * custom options for esbuild
56
- * ```ts
57
- * // default options
58
- * const options = {
59
- * entryPoints: {
60
- * entry: appEntryPath,
61
- * ...moduleEntryMap,
62
- * },
63
- * bundle: true,
64
- * platform: 'node',
65
- * outdir: entryOutputDirPath,
66
- * minify,
67
- * sourcemap,
68
- * entryNames: '[dir]/[name]',
69
- * assetNames: '[dir]/[name]',
70
- * external: ['electron', 'original-fs'],
71
- * loader: {
72
- * '.node': 'empty',
73
- * },
74
- * }
75
- * ```
76
- */
77
- overrideEsbuildOptions?: BuildOptions;
78
- /**
79
- * resolve extra files, such as `.node`
80
- */
81
- postBuild?: (args: {
82
- /**
83
- * get path from `entryOutputDirPath`
84
- */
85
- getPathFromEntryOutputDir: (...paths: string[]) => string;
86
- /**
87
- * copy file to `entryOutputDirPath`
88
- *
89
- * if `to` absent, set to `basename(from)`
90
- *
91
- * if `skipIfExist` absent, skip copy if `to` exist
92
- */
93
- existsAndCopyToEntryOutputDir: (options: {
94
- from: string;
95
- to?: string;
96
- /**
97
- * skip copy if `to` exist
98
- * @default true
99
- */
100
- skipIfExist?: boolean;
101
- }) => void;
102
- }) => Promisable<void>;
103
- };
104
- type GeneratorOverrideFunctions = {
105
- /**
106
- * custom signature generate function
107
- * @param buffer file buffer
108
- * @param privateKey private key
109
- * @param cert certificate string, **EOL must be '\n'**
110
- * @param version current version
111
- */
112
- generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
113
- /**
114
- * custom generate version json function
115
- * @param existingJson The existing JSON object.
116
- * @param buffer file buffer
117
- * @param signature generated signature
118
- * @param version current version
119
- * @param minVersion The minimum version
120
- * @returns The updated version json
121
- */
122
- generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
123
- };
124
- type ElectronUpdaterOptions = {
125
- /**
126
- * mini version of entry
127
- * @default '0.0.0'
128
- */
129
- minimumVersion?: string;
130
- /**
131
- * config for entry (app.asar)
132
- */
133
- entry?: Partial<BuildEntryOption>;
134
- /**
135
- * paths config
136
- */
137
- paths?: {
138
- /**
139
- * Path to asar file
140
- * @default `release/${app.name}.asar`
141
- */
142
- asarOutputPath?: string;
143
- /**
144
- * Path to version info output, content is {@link UpdateJSON}
145
- * @default `version.json`
146
- */
147
- versionPath?: string;
148
- /**
149
- * Path to gzipped asar file
150
- * @default `release/${app.name}-${version}.asar.gz`
151
- */
152
- gzipPath?: string;
153
- /**
154
- * Path to electron build output
155
- * @default `dist-electron`
156
- */
157
- electronDistPath?: string;
158
- /**
159
- * Path to renderer build output
160
- * @default `dist`
161
- */
162
- rendererDistPath?: string;
163
- };
164
- /**
165
- * signature config
166
- */
167
- keys?: {
168
- /**
169
- * path to the pem file that contains private key
170
- * if not ended with .pem, it will be appended
171
- *
172
- * **if `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
173
- * @default 'keys/private.pem'
174
- */
175
- privateKeyPath?: string;
176
- /**
177
- * path to the pem file that contains public key
178
- * if not ended with .pem, it will be appended
179
- *
180
- * **if `UPDATER_CERT` is set, will read it instead of read from `certPath`**
181
- * @default 'keys/cert.pem'
182
- */
183
- certPath?: string;
184
- /**
185
- * length of the key
186
- * @default 2048
187
- */
188
- keyLength?: number;
189
- /**
190
- * X509 certificate info
191
- *
192
- * only generate simple **self-signed** certificate **without extensions**
193
- */
194
- certInfo?: {
195
- /**
196
- * the subject of the certificate
197
- *
198
- * @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
199
- */
200
- subject?: DistinguishedName;
201
- /**
202
- * expire days of the certificate
203
- *
204
- * @default 3650
205
- */
206
- days?: number;
207
- };
208
- overrideGenerator?: GeneratorOverrideFunctions;
209
- };
210
- };
211
-
212
- type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
213
- [P in K]-?: T[P];
214
- };
215
- type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
216
- [P in NewKey]: T[Key];
217
- };
218
- type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
219
- /**
220
- * startup function for debug (see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template})
221
- * @example
222
- * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
223
- * const options = buildElectronPluginOptions({
224
- * // ...
225
- * main: {
226
- * // ...
227
- * startup: debugStartup
228
- * },
229
- * })
230
- */
231
- declare function debugStartup(args: {
232
- startup: (argv?: string[]) => Promise<void>;
233
- reload: () => void;
234
- }): void;
235
- type ElectronWithUpdaterOptions = {
236
- /**
237
- * whether is in build mode
238
- * ```ts
239
- * export default defineConfig(({ command }) => {
240
- * const isBuild = command === 'build'
241
- * })
242
- * ```
243
- */
244
- isBuild: boolean;
245
- /**
246
- * name, version and main in `package.json`
247
- * ```ts
248
- * import pkg from './package.json'
249
- * ```
250
- */
251
- pkg: PKG;
252
- /**
253
- * main options
254
- */
255
- main: Prettify<MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'>>;
256
- /**
257
- * preload options
258
- */
259
- preload: Prettify<MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'>>;
260
- /**
261
- * updater options
262
- */
263
- updater?: ElectronUpdaterOptions;
264
- /**
265
- * use NotBundle() plugin in main
266
- * @default true
267
- */
268
- useNotBundle?: boolean;
269
- /**
270
- * Whether to log parsed options
271
- */
272
- logParsedOptions?: boolean;
273
- };
274
- /**
275
- * build options for `vite-plugin-electron/simple`
276
- * - integrate with updater
277
- * - only contains `main` and `preload` configs
278
- * - remove old electron files
279
- * - externalize dependencies
280
- * - auto restart when entry file changes
281
- * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
282
- * - no `vite-plugin-electron-renderer` config
283
- *
284
- * you can override all the configs
285
- *
286
- * **Limitation**: entry file change cannot trigger auto restart
287
- *
288
- * @example
289
- * import { defineConfig } from 'vite'
290
- * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
291
- * import pkg from './package.json'
292
- *
293
- * export default defineConfig(async ({ command }) => {
294
- * const isBuild = command === 'build'
295
- * return {
296
- * plugins: [
297
- * electronWithUpdater({
298
- * pkg,
299
- * isBuild,
300
- * logParsedOptions: true,
301
- * main: {
302
- * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
303
- * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
304
- * onstart: debugStartup,
305
- * },
306
- * preload: {
307
- * files: './electron/preload/index.ts',
308
- * },
309
- * updater: {
310
- * // options
311
- * }
312
- * }),
313
- * ],
314
- * server: process.env.VSCODE_DEBUG && (() => {
315
- * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
316
- * return {
317
- * host: url.hostname,
318
- * port: +url.port,
319
- * }
320
- * })(),
321
- * }
322
- * })
323
- */
324
- declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[];
325
-
326
- export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };