electron-incremental-update 3.0.0-beta.4 → 3.0.0-beta.6

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.mts CHANGED
@@ -1,50 +1,24 @@
1
- import { SpawnOptions } from "node:child_process";
2
- import { BuildEnvironmentOptions, InlineConfig, LibraryOptions, PluginOption, UserConfig, UserConfigFn, build } from "vite";
1
+ import { Plugin, UserConfig } from "vite";
2
+ import { MultiEnvElectronOptions } from "vite-plugin-electron/multi-env";
3
+ import { RolldownOrRollupOptions } from "vite-plugin-electron";
3
4
 
4
- //#region src/vite/bytecode/utils.d.ts
5
- /**
6
- * Obfuscate string
7
- * @param code source code
8
- * @param sourcemap whether to generate sourcemap
9
- * @param offset custom offset
10
- */
11
- declare function convertLiteral(code: string, sourcemap?: boolean, offset?: number): {
12
- code: string;
13
- map?: any;
14
- };
15
- //#endregion
16
- //#region node_modules/@subframe7536/type-utils/index.d.ts
5
+ //#region src/utils/type.d.ts
17
6
  type Promisable<T> = T | Promise<T>;
18
- type AnyFunction<Return = any> = (...args: any[]) => Return;
19
- //#endregion
20
- //#region src/vite/electron/core.d.ts
21
- interface ElectronOptions {
22
- /**
23
- * Shortcut of `build.lib.entry`
24
- */
25
- entry?: LibraryOptions["entry"];
26
- vite?: InlineConfig;
27
- /**
28
- * Triggered when Vite is built every time -- `vite serve` command only.
29
- *
30
- * If this `onstart` is passed, Electron App will not start automatically.
31
- * However, you can start Electroo App via `startup` function.
32
- */
33
- onstart?: (args: {
34
- /**
35
- * Electron App startup function.
36
- * It will mount the Electron App child-process to `process.electronApp`.
37
- * - argv: electron startup arguments (default `['.', '--no-sandbox']`)
38
- * - options: options for `child_process.spawn`
39
- * - customElectronPkg: custom electron package name (default: `'electron'`)
40
- */
41
- startup: (argv?: string[], options?: SpawnOptions, customElectronPkg?: string) => Promise<void>; /** Reload Electron-Renderer */
42
- reload: () => void;
43
- }) => void | Promise<void>;
44
- }
7
+ type AnyFunction = (...args: any[]) => any;
45
8
  //#endregion
46
- //#region src/vite/electron/utils.d.ts
47
- type RolldownOptions = Exclude<BuildEnvironmentOptions["rolldownOptions"], undefined>;
9
+ //#region src/vite/startup.d.ts
10
+ /**
11
+ * Filter error messages from stdout/stderr during startup
12
+ * @param args - Startup arguments
13
+ * @param filter - Filter function to determine which messages to show
14
+ */
15
+ declare function filterErrorMessageStartup(filter: (msg: string) => boolean): Promise<void>;
16
+ /**
17
+ * Fix Windows character encoding by setting code page to UTF-8
18
+ * @param fn - Function to wrap with encoding fix
19
+ * @returns Wrapped function with Windows encoding fix
20
+ */
21
+ declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
48
22
  //#endregion
49
23
  //#region src/utils/version.d.ts
50
24
  /**
@@ -75,49 +49,69 @@ type UpdateJSON = UpdateInfo & {
75
49
  };
76
50
  //#endregion
77
51
  //#region src/vite/bytecode/index.d.ts
52
+ /** Options for bytecode compilation */
78
53
  interface BytecodeOptions {
79
- enable: boolean;
54
+ /**
55
+ * Enable bytecode compilation
56
+ * @default true
57
+ */
58
+ enable?: boolean;
80
59
  /**
81
60
  * Enable in preload script. Remember to set `sandbox: false` when creating window
82
61
  */
83
62
  preload?: boolean;
84
63
  /**
85
- * Custom electron binary path
64
+ * Custom electron binary path for bytecode generation
86
65
  */
87
66
  electronPath?: string;
88
67
  /**
89
68
  * Before transformed code compile function. If return `Falsy` value, it will be ignored
90
- * @param code transformed code
91
- * @param id file path
69
+ * @param code - Transformed code
70
+ * @param id - File path
71
+ * @returns Transformed code or falsy to ignore
92
72
  */
93
73
  beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
94
74
  }
95
75
  //#endregion
96
- //#region src/vite/key.d.ts
76
+ //#region src/vite/utils/key.d.ts
77
+ /**
78
+ * Distinguished name for certificate generation
79
+ */
97
80
  interface DistinguishedName {
81
+ /** Country name (2-letter code) */
98
82
  countryName?: string;
83
+ /** State or province name */
99
84
  stateOrProvinceName?: string;
85
+ /** Locality/city name */
100
86
  localityName?: string;
87
+ /** Organization name */
101
88
  organizationName?: string;
89
+ /** Organizational unit name */
102
90
  organizationalUnitName?: string;
91
+ /** Common name */
103
92
  commonName?: string;
93
+ /** Serial number */
104
94
  serialNumber?: string;
95
+ /** Title */
105
96
  title?: string;
97
+ /** Description */
106
98
  description?: string;
99
+ /** Business category */
107
100
  businessCategory?: string;
101
+ /** Email address */
108
102
  emailAddress?: string;
109
103
  }
110
104
  //#endregion
111
- //#region src/vite/option.d.ts
105
+ //#region src/vite/types.d.ts
112
106
  interface CommonBuildOption {
113
107
  /**
114
108
  * Shortcut of `build.rolldownOptions.input`
115
109
  */
116
- files: NonNullable<ElectronOptions["entry"]>;
110
+ files: NonNullable<MultiEnvElectronOptions["input"]>;
117
111
  /**
118
112
  * Override vite options
119
113
  */
120
- vite?: ElectronOptions["vite"] & {
114
+ options?: MultiEnvElectronOptions["options"] & {
121
115
  build?: {
122
116
  outDir: never;
123
117
  sourcemap: never;
@@ -131,21 +125,6 @@ interface CommonBuildOption {
131
125
  };
132
126
  }
133
127
  interface ElectronWithUpdaterOptions {
134
- /**
135
- * Whether is in build mode
136
- * ```ts
137
- * export default defineConfig(({ command }) => {
138
- * const isBuild = command === 'build'
139
- * })
140
- * ```
141
- */
142
- isBuild: boolean;
143
- /**
144
- * Project root directory. Can be an absolute path, or a path relative from
145
- * the location of the config file itself.
146
- * @default process.cwd()
147
- */
148
- root?: string;
149
128
  /**
150
129
  * Whether to generate sourcemap
151
130
  * @default !isBuild || !!process.env.VSCODE_DEBUG
@@ -165,9 +144,15 @@ interface ElectronWithUpdaterOptions {
165
144
  */
166
145
  bytecode?: boolean | BytecodeOptions;
167
146
  /**
168
- * Use `NotBundle()` plugin in main
147
+ * Faster dev startup by externalize all node modules in entry and main.
148
+ *
149
+ * Only works in development (`isBuild === false`).
169
150
  * @default true
170
151
  */
152
+ notBundle?: boolean | RolldownOrRollupOptions["external"];
153
+ /**
154
+ * @deprecated use `notBundle` instead
155
+ */
171
156
  useNotBundle?: boolean;
172
157
  /**
173
158
  * Whether to generate version json
@@ -175,12 +160,21 @@ interface ElectronWithUpdaterOptions {
175
160
  */
176
161
  buildVersionJson?: boolean;
177
162
  /**
163
+ * Generate and serve a local update package during dev startup.
164
+ *
165
+ * This is useful for testing update checks, simulated download progress,
166
+ * and restart/install behavior without publishing a remote release.
167
+ *
168
+ * @default false
169
+ */
170
+ localDevUpdate?: boolean | LocalDevUpdateOptions;
171
+ /**
178
172
  * Addtional `external` option in `build.rolldownOptions`,
179
173
  *
180
- * If is in dev and `entry.postBuild` is not setup,
174
+ * If equals `true`,
181
175
  * external `dependencies` in `package.json` by default
182
176
  */
183
- external?: (string | RegExp)[];
177
+ external?: (string | RegExp)[] | boolean;
184
178
  /**
185
179
  * Options for entry (app.asar)
186
180
  *
@@ -250,7 +244,7 @@ interface ElectronWithUpdaterOptions {
250
244
  * @param options options for `child_process.spawn`
251
245
  * @param customElectronPkg custom electron package name (default: 'electron')
252
246
  */
253
- onstart?: ElectronOptions["onstart"];
247
+ onstart?: MultiEnvElectronOptions["onstart"];
254
248
  } & CommonBuildOption;
255
249
  /**
256
250
  * Preload process options
@@ -263,29 +257,37 @@ interface ElectronWithUpdaterOptions {
263
257
  */
264
258
  updater?: UpdaterOptions;
265
259
  }
266
- interface GeneratorOverrideFunctions {
260
+ interface LocalDevUpdateOptions {
267
261
  /**
268
- * Custom signature generate function
269
- * @param buffer file buffer
270
- * @param privateKey private key
271
- * @param cert certificate string, **EOL must be `\n`**
272
- * @param version current version
262
+ * Package file used for local dev update name/version.
263
+ *
264
+ * This is useful when the Electron app package is not the project root
265
+ * package, such as a playground or example app.
266
+ *
267
+ * @default project package.json
273
268
  */
274
- generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => Promisable<string>;
269
+ packageJsonPath?: string;
275
270
  /**
276
- * Custom generate update json function
277
- * @param existingJson The existing JSON object.
278
- * @param buffer file buffer
279
- * @param signature generated signature
280
- * @param version current version
281
- * @param minVersion The minimum version
271
+ * Directory that contains local update resources.
272
+ *
273
+ * The generated version file is written under `{baseDir}/{versionPath}` and
274
+ * update archives are written as `{baseDir}/{name}-{version}.asar.gz`.
275
+ *
276
+ * @default 'release/local-update'
282
277
  */
283
- generateUpdateJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => Promisable<UpdateJSON>;
278
+ baseDir?: string;
284
279
  /**
285
- * Custom generate zip file buffer
286
- * @param buffer source buffer
280
+ * Local read chunk size for simulated download progress.
281
+ *
282
+ * @default LocalDevProvider default
287
283
  */
288
- generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
284
+ chunkSize?: number;
285
+ /**
286
+ * Delay between simulated progress chunks in milliseconds.
287
+ *
288
+ * @default LocalDevProvider default
289
+ */
290
+ chunkDelay?: number;
289
291
  }
290
292
  interface UpdaterOptions {
291
293
  /**
@@ -309,7 +311,7 @@ interface UpdaterOptions {
309
311
  entryOutDir?: string;
310
312
  /**
311
313
  * Path to version info output, content is {@link UpdateJSON}
312
- * @default `version.json`
314
+ * @default `release/version.json`
313
315
  */
314
316
  versionPath?: string;
315
317
  /**
@@ -375,80 +377,45 @@ interface UpdaterOptions {
375
377
  };
376
378
  overrideGenerator?: GeneratorOverrideFunctions;
377
379
  }
380
+ interface GeneratorOverrideFunctions {
381
+ /**
382
+ * Custom signature generate function
383
+ * @param buffer file buffer
384
+ * @param privateKey private key
385
+ * @param cert certificate string, **EOL must be `\n`**
386
+ * @param version current version
387
+ */
388
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => Promisable<string>;
389
+ /**
390
+ * Custom generate update json function
391
+ * @param existingJson The existing JSON object.
392
+ * @param signature generated signature
393
+ * @param version current version
394
+ * @param minVersion The minimum version
395
+ */
396
+ generateUpdateJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => Promisable<UpdateJSON>;
397
+ /**
398
+ * Custom generate zip file buffer
399
+ * @param buffer source buffer
400
+ */
401
+ generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
402
+ }
378
403
  //#endregion
379
404
  //#region src/vite/core.d.ts
380
- interface ElectronSimpleOptions {
381
- main: ElectronOptions;
382
- preload?: Omit<ElectronOptions, "entry"> & {
383
- /**
384
- * Shortcut of `build.rolldownOptions.input`.
385
- *
386
- * Preload scripts may contain Web assets, so use the `build.rolldownOptions.input` instead `build.lib.entry`.
387
- */
388
- input: RolldownOptions["input"];
389
- };
390
- }
391
- type StartupFn = NonNullable<NonNullable<ElectronSimpleOptions["main"]>["onstart"]>;
392
- /**
393
- * Startup function for debug
394
- * @see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
395
- * @example
396
- * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
397
- * const options = buildElectronPluginOptions({
398
- * // ...
399
- * main: {
400
- * // ...
401
- * startup: debugStartup
402
- * },
403
- * })
404
- */
405
- declare const debugStartup: StartupFn;
406
- /**
407
- * Startup function to filter unwanted error message
408
- * @see {@link https://github.com/electron/electron/issues/46903#issuecomment-2848483520 reference}
409
- * @example
410
- * import { filterErrorMessageStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
411
- * const options = buildElectronPluginOptions({
412
- * // ...
413
- * main: {
414
- * // ...
415
- * startup: args => filterErrorMessageStartup(
416
- * args,
417
- * // ignore error message when function returns false
418
- * msg => !/"code":-32601/.test(msg)
419
- * )
420
- * },
421
- * })
422
- */
423
- declare function filterErrorMessageStartup(args: Parameters<StartupFn>[0], filter: (msg: string) => boolean): Promise<void>;
424
405
  /**
425
- * Startup function util to fix Windows terminal charset
426
- * @example
427
- * import { debugStartup, fixWinCharEncoding, buildElectronPluginOptions } from 'electron-incremental-update/vite'
428
- * const options = buildElectronPluginOptions({
429
- * // ...
430
- * main: {
431
- * // ...
432
- * startup: fixWinCharEncoding(debugStartup)
433
- * },
434
- * })
435
- */
436
- declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
437
- /**
438
- * Base on `./electron/simple`
406
+ * Base on `vite-plugin-electron/multi-env`
439
407
  * - integrate with updater
440
408
  * - no `renderer` config
441
409
  * - remove old output file
442
410
  * - externalize dependencies
443
411
  * - auto restart when entry file changes
444
- * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
445
412
  *
446
- * You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
413
+ * You can override all the environment configs, except output directories (use `options.updater.paths.electronDistPath` instead)
447
414
  *
448
415
  * @example
449
416
  * ```ts
450
417
  * import { defineConfig } from 'vite'
451
- * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
418
+ * import { electronWithUpdater } from 'electron-incremental-update/vite'
452
419
  *
453
420
  * export default defineConfig(async ({ command }) => {
454
421
  * const isBuild = command === 'build'
@@ -458,8 +425,6 @@ declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
458
425
  * isBuild,
459
426
  * main: {
460
427
  * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
461
- * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
462
- * onstart: debugStartup,
463
428
  * },
464
429
  * preload: {
465
430
  * files: './electron/preload/index.ts',
@@ -469,26 +434,18 @@ declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
469
434
  * }
470
435
  * }),
471
436
  * ],
472
- * server: process.env.VSCODE_DEBUG && (() => {
473
- * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
474
- * return {
475
- * host: url.hostname,
476
- * port: +url.port,
477
- * }
478
- * })(),
479
437
  * }
480
438
  * })
481
439
  * ```
482
440
  */
483
- declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
441
+ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<Plugin[] | undefined>;
484
442
  //#endregion
485
443
  //#region src/vite/define.d.ts
486
- type MakeOptional<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
487
- interface ElectronViteHelperOptions extends MakeOptional<ElectronWithUpdaterOptions, "isBuild"> {
444
+ interface ElectronViteHelperOptions extends ElectronWithUpdaterOptions {
488
445
  /**
489
446
  * Config for renderer process
490
447
  */
491
- renderer?: Omit<UserConfig, "root">;
448
+ renderer?: UserConfig;
492
449
  }
493
450
  /**
494
451
  * Vite config helper
@@ -500,8 +457,6 @@ interface ElectronViteHelperOptions extends MakeOptional<ElectronWithUpdaterOpti
500
457
  * export default defineElectronConfig({
501
458
  * main: {
502
459
  * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
503
- * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
504
- * onstart: debugStartup,
505
460
  * },
506
461
  * preload: {
507
462
  * files: './electron/preload/index.ts',
@@ -521,6 +476,6 @@ interface ElectronViteHelperOptions extends MakeOptional<ElectronWithUpdaterOpti
521
476
  * })
522
477
  * ```
523
478
  */
524
- declare function defineElectronConfig(options: ElectronViteHelperOptions): UserConfigFn;
479
+ declare function defineElectronConfig(options: ElectronViteHelperOptions): UserConfig;
525
480
  //#endregion
526
- export { type ElectronViteHelperOptions, type ElectronWithUpdaterOptions, convertLiteral, debugStartup, electronWithUpdater as default, electronWithUpdater, defineElectronConfig, filterErrorMessageStartup, fixWinCharEncoding };
481
+ export { type ElectronViteHelperOptions, type ElectronWithUpdaterOptions, type LocalDevUpdateOptions, electronWithUpdater as default, electronWithUpdater, defineElectronConfig, filterErrorMessageStartup, fixWinCharEncoding };