electron-incremental-update 3.0.0-beta.6 → 3.1.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.
@@ -27,6 +27,11 @@ interface Version {
27
27
  }
28
28
  /**
29
29
  * Parse version string to {@link Version}, like `0.2.0-beta.1`
30
+ *
31
+ * **Supported format**: `major.minor.patch[-stage[.stageVersion]]`
32
+ *
33
+ * Build metadata (`+build`) and complex semver prerelease identifiers
34
+ * (e.g. `1.0.0-beta.1.2`) are not supported yet.
30
35
  * @param version version string
31
36
  */
32
37
  declare function parseVersion(version: string): Version;
@@ -138,7 +143,7 @@ interface IProvider {
138
143
  * Function to decompress file using brotli
139
144
  * @param buffer compressed file buffer
140
145
  */
141
- unzipFile: (buffer: Buffer) => Promise<Buffer>;
146
+ decompressFile: (buffer: Buffer) => Promise<Buffer>;
142
147
  /**
143
148
  * Verify asar signature,
144
149
  * if signature is valid, returns the version, otherwise returns `undefined`
@@ -147,8 +152,18 @@ interface IProvider {
147
152
  * @param signature signature
148
153
  * @param cert certificate
149
154
  */
150
- verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
155
+ verifySignature: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
151
156
  }
157
+ /**
158
+ * Custom URL handler for GitHub provider, useful for mirrors and custom gateways
159
+ * @param url original URL
160
+ * @example
161
+ * (url) => {
162
+ * url.hostname = 'mirror.ghproxy.com'
163
+ * url.pathname = 'https://github.com' + url.pathname
164
+ * return url
165
+ * }
166
+ */
152
167
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
153
168
  //#endregion
154
169
  export { VersionJSON as a, Version as c, isUpdateJSON as d, parseVersion as f, UpdateInfoWithURL as i, defaultIsLowerVersion as l, Promisable as m, IProvider as n, UpdateInfo as o, Arrayable as p, URLHandler as r, UpdateJSON as s, DownloadingInfo as t, defaultVersionJsonGenerator as u };
@@ -27,6 +27,11 @@ interface Version {
27
27
  }
28
28
  /**
29
29
  * Parse version string to {@link Version}, like `0.2.0-beta.1`
30
+ *
31
+ * **Supported format**: `major.minor.patch[-stage[.stageVersion]]`
32
+ *
33
+ * Build metadata (`+build`) and complex semver prerelease identifiers
34
+ * (e.g. `1.0.0-beta.1.2`) are not supported yet.
30
35
  * @param version version string
31
36
  */
32
37
  declare function parseVersion(version: string): Version;
@@ -138,7 +143,7 @@ interface IProvider {
138
143
  * Function to decompress file using brotli
139
144
  * @param buffer compressed file buffer
140
145
  */
141
- unzipFile: (buffer: Buffer) => Promise<Buffer>;
146
+ decompressFile: (buffer: Buffer) => Promise<Buffer>;
142
147
  /**
143
148
  * Verify asar signature,
144
149
  * if signature is valid, returns the version, otherwise returns `undefined`
@@ -147,8 +152,18 @@ interface IProvider {
147
152
  * @param signature signature
148
153
  * @param cert certificate
149
154
  */
150
- verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
155
+ verifySignature: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
151
156
  }
157
+ /**
158
+ * Custom URL handler for GitHub provider, useful for mirrors and custom gateways
159
+ * @param url original URL
160
+ * @example
161
+ * (url) => {
162
+ * url.hostname = 'mirror.ghproxy.com'
163
+ * url.pathname = 'https://github.com' + url.pathname
164
+ * return url
165
+ * }
166
+ */
152
167
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
153
168
  //#endregion
154
169
  export { VersionJSON as a, Version as c, isUpdateJSON as d, parseVersion as f, UpdateInfoWithURL as i, defaultIsLowerVersion as l, Promisable as m, IProvider as n, UpdateInfo as o, Arrayable as p, URLHandler as r, UpdateJSON as s, DownloadingInfo as t, defaultVersionJsonGenerator as u };
package/dist/utils.cjs CHANGED
@@ -1,19 +1,19 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_zip = require("./zip-D1dbBzw4.cjs");
3
- const require_electron = require("./electron-D_8AbLQ5.cjs");
4
- const require_download = require("./download-BYnkme_X.cjs");
5
- exports.aesDecrypt = require_zip.aesDecrypt;
6
- exports.aesEncrypt = require_zip.aesEncrypt;
2
+ const require_crypto = require("./crypto-BSky88mL.cjs");
3
+ const require_electron = require("./electron-CaS0I3S2.cjs");
4
+ const require_download = require("./download-KySXUyWC.cjs");
5
+ exports.aesDecrypt = require_crypto.aesDecrypt;
6
+ exports.aesEncrypt = require_crypto.aesEncrypt;
7
7
  exports.beautifyDevTools = require_electron.beautifyDevTools;
8
+ exports.defaultCompressFile = require_crypto.defaultCompressFile;
9
+ exports.defaultDecompressFile = require_crypto.defaultDecompressFile;
8
10
  exports.defaultDownloadAsar = require_download.defaultDownloadAsar;
9
11
  exports.defaultDownloadText = require_download.defaultDownloadText;
10
12
  exports.defaultDownloadUpdateJSON = require_download.defaultDownloadUpdateJSON;
11
- exports.defaultIsLowerVersion = require_zip.defaultIsLowerVersion;
12
- exports.defaultSignature = require_zip.defaultSignature;
13
- exports.defaultUnzipFile = require_zip.defaultUnzipFile;
14
- exports.defaultVerifySignature = require_zip.defaultVerifySignature;
15
- exports.defaultVersionJsonGenerator = require_zip.defaultVersionJsonGenerator;
16
- exports.defaultZipFile = require_zip.defaultZipFile;
13
+ exports.defaultIsLowerVersion = require_crypto.defaultIsLowerVersion;
14
+ exports.defaultSignature = require_crypto.defaultSignature;
15
+ exports.defaultVerifySignature = require_crypto.defaultVerifySignature;
16
+ exports.defaultVersionJsonGenerator = require_crypto.defaultVersionJsonGenerator;
17
17
  exports.disableHWAccForWin7 = require_electron.disableHWAccForWin7;
18
18
  exports.downloadUtil = require_download.downloadUtil;
19
19
  exports.getAppVersion = require_electron.getAppVersion;
@@ -25,15 +25,15 @@ exports.getPathFromMain = require_electron.getPathFromMain;
25
25
  exports.getPathFromPreload = require_electron.getPathFromPreload;
26
26
  exports.getPathFromPublic = require_electron.getPathFromPublic;
27
27
  exports.handleUnexpectedErrors = require_electron.handleUnexpectedErrors;
28
- exports.hashBuffer = require_zip.hashBuffer;
28
+ exports.hashBuffer = require_crypto.hashBuffer;
29
29
  exports.importNative = require_electron.importNative;
30
30
  exports.isDev = require_electron.isDev;
31
31
  exports.isLinux = require_electron.isLinux;
32
32
  exports.isMac = require_electron.isMac;
33
- exports.isUpdateJSON = require_zip.isUpdateJSON;
33
+ exports.isUpdateJSON = require_crypto.isUpdateJSON;
34
34
  exports.isWin = require_electron.isWin;
35
35
  exports.loadPage = require_electron.loadPage;
36
- exports.parseVersion = require_zip.parseVersion;
36
+ exports.parseVersion = require_crypto.parseVersion;
37
37
  exports.reloadOnPreloadScriptChanged = require_electron.reloadOnPreloadScriptChanged;
38
38
  exports.requireNative = require_electron.requireNative;
39
39
  exports.resolveJson = require_download.resolveJson;
package/dist/utils.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as Version, d as isUpdateJSON, f as parseVersion, l as defaultIsLowerVersion, o as UpdateInfo, s as UpdateJSON, u as defaultVersionJsonGenerator } from "./types-BOqQ_r5Q.cjs";
2
- import { a as getHeader, i as downloadUtil, n as defaultDownloadText, o as resolveJson, r as defaultDownloadUpdateJSON, t as defaultDownloadAsar } from "./download-BjWmHHAu.cjs";
1
+ import { c as Version, d as isUpdateJSON, f as parseVersion, l as defaultIsLowerVersion, o as UpdateInfo, s as UpdateJSON, u as defaultVersionJsonGenerator } from "./types-q78spjKB.cjs";
2
+ import { a as getHeader, i as downloadUtil, n as defaultDownloadText, o as resolveJson, r as defaultDownloadUpdateJSON, t as defaultDownloadAsar } from "./download-BVmLiAvB.cjs";
3
3
  import { BrowserWindow } from "electron";
4
4
 
5
5
  //#region src/utils/crypto.d.ts
@@ -149,16 +149,16 @@ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
149
149
  */
150
150
  declare function reloadOnPreloadScriptChanged(): void;
151
151
  //#endregion
152
- //#region src/utils/zip.d.ts
152
+ //#region src/utils/compress.d.ts
153
153
  /**
154
154
  * Default function to compress file using brotli
155
155
  * @param buffer uncompressed file buffer
156
156
  */
157
- declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
157
+ declare function defaultCompressFile(buffer: Buffer): Promise<Buffer>;
158
158
  /**
159
159
  * Default function to decompress file using brotli
160
160
  * @param buffer compressed file buffer
161
161
  */
162
- declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
162
+ declare function defaultDecompressFile(buffer: Buffer): Promise<Buffer>;
163
163
  //#endregion
164
- export { UpdateInfo, UpdateJSON, Version, aesDecrypt, aesEncrypt, beautifyDevTools, defaultDownloadAsar, defaultDownloadText, defaultDownloadUpdateJSON, defaultIsLowerVersion, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultVersionJsonGenerator, defaultZipFile, disableHWAccForWin7, downloadUtil, getAppVersion, getEntryVersion, getHeader, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, hashBuffer, importNative, isDev, isLinux, isMac, isUpdateJSON, isWin, loadPage, parseVersion, reloadOnPreloadScriptChanged, requireNative, resolveJson, restartApp, setAppUserModelId, setPortableAppDataPath, setPortableDataPath, singleInstance };
164
+ export { UpdateInfo, UpdateJSON, Version, aesDecrypt, aesEncrypt, beautifyDevTools, defaultCompressFile, defaultDecompressFile, defaultDownloadAsar, defaultDownloadText, defaultDownloadUpdateJSON, defaultIsLowerVersion, defaultSignature, defaultVerifySignature, defaultVersionJsonGenerator, disableHWAccForWin7, downloadUtil, getAppVersion, getEntryVersion, getHeader, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, hashBuffer, importNative, isDev, isLinux, isMac, isUpdateJSON, isWin, loadPage, parseVersion, reloadOnPreloadScriptChanged, requireNative, resolveJson, restartApp, setAppUserModelId, setPortableAppDataPath, setPortableDataPath, singleInstance };
package/dist/utils.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as Version, d as isUpdateJSON, f as parseVersion, l as defaultIsLowerVersion, o as UpdateInfo, s as UpdateJSON, u as defaultVersionJsonGenerator } from "./types-BOqQ_r5Q.mjs";
2
- import { a as getHeader, i as downloadUtil, n as defaultDownloadText, o as resolveJson, r as defaultDownloadUpdateJSON, t as defaultDownloadAsar } from "./download-DVWJfV3S.mjs";
1
+ import { c as Version, d as isUpdateJSON, f as parseVersion, l as defaultIsLowerVersion, o as UpdateInfo, s as UpdateJSON, u as defaultVersionJsonGenerator } from "./types-q78spjKB.mjs";
2
+ import { a as getHeader, i as downloadUtil, n as defaultDownloadText, o as resolveJson, r as defaultDownloadUpdateJSON, t as defaultDownloadAsar } from "./download-GONr15zK.mjs";
3
3
  import { BrowserWindow } from "electron";
4
4
 
5
5
  //#region src/utils/crypto.d.ts
@@ -149,16 +149,16 @@ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
149
149
  */
150
150
  declare function reloadOnPreloadScriptChanged(): void;
151
151
  //#endregion
152
- //#region src/utils/zip.d.ts
152
+ //#region src/utils/compress.d.ts
153
153
  /**
154
154
  * Default function to compress file using brotli
155
155
  * @param buffer uncompressed file buffer
156
156
  */
157
- declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
157
+ declare function defaultCompressFile(buffer: Buffer): Promise<Buffer>;
158
158
  /**
159
159
  * Default function to decompress file using brotli
160
160
  * @param buffer compressed file buffer
161
161
  */
162
- declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
162
+ declare function defaultDecompressFile(buffer: Buffer): Promise<Buffer>;
163
163
  //#endregion
164
- export { UpdateInfo, UpdateJSON, Version, aesDecrypt, aesEncrypt, beautifyDevTools, defaultDownloadAsar, defaultDownloadText, defaultDownloadUpdateJSON, defaultIsLowerVersion, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultVersionJsonGenerator, defaultZipFile, disableHWAccForWin7, downloadUtil, getAppVersion, getEntryVersion, getHeader, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, hashBuffer, importNative, isDev, isLinux, isMac, isUpdateJSON, isWin, loadPage, parseVersion, reloadOnPreloadScriptChanged, requireNative, resolveJson, restartApp, setAppUserModelId, setPortableAppDataPath, setPortableDataPath, singleInstance };
164
+ export { UpdateInfo, UpdateJSON, Version, aesDecrypt, aesEncrypt, beautifyDevTools, defaultCompressFile, defaultDecompressFile, defaultDownloadAsar, defaultDownloadText, defaultDownloadUpdateJSON, defaultIsLowerVersion, defaultSignature, defaultVerifySignature, defaultVersionJsonGenerator, disableHWAccForWin7, downloadUtil, getAppVersion, getEntryVersion, getHeader, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, hashBuffer, importNative, isDev, isLinux, isMac, isUpdateJSON, isWin, loadPage, parseVersion, reloadOnPreloadScriptChanged, requireNative, resolveJson, restartApp, setAppUserModelId, setPortableAppDataPath, setPortableDataPath, singleInstance };
package/dist/utils.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as defaultSignature, c as defaultIsLowerVersion, d as parseVersion, i as aesEncrypt, l as defaultVersionJsonGenerator, n as defaultZipFile, o as defaultVerifySignature, r as aesDecrypt, s as hashBuffer, t as defaultUnzipFile, u as isUpdateJSON } from "./zip-DUK3opmV.mjs";
2
- import { C as singleInstance, S as setPortableDataPath, _ as reloadOnPreloadScriptChanged, a as getPathFromAppNameAsar, b as setAppUserModelId, c as getPathFromPreload, d as importNative, f as isDev, g as loadPage, h as isWin, i as getEntryVersion, l as getPathFromPublic, m as isMac, n as disableHWAccForWin7, o as getPathFromEntryAsar, p as isLinux, r as getAppVersion, s as getPathFromMain, t as beautifyDevTools, u as handleUnexpectedErrors, v as requireNative, x as setPortableAppDataPath, y as restartApp } from "./electron-BInvFJ-W.mjs";
3
- import { a as getHeader, i as downloadUtil, n as defaultDownloadText, o as resolveJson, r as defaultDownloadUpdateJSON, t as defaultDownloadAsar } from "./download-BGaAyi1Z.mjs";
4
- export { aesDecrypt, aesEncrypt, beautifyDevTools, defaultDownloadAsar, defaultDownloadText, defaultDownloadUpdateJSON, defaultIsLowerVersion, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultVersionJsonGenerator, defaultZipFile, disableHWAccForWin7, downloadUtil, getAppVersion, getEntryVersion, getHeader, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, hashBuffer, importNative, isDev, isLinux, isMac, isUpdateJSON, isWin, loadPage, parseVersion, reloadOnPreloadScriptChanged, requireNative, resolveJson, restartApp, setAppUserModelId, setPortableAppDataPath, setPortableDataPath, singleInstance };
1
+ import { a as hashBuffer, c as defaultIsLowerVersion, d as parseVersion, i as defaultVerifySignature, l as defaultVersionJsonGenerator, n as aesEncrypt, o as defaultCompressFile, r as defaultSignature, s as defaultDecompressFile, t as aesDecrypt, u as isUpdateJSON } from "./crypto-DZzMmoz2.mjs";
2
+ import { C as singleInstance, S as setPortableDataPath, _ as reloadOnPreloadScriptChanged, a as getPathFromAppNameAsar, b as setAppUserModelId, c as getPathFromPreload, d as importNative, f as isDev, g as loadPage, h as isWin, i as getEntryVersion, l as getPathFromPublic, m as isMac, n as disableHWAccForWin7, o as getPathFromEntryAsar, p as isLinux, r as getAppVersion, s as getPathFromMain, t as beautifyDevTools, u as handleUnexpectedErrors, v as requireNative, x as setPortableAppDataPath, y as restartApp } from "./electron-BrIF1urZ.mjs";
3
+ import { a as getHeader, i as downloadUtil, n as defaultDownloadText, o as resolveJson, r as defaultDownloadUpdateJSON, t as defaultDownloadAsar } from "./download-BdX4fZYM.mjs";
4
+ export { aesDecrypt, aesEncrypt, beautifyDevTools, defaultCompressFile, defaultDecompressFile, defaultDownloadAsar, defaultDownloadText, defaultDownloadUpdateJSON, defaultIsLowerVersion, defaultSignature, defaultVerifySignature, defaultVersionJsonGenerator, disableHWAccForWin7, downloadUtil, getAppVersion, getEntryVersion, getHeader, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, hashBuffer, importNative, isDev, isLinux, isMac, isUpdateJSON, isWin, loadPage, parseVersion, reloadOnPreloadScriptChanged, requireNative, resolveJson, restartApp, setAppUserModelId, setPortableAppDataPath, setPortableDataPath, singleInstance };
package/dist/vite.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Plugin, UserConfig } from "vite";
2
2
  import { MultiEnvElectronOptions } from "vite-plugin-electron/multi-env";
3
- import { RolldownOrRollupOptions } from "vite-plugin-electron";
4
3
 
5
4
  //#region src/utils/type.d.ts
6
5
  type Promisable<T> = T | Promise<T>;
@@ -124,7 +123,12 @@ interface CommonBuildOption {
124
123
  };
125
124
  };
126
125
  }
127
- interface ElectronWithUpdaterOptions {
126
+ interface ElectronWithUpdaterOptions extends Pick<MultiEnvElectronOptions, "bundleDeps"> {
127
+ /**
128
+ * `electron-incremental-update` and its subpath imports are always bundled,
129
+ * regardless of this dependency policy.
130
+ */
131
+ bundleDeps?: MultiEnvElectronOptions["bundleDeps"];
128
132
  /**
129
133
  * Whether to generate sourcemap
130
134
  * @default !isBuild || !!process.env.VSCODE_DEBUG
@@ -144,17 +148,6 @@ interface ElectronWithUpdaterOptions {
144
148
  */
145
149
  bytecode?: boolean | BytecodeOptions;
146
150
  /**
147
- * Faster dev startup by externalize all node modules in entry and main.
148
- *
149
- * Only works in development (`isBuild === false`).
150
- * @default true
151
- */
152
- notBundle?: boolean | RolldownOrRollupOptions["external"];
153
- /**
154
- * @deprecated use `notBundle` instead
155
- */
156
- useNotBundle?: boolean;
157
- /**
158
151
  * Whether to generate version json
159
152
  * @default isCI
160
153
  */
@@ -271,7 +264,7 @@ interface LocalDevUpdateOptions {
271
264
  * Directory that contains local update resources.
272
265
  *
273
266
  * The generated version file is written under `{baseDir}/{versionPath}` and
274
- * update archives are written as `{baseDir}/{name}-{version}.asar.gz`.
267
+ * update archives are written as `{baseDir}/{name}-{version}.asar.br`.
275
268
  *
276
269
  * @default 'release/local-update'
277
270
  */
@@ -315,10 +308,10 @@ interface UpdaterOptions {
315
308
  */
316
309
  versionPath?: string;
317
310
  /**
318
- * Path to gzipped asar file
319
- * @default `release/${app.name}-${version}.asar.gz`
311
+ * Path to compressed asar file
312
+ * @default `release/${app.name}-${version}.asar.br`
320
313
  */
321
- gzipPath?: string;
314
+ compressedPath?: string;
322
315
  /**
323
316
  * Path to electron build output
324
317
  * @default `dist-electron`
@@ -395,10 +388,10 @@ interface GeneratorOverrideFunctions {
395
388
  */
396
389
  generateUpdateJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => Promisable<UpdateJSON>;
397
390
  /**
398
- * Custom generate zip file buffer
391
+ * Custom generate compressed file buffer
399
392
  * @param buffer source buffer
400
393
  */
401
- generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
394
+ generateCompressedFile?: (buffer: Buffer) => Promisable<Buffer>;
402
395
  }
403
396
  //#endregion
404
397
  //#region src/vite/core.d.ts
@@ -442,10 +435,15 @@ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promi
442
435
  //#endregion
443
436
  //#region src/vite/define.d.ts
444
437
  interface ElectronViteHelperOptions extends ElectronWithUpdaterOptions {
438
+ /**
439
+ * Root dir of project
440
+ * @default process.cwd()
441
+ */
442
+ root?: string;
445
443
  /**
446
444
  * Config for renderer process
447
445
  */
448
- renderer?: UserConfig;
446
+ renderer?: Omit<UserConfig, "root">;
449
447
  }
450
448
  /**
451
449
  * Vite config helper
@@ -455,6 +453,7 @@ interface ElectronViteHelperOptions extends ElectronWithUpdaterOptions {
455
453
  * import { defineElectronConfig } from 'electron-incremental-update/vite'
456
454
  *
457
455
  * export default defineElectronConfig({
456
+ * // root: './apps'
458
457
  * main: {
459
458
  * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
460
459
  * },
@@ -465,13 +464,7 @@ interface ElectronViteHelperOptions extends ElectronWithUpdaterOptions {
465
464
  * // options
466
465
  * },
467
466
  * renderer: {
468
- * server: process.env.VSCODE_DEBUG && (() => {
469
- * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
470
- * return {
471
- * host: url.hostname,
472
- * port: +url.port,
473
- * }
474
- * })(),
467
+ * // plugins: []
475
468
  * }
476
469
  * })
477
470
  * ```
package/dist/vite.mjs CHANGED
@@ -5,8 +5,8 @@ import { isCI } from "ci-info";
5
5
  import { createLogger, mergeConfig, normalizePath } from "vite";
6
6
  import { electronPluginFactory } from "vite-plugin-electron/multi-env";
7
7
  import { esmShim } from "vite-plugin-electron/plugin";
8
- import crypto from "node:crypto";
9
8
  import zlib from "node:zlib";
9
+ import crypto from "node:crypto";
10
10
  import cp from "node:child_process";
11
11
  import * as babel from "@babel/core";
12
12
  import { copyFile, cp as cp$1, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
@@ -41,6 +41,20 @@ function fixWinCharEncoding(fn) {
41
41
  });
42
42
  }
43
43
  //#endregion
44
+ //#region package.json
45
+ var name = "electron-incremental-update";
46
+ //#endregion
47
+ //#region src/utils/compress.ts
48
+ /**
49
+ * Default function to compress file using brotli
50
+ * @param buffer uncompressed file buffer
51
+ */
52
+ async function defaultCompressFile(buffer) {
53
+ return new Promise((resolve, reject) => {
54
+ zlib.brotliCompress(buffer, (err, buffer) => err ? reject(err) : resolve(buffer));
55
+ });
56
+ }
57
+ //#endregion
44
58
  //#region src/utils/crypto.ts
45
59
  function hashBuffer(data, length) {
46
60
  const hash = crypto.createHash("SHA256").update(data).digest("binary");
@@ -65,6 +79,11 @@ function defaultSignature(buffer, privateKey, cert, version) {
65
79
  const REG_VERSION = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9]+)(?:\.(\d+))?)?$/i;
66
80
  /**
67
81
  * Parse version string to {@link Version}, like `0.2.0-beta.1`
82
+ *
83
+ * **Supported format**: `major.minor.patch[-stage[.stageVersion]]`
84
+ *
85
+ * Build metadata (`+build`) and complex semver prerelease identifiers
86
+ * (e.g. `1.0.0-beta.1.2`) are not supported yet.
68
87
  * @param version version string
69
88
  */
70
89
  function parseVersion(version) {
@@ -114,17 +133,6 @@ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVe
114
133
  return existingJson;
115
134
  }
116
135
  //#endregion
117
- //#region src/utils/zip.ts
118
- /**
119
- * Default function to compress file using brotli
120
- * @param buffer uncompressed file buffer
121
- */
122
- async function defaultZipFile(buffer) {
123
- return new Promise((resolve, reject) => {
124
- zlib.brotliCompress(buffer, (err, buffer) => err ? reject(err) : resolve(buffer));
125
- });
126
- }
127
- //#endregion
128
136
  //#region src/vite/constant.ts
129
137
  const id = "electron-incremental-update";
130
138
  const bytecodeId = `${id}-bytecode`;
@@ -446,14 +454,14 @@ async function prepareLocalDevUpdateResource({ root, pkg, buildAsarOption, versi
446
454
  const stagedElectronDistPath = path.join(workDir, "dist-electron");
447
455
  const resolvedVersionPath = path.join(localDevUpdate.baseDir, versionPath);
448
456
  const asarPath = path.join(localDevUpdate.baseDir, `${pkg.name}.asar`);
449
- const gzipPath = path.join(localDevUpdate.baseDir, `${pkg.name}-${targetVersion}.asar.gz`);
457
+ const compressedPath = path.join(localDevUpdate.baseDir, `${pkg.name}-${targetVersion}.asar.br`);
450
458
  try {
451
459
  await mkdir(localDevUpdate.baseDir, { recursive: true });
452
460
  await mkdir(path.dirname(resolvedVersionPath), { recursive: true });
453
461
  await cp$1(path.resolve(root, buildAsarOption.electronDistPath), stagedElectronDistPath, { recursive: true });
454
462
  await writeFile(path.join(stagedElectronDistPath, "version"), targetVersion, "utf-8");
455
463
  await createPackage(stagedElectronDistPath, asarPath);
456
- await writeFile(gzipPath, await buildAsarOption.generateGzipFile(await readFile(asarPath)));
464
+ await writeFile(compressedPath, await buildAsarOption.generateCompressedFile(await readFile(asarPath)));
457
465
  const updateJSON = defaultVersionJsonGenerator(await readExistingUpdateJSON(resolvedVersionPath, targetVersion), LOCAL_DEV_SIGNATURE, targetVersion, minimumVersion);
458
466
  if (!isUpdateJSON(updateJSON)) throw new Error("Invalid local dev update json");
459
467
  await writeFile(resolvedVersionPath, JSON.stringify(updateJSON, null, 2), "utf-8");
@@ -565,20 +573,20 @@ function copyAndSkipIfExist(from, to, skipIfExist) {
565
573
  * @param options - Asar build options
566
574
  * @returns Buffer of the built asar file
567
575
  */
568
- async function buildAsar(root, { version, asarOutputPath, electronDistPath, rendererDistPath, gzipPath, generateGzipFile }) {
576
+ async function buildAsar(root, { version, asarOutputPath, electronDistPath, rendererDistPath, compressedPath, generateCompressedFile }) {
569
577
  electronDistPath = path.resolve(root, electronDistPath);
570
578
  asarOutputPath = path.resolve(root, asarOutputPath);
571
579
  rendererDistPath = path.resolve(root, rendererDistPath);
572
- gzipPath = path.resolve(root, gzipPath);
580
+ compressedPath = path.resolve(root, compressedPath);
573
581
  const rPath = path.join(electronDistPath, "renderer");
574
582
  await fs.promises.cp(rendererDistPath, rPath, { recursive: true });
575
583
  fs.writeFileSync(path.join(electronDistPath, "version"), version);
576
584
  await fs.promises.mkdir(path.dirname(asarOutputPath), { recursive: true });
577
585
  await createPackage(electronDistPath, asarOutputPath);
578
- const buf = await generateGzipFile(fs.readFileSync(asarOutputPath));
579
- await fs.promises.mkdir(path.dirname(gzipPath), { recursive: true });
580
- fs.writeFileSync(gzipPath, buf);
581
- log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
586
+ const buf = await generateCompressedFile(fs.readFileSync(asarOutputPath));
587
+ await fs.promises.mkdir(path.dirname(compressedPath), { recursive: true });
588
+ fs.writeFileSync(compressedPath, buf);
589
+ log.info(`Build update asar to '${compressedPath}' [${readableSize(buf.length)}]`, { timestamp: true });
582
590
  return buf;
583
591
  }
584
592
  /**
@@ -586,7 +594,8 @@ async function buildAsar(root, { version, asarOutputPath, electronDistPath, rend
586
594
  * @param options - Version build options
587
595
  * @param asarBuffer - Buffer of the asar file to sign
588
596
  */
589
- async function buildUpdateJson({ versionPath, privateKey, cert, version, minimumVersion, generateSignature, generateUpdateJson }, asarBuffer) {
597
+ async function buildUpdateJson(root, { versionPath, privateKey, cert, version, minimumVersion, generateSignature, generateUpdateJson }, asarBuffer) {
598
+ const resolvedVersionPath = path.resolve(root, versionPath);
590
599
  let _json = {
591
600
  beta: {
592
601
  minimumVersion: version,
@@ -605,9 +614,9 @@ async function buildUpdateJson({ versionPath, privateKey, cert, version, minimum
605
614
  const sig = await generateSignature(asarBuffer, privateKey, cert, version);
606
615
  _json = await generateUpdateJson(_json, sig, version, minimumVersion);
607
616
  if (!isUpdateJSON(_json)) throw new Error("Invalid update json");
608
- await fs.promises.mkdir(path.dirname(versionPath), { recursive: true });
609
- fs.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
610
- log.info(`build update json to '${versionPath}'`, { timestamp: true });
617
+ await fs.promises.mkdir(path.dirname(resolvedVersionPath), { recursive: true });
618
+ fs.writeFileSync(resolvedVersionPath, JSON.stringify(_json, null, 2));
619
+ log.info(`Build update json to '${resolvedVersionPath}'`, { timestamp: true });
611
620
  }
612
621
  //#endregion
613
622
  //#region src/vite/utils/key.ts
@@ -678,10 +687,10 @@ function parseSubjects(subject) {
678
687
  //#endregion
679
688
  //#region src/vite/core.ts
680
689
  async function resolveUpdaterOption(root, pkg, options = {}, resolveSignatureKeys = true) {
681
- const { minimumVersion = "0.0.0", paths: { asarOutputPath = `release/${pkg.name}.asar`, gzipPath = `release/${pkg.name}-${pkg.version}.asar.gz`, entryOutDir = "dist-entry", electronDistPath = "dist-electron", rendererDistPath = "dist", versionPath = "release/version.json" } = {}, keys: { privateKeyPath = "keys/private.pem", certPath = "keys/cert.pem", keyLength = 2048, certInfo: { subject = {
690
+ const { minimumVersion = "0.0.0", paths: { asarOutputPath = `release/${pkg.name}.asar`, compressedPath = `release/${pkg.name}-${pkg.version}.asar.br`, entryOutDir = "dist-entry", electronDistPath = "dist-electron", rendererDistPath = "dist", versionPath = "release/version.json" } = {}, keys: { privateKeyPath = "keys/private.pem", certPath = "keys/cert.pem", keyLength = 2048, certInfo: { subject = {
682
691
  commonName: pkg.name,
683
692
  organizationName: `org.${pkg.name}`
684
- }, days = 3650 } = {} } = {}, overrideGenerator: { generateGzipFile = defaultZipFile, generateSignature = defaultSignature, generateUpdateJson = defaultVersionJsonGenerator } = {} } = options;
693
+ }, days = 3650 } = {} } = {}, overrideGenerator: { generateCompressedFile = defaultCompressFile, generateSignature = defaultSignature, generateUpdateJson = defaultVersionJsonGenerator } = {} } = options;
685
694
  const { privateKey, cert } = resolveSignatureKeys ? await parseKeys({
686
695
  keyLength,
687
696
  privateKeyPath: path.resolve(root, privateKeyPath),
@@ -696,10 +705,10 @@ async function resolveUpdaterOption(root, pkg, options = {}, resolveSignatureKey
696
705
  buildAsarOption: {
697
706
  version: pkg.version,
698
707
  asarOutputPath,
699
- gzipPath,
708
+ compressedPath,
700
709
  electronDistPath,
701
710
  rendererDistPath,
702
- generateGzipFile
711
+ generateCompressedFile
703
712
  },
704
713
  buildVersionOption: {
705
714
  version: pkg.version,
@@ -730,7 +739,7 @@ function normalizeVersionPath(versionPath) {
730
739
  return new URL(versionPath, "file://").pathname.slice(1);
731
740
  }
732
741
  async function createElectronOptions(options, context) {
733
- const { entry, main, preload, sourcemap = context.isDev || !!process.env.VSCODE_DEBUG, minify = !context.isDev, buildVersionJson, notBundle = true, external, updater, bytecode, localDevUpdate } = options;
742
+ const { entry, main, preload, sourcemap = context.isDev || !!process.env.VSCODE_DEBUG, minify = !context.isDev, buildVersionJson, bundleDeps, external, updater, bytecode, localDevUpdate } = options;
734
743
  const pkg = context.packageJson;
735
744
  if (!pkg || !pkg.version || !pkg.name || !pkg.main) throw new Error("package.json not found or invalid, must contains version, name and main field");
736
745
  const isESM = pkg.type === "module";
@@ -790,13 +799,14 @@ async function createElectronOptions(options, context) {
790
799
  name: "main",
791
800
  input: main.files,
792
801
  onstart: mainOnstart,
793
- notBundle,
802
+ bundleDeps,
794
803
  plugins: [isESM && esmShim(), bytecodeOptions && bytecodePlugin("main", minify, isESM, bytecodeOptions)],
795
804
  options: mergeConfig({
796
805
  build: {
797
806
  sourcemap,
798
807
  minify,
799
808
  outDir: `${buildAsarOption.electronDistPath}/main`,
809
+ reportCompressedSize: false,
800
810
  rolldownOptions: {
801
811
  external: finalExternal,
802
812
  output: {
@@ -806,6 +816,7 @@ async function createElectronOptions(options, context) {
806
816
  }
807
817
  }
808
818
  },
819
+ resolve: { noExternal: [name] },
809
820
  define
810
821
  }, main.options ?? {})
811
822
  }];
@@ -814,13 +825,14 @@ async function createElectronOptions(options, context) {
814
825
  onstart(args) {
815
826
  args.reload();
816
827
  },
817
- notBundle,
828
+ bundleDeps,
818
829
  input: preload.files,
819
830
  plugins: [isESM && esmShim(), bytecodeOptions && bytecodePlugin("preload", minify, isESM, bytecodeOptions)],
820
831
  options: mergeConfig({
821
832
  build: {
822
- sourcemap: sourcemap ? "inline" : void 0,
823
833
  minify,
834
+ sourcemap: sourcemap ? "inline" : void 0,
835
+ reportCompressedSize: false,
824
836
  outDir: `${buildAsarOption.electronDistPath}/preload`,
825
837
  rolldownOptions: {
826
838
  external: finalExternal,
@@ -832,6 +844,7 @@ async function createElectronOptions(options, context) {
832
844
  }
833
845
  }
834
846
  },
847
+ resolve: { noExternal: [name] },
835
848
  define
836
849
  }, preload?.options ?? {})
837
850
  });
@@ -842,7 +855,7 @@ async function createElectronOptions(options, context) {
842
855
  if (mainOnstart) await mainOnstart(args);
843
856
  else await args.startup();
844
857
  },
845
- notBundle,
858
+ bundleDeps,
846
859
  plugins: [
847
860
  isESM && esmShim(),
848
861
  bytecodeOptions && bytecodePlugin("entry", minify, isESM, bytecodeOptions),
@@ -869,7 +882,7 @@ async function createElectronOptions(options, context) {
869
882
  if (context.isDev) return;
870
883
  const buffer = await buildAsar(context.root, buildAsarOption);
871
884
  if (!buildVersionJson && !isCI) log.warn("No `buildVersionJson` option setup, skip build version json. Only build in CI by default", { timestamp: true });
872
- else await buildUpdateJson(buildVersionOption, buffer);
885
+ else await buildUpdateJson(context.root, buildVersionOption, buffer);
873
886
  }
874
887
  }
875
888
  ],
@@ -878,6 +891,7 @@ async function createElectronOptions(options, context) {
878
891
  sourcemap,
879
892
  minify,
880
893
  outDir: entryOutDir,
894
+ reportCompressedSize: false,
881
895
  rolldownOptions: {
882
896
  external: finalExternal,
883
897
  output: {
@@ -887,6 +901,7 @@ async function createElectronOptions(options, context) {
887
901
  }
888
902
  }
889
903
  },
904
+ resolve: { noExternal: [name] },
890
905
  define
891
906
  }, entry.options || {})
892
907
  });
@@ -944,6 +959,7 @@ async function electronWithUpdater(options) {
944
959
  * import { defineElectronConfig } from 'electron-incremental-update/vite'
945
960
  *
946
961
  * export default defineElectronConfig({
962
+ * // root: './apps'
947
963
  * main: {
948
964
  * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
949
965
  * },
@@ -954,13 +970,7 @@ async function electronWithUpdater(options) {
954
970
  * // options
955
971
  * },
956
972
  * renderer: {
957
- * server: process.env.VSCODE_DEBUG && (() => {
958
- * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
959
- * return {
960
- * host: url.hostname,
961
- * port: +url.port,
962
- * }
963
- * })(),
973
+ * // plugins: []
964
974
  * }
965
975
  * })
966
976
  * ```
@@ -970,6 +980,7 @@ function defineElectronConfig(options) {
970
980
  const result = options.renderer ?? {};
971
981
  result.plugins ??= [];
972
982
  result.plugins.push(electronPlugin);
983
+ result.root = options.root;
973
984
  const rendererDistPath = options.updater?.paths?.rendererDistPath;
974
985
  if (rendererDistPath) {
975
986
  result.build ??= {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "3.0.0-beta.6",
3
+ "version": "3.1.0",
4
4
  "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
5
5
  "keywords": [
6
6
  "bytecode",
@@ -56,11 +56,9 @@
56
56
  "build": "tsdown",
57
57
  "play": "bun run build && vite",
58
58
  "play:build": "vite build",
59
- "release": "bun run format && bun run lint && bun run test && bun run build && bumpp --all",
59
+ "release": "bun run qa && bun run test && bun run build && bumpp --all",
60
60
  "test": "bun test --preload ./tests/setup.ts",
61
61
  "test:dev": "bun test --watch",
62
- "format": "oxfmt",
63
- "lint": "oxlint --fix",
64
62
  "qa": "oxlint --fix && oxfmt && tsc --noEmit"
65
63
  },
66
64
  "dependencies": {
@@ -68,18 +66,18 @@
68
66
  "@babel/plugin-transform-template-literals": "^7.29.7",
69
67
  "ci-info": "^4.4.0",
70
68
  "selfsigned": "^5.5.0",
71
- "vite-plugin-electron": "~1.0.4"
69
+ "vite-plugin-electron": "^1.1.0"
72
70
  },
73
71
  "devDependencies": {
74
72
  "@subf/config": "^0.2.1",
75
- "@tsdown/css": "^0.22.1",
73
+ "@tsdown/css": "^0.22.2",
76
74
  "@types/babel__core": "^7.20.5",
77
75
  "@types/bun": "^1.3.14",
78
76
  "bumpp": "^11.1.0",
79
77
  "electron": "42.2.0",
80
- "oxfmt": "^0.53.0",
81
- "oxlint": "^1.68.0",
82
- "tsdown": "^0.22.1",
78
+ "oxfmt": "^0.54.0",
79
+ "oxlint": "^1.69.0",
80
+ "tsdown": "^0.22.2",
83
81
  "typescript": "^6.0.3",
84
82
  "vite": "^8.0.16"
85
83
  },