electron-incremental-update 2.4.2 → 3.0.0-beta.2

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.
Files changed (47) hide show
  1. package/README.md +72 -43
  2. package/dist/download-BN4uMS4_.d.mts +39 -0
  3. package/dist/download-DO7iuxEJ.d.cts +39 -0
  4. package/dist/electron-BFoZUBhU.cjs +320 -0
  5. package/dist/electron-CJIoO4ny.mjs +180 -0
  6. package/dist/index.cjs +259 -331
  7. package/dist/index.d.cts +179 -169
  8. package/dist/index.d.mts +204 -0
  9. package/dist/index.mjs +271 -0
  10. package/dist/provider.cjs +142 -356
  11. package/dist/provider.d.cts +116 -117
  12. package/dist/provider.d.mts +133 -0
  13. package/dist/provider.mjs +152 -0
  14. package/dist/types-BM9Jfu7q.d.cts +154 -0
  15. package/dist/types-DASqEPXE.d.mts +154 -0
  16. package/dist/utils.cjs +43 -381
  17. package/dist/utils.d.cts +117 -85
  18. package/dist/utils.d.mts +161 -0
  19. package/dist/utils.mjs +5 -0
  20. package/dist/version--eVB2A7n.mjs +72 -0
  21. package/dist/version-aPrLuz_-.cjs +129 -0
  22. package/dist/vite.d.mts +565 -0
  23. package/dist/vite.mjs +1222 -0
  24. package/dist/zip-BCC7FAQ_.cjs +264 -0
  25. package/dist/zip-Dwm7s1C9.mjs +185 -0
  26. package/package.json +65 -65
  27. package/dist/chunk-AAAM44NW.js +0 -70
  28. package/dist/chunk-IVHNGRZY.js +0 -122
  29. package/dist/chunk-PD4EV4MM.js +0 -147
  30. package/dist/index.d.ts +0 -194
  31. package/dist/index.js +0 -309
  32. package/dist/provider.d.ts +0 -134
  33. package/dist/provider.js +0 -178
  34. package/dist/types-CU7GyVez.d.cts +0 -151
  35. package/dist/types-CU7GyVez.d.ts +0 -151
  36. package/dist/utils.d.ts +0 -129
  37. package/dist/utils.js +0 -3
  38. package/dist/vite.d.ts +0 -533
  39. package/dist/vite.js +0 -945
  40. package/dist/zip-Blmn2vzE.d.cts +0 -71
  41. package/dist/zip-CnSv_Njj.d.ts +0 -71
  42. package/provider.d.ts +0 -1
  43. package/provider.js +0 -1
  44. package/utils.d.ts +0 -1
  45. package/utils.js +0 -1
  46. package/vite.d.ts +0 -1
  47. package/vite.js +0 -1
@@ -0,0 +1,565 @@
1
+ import "local-pkg";
2
+ import { SpawnOptions } from "node:child_process";
3
+ import { BuildEnvironmentOptions, InlineConfig, LibraryOptions, PluginOption, UserConfig, UserConfigFn, build } from "vite";
4
+
5
+ //#region src/vite/bytecode/utils.d.ts
6
+ /**
7
+ * Obfuscate string
8
+ * @param code source code
9
+ * @param sourcemap whether to generate sourcemap
10
+ * @param offset custom offset
11
+ */
12
+ declare function convertLiteral(code: string, sourcemap?: boolean, offset?: number): {
13
+ code: string;
14
+ map?: any;
15
+ };
16
+ //#endregion
17
+ //#region node_modules/@subframe7536/type-utils/index.d.ts
18
+ type Promisable<T> = T | Promise<T>;
19
+ type AnyFunction<Return = any> = (...args: any[]) => Return;
20
+ //#endregion
21
+ //#region src/vite/electron/utils.d.ts
22
+ type RolldownOptions = Exclude<BuildEnvironmentOptions["rolldownOptions"], undefined>;
23
+ //#endregion
24
+ //#region src/vite/electron/core.d.ts
25
+ interface ElectronOptions {
26
+ /**
27
+ * Shortcut of `build.lib.entry`
28
+ */
29
+ entry?: LibraryOptions["entry"];
30
+ vite?: InlineConfig;
31
+ /**
32
+ * Triggered when Vite is built every time -- `vite serve` command only.
33
+ *
34
+ * If this `onstart` is passed, Electron App will not start automatically.
35
+ * However, you can start Electroo App via `startup` function.
36
+ */
37
+ onstart?: (args: {
38
+ /**
39
+ * Electron App startup function.
40
+ * It will mount the Electron App child-process to `process.electronApp`.
41
+ * @param argv default value `['.', '--no-sandbox']`
42
+ * @param options options for `child_process.spawn`
43
+ * @param customElectronPkg custom electron package name (default: 'electron')
44
+ */
45
+ startup: (argv?: string[], options?: SpawnOptions, customElectronPkg?: string) => Promise<void>; /** Reload Electron-Renderer */
46
+ reload: () => void;
47
+ }) => void | Promise<void>;
48
+ }
49
+ //#endregion
50
+ //#region src/vite/electron/simple.d.ts
51
+ interface ElectronSimpleOptions {
52
+ main: ElectronOptions;
53
+ preload?: Omit<ElectronOptions, "entry"> & {
54
+ /**
55
+ * Shortcut of `build.rolldownOptions.input`.
56
+ *
57
+ * Preload scripts may contain Web assets, so use the `build.rolldownOptions.input` instead `build.lib.entry`.
58
+ */
59
+ input: RolldownOptions["input"];
60
+ };
61
+ }
62
+ //#endregion
63
+ //#region src/utils/version.d.ts
64
+ /**
65
+ * Update info json
66
+ */
67
+ interface UpdateInfo {
68
+ /**
69
+ * Update Asar signature
70
+ */
71
+ signature: string;
72
+ /**
73
+ * Minimum version
74
+ */
75
+ minimumVersion: string;
76
+ /**
77
+ * Target version
78
+ */
79
+ version: string;
80
+ }
81
+ /**
82
+ * {@link UpdateInfo} with beta
83
+ */
84
+ type UpdateJSON = UpdateInfo & {
85
+ /**
86
+ * Beta update info
87
+ */
88
+ beta: UpdateInfo;
89
+ };
90
+ //#endregion
91
+ //#region src/vite/bytecode/index.d.ts
92
+ interface BytecodeOptions {
93
+ enable: boolean;
94
+ /**
95
+ * Enable in preload script. Remember to set `sandbox: false` when creating window
96
+ */
97
+ preload?: boolean;
98
+ /**
99
+ * Custom electron binary path
100
+ */
101
+ electronPath?: string;
102
+ /**
103
+ * Before transformed code compile function. If return `Falsy` value, it will be ignored
104
+ * @param code transformed code
105
+ * @param id file path
106
+ */
107
+ beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
108
+ }
109
+ //#endregion
110
+ //#region src/vite/key.d.ts
111
+ interface DistinguishedName {
112
+ countryName?: string;
113
+ stateOrProvinceName?: string;
114
+ localityName?: string;
115
+ organizationName?: string;
116
+ organizationalUnitName?: string;
117
+ commonName?: string;
118
+ serialNumber?: string;
119
+ title?: string;
120
+ description?: string;
121
+ businessCategory?: string;
122
+ emailAddress?: string;
123
+ }
124
+ //#endregion
125
+ //#region src/vite/option.d.ts
126
+ interface ViteOverride {
127
+ /**
128
+ * Override vite options
129
+ */
130
+ vite?: ElectronOptions["vite"] & {
131
+ build?: {
132
+ outDir: never;
133
+ rolldownOptions?: {
134
+ output?: {
135
+ dir: never;
136
+ };
137
+ };
138
+ };
139
+ };
140
+ }
141
+ interface ElectronWithUpdaterOptions {
142
+ /**
143
+ * Whether is in build mode
144
+ * ```ts
145
+ * export default defineConfig(({ command }) => {
146
+ * const isBuild = command === 'build'
147
+ * })
148
+ * ```
149
+ */
150
+ isBuild: boolean;
151
+ /**
152
+ * Whether to generate sourcemap
153
+ * @default !isBuild
154
+ */
155
+ sourcemap?: boolean;
156
+ /**
157
+ * Whether to minify the code
158
+ * @default isBuild
159
+ */
160
+ minify?: boolean;
161
+ /**
162
+ * Whether to generate bytecode
163
+ *
164
+ * **Only support CommonJS**
165
+ *
166
+ * 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
167
+ */
168
+ bytecode?: boolean | BytecodeOptions;
169
+ /**
170
+ * Use `NotBundle()` plugin in main
171
+ * @default true
172
+ */
173
+ useNotBundle?: boolean;
174
+ /**
175
+ * Whether to generate version json
176
+ * @default isCI
177
+ */
178
+ buildVersionJson?: boolean;
179
+ /**
180
+ * Options for entry (app.asar)
181
+ */
182
+ entry?: BuildEntryOption;
183
+ /**
184
+ * Main process options
185
+ *
186
+ * To change output directories, use `options.updater.paths.electronDistPath` instead
187
+ */
188
+ main: {
189
+ /**
190
+ * Shortcut of `build.rolldownOptions.input`
191
+ */
192
+ files: NonNullable<ElectronOptions["entry"]>;
193
+ /**
194
+ * Electron App startup function.
195
+ *
196
+ * It will mount the Electron App child-process to `process.electronApp`.
197
+ * @param argv default value `['.', '--no-sandbox']`
198
+ * @param options options for `child_process.spawn`
199
+ * @param customElectronPkg custom electron package name (default: 'electron')
200
+ */
201
+ onstart?: ElectronOptions["onstart"];
202
+ } & ViteOverride;
203
+ /**
204
+ * Preload process options
205
+ *
206
+ * To change output directories, use `options.updater.paths.electronDistPath` instead
207
+ */
208
+ preload: {
209
+ /**
210
+ * Shortcut of `build.rolldownOptions.input`.
211
+ *
212
+ * Preload scripts may contain Web assets, so use the `build.rolldownOptions.input` instead `build.lib.entry`.
213
+ */
214
+ files: NonNullable<ElectronOptions["entry"]>;
215
+ } & ViteOverride;
216
+ /**
217
+ * Updater options
218
+ */
219
+ updater?: UpdaterOptions;
220
+ }
221
+ interface BuildEntryOption {
222
+ /**
223
+ * Override to minify on entry
224
+ * @default isBuild
225
+ */
226
+ minify?: boolean;
227
+ /**
228
+ * Override to generate sourcemap on entry
229
+ */
230
+ sourcemap?: boolean;
231
+ /**
232
+ * Path to app entry output file
233
+ * @default 'dist-entry'
234
+ */
235
+ outDir?: string;
236
+ /**
237
+ * Path to app entry file
238
+ * @default 'electron/entry.ts'
239
+ */
240
+ files?: NonNullable<ElectronOptions["entry"]>;
241
+ /**
242
+ * Skip process dynamic require
243
+ *
244
+ * Useful for `better-sqlite3` and other old packages
245
+ */
246
+ ignoreDynamicRequires?: boolean;
247
+ /**
248
+ * `external` option in `build.rolldownOptions`,
249
+ * default is node built-in modules or native modules.
250
+ *
251
+ * If is in dev and {@link postBuild} is not setup, will also
252
+ * external `dependencies` in `package.json`
253
+ */
254
+ external?: NonNullable<NonNullable<InlineConfig["build"]>["rolldownOptions"]>["external"];
255
+ /**
256
+ * Custom options for `vite` build
257
+ * ```ts
258
+ * const options = {
259
+ * plugins: [esm(), bytecodePlugin()], // load on needed
260
+ * build: {
261
+ * sourcemap,
262
+ * minify,
263
+ * outDir: entryOutputDirPath,
264
+ * commonjsOptions: { ignoreDynamicRequires },
265
+ * rolldownOptions: { external },
266
+ * },
267
+ * define,
268
+ * }
269
+ * ```
270
+ */
271
+ vite?: InlineConfig;
272
+ /**
273
+ * By default, all the unbundled modules will be packaged by packager like `electron-builder`.
274
+ * If setup, all the `dependencies` in `package.json` will be bundled by default, and you need
275
+ * to manually handle the native module files.
276
+ *
277
+ * If you are using `electron-buidler`, don't forget to append `'!node_modules/**'` in
278
+ * electron-build config's `files` array
279
+ */
280
+ postBuild?: (args: {
281
+ /**
282
+ * Whether is in build mode
283
+ */
284
+ isBuild: boolean;
285
+ /**
286
+ * Get path from `entryOutputDirPath`
287
+ */
288
+ getPathFromEntryOutputDir: (...paths: string[]) => string;
289
+ /**
290
+ * Check exist and copy file to `entryOutputDirPath`
291
+ *
292
+ * If `to` absent, set to `basename(from)`
293
+ *
294
+ * If `skipIfExist` absent, skip copy if `to` exist
295
+ */
296
+ copyToEntryOutputDir: (options: {
297
+ from: string;
298
+ to?: string;
299
+ /**
300
+ * Skip copy if `to` exist
301
+ * @default true
302
+ */
303
+ skipIfExist?: boolean;
304
+ }) => void;
305
+ /**
306
+ * Copy specified modules to entry output dir, just like `external` option in rolldown
307
+ */
308
+ copyModules: (options: {
309
+ /**
310
+ * External Modules
311
+ */
312
+ modules: string[];
313
+ /**
314
+ * Skip copy if `to` exist
315
+ * @default true
316
+ */
317
+ skipIfExist?: boolean;
318
+ }) => void;
319
+ }) => Promisable<void>;
320
+ }
321
+ interface GeneratorOverrideFunctions {
322
+ /**
323
+ * Custom signature generate function
324
+ * @param buffer file buffer
325
+ * @param privateKey private key
326
+ * @param cert certificate string, **EOL must be `\n`**
327
+ * @param version current version
328
+ */
329
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => Promisable<string>;
330
+ /**
331
+ * Custom generate update json function
332
+ * @param existingJson The existing JSON object.
333
+ * @param buffer file buffer
334
+ * @param signature generated signature
335
+ * @param version current version
336
+ * @param minVersion The minimum version
337
+ */
338
+ generateUpdateJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => Promisable<UpdateJSON>;
339
+ /**
340
+ * Custom generate zip file buffer
341
+ * @param buffer source buffer
342
+ */
343
+ generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
344
+ }
345
+ interface UpdaterOptions {
346
+ /**
347
+ * Minimum version of entry
348
+ * @default '0.0.0'
349
+ */
350
+ minimumVersion?: string;
351
+ /**
352
+ * Options for paths
353
+ */
354
+ paths?: {
355
+ /**
356
+ * Path to asar file
357
+ * @default `release/${app.name}.asar`
358
+ */
359
+ asarOutputPath?: string;
360
+ /**
361
+ * Path to version info output, content is {@link UpdateJSON}
362
+ * @default `version.json`
363
+ */
364
+ versionPath?: string;
365
+ /**
366
+ * Path to gzipped asar file
367
+ * @default `release/${app.name}-${version}.asar.gz`
368
+ */
369
+ gzipPath?: string;
370
+ /**
371
+ * Path to electron build output
372
+ * @default `dist-electron`
373
+ */
374
+ electronDistPath?: string;
375
+ /**
376
+ * Path to renderer build output
377
+ * @default `dist`
378
+ */
379
+ rendererDistPath?: string;
380
+ };
381
+ /**
382
+ * signature config
383
+ */
384
+ keys?: {
385
+ /**
386
+ * Path to the pem file that contains private key
387
+ * If not ended with .pem, it will be appended
388
+ *
389
+ * **If `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
390
+ * @default 'keys/private.pem'
391
+ */
392
+ privateKeyPath?: string;
393
+ /**
394
+ * Path to the pem file that contains public key
395
+ * If not ended with .pem, it will be appended
396
+ *
397
+ * **If `UPDATER_CERT` is set, will read it instead of read from `certPath`**
398
+ * @default 'keys/cert.pem'
399
+ */
400
+ certPath?: string;
401
+ /**
402
+ * Length of the key
403
+ * @default 2048
404
+ */
405
+ keyLength?: number;
406
+ /**
407
+ * X509 certificate info
408
+ *
409
+ * Only generate simple **self-signed** certificate **without extensions**
410
+ */
411
+ certInfo?: {
412
+ /**
413
+ * The subject of the certificate
414
+ *
415
+ * @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
416
+ */
417
+ subject?: DistinguishedName;
418
+ /**
419
+ * Expire days of the certificate
420
+ *
421
+ * @default 3650
422
+ */
423
+ days?: number;
424
+ };
425
+ };
426
+ overrideGenerator?: GeneratorOverrideFunctions;
427
+ }
428
+ //#endregion
429
+ //#region src/vite/core.d.ts
430
+ type StartupFn = NonNullable<NonNullable<ElectronSimpleOptions["main"]>["onstart"]>;
431
+ /**
432
+ * Startup function for debug
433
+ * @see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
434
+ * @example
435
+ * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
436
+ * const options = buildElectronPluginOptions({
437
+ * // ...
438
+ * main: {
439
+ * // ...
440
+ * startup: debugStartup
441
+ * },
442
+ * })
443
+ */
444
+ declare const debugStartup: StartupFn;
445
+ /**
446
+ * Startup function to filter unwanted error message
447
+ * @see {@link https://github.com/electron/electron/issues/46903#issuecomment-2848483520 reference}
448
+ * @example
449
+ * import { filterErrorMessageStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
450
+ * const options = buildElectronPluginOptions({
451
+ * // ...
452
+ * main: {
453
+ * // ...
454
+ * startup: args => filterErrorMessageStartup(
455
+ * args,
456
+ * // ignore error message when function returns false
457
+ * msg => !/"code":-32601/.test(msg)
458
+ * )
459
+ * },
460
+ * })
461
+ */
462
+ declare function filterErrorMessageStartup(args: Parameters<StartupFn>[0], filter: (msg: string) => boolean): Promise<void>;
463
+ /**
464
+ * Startup function util to fix Windows terminal charset
465
+ * @example
466
+ * import { debugStartup, fixWinCharEncoding, buildElectronPluginOptions } from 'electron-incremental-update/vite'
467
+ * const options = buildElectronPluginOptions({
468
+ * // ...
469
+ * main: {
470
+ * // ...
471
+ * startup: fixWinCharEncoding(debugStartup)
472
+ * },
473
+ * })
474
+ */
475
+ declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
476
+ /**
477
+ * Base on `./electron/simple`
478
+ * - integrate with updater
479
+ * - no `renderer` config
480
+ * - remove old output file
481
+ * - externalize dependencies
482
+ * - auto restart when entry file changes
483
+ * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
484
+ *
485
+ * You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
486
+ *
487
+ * @example
488
+ * ```ts
489
+ * import { defineConfig } from 'vite'
490
+ * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
491
+ *
492
+ * export default defineConfig(async ({ command }) => {
493
+ * const isBuild = command === 'build'
494
+ * return {
495
+ * plugins: [
496
+ * electronWithUpdater({
497
+ * isBuild,
498
+ * main: {
499
+ * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
500
+ * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
501
+ * onstart: debugStartup,
502
+ * },
503
+ * preload: {
504
+ * files: './electron/preload/index.ts',
505
+ * },
506
+ * updater: {
507
+ * // options
508
+ * }
509
+ * }),
510
+ * ],
511
+ * server: process.env.VSCODE_DEBUG && (() => {
512
+ * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
513
+ * return {
514
+ * host: url.hostname,
515
+ * port: +url.port,
516
+ * }
517
+ * })(),
518
+ * }
519
+ * })
520
+ * ```
521
+ */
522
+ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
523
+ //#endregion
524
+ //#region src/vite/define.d.ts
525
+ type MakeOptional<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
526
+ interface ElectronViteHelperOptions extends MakeOptional<ElectronWithUpdaterOptions, "isBuild"> {
527
+ /**
528
+ * Config for renderer process
529
+ */
530
+ renderer?: UserConfig;
531
+ }
532
+ /**
533
+ * Vite config helper
534
+ * @see {@link electronWithUpdater}
535
+ * @example
536
+ * ```ts
537
+ * import { defineElectronConfig } from 'electron-incremental-update/vite'
538
+ *
539
+ * export default defineElectronConfig({
540
+ * main: {
541
+ * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
542
+ * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
543
+ * onstart: debugStartup,
544
+ * },
545
+ * preload: {
546
+ * files: './electron/preload/index.ts',
547
+ * },
548
+ * updater: {
549
+ * // options
550
+ * },
551
+ * renderer: {
552
+ * server: process.env.VSCODE_DEBUG && (() => {
553
+ * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
554
+ * return {
555
+ * host: url.hostname,
556
+ * port: +url.port,
557
+ * }
558
+ * })(),
559
+ * }
560
+ * })
561
+ * ```
562
+ */
563
+ declare function defineElectronConfig(options: ElectronViteHelperOptions): UserConfigFn;
564
+ //#endregion
565
+ export { type ElectronViteHelperOptions, type ElectronWithUpdaterOptions, convertLiteral, debugStartup, electronWithUpdater as default, electronWithUpdater, defineElectronConfig, filterErrorMessageStartup, fixWinCharEncoding };