electron-incremental-update 2.0.0-beta.2 → 2.0.0-beta.4

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/dist/vite.d.ts ADDED
@@ -0,0 +1,397 @@
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
+
6
+ /**
7
+ * update info json
8
+ */
9
+ type UpdateInfo = {
10
+ signature: string;
11
+ minimumVersion: string;
12
+ version: string;
13
+ size: number;
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, buffer: Buffer, 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
+ /**
238
+ * strings that should be transformed
239
+ */
240
+ protectedStrings?: string[];
241
+ /**
242
+ * Remember to set `sandbox: false` when creating window
243
+ */
244
+ enablePreload?: boolean;
245
+ }
246
+
247
+ type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
248
+ [P in K]-?: T[P];
249
+ };
250
+ type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
251
+ [P in NewKey]: T[Key];
252
+ };
253
+ type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
254
+ /**
255
+ * startup function for debug (see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template})
256
+ * @example
257
+ * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
258
+ * const options = buildElectronPluginOptions({
259
+ * // ...
260
+ * main: {
261
+ * // ...
262
+ * startup: debugStartup
263
+ * },
264
+ * })
265
+ */
266
+ declare function debugStartup(args: {
267
+ startup: (argv?: string[]) => Promise<void>;
268
+ reload: () => void;
269
+ }): void;
270
+ type ExcludeOutputDirOptions = {
271
+ vite?: {
272
+ build?: {
273
+ outDir: never;
274
+ rollupOptions?: {
275
+ output?: {
276
+ dir: never;
277
+ };
278
+ };
279
+ };
280
+ };
281
+ };
282
+ interface ElectronWithUpdaterOptions {
283
+ /**
284
+ * whether is in build mode
285
+ * ```ts
286
+ * export default defineConfig(({ command }) => {
287
+ * const isBuild = command === 'build'
288
+ * })
289
+ * ```
290
+ */
291
+ isBuild: boolean;
292
+ /**
293
+ * manually setup package.json, read name, version and main
294
+ * ```ts
295
+ * import pkg from './package.json'
296
+ * ```
297
+ */
298
+ pkg?: PKG;
299
+ /**
300
+ * whether to generate sourcemap
301
+ * @default !isBuild
302
+ */
303
+ sourcemap?: boolean;
304
+ /**
305
+ * whether to minify the code
306
+ * @default isBuild
307
+ */
308
+ minify?: boolean;
309
+ /**
310
+ * whether to generate bytecode
311
+ *
312
+ * **only support commonjs**
313
+ *
314
+ * 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
315
+ */
316
+ bytecode?: boolean | BytecodeOptions;
317
+ /**
318
+ * use NotBundle() plugin in main
319
+ * @default true
320
+ */
321
+ useNotBundle?: boolean;
322
+ /**
323
+ * Whether to log parsed options
324
+ *
325
+ * to show certificate and private keys, set `logParsedOptions: { showKeys: true }`
326
+ */
327
+ logParsedOptions?: boolean | {
328
+ showKeys: boolean;
329
+ };
330
+ /**
331
+ * main process options
332
+ *
333
+ * to change output directories, use `options.updater.paths.electronDistPath` instead
334
+ */
335
+ main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
336
+ /**
337
+ * preload process options
338
+ *
339
+ * to change output directories, use `options.updater.paths.electronDistPath` instead
340
+ */
341
+ preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
342
+ /**
343
+ * updater options
344
+ */
345
+ updater?: ElectronUpdaterOptions;
346
+ }
347
+ /**
348
+ * build options for `vite-plugin-electron/simple`
349
+ * - integrate with updater
350
+ * - only contains `main` and `preload` configs
351
+ * - remove old electron files
352
+ * - externalize dependencies
353
+ * - auto restart when entry file changes
354
+ * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
355
+ * - no `vite-plugin-electron-renderer` config
356
+ *
357
+ * you can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
358
+ *
359
+ * @example
360
+ * import { defineConfig } from 'vite'
361
+ * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
362
+ * import pkg from './package.json'
363
+ *
364
+ * export default defineConfig(async ({ command }) => {
365
+ * const isBuild = command === 'build'
366
+ * return {
367
+ * plugins: [
368
+ * electronWithUpdater({
369
+ * pkg,
370
+ * isBuild,
371
+ * logParsedOptions: true,
372
+ * main: {
373
+ * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
374
+ * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
375
+ * onstart: debugStartup,
376
+ * },
377
+ * preload: {
378
+ * files: './electron/preload/index.ts',
379
+ * },
380
+ * updater: {
381
+ * // options
382
+ * }
383
+ * }),
384
+ * ],
385
+ * server: process.env.VSCODE_DEBUG && (() => {
386
+ * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
387
+ * return {
388
+ * host: url.hostname,
389
+ * port: +url.port,
390
+ * }
391
+ * })(),
392
+ * }
393
+ * })
394
+ */
395
+ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
396
+
397
+ export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };