electron-incremental-update 2.0.0-beta.9 → 2.0.1

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,19 @@ 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
+ * Custom electron binary path
242
+ */
243
+ electronPath?: string;
244
+ /**
245
+ * Before transformed code compile function. If return `Falsy` value, it will be ignored
244
246
  * @param code transformed code
245
247
  * @param id file path
246
248
  */
247
- beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined>;
249
+ beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
248
250
  }
249
251
 
250
252
  type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
@@ -284,7 +286,7 @@ type ExcludeOutputDirOptions = {
284
286
  };
285
287
  interface ElectronWithUpdaterOptions {
286
288
  /**
287
- * whether is in build mode
289
+ * Whether is in build mode
288
290
  * ```ts
289
291
  * export default defineConfig(({ command }) => {
290
292
  * const isBuild = command === 'build'
@@ -293,113 +295,79 @@ interface ElectronWithUpdaterOptions {
293
295
  */
294
296
  isBuild: boolean;
295
297
  /**
296
- * manually setup package.json, read name, version and main
298
+ * Manually setup package.json, read name, version and main,
299
+ * use `local-pkg` of `loadPackageJSON()` to load package.json by default
297
300
  * ```ts
298
301
  * import pkg from './package.json'
299
302
  * ```
300
303
  */
301
304
  pkg?: PKG;
302
305
  /**
303
- * whether to generate sourcemap
306
+ * Whether to generate sourcemap
304
307
  * @default !isBuild
305
308
  */
306
309
  sourcemap?: boolean;
307
310
  /**
308
- * whether to minify the code
311
+ * Whether to minify the code
309
312
  * @default isBuild
310
313
  */
311
314
  minify?: boolean;
312
315
  /**
313
- * whether to generate bytecode
316
+ * Whether to generate bytecode
314
317
  *
315
- * **only support commonjs**
318
+ * **Only support CommonJS**
316
319
  *
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
320
+ * 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
321
  */
319
322
  bytecode?: boolean | BytecodeOptions;
320
323
  /**
321
- * use NotBundle() plugin in main
324
+ * Use `NotBundle()` plugin in main
322
325
  * @default true
323
326
  */
324
327
  useNotBundle?: boolean;
325
328
  /**
326
- * whether to generate version json
329
+ * Whether to generate version json
327
330
  * @default isCI
328
331
  */
329
332
  buildVersionJson?: boolean;
330
333
  /**
331
334
  * Whether to log parsed options
332
335
  *
333
- * to show certificate and private keys, set `logParsedOptions: { showKeys: true }`
336
+ * To show certificate and private keys, set `logParsedOptions: { showKeys: true }`
334
337
  */
335
338
  logParsedOptions?: boolean | {
336
339
  showKeys: boolean;
337
340
  };
338
341
  /**
339
- * main process options
342
+ * Main process options
340
343
  *
341
- * to change output directories, use `options.updater.paths.electronDistPath` instead
344
+ * To change output directories, use `options.updater.paths.electronDistPath` instead
342
345
  */
343
346
  main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
344
347
  /**
345
- * preload process options
348
+ * Preload process options
346
349
  *
347
- * to change output directories, use `options.updater.paths.electronDistPath` instead
350
+ * To change output directories, use `options.updater.paths.electronDistPath` instead
348
351
  */
349
352
  preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
350
353
  /**
351
- * updater options
354
+ * Updater options
352
355
  */
353
356
  updater?: ElectronUpdaterOptions;
354
357
  }
355
358
  /**
356
- * build options for `vite-plugin-electron/simple`
359
+ * Base on `vite-plugin-electron/simple`
357
360
  * - integrate with updater
358
- * - only contains `main` and `preload` configs
359
- * - remove old electron files
361
+ * - no `renderer` config
362
+ * - remove old output file
360
363
  * - externalize dependencies
361
364
  * - auto restart when entry file changes
362
365
  * - 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
366
  *
365
- * you can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
367
+ * You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
366
368
  *
367
369
  * @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
370
  */
403
371
  declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
404
372
 
405
- export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };
373
+ export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater as default, electronWithUpdater };