electron-incremental-update 0.9.1 → 1.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/utils.mjs CHANGED
@@ -1,41 +1,35 @@
1
1
  import {
2
- DEFAULT_APP_NAME,
3
- NoSuchNativeModuleError,
4
2
  disableHWAccForWin7,
5
- getAppVersion,
6
- getElectronVersion,
7
- getLocale,
8
- getProductAsarPath,
9
- handleUnexpectedErrors,
3
+ getPathFromAppNameAsar,
4
+ getPaths,
5
+ getVersions,
10
6
  is,
11
- isNoSuchNativeModuleError,
12
- parseGithubCdnURL,
13
- requireNative,
7
+ loadNativeModuleFromEntry,
14
8
  restartApp,
15
9
  setAppUserModelId,
16
10
  setPortableAppDataPath,
17
11
  singleInstance,
18
12
  waitAppReady
19
- } from "./chunk-SPZL37O5.mjs";
13
+ } from "./chunk-OUZLSVQC.mjs";
20
14
  import {
15
+ handleUnexpectedErrors,
16
+ isUpdateJSON,
17
+ parseGithubCdnURL,
21
18
  parseVersion,
22
19
  unzipFile,
23
20
  zipFile
24
- } from "./chunk-CMBFI77K.mjs";
21
+ } from "./chunk-GB6VLKJZ.mjs";
25
22
  export {
26
- DEFAULT_APP_NAME,
27
- NoSuchNativeModuleError,
28
23
  disableHWAccForWin7,
29
- getAppVersion,
30
- getElectronVersion,
31
- getLocale,
32
- getProductAsarPath,
24
+ getPathFromAppNameAsar,
25
+ getPaths,
26
+ getVersions,
33
27
  handleUnexpectedErrors,
34
28
  is,
35
- isNoSuchNativeModuleError,
29
+ isUpdateJSON,
30
+ loadNativeModuleFromEntry,
36
31
  parseGithubCdnURL,
37
32
  parseVersion,
38
- requireNative,
39
33
  restartApp,
40
34
  setAppUserModelId,
41
35
  setPortableAppDataPath,
package/dist/vite.d.mts CHANGED
@@ -1,6 +1,14 @@
1
1
  import { Plugin } from 'vite';
2
- import { U as UpdateJSON } from './updateJson-synsK-Pt.mjs';
2
+ import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
3
+ import { Promisable, Prettify } from '@subframe7536/type-utils';
4
+ import { BuildOptions } from 'esbuild';
5
+ import { a as UpdateJSON } from './noDep-TvZoKVF8.mjs';
3
6
 
7
+ type PKG = {
8
+ name: string;
9
+ version: string;
10
+ main: string;
11
+ };
4
12
  type DistinguishedName = {
5
13
  countryName?: string;
6
14
  stateOrProvinceName?: string;
@@ -14,6 +22,85 @@ type DistinguishedName = {
14
22
  businessCategory?: string;
15
23
  emailAddress?: string;
16
24
  };
25
+ type BuildEntryOption = {
26
+ /**
27
+ * whether to minify
28
+ * @default isBuild
29
+ */
30
+ minify: boolean;
31
+ /**
32
+ * Whether to generate sourcemap
33
+ * @default isBuild
34
+ */
35
+ sourcemap: boolean;
36
+ /**
37
+ * path to app entry output file
38
+ * @default 'dist-entry'
39
+ */
40
+ entryOutputDirPath: string;
41
+ /**
42
+ * path to app entry file
43
+ * @default 'electron/entry.ts'
44
+ */
45
+ appEntryPath: string;
46
+ /**
47
+ * esbuild path map of native modules in entry directory
48
+ *
49
+ * @default {}
50
+ * @example
51
+ * { db: './electron/native/db.ts' }
52
+ */
53
+ nativeModuleEntryMap?: Record<string, string>;
54
+ /**
55
+ * custom options for esbuild
56
+ * ```ts
57
+ * // default options
58
+ * const options = {
59
+ * entryPoints: {
60
+ * entry: appEntryPath,
61
+ * ...moduleEntryMap,
62
+ * },
63
+ * bundle: true,
64
+ * platform: 'node',
65
+ * outdir: entryOutputDirPath,
66
+ * minify,
67
+ * sourcemap,
68
+ * entryNames: '[dir]/[name]',
69
+ * assetNames: '[dir]/[name]',
70
+ * external: ['electron', 'original-fs'],
71
+ * loader: {
72
+ * '.node': 'empty',
73
+ * },
74
+ * }
75
+ * ```
76
+ */
77
+ overrideEsbuildOptions?: BuildOptions;
78
+ /**
79
+ * resolve extra files, such as `.node`
80
+ */
81
+ postBuild?: (args: {
82
+ /**
83
+ * get path from `entryOutputDirPath`
84
+ */
85
+ getPathFromEntryOutputDir: (...paths: string[]) => string;
86
+ /**
87
+ * copy file to `entryOutputDirPath`
88
+ *
89
+ * if `to` absent, set to `basename(from)`
90
+ *
91
+ * if `skipIfExist` absent, skip copy if `to` exist
92
+ */
93
+ existsAndCopyToEntryOutputDir: (options: {
94
+ from: string;
95
+ to?: string;
96
+ /**
97
+ * skip copy if `to` exist
98
+ * @default true
99
+ */
100
+ skipIfExist?: boolean;
101
+ }) => void;
102
+ }) => Promisable<void>;
103
+ };
17
104
  type GeneratorOverrideFunctions = {
18
105
  /**
19
106
  * custom signature generate function
@@ -34,49 +121,23 @@ type GeneratorOverrideFunctions = {
34
121
  */
35
122
  generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
36
123
  };
37
- type Options = {
38
- /**
39
- * whether is in build mode
40
- */
41
- isBuild: boolean;
42
- /**
43
- * the name of you application
44
- *
45
- * you can set as 'name' in `package.json`
46
- */
47
- productName: string;
48
- /**
49
- * the version of you application
50
- *
51
- * you can set as 'version' in `package.json`
52
- */
53
- version: string;
124
+ type ElectronUpdaterOptions = {
54
125
  /**
55
126
  * mini version of entry
56
- * @default version
127
+ * @default '0.0.0'
57
128
  */
58
129
  minimumVersion?: string;
59
130
  /**
60
- * Whether to minify entry file
131
+ * config for entry (app.asar)
61
132
  */
62
- minify?: boolean;
133
+ entry?: Partial<BuildEntryOption>;
63
134
  /**
64
135
  * paths config
65
136
  */
66
137
  paths?: {
67
- /**
68
- * Path to app entry file
69
- * @default 'electron/app.ts'
70
- */
71
- entryPath?: string;
72
- /**
73
- * Path to app entry output file
74
- * @default 'app.js'
75
- */
76
- entryOutputPath?: string;
77
138
  /**
78
139
  * Path to asar file
79
- * @default `release/${productName}.asar`
140
+ * @default `release/${app.name}.asar`
80
141
  */
81
142
  asarOutputPath?: string;
82
143
  /**
@@ -86,7 +147,7 @@ type Options = {
86
147
  versionPath?: string;
87
148
  /**
88
149
  * Path to gzipped asar file
89
- * @default `release/${productName}-${version}.asar.gz`
150
+ * @default `release/${app.name}-${version}.asar.gz`
90
151
  */
91
152
  gzipPath?: string;
92
153
  /**
@@ -105,19 +166,23 @@ type Options = {
105
166
  */
106
167
  keys?: {
107
168
  /**
108
- * Path to the pem file that contains private key
169
+ * path to the pem file that contains private key
109
170
  * if not ended with .pem, it will be appended
171
+ *
172
+ * **if `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
110
173
  * @default 'keys/private.pem'
111
174
  */
112
175
  privateKeyPath?: string;
113
176
  /**
114
- * Path to the pem file that contains public key
177
+ * path to the pem file that contains public key
115
178
  * if not ended with .pem, it will be appended
179
+ *
180
+ * **if `UPDATER_CERT` is set, will read it instead of read from `certPath`**
116
181
  * @default 'keys/cert.pem'
117
182
  */
118
183
  certPath?: string;
119
184
  /**
120
- * Length of the key
185
+ * length of the key
121
186
  * @default 2048
122
187
  */
123
188
  keyLength?: number;
@@ -130,20 +195,132 @@ type Options = {
130
195
  /**
131
196
  * the subject of the certificate
132
197
  *
133
- * @default { commonName: productName, organizationName: `org.${productName}` }
198
+ * @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
134
199
  */
135
200
  subject?: DistinguishedName;
136
201
  /**
137
202
  * expire days of the certificate
138
203
  *
139
- * @default 365
204
+ * @default 3650
140
205
  */
141
206
  days?: number;
142
207
  };
143
- overrideFunctions?: GeneratorOverrideFunctions;
208
+ overrideGenerator?: GeneratorOverrideFunctions;
144
209
  };
145
210
  };
146
211
 
147
- declare function ElectronUpdater(options: Options): Plugin;
212
+ type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
213
+ [P in K]-?: T[P];
214
+ };
215
+ type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
216
+ [P in NewKey]: T[Key];
217
+ };
218
+ type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
219
+ /**
220
+ * startup function for debug (see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template})
221
+ * @example
222
+ * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
223
+ * const options = buildElectronPluginOptions({
224
+ * // ...
225
+ * main: {
226
+ * // ...
227
+ * startup: debugStartup
228
+ * },
229
+ * })
230
+ */
231
+ declare function debugStartup(args: {
232
+ startup: (argv?: string[]) => Promise<void>;
233
+ reload: () => void;
234
+ }): void;
235
+ type ElectronWithUpdaterOptions = {
236
+ /**
237
+ * whether is in build mode
238
+ * ```ts
239
+ * export default defineConfig(({ command }) => {
240
+ * const isBuild = command === 'build'
241
+ * })
242
+ * ```
243
+ */
244
+ isBuild: boolean;
245
+ /**
246
+ * name, version and main in `package.json`
247
+ * ```ts
248
+ * import pkg from './package.json'
249
+ * ```
250
+ */
251
+ pkg: PKG;
252
+ /**
253
+ * main options
254
+ */
255
+ main: Prettify<MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'>>;
256
+ /**
257
+ * preload options
258
+ */
259
+ preload: Prettify<MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'>>;
260
+ /**
261
+ * updater options
262
+ */
263
+ updater?: ElectronUpdaterOptions;
264
+ /**
265
+ * use NotBundle() plugin in main
266
+ * @default true
267
+ */
268
+ useNotBundle?: boolean;
269
+ /**
270
+ * Whether to log parsed options
271
+ */
272
+ logParsedOptions?: boolean;
273
+ };
274
+ /**
275
+ * build options for `vite-plugin-electron/simple`
276
+ * - integrate with updater
277
+ * - only contains `main` and `preload` configs
278
+ * - remove old electron files
279
+ * - externalize dependencies
280
+ * - auto restart when entry file changes
281
+ * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
282
+ * - no `vite-plugin-electron-renderer` config
283
+ *
284
+ * you can override all the configs
285
+ *
286
+ * **Limitation**: entry file change cannot trigger auto restart
287
+ *
288
+ * @example
289
+ * import { defineConfig } from 'vite'
290
+ * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
291
+ * import pkg from './package.json'
292
+ *
293
+ * export default defineConfig(async ({ command }) => {
294
+ * const isBuild = command === 'build'
295
+ * return {
296
+ * plugins: [
297
+ * electronWithUpdater({
298
+ * pkg,
299
+ * isBuild,
300
+ * logParsedOptions: true,
301
+ * main: {
302
+ * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
303
+ * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
304
+ * onstart: debugStartup,
305
+ * },
306
+ * preload: {
307
+ * files: './electron/preload/index.ts',
308
+ * },
309
+ * updater: {
310
+ * // options
311
+ * }
312
+ * }),
313
+ * ],
314
+ * server: process.env.VSCODE_DEBUG && (() => {
315
+ * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
316
+ * return {
317
+ * host: url.hostname,
318
+ * port: +url.port,
319
+ * }
320
+ * })(),
321
+ * }
322
+ * })
323
+ */
324
+ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[];
148
325
 
149
- export { ElectronUpdater, type Options };
326
+ export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };