electron-incremental-update 2.0.0-beta.8 → 2.0.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.
package/dist/vite.d.ts CHANGED
@@ -5,7 +5,7 @@ import { BuildOptions } from 'esbuild';
5
5
  export { isCI } from 'ci-info';
6
6
 
7
7
  /**
8
- * update info json
8
+ * Update info json
9
9
  */
10
10
  type UpdateInfo = {
11
11
  signature: string;
@@ -23,6 +23,7 @@ interface PKG {
23
23
  name: string;
24
24
  version: string;
25
25
  main: string;
26
+ type: 'commonjs' | 'module';
26
27
  }
27
28
  interface DistinguishedName {
28
29
  countryName?: string;
@@ -39,27 +40,26 @@ interface DistinguishedName {
39
40
  }
40
41
  interface BuildEntryOption {
41
42
  /**
42
- * whether to minify
43
+ * Override to minify on entry
43
44
  * @default isBuild
44
45
  */
45
46
  minify?: boolean;
46
47
  /**
47
- * whether to generate sourcemap
48
- * @default isBuild
48
+ * Override to generate sourcemap on entry
49
49
  */
50
50
  sourcemap?: boolean;
51
51
  /**
52
- * path to app entry output file
52
+ * Path to app entry output file
53
53
  * @default 'dist-entry'
54
54
  */
55
55
  entryOutputDirPath?: string;
56
56
  /**
57
- * path to app entry file
57
+ * Path to app entry file
58
58
  * @default 'electron/entry.ts'
59
59
  */
60
60
  appEntryPath?: string;
61
61
  /**
62
- * esbuild path map of native modules in entry directory
62
+ * Esbuild path map of native modules in entry directory
63
63
  *
64
64
  * @default {}
65
65
  * @example
@@ -67,7 +67,7 @@ interface BuildEntryOption {
67
67
  */
68
68
  nativeModuleEntryMap?: Record<string, string>;
69
69
  /**
70
- * custom options for esbuild
70
+ * Custom options for esbuild
71
71
  * ```ts
72
72
  * // default options
73
73
  * const options = {
@@ -86,34 +86,32 @@ interface BuildEntryOption {
86
86
  * loader: {
87
87
  * '.node': 'empty',
88
88
  * },
89
- * define: {
90
- * __SIGNATURE_CERT__: JSON.stringify(cert),
91
- * },
89
+ * define,
92
90
  * }
93
91
  * ```
94
92
  */
95
93
  overrideEsbuildOptions?: BuildOptions;
96
94
  /**
97
- * resolve extra files on startup, such as `.node`
95
+ * Resolve extra files on startup, such as `.node`
98
96
  * @remark won't trigger will reload
99
97
  */
100
98
  postBuild?: (args: {
101
99
  /**
102
- * get path from `entryOutputDirPath`
100
+ * Get path from `entryOutputDirPath`
103
101
  */
104
102
  getPathFromEntryOutputDir: (...paths: string[]) => string;
105
103
  /**
106
- * check exist and copy file to `entryOutputDirPath`
104
+ * Check exist and copy file to `entryOutputDirPath`
107
105
  *
108
- * if `to` absent, set to `basename(from)`
106
+ * If `to` absent, set to `basename(from)`
109
107
  *
110
- * if `skipIfExist` absent, skip copy if `to` exist
108
+ * If `skipIfExist` absent, skip copy if `to` exist
111
109
  */
112
110
  copyToEntryOutputDir: (options: {
113
111
  from: string;
114
112
  to?: string;
115
113
  /**
116
- * skip copy if `to` exist
114
+ * Skip copy if `to` exist
117
115
  * @default true
118
116
  */
119
117
  skipIfExist?: boolean;
@@ -122,15 +120,15 @@ interface BuildEntryOption {
122
120
  }
123
121
  interface GeneratorOverrideFunctions {
124
122
  /**
125
- * custom signature generate function
123
+ * Custom signature generate function
126
124
  * @param buffer file buffer
127
125
  * @param privateKey private key
128
126
  * @param cert certificate string, **EOL must be '\n'**
129
127
  * @param version current version
130
128
  */
131
- generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
129
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => Promisable<string>;
132
130
  /**
133
- * custom generate version json function
131
+ * Custom generate version json function
134
132
  * @param existingJson The existing JSON object.
135
133
  * @param buffer file buffer
136
134
  * @param signature generated signature
@@ -138,25 +136,25 @@ interface GeneratorOverrideFunctions {
138
136
  * @param minVersion The minimum version
139
137
  * @returns The updated version json
140
138
  */
141
- generateVersionJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
139
+ generateVersionJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => Promisable<UpdateJSON>;
142
140
  /**
143
- * custom generate zip file buffer
141
+ * Custom generate zip file buffer
144
142
  * @param buffer source buffer
145
143
  */
146
- generateGzipFile?: (buffer: Buffer) => Promise<Buffer>;
144
+ generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
147
145
  }
148
146
  interface ElectronUpdaterOptions {
149
147
  /**
150
- * mini version of entry
148
+ * Minimum version of entry
151
149
  * @default '0.0.0'
152
150
  */
153
151
  minimumVersion?: string;
154
152
  /**
155
- * config for entry (app.asar)
153
+ * Options for entry (app.asar)
156
154
  */
157
155
  entry?: BuildEntryOption;
158
156
  /**
159
- * paths config
157
+ * Options for paths
160
158
  */
161
159
  paths?: {
162
160
  /**
@@ -190,40 +188,40 @@ interface ElectronUpdaterOptions {
190
188
  */
191
189
  keys?: {
192
190
  /**
193
- * path to the pem file that contains private key
194
- * if not ended with .pem, it will be appended
191
+ * Path to the pem file that contains private key
192
+ * If not ended with .pem, it will be appended
195
193
  *
196
- * **if `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
194
+ * **If `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
197
195
  * @default 'keys/private.pem'
198
196
  */
199
197
  privateKeyPath?: string;
200
198
  /**
201
- * path to the pem file that contains public key
202
- * if not ended with .pem, it will be appended
199
+ * Path to the pem file that contains public key
200
+ * If not ended with .pem, it will be appended
203
201
  *
204
- * **if `UPDATER_CERT` is set, will read it instead of read from `certPath`**
202
+ * **If `UPDATER_CERT` is set, will read it instead of read from `certPath`**
205
203
  * @default 'keys/cert.pem'
206
204
  */
207
205
  certPath?: string;
208
206
  /**
209
- * length of the key
207
+ * Length of the key
210
208
  * @default 2048
211
209
  */
212
210
  keyLength?: number;
213
211
  /**
214
212
  * X509 certificate info
215
213
  *
216
- * only generate simple **self-signed** certificate **without extensions**
214
+ * Only generate simple **self-signed** certificate **without extensions**
217
215
  */
218
216
  certInfo?: {
219
217
  /**
220
- * the subject of the certificate
218
+ * The subject of the certificate
221
219
  *
222
220
  * @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
223
221
  */
224
222
  subject?: DistinguishedName;
225
223
  /**
226
- * expire days of the certificate
224
+ * Expire days of the certificate
227
225
  *
228
226
  * @default 3650
229
227
  */
@@ -236,15 +234,15 @@ interface ElectronUpdaterOptions {
236
234
  interface BytecodeOptions {
237
235
  enable: boolean;
238
236
  /**
239
- * Remember to set `sandbox: false` when creating window
237
+ * Enable in preload script. Remember to set `sandbox: false` when creating window
240
238
  */
241
239
  preload?: boolean;
242
240
  /**
243
- * before transformed code compile callback, if return `null` or `undefined`, it will be ignored
241
+ * Before transformed code compile function. If return `Falsy` value, it will be ignored
244
242
  * @param code transformed code
245
243
  * @param id file path
246
244
  */
247
- beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined>;
245
+ beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
248
246
  }
249
247
 
250
248
  type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
@@ -284,7 +282,7 @@ type ExcludeOutputDirOptions = {
284
282
  };
285
283
  interface ElectronWithUpdaterOptions {
286
284
  /**
287
- * whether is in build mode
285
+ * Whether is in build mode
288
286
  * ```ts
289
287
  * export default defineConfig(({ command }) => {
290
288
  * const isBuild = command === 'build'
@@ -293,113 +291,79 @@ interface ElectronWithUpdaterOptions {
293
291
  */
294
292
  isBuild: boolean;
295
293
  /**
296
- * manually setup package.json, read name, version and main
294
+ * Manually setup package.json, read name, version and main,
295
+ * use `local-pkg` of `loadPackageJSON()` to load package.json by default
297
296
  * ```ts
298
297
  * import pkg from './package.json'
299
298
  * ```
300
299
  */
301
300
  pkg?: PKG;
302
301
  /**
303
- * whether to generate sourcemap
302
+ * Whether to generate sourcemap
304
303
  * @default !isBuild
305
304
  */
306
305
  sourcemap?: boolean;
307
306
  /**
308
- * whether to minify the code
307
+ * Whether to minify the code
309
308
  * @default isBuild
310
309
  */
311
310
  minify?: boolean;
312
311
  /**
313
- * whether to generate bytecode
312
+ * Whether to generate bytecode
314
313
  *
315
- * **only support commonjs**
314
+ * **Only support CommonJS**
316
315
  *
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
316
+ * 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
317
  */
319
318
  bytecode?: boolean | BytecodeOptions;
320
319
  /**
321
- * use NotBundle() plugin in main
320
+ * Use `NotBundle()` plugin in main
322
321
  * @default true
323
322
  */
324
323
  useNotBundle?: boolean;
325
324
  /**
326
- * whether to generate version json
325
+ * Whether to generate version json
327
326
  * @default isCI
328
327
  */
329
328
  buildVersionJson?: boolean;
330
329
  /**
331
330
  * Whether to log parsed options
332
331
  *
333
- * to show certificate and private keys, set `logParsedOptions: { showKeys: true }`
332
+ * To show certificate and private keys, set `logParsedOptions: { showKeys: true }`
334
333
  */
335
334
  logParsedOptions?: boolean | {
336
335
  showKeys: boolean;
337
336
  };
338
337
  /**
339
- * main process options
338
+ * Main process options
340
339
  *
341
- * to change output directories, use `options.updater.paths.electronDistPath` instead
340
+ * To change output directories, use `options.updater.paths.electronDistPath` instead
342
341
  */
343
342
  main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
344
343
  /**
345
- * preload process options
344
+ * Preload process options
346
345
  *
347
- * to change output directories, use `options.updater.paths.electronDistPath` instead
346
+ * To change output directories, use `options.updater.paths.electronDistPath` instead
348
347
  */
349
348
  preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
350
349
  /**
351
- * updater options
350
+ * Updater options
352
351
  */
353
352
  updater?: ElectronUpdaterOptions;
354
353
  }
355
354
  /**
356
- * build options for `vite-plugin-electron/simple`
355
+ * Base on `vite-plugin-electron/simple`
357
356
  * - integrate with updater
358
- * - only contains `main` and `preload` configs
359
- * - remove old electron files
357
+ * - no `renderer` config
358
+ * - remove old output file
360
359
  * - externalize dependencies
361
360
  * - auto restart when entry file changes
362
361
  * - 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
362
  *
365
- * you can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
363
+ * You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
366
364
  *
367
365
  * @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
366
  */
403
367
  declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
404
368
 
405
- export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };
369
+ export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater as default, electronWithUpdater };