electron-incremental-update 2.0.0-beta.6 → 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.
@@ -0,0 +1,80 @@
1
+ import { BrowserWindow } from 'electron';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-DPF5IFkK.js';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './types-CItP6bL-.js';
4
+ import { U as Updater } from './core-DJdvtwvU.js';
5
+ import '@subframe7536/type-utils';
6
+ import 'node:events';
7
+
8
+ /**
9
+ * compile time dev check
10
+ */
11
+ declare const isDev: boolean;
12
+ declare const isWin: boolean;
13
+ declare const isMac: boolean;
14
+ declare const isLinux: boolean;
15
+ /**
16
+ * get the absolute path of `${electron.app.name}.asar` (not `app.asar`)
17
+ *
18
+ * if is in dev, **always** return `'DEV.asar'`
19
+ */
20
+ declare function getPathFromAppNameAsar(...paths: string[]): string;
21
+ /**
22
+ * get app version, if is in dev, return `getEntryVersion()`
23
+ */
24
+ declare function getAppVersion(): string;
25
+ /**
26
+ * get entry version
27
+ */
28
+ declare function getEntryVersion(): string;
29
+ /**
30
+ * use `require` to load native module from entry
31
+ * @param moduleName file name in entry
32
+ */
33
+ declare function requireNative<T = any>(moduleName: string): T;
34
+ /**
35
+ * Restarts the Electron app.
36
+ */
37
+ declare function restartApp(): void;
38
+ /**
39
+ * fix app use model id, only for Windows
40
+ * @param id app id, default is `org.${electron.app.name}`
41
+ */
42
+ declare function setAppUserModelId(id?: string): void;
43
+ /**
44
+ * disable hardware acceleration for Windows 7
45
+ */
46
+ declare function disableHWAccForWin7(): void;
47
+ /**
48
+ * keep single electron instance and auto restore window on `second-instance` event
49
+ * @param window brwoser window to show
50
+ * @returns `false` if the app is running
51
+ */
52
+ declare function singleInstance(window?: BrowserWindow): boolean;
53
+ /**
54
+ * set `AppData` dir to the dir of .exe file
55
+ *
56
+ * useful for portable Windows app
57
+ * @param dirName dir name, default to `data`
58
+ */
59
+ declare function setPortableAppDataPath(dirName?: string): void;
60
+ /**
61
+ * load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
62
+ * @param win window
63
+ * @param htmlFilePath html file path, default is `index.html`
64
+ */
65
+ declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
66
+ declare function getPathFromPreload(...paths: string[]): string;
67
+ declare function getPathFromPublic(...paths: string[]): string;
68
+ declare function getPathFromEntryAsar(...paths: string[]): string;
69
+ /**
70
+ * handle all unhandled error
71
+ * @param callback callback function
72
+ */
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
+
75
+ /**
76
+ * auto check update, download and install
77
+ */
78
+ declare function autoUpdate(updater: Updater): Promise<void>;
79
+
80
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.js CHANGED
@@ -1,7 +1,6 @@
1
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-DFNDKSE6.js';
2
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-N77WQ5WB.js';
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
- export { isCI } from 'ci-info';
5
4
 
6
5
  // src/utils/updater.ts
7
6
  async function autoUpdate(updater) {
package/dist/vite.d.ts ADDED
@@ -0,0 +1,405 @@
1
+ import { PluginOption } from 'vite';
2
+ import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
3
+ import { Promisable } from '@subframe7536/type-utils';
4
+ import { BuildOptions } from 'esbuild';
5
+ export { isCI } from 'ci-info';
6
+
7
+ /**
8
+ * update info json
9
+ */
10
+ type UpdateInfo = {
11
+ signature: string;
12
+ minimumVersion: string;
13
+ version: string;
14
+ };
15
+ /**
16
+ * {@link UpdateInfo} with beta
17
+ */
18
+ type UpdateJSON = UpdateInfo & {
19
+ beta: UpdateInfo;
20
+ };
21
+
22
+ interface PKG {
23
+ name: string;
24
+ version: string;
25
+ main: string;
26
+ }
27
+ interface DistinguishedName {
28
+ countryName?: string;
29
+ stateOrProvinceName?: string;
30
+ localityName?: string;
31
+ organizationName?: string;
32
+ organizationalUnitName?: string;
33
+ commonName?: string;
34
+ serialNumber?: string;
35
+ title?: string;
36
+ description?: string;
37
+ businessCategory?: string;
38
+ emailAddress?: string;
39
+ }
40
+ interface BuildEntryOption {
41
+ /**
42
+ * whether to minify
43
+ * @default isBuild
44
+ */
45
+ minify?: boolean;
46
+ /**
47
+ * whether to generate sourcemap
48
+ * @default isBuild
49
+ */
50
+ sourcemap?: boolean;
51
+ /**
52
+ * path to app entry output file
53
+ * @default 'dist-entry'
54
+ */
55
+ entryOutputDirPath?: string;
56
+ /**
57
+ * path to app entry file
58
+ * @default 'electron/entry.ts'
59
+ */
60
+ appEntryPath?: string;
61
+ /**
62
+ * esbuild path map of native modules in entry directory
63
+ *
64
+ * @default {}
65
+ * @example
66
+ * { db: './electron/native/db.ts' }
67
+ */
68
+ nativeModuleEntryMap?: Record<string, string>;
69
+ /**
70
+ * custom options for esbuild
71
+ * ```ts
72
+ * // default options
73
+ * const options = {
74
+ * entryPoints: {
75
+ * entry: appEntryPath,
76
+ * ...moduleEntryMap,
77
+ * },
78
+ * bundle: true,
79
+ * platform: 'node',
80
+ * outdir: entryOutputDirPath,
81
+ * minify,
82
+ * sourcemap,
83
+ * entryNames: '[dir]/[name]',
84
+ * assetNames: '[dir]/[name]',
85
+ * external: ['electron', 'original-fs'],
86
+ * loader: {
87
+ * '.node': 'empty',
88
+ * },
89
+ * define: {
90
+ * __SIGNATURE_CERT__: JSON.stringify(cert),
91
+ * },
92
+ * }
93
+ * ```
94
+ */
95
+ overrideEsbuildOptions?: BuildOptions;
96
+ /**
97
+ * resolve extra files on startup, such as `.node`
98
+ * @remark won't trigger will reload
99
+ */
100
+ postBuild?: (args: {
101
+ /**
102
+ * get path from `entryOutputDirPath`
103
+ */
104
+ getPathFromEntryOutputDir: (...paths: string[]) => string;
105
+ /**
106
+ * check exist and copy file to `entryOutputDirPath`
107
+ *
108
+ * if `to` absent, set to `basename(from)`
109
+ *
110
+ * if `skipIfExist` absent, skip copy if `to` exist
111
+ */
112
+ copyToEntryOutputDir: (options: {
113
+ from: string;
114
+ to?: string;
115
+ /**
116
+ * skip copy if `to` exist
117
+ * @default true
118
+ */
119
+ skipIfExist?: boolean;
120
+ }) => void;
121
+ }) => Promisable<void>;
122
+ }
123
+ interface GeneratorOverrideFunctions {
124
+ /**
125
+ * custom signature generate function
126
+ * @param buffer file buffer
127
+ * @param privateKey private key
128
+ * @param cert certificate string, **EOL must be '\n'**
129
+ * @param version current version
130
+ */
131
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
132
+ /**
133
+ * custom generate version json function
134
+ * @param existingJson The existing JSON object.
135
+ * @param buffer file buffer
136
+ * @param signature generated signature
137
+ * @param version current version
138
+ * @param minVersion The minimum version
139
+ * @returns The updated version json
140
+ */
141
+ generateVersionJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
142
+ /**
143
+ * custom generate zip file buffer
144
+ * @param buffer source buffer
145
+ */
146
+ generateGzipFile?: (buffer: Buffer) => Promise<Buffer>;
147
+ }
148
+ interface ElectronUpdaterOptions {
149
+ /**
150
+ * mini version of entry
151
+ * @default '0.0.0'
152
+ */
153
+ minimumVersion?: string;
154
+ /**
155
+ * config for entry (app.asar)
156
+ */
157
+ entry?: BuildEntryOption;
158
+ /**
159
+ * paths config
160
+ */
161
+ paths?: {
162
+ /**
163
+ * Path to asar file
164
+ * @default `release/${app.name}.asar`
165
+ */
166
+ asarOutputPath?: string;
167
+ /**
168
+ * Path to version info output, content is {@link UpdateJSON}
169
+ * @default `version.json`
170
+ */
171
+ versionPath?: string;
172
+ /**
173
+ * Path to gzipped asar file
174
+ * @default `release/${app.name}-${version}.asar.gz`
175
+ */
176
+ gzipPath?: string;
177
+ /**
178
+ * Path to electron build output
179
+ * @default `dist-electron`
180
+ */
181
+ electronDistPath?: string;
182
+ /**
183
+ * Path to renderer build output
184
+ * @default `dist`
185
+ */
186
+ rendererDistPath?: string;
187
+ };
188
+ /**
189
+ * signature config
190
+ */
191
+ keys?: {
192
+ /**
193
+ * path to the pem file that contains private key
194
+ * if not ended with .pem, it will be appended
195
+ *
196
+ * **if `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
197
+ * @default 'keys/private.pem'
198
+ */
199
+ privateKeyPath?: string;
200
+ /**
201
+ * path to the pem file that contains public key
202
+ * if not ended with .pem, it will be appended
203
+ *
204
+ * **if `UPDATER_CERT` is set, will read it instead of read from `certPath`**
205
+ * @default 'keys/cert.pem'
206
+ */
207
+ certPath?: string;
208
+ /**
209
+ * length of the key
210
+ * @default 2048
211
+ */
212
+ keyLength?: number;
213
+ /**
214
+ * X509 certificate info
215
+ *
216
+ * only generate simple **self-signed** certificate **without extensions**
217
+ */
218
+ certInfo?: {
219
+ /**
220
+ * the subject of the certificate
221
+ *
222
+ * @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
223
+ */
224
+ subject?: DistinguishedName;
225
+ /**
226
+ * expire days of the certificate
227
+ *
228
+ * @default 3650
229
+ */
230
+ days?: number;
231
+ };
232
+ };
233
+ overrideGenerator?: GeneratorOverrideFunctions;
234
+ }
235
+
236
+ interface BytecodeOptions {
237
+ enable: boolean;
238
+ /**
239
+ * Remember to set `sandbox: false` when creating window
240
+ */
241
+ preload?: boolean;
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
246
+ */
247
+ beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined>;
248
+ }
249
+
250
+ type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
251
+ [P in K]-?: T[P];
252
+ };
253
+ type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
254
+ [P in NewKey]: T[Key];
255
+ };
256
+ type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
257
+ /**
258
+ * startup function for debug (see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template})
259
+ * @example
260
+ * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
261
+ * const options = buildElectronPluginOptions({
262
+ * // ...
263
+ * main: {
264
+ * // ...
265
+ * startup: debugStartup
266
+ * },
267
+ * })
268
+ */
269
+ declare function debugStartup(args: {
270
+ startup: (argv?: string[]) => Promise<void>;
271
+ reload: () => void;
272
+ }): void;
273
+ type ExcludeOutputDirOptions = {
274
+ vite?: {
275
+ build?: {
276
+ outDir: never;
277
+ rollupOptions?: {
278
+ output?: {
279
+ dir: never;
280
+ };
281
+ };
282
+ };
283
+ };
284
+ };
285
+ interface ElectronWithUpdaterOptions {
286
+ /**
287
+ * whether is in build mode
288
+ * ```ts
289
+ * export default defineConfig(({ command }) => {
290
+ * const isBuild = command === 'build'
291
+ * })
292
+ * ```
293
+ */
294
+ isBuild: boolean;
295
+ /**
296
+ * manually setup package.json, read name, version and main
297
+ * ```ts
298
+ * import pkg from './package.json'
299
+ * ```
300
+ */
301
+ pkg?: PKG;
302
+ /**
303
+ * whether to generate sourcemap
304
+ * @default !isBuild
305
+ */
306
+ sourcemap?: boolean;
307
+ /**
308
+ * whether to minify the code
309
+ * @default isBuild
310
+ */
311
+ minify?: boolean;
312
+ /**
313
+ * whether to generate bytecode
314
+ *
315
+ * **only support commonjs**
316
+ *
317
+ * only main process by default, if you want to use in preload script, please use `electronWithUpdater({ bytecode: { enablePreload: true } })` and set `sandbox: false` when creating window
318
+ */
319
+ bytecode?: boolean | BytecodeOptions;
320
+ /**
321
+ * use NotBundle() plugin in main
322
+ * @default true
323
+ */
324
+ useNotBundle?: boolean;
325
+ /**
326
+ * whether to generate version json
327
+ * @default isCI
328
+ */
329
+ buildVersionJson?: boolean;
330
+ /**
331
+ * Whether to log parsed options
332
+ *
333
+ * to show certificate and private keys, set `logParsedOptions: { showKeys: true }`
334
+ */
335
+ logParsedOptions?: boolean | {
336
+ showKeys: boolean;
337
+ };
338
+ /**
339
+ * main process options
340
+ *
341
+ * to change output directories, use `options.updater.paths.electronDistPath` instead
342
+ */
343
+ main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
344
+ /**
345
+ * preload process options
346
+ *
347
+ * to change output directories, use `options.updater.paths.electronDistPath` instead
348
+ */
349
+ preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
350
+ /**
351
+ * updater options
352
+ */
353
+ updater?: ElectronUpdaterOptions;
354
+ }
355
+ /**
356
+ * build options for `vite-plugin-electron/simple`
357
+ * - integrate with updater
358
+ * - only contains `main` and `preload` configs
359
+ * - remove old electron files
360
+ * - externalize dependencies
361
+ * - auto restart when entry file changes
362
+ * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
363
+ * - no `vite-plugin-electron-renderer` config
364
+ *
365
+ * you can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
366
+ *
367
+ * @example
368
+ * import { defineConfig } from 'vite'
369
+ * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
370
+ * import pkg from './package.json'
371
+ *
372
+ * export default defineConfig(async ({ command }) => {
373
+ * const isBuild = command === 'build'
374
+ * return {
375
+ * plugins: [
376
+ * electronWithUpdater({
377
+ * pkg,
378
+ * isBuild,
379
+ * logParsedOptions: true,
380
+ * main: {
381
+ * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
382
+ * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
383
+ * onstart: debugStartup,
384
+ * },
385
+ * preload: {
386
+ * files: './electron/preload/index.ts',
387
+ * },
388
+ * updater: {
389
+ * // options
390
+ * }
391
+ * }),
392
+ * ],
393
+ * server: process.env.VSCODE_DEBUG && (() => {
394
+ * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
395
+ * return {
396
+ * host: url.hostname,
397
+ * port: +url.port,
398
+ * }
399
+ * })(),
400
+ * }
401
+ * })
402
+ */
403
+ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
404
+
405
+ export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };