electron-incremental-update 2.0.0-beta.4 → 2.0.0-beta.5

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.
@@ -6,10 +6,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/utils/version.ts
9
- function handleUnexpectedErrors(callback) {
10
- process.on("uncaughtException", callback);
11
- process.on("unhandledRejection", callback);
12
- }
13
9
  function parseVersion(version) {
14
10
  const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
15
11
  if (!match) {
@@ -54,23 +50,21 @@ function defaultIsLowerVersion(oldVer, newVer) {
54
50
  return false;
55
51
  }
56
52
  function isUpdateJSON(json) {
57
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
53
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
58
54
  return is(json) && is(json?.beta);
59
55
  }
60
- function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
56
+ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
61
57
  existingJson.beta = {
62
58
  version,
63
59
  minimumVersion,
64
- signature,
65
- size: buffer.length
60
+ signature
66
61
  };
67
62
  if (!parseVersion(version).stage) {
68
63
  existingJson.version = version;
69
64
  existingJson.minimumVersion = minimumVersion;
70
65
  existingJson.signature = signature;
71
- existingJson.size = buffer.length;
72
66
  }
73
67
  return existingJson;
74
68
  }
75
69
 
76
- export { __require, defaultIsLowerVersion, defaultVersionJsonGenerator, handleUnexpectedErrors, isUpdateJSON, parseVersion };
70
+ export { __require, defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion };
@@ -1,4 +1,4 @@
1
- import { __require } from './chunk-BVFQWBLK.js';
1
+ import { __require } from './chunk-72ZAJ7AF.js';
2
2
  import { readFileSync, existsSync, mkdirSync } from 'node:fs';
3
3
  import { join, dirname } from 'node:path';
4
4
  import { app } from 'electron';
@@ -73,5 +73,9 @@ function getPathFromPublic(...paths) {
73
73
  function getPathFromEntryAsar(...paths) {
74
74
  return join(app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
75
75
  }
76
+ function handleUnexpectedErrors(callback) {
77
+ process.on("uncaughtException", callback);
78
+ process.on("unhandledRejection", callback);
79
+ }
76
80
 
77
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
81
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-Bz1VD18z.js';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-C5P0h_bB.js';
3
3
 
4
4
  declare const ErrorInfo: {
5
5
  readonly download: "Download failed";
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-Bz1VD18z.cjs';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-C5P0h_bB.cjs';
3
3
 
4
4
  declare const ErrorInfo: {
5
5
  readonly download: "Download failed";
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
14
14
 
15
15
  // src/utils/version.ts
16
16
  function isUpdateJSON(json) {
17
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
17
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
18
18
  return is(json) && is(json?.beta);
19
19
  }
20
20
  var isDev = __EIU_IS_DEV__;
@@ -128,14 +128,13 @@ var Updater = class extends events.EventEmitter {
128
128
  if (!_data) {
129
129
  return emitUnavailable("failed to get update info");
130
130
  }
131
- let { signature, size, version, minimumVersion, beta } = _data;
131
+ let { signature, version, minimumVersion, beta } = _data;
132
132
  if (this.receiveBeta) {
133
133
  version = beta.version;
134
134
  signature = beta.signature;
135
135
  minimumVersion = beta.minimumVersion;
136
- size = beta.size;
137
136
  }
138
- this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
137
+ this.logger?.debug(`checked update, version: ${version}, signature: ${signature}`);
139
138
  if (isDev && !this.forceUpdate && !data) {
140
139
  return emitUnavailable("skip check update in dev mode, to force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON");
141
140
  }
@@ -150,7 +149,7 @@ var Updater = class extends events.EventEmitter {
150
149
  return emitUnavailable(`current version (${appVersion}) < new version (${version})`);
151
150
  }
152
151
  this.logger?.info(`update available: ${version}`);
153
- this.info = { signature, minimumVersion, version, size };
152
+ this.info = { signature, minimumVersion, version };
154
153
  this.emit("update-available", this.info);
155
154
  return true;
156
155
  }
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { U as Updater, a as UpdaterOption, L as Logger } from './core-CW7TMqi7.cjs';
2
- export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-CW7TMqi7.cjs';
3
- import { I as IProvider } from './types-Bz1VD18z.cjs';
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-DmU2Vk_S.cjs';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-DmU2Vk_S.cjs';
3
+ import { I as IProvider } from './types-C5P0h_bB.cjs';
4
4
  import 'node:events';
5
5
  import '@subframe7536/type-utils';
6
6
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { U as Updater, a as UpdaterOption, L as Logger } from './core-D6QlpOgp.js';
2
- export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-D6QlpOgp.js';
3
- import { I as IProvider } from './types-Bz1VD18z.js';
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-CXETH_bb.js';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-CXETH_bb.js';
3
+ import { I as IProvider } from './types-C5P0h_bB.js';
4
4
  import 'node:events';
5
5
  import '@subframe7536/type-utils';
6
6
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-PNYRQYFC.js';
2
- import { isUpdateJSON, __require } from './chunk-BVFQWBLK.js';
1
+ import { isDev, getEntryVersion, getAppVersion, getPathFromAppNameAsar, restartApp } from './chunk-DFNDKSE6.js';
2
+ import { isUpdateJSON, __require } from './chunk-72ZAJ7AF.js';
3
3
  import { join } from 'node:path';
4
4
  import { writeFileSync, existsSync, renameSync } from 'node:fs';
5
5
  import { app } from 'electron';
@@ -98,14 +98,13 @@ var Updater = class extends EventEmitter {
98
98
  if (!_data) {
99
99
  return emitUnavailable("failed to get update info");
100
100
  }
101
- let { signature, size, version, minimumVersion, beta } = _data;
101
+ let { signature, version, minimumVersion, beta } = _data;
102
102
  if (this.receiveBeta) {
103
103
  version = beta.version;
104
104
  signature = beta.signature;
105
105
  minimumVersion = beta.minimumVersion;
106
- size = beta.size;
107
106
  }
108
- this.logger?.debug(`checked update, version: ${version}, size: ${size}, signature: ${signature}`);
107
+ this.logger?.debug(`checked update, version: ${version}, signature: ${signature}`);
109
108
  if (isDev && !this.forceUpdate && !data) {
110
109
  return emitUnavailable("skip check update in dev mode, to force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON");
111
110
  }
@@ -120,7 +119,7 @@ var Updater = class extends EventEmitter {
120
119
  return emitUnavailable(`current version (${appVersion}) < new version (${version})`);
121
120
  }
122
121
  this.logger?.info(`update available: ${version}`);
123
- this.info = { signature, minimumVersion, version, size };
122
+ this.info = { signature, minimumVersion, version };
124
123
  this.emit("update-available", this.info);
125
124
  return true;
126
125
  }
package/dist/provider.cjs CHANGED
@@ -52,11 +52,19 @@ function defaultIsLowerVersion(oldVer, newVer) {
52
52
  return false;
53
53
  }
54
54
  function isUpdateJSON(json) {
55
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
55
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
56
56
  return is(json) && is(json?.beta);
57
57
  }
58
58
 
59
59
  // src/provider/download.ts
60
+ function getHeader(response, headerKey) {
61
+ const value = response.headers[headerKey];
62
+ if (Array.isArray(value)) {
63
+ return value.length === 0 ? null : value[value.length - 1];
64
+ } else {
65
+ return value;
66
+ }
67
+ }
60
68
  async function downloadFn(url, headers, onResponse) {
61
69
  await electron.app.whenReady();
62
70
  return new Promise((resolve, reject) => {
@@ -89,10 +97,11 @@ async function defaultDownloadUpdateJSON(url, headers) {
89
97
  });
90
98
  });
91
99
  }
92
- async function defaultDownloadAsar(url, headers, total, onDownloading) {
100
+ async function defaultDownloadAsar(url, headers, onDownloading) {
93
101
  let transferred = 0;
94
102
  let time = Date.now();
95
103
  return await downloadFn(url, headers, (resp, resolve) => {
104
+ const total = getHeader(resp.headers, "content-length") || -1;
96
105
  let data = [];
97
106
  resp.on("data", (chunk) => {
98
107
  transferred += chunk.length;
@@ -182,11 +191,10 @@ var GitHubProvider = class extends BaseProvider {
182
191
  { accept: "application/json", ...this.options.extraHeaders }
183
192
  );
184
193
  }
185
- async downloadAsar(name, { version, size }, onDownloading) {
194
+ async downloadAsar(name, info, onDownloading) {
186
195
  return await defaultDownloadAsar(
187
- await this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
196
+ await this.parseURL(true, `releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
188
197
  { accept: "application/octet-stream", ...this.options.extraHeaders },
189
- size,
190
198
  onDownloading
191
199
  );
192
200
  }
@@ -196,3 +204,4 @@ exports.BaseProvider = BaseProvider;
196
204
  exports.GitHubProvider = GitHubProvider;
197
205
  exports.defaultDownloadAsar = defaultDownloadAsar;
198
206
  exports.defaultDownloadUpdateJSON = defaultDownloadUpdateJSON;
207
+ exports.getHeader = getHeader;
@@ -1,6 +1,6 @@
1
- import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-Bz1VD18z.cjs';
1
+ import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-C5P0h_bB.cjs';
2
2
  import { f as defaultVerify, a as defaultUnzipFile } from './zip-WRrEMkgp.cjs';
3
- import '@subframe7536/type-utils';
3
+ import { Arrayable } from '@subframe7536/type-utils';
4
4
 
5
5
  declare abstract class BaseProvider implements IProvider {
6
6
  name: string;
@@ -55,10 +55,11 @@ declare class GitHubProvider extends BaseProvider {
55
55
  set urlHandler(handler: URLHandler);
56
56
  private parseURL;
57
57
  downloadJSON(versionPath: string): Promise<UpdateJSON>;
58
- downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
58
+ downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
59
59
  }
60
60
 
61
+ declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
61
62
  declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
62
- declare function defaultDownloadAsar(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
63
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
63
64
 
64
- export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON };
65
+ export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
@@ -1,6 +1,6 @@
1
- import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-Bz1VD18z.js';
1
+ import { I as IProvider, d as defaultIsLowerVersion, a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, c as URLHandler, O as OnDownloading } from './types-C5P0h_bB.js';
2
2
  import { f as defaultVerify, a as defaultUnzipFile } from './zip-WRrEMkgp.js';
3
- import '@subframe7536/type-utils';
3
+ import { Arrayable } from '@subframe7536/type-utils';
4
4
 
5
5
  declare abstract class BaseProvider implements IProvider {
6
6
  name: string;
@@ -55,10 +55,11 @@ declare class GitHubProvider extends BaseProvider {
55
55
  set urlHandler(handler: URLHandler);
56
56
  private parseURL;
57
57
  downloadJSON(versionPath: string): Promise<UpdateJSON>;
58
- downloadAsar(name: string, { version, size }: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
58
+ downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
59
59
  }
60
60
 
61
+ declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
61
62
  declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
62
- declare function defaultDownloadAsar(url: string, headers: Record<string, any>, total: number, onDownloading?: OnDownloading): Promise<Buffer>;
63
+ declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
63
64
 
64
- export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON };
65
+ export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
package/dist/provider.js CHANGED
@@ -1,8 +1,16 @@
1
1
  import { defaultVerify, defaultUnzipFile } from './chunk-JSYIRKTR.js';
2
- import { defaultIsLowerVersion, isUpdateJSON } from './chunk-BVFQWBLK.js';
2
+ import { defaultIsLowerVersion, isUpdateJSON } from './chunk-72ZAJ7AF.js';
3
3
  import { URL } from 'node:url';
4
4
  import { app, net } from 'electron';
5
5
 
6
+ function getHeader(response, headerKey) {
7
+ const value = response.headers[headerKey];
8
+ if (Array.isArray(value)) {
9
+ return value.length === 0 ? null : value[value.length - 1];
10
+ } else {
11
+ return value;
12
+ }
13
+ }
6
14
  async function downloadFn(url, headers, onResponse) {
7
15
  await app.whenReady();
8
16
  return new Promise((resolve, reject) => {
@@ -35,10 +43,11 @@ async function defaultDownloadUpdateJSON(url, headers) {
35
43
  });
36
44
  });
37
45
  }
38
- async function defaultDownloadAsar(url, headers, total, onDownloading) {
46
+ async function defaultDownloadAsar(url, headers, onDownloading) {
39
47
  let transferred = 0;
40
48
  let time = Date.now();
41
49
  return await downloadFn(url, headers, (resp, resolve) => {
50
+ const total = getHeader(resp.headers, "content-length") || -1;
42
51
  let data = [];
43
52
  resp.on("data", (chunk) => {
44
53
  transferred += chunk.length;
@@ -100,14 +109,13 @@ var GitHubProvider = class extends BaseProvider {
100
109
  { accept: "application/json", ...this.options.extraHeaders }
101
110
  );
102
111
  }
103
- async downloadAsar(name, { version, size }, onDownloading) {
112
+ async downloadAsar(name, info, onDownloading) {
104
113
  return await defaultDownloadAsar(
105
- await this.parseURL(true, `releases/download/v${version}/${name}-${version}.asar.gz`),
114
+ await this.parseURL(true, `releases/download/v${info.version}/${name}-${info.version}.asar.gz`),
106
115
  { accept: "application/octet-stream", ...this.options.extraHeaders },
107
- size,
108
116
  onDownloading
109
117
  );
110
118
  }
111
119
  };
112
120
 
113
- export { BaseProvider, GitHubProvider, defaultDownloadAsar, defaultDownloadUpdateJSON };
121
+ export { BaseProvider, GitHubProvider, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
@@ -1,10 +1,5 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
2
 
3
- /**
4
- * handle all unhandled error
5
- * @param callback callback function
6
- */
7
- declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
8
3
  interface Version {
9
4
  major: number;
10
5
  minor: number;
@@ -21,7 +16,6 @@ type UpdateInfo = {
21
16
  signature: string;
22
17
  minimumVersion: string;
23
18
  version: string;
24
- size: number;
25
19
  };
26
20
  /**
27
21
  * {@link UpdateInfo} with beta
@@ -30,7 +24,7 @@ type UpdateJSON = UpdateInfo & {
30
24
  beta: UpdateInfo;
31
25
  };
32
26
  declare function isUpdateJSON(json: any): json is UpdateJSON;
33
- declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minimumVersion: string): UpdateJSON;
27
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
34
28
 
35
29
  type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
36
30
  type OnDownloading = (progress: DownloadingInfo) => void;
@@ -41,10 +35,14 @@ interface DownloadingInfo {
41
35
  delta: number;
42
36
  /**
43
37
  * downloaded percent, 0 ~ 100
38
+ *
39
+ * If not `Content-Length` header, will be nagative
44
40
  */
45
41
  percent: number;
46
42
  /**
47
43
  * total size
44
+ *
45
+ * If not `Content-Length` header, will be -1
48
46
  */
49
47
  total: number;
50
48
  /**
@@ -102,4 +100,4 @@ interface IProvider {
102
100
  verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
103
101
  }
104
102
 
105
- export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, handleUnexpectedErrors as h, isUpdateJSON as i, parseVersion as p };
103
+ export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
@@ -1,10 +1,5 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
2
 
3
- /**
4
- * handle all unhandled error
5
- * @param callback callback function
6
- */
7
- declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
8
3
  interface Version {
9
4
  major: number;
10
5
  minor: number;
@@ -21,7 +16,6 @@ type UpdateInfo = {
21
16
  signature: string;
22
17
  minimumVersion: string;
23
18
  version: string;
24
- size: number;
25
19
  };
26
20
  /**
27
21
  * {@link UpdateInfo} with beta
@@ -30,7 +24,7 @@ type UpdateJSON = UpdateInfo & {
30
24
  beta: UpdateInfo;
31
25
  };
32
26
  declare function isUpdateJSON(json: any): json is UpdateJSON;
33
- declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minimumVersion: string): UpdateJSON;
27
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
34
28
 
35
29
  type URLHandler = (url: URL, isDownloadAsar: boolean) => Promisable<URL | string | undefined | null>;
36
30
  type OnDownloading = (progress: DownloadingInfo) => void;
@@ -41,10 +35,14 @@ interface DownloadingInfo {
41
35
  delta: number;
42
36
  /**
43
37
  * downloaded percent, 0 ~ 100
38
+ *
39
+ * If not `Content-Length` header, will be nagative
44
40
  */
45
41
  percent: number;
46
42
  /**
47
43
  * total size
44
+ *
45
+ * If not `Content-Length` header, will be -1
48
46
  */
49
47
  total: number;
50
48
  /**
@@ -102,4 +100,4 @@ interface IProvider {
102
100
  verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
103
101
  }
104
102
 
105
- export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, handleUnexpectedErrors as h, isUpdateJSON as i, parseVersion as p };
103
+ export { type DownloadingInfo as D, type IProvider as I, type OnDownloading as O, type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, type URLHandler as c, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
package/dist/utils.cjs CHANGED
@@ -82,6 +82,10 @@ function getPathFromPublic(...paths) {
82
82
  function getPathFromEntryAsar(...paths) {
83
83
  return path.join(electron.app.getAppPath(), __EIU_ENTRY_DIST_PATH__, ...paths);
84
84
  }
85
+ function handleUnexpectedErrors(callback) {
86
+ process.on("uncaughtException", callback);
87
+ process.on("unhandledRejection", callback);
88
+ }
85
89
  async function defaultZipFile(buffer) {
86
90
  return new Promise((resolve, reject) => {
87
91
  zlib.brotliCompress(buffer, (err, buffer2) => {
@@ -106,10 +110,6 @@ async function defaultUnzipFile(buffer) {
106
110
  }
107
111
 
108
112
  // src/utils/version.ts
109
- function handleUnexpectedErrors(callback) {
110
- process.on("uncaughtException", callback);
111
- process.on("unhandledRejection", callback);
112
- }
113
113
  function parseVersion(version) {
114
114
  const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
115
115
  if (!match) {
@@ -154,21 +154,19 @@ function defaultIsLowerVersion(oldVer, newVer) {
154
154
  return false;
155
155
  }
156
156
  function isUpdateJSON(json) {
157
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
157
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
158
158
  return is(json) && is(json?.beta);
159
159
  }
160
- function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
160
+ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
161
161
  existingJson.beta = {
162
162
  version,
163
163
  minimumVersion,
164
- signature,
165
- size: buffer.length
164
+ signature
166
165
  };
167
166
  if (!parseVersion(version).stage) {
168
167
  existingJson.version = version;
169
168
  existingJson.minimumVersion = minimumVersion;
170
169
  existingJson.signature = signature;
171
- existingJson.size = buffer.length;
172
170
  }
173
171
  return existingJson;
174
172
  }
package/dist/utils.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BrowserWindow } from 'electron';
2
2
  export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerify, d as defaultZipFile, h as hashBuffer } from './zip-WRrEMkgp.cjs';
3
- export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './types-Bz1VD18z.cjs';
4
- import { U as Updater } from './core-CW7TMqi7.cjs';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './types-C5P0h_bB.cjs';
4
+ import { U as Updater } from './core-DmU2Vk_S.cjs';
5
5
  import '@subframe7536/type-utils';
6
6
  import 'node:events';
7
7
 
@@ -66,10 +66,15 @@ declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
66
66
  declare function getPathFromPreload(...paths: string[]): string;
67
67
  declare function getPathFromPublic(...paths: string[]): string;
68
68
  declare function getPathFromEntryAsar(...paths: string[]): string;
69
+ /**
70
+ * handle all unhandled error
71
+ * @param callback callback function
72
+ */
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
69
74
 
70
75
  /**
71
76
  * auto check update, download and install
72
77
  */
73
78
  declare function autoUpdate(updater: Updater): Promise<void>;
74
79
 
75
- export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
80
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BrowserWindow } from 'electron';
2
2
  export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerify, d as defaultZipFile, h as hashBuffer } from './zip-WRrEMkgp.js';
3
- export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, h as handleUnexpectedErrors, i as isUpdateJSON, p as parseVersion } from './types-Bz1VD18z.js';
4
- import { U as Updater } from './core-D6QlpOgp.js';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './types-C5P0h_bB.js';
4
+ import { U as Updater } from './core-CXETH_bb.js';
5
5
  import '@subframe7536/type-utils';
6
6
  import 'node:events';
7
7
 
@@ -66,10 +66,15 @@ declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
66
66
  declare function getPathFromPreload(...paths: string[]): string;
67
67
  declare function getPathFromPublic(...paths: string[]): string;
68
68
  declare function getPathFromEntryAsar(...paths: string[]): string;
69
+ /**
70
+ * handle all unhandled error
71
+ * @param callback callback function
72
+ */
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
69
74
 
70
75
  /**
71
76
  * auto check update, download and install
72
77
  */
73
78
  declare function autoUpdate(updater: Updater): Promise<void>;
74
79
 
75
- export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
80
+ export { autoUpdate, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance };
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
- export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-PNYRQYFC.js';
1
+ export { disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-DFNDKSE6.js';
2
2
  export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer } from './chunk-JSYIRKTR.js';
3
- export { defaultIsLowerVersion, defaultVersionJsonGenerator, handleUnexpectedErrors, isUpdateJSON, parseVersion } from './chunk-BVFQWBLK.js';
3
+ export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-72ZAJ7AF.js';
4
4
 
5
5
  // src/utils/updater.ts
6
6
  async function autoUpdate(updater) {
package/dist/vite.d.ts CHANGED
@@ -10,7 +10,6 @@ type UpdateInfo = {
10
10
  signature: string;
11
11
  minimumVersion: string;
12
12
  version: string;
13
- size: number;
14
13
  };
15
14
  /**
16
15
  * {@link UpdateInfo} with beta
@@ -138,7 +137,7 @@ interface GeneratorOverrideFunctions {
138
137
  * @param minVersion The minimum version
139
138
  * @returns The updated version json
140
139
  */
141
- generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
140
+ generateVersionJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
142
141
  /**
143
142
  * custom generate zip file buffer
144
143
  * @param buffer source buffer
@@ -319,6 +318,11 @@ interface ElectronWithUpdaterOptions {
319
318
  * @default true
320
319
  */
321
320
  useNotBundle?: boolean;
321
+ /**
322
+ * whether to generate version json
323
+ * @default isCI
324
+ */
325
+ buildVersionJson?: boolean;
322
326
  /**
323
327
  * Whether to log parsed options
324
328
  *
package/dist/vite.js CHANGED
@@ -5,6 +5,7 @@ import ElectronSimple from 'vite-plugin-electron/simple';
5
5
  import { startup } from 'vite-plugin-electron';
6
6
  import { notBundle } from 'vite-plugin-electron/plugin';
7
7
  import { getPackageInfoSync, loadPackageJSON } from 'local-pkg';
8
+ import { isCI } from 'ci-info';
8
9
  import Asar from '@electron/asar';
9
10
  import { build } from 'esbuild';
10
11
  import { spawn } from 'node:child_process';
@@ -41,21 +42,19 @@ function parseVersion(version) {
41
42
  return ret;
42
43
  }
43
44
  function isUpdateJSON(json) {
44
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
45
+ const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
45
46
  return is(json) && is(json?.beta);
46
47
  }
47
- function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
48
+ function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
48
49
  existingJson.beta = {
49
50
  version,
50
51
  minimumVersion,
51
- signature,
52
- size: buffer.length
52
+ signature
53
53
  };
54
54
  if (!parseVersion(version).stage) {
55
55
  existingJson.version = version;
56
56
  existingJson.minimumVersion = minimumVersion;
57
57
  existingJson.signature = signature;
58
- existingJson.size = buffer.length;
59
58
  }
60
59
  return existingJson;
61
60
  }
@@ -159,6 +158,17 @@ function obfuscateString(input) {
159
158
  return `(${decodeFn})([${hexArray.join(",")}],${offset})`;
160
159
  }
161
160
 
161
+ // src/build-plugins/utils.ts
162
+ function readableSize(size) {
163
+ const units = ["B", "KB", "MB", "GB"];
164
+ let i = 0;
165
+ while (size >= 1024 && i < units.length - 1) {
166
+ size /= 1024;
167
+ i++;
168
+ }
169
+ return `${size.toFixed(2)} ${units[i]}`;
170
+ }
171
+
162
172
  // src/build-plugins/build.ts
163
173
  async function buildAsar({
164
174
  version,
@@ -173,6 +183,7 @@ async function buildAsar({
173
183
  await Asar.createPackage(electronDistPath, asarOutputPath);
174
184
  const buf = await generateGzipFile(readFileSync(asarOutputPath));
175
185
  writeFileSync(gzipPath, buf);
186
+ log.info(`build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
176
187
  return buf;
177
188
  }
178
189
  async function buildVersion({
@@ -188,12 +199,10 @@ async function buildVersion({
188
199
  beta: {
189
200
  minimumVersion: version,
190
201
  signature: "",
191
- size: 0,
192
202
  version
193
203
  },
194
204
  minimumVersion: version,
195
205
  signature: "",
196
- size: 0,
197
206
  version
198
207
  };
199
208
  if (existsSync(versionPath)) {
@@ -208,11 +217,12 @@ async function buildVersion({
208
217
  }
209
218
  }
210
219
  const sig = await generateSignature(asarBuffer, privateKey, cert, version);
211
- _json = await generateVersionJson(_json, asarBuffer, sig, version, minimumVersion);
220
+ _json = await generateVersionJson(_json, sig, version, minimumVersion);
212
221
  if (!isUpdateJSON(_json)) {
213
222
  throw new Error("invalid version info");
214
223
  }
215
224
  writeFileSync(versionPath, JSON.stringify(_json, null, 2));
225
+ log.info(`build version info to '${versionPath}'`, { timestamp: true });
216
226
  }
217
227
  async function buildEntry({
218
228
  sourcemap,
@@ -274,7 +284,7 @@ async function buildEntry({
274
284
  { timestamp: true }
275
285
  );
276
286
  }
277
- bytecodeLog.info(`${filePaths.length} bundles compiled into bytecode`, { timestamp: true });
287
+ bytecodeLog.info(`${filePaths.length} file${filePaths.length > 1 ? "s" : ""} compiled into bytecode`, { timestamp: true });
278
288
  }
279
289
  function getCert(code) {
280
290
  const cert = code.match(/-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n/)?.[0];
@@ -421,19 +431,6 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
421
431
  };
422
432
  return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
423
433
  }
424
-
425
- // src/build-plugins/utils.ts
426
- function readableSize(size) {
427
- const units = ["B", "KB", "MB", "GB"];
428
- let i = 0;
429
- while (size >= 1024 && i < units.length - 1) {
430
- size /= 1024;
431
- i++;
432
- }
433
- return `${size.toFixed(2)} ${units[i]}`;
434
- }
435
-
436
- // src/build-plugins/bytecode/index.ts
437
434
  function bytecodePlugin(isBuild, env, options = {}) {
438
435
  if (!isBuild) {
439
436
  return null;
@@ -571,7 +568,7 @@ ${bytecodeLoaderBlock}`) : _code;
571
568
  const outDir = `${normalizePath(path2.relative(config.root, path2.resolve(config.root, config.build.outDir)))}/`;
572
569
  bytecodeFiles.forEach((file) => {
573
570
  bytecodeLog.info(
574
- `${outDir}${file.name} => ${readableSize(file.size)}`,
571
+ `${outDir}${file.name} [${readableSize(file.size)}]`,
575
572
  { timestamp: true }
576
573
  );
577
574
  });
@@ -619,6 +616,7 @@ async function electronWithUpdater(options) {
619
616
  preload: _preload,
620
617
  sourcemap = !isBuild,
621
618
  minify = isBuild,
619
+ buildVersionJson = isCI,
622
620
  updater,
623
621
  bytecode,
624
622
  useNotBundle = true,
@@ -738,9 +736,9 @@ async function electronWithUpdater(options) {
738
736
  await _buildEntry();
739
737
  await _postBuild();
740
738
  const buffer = await buildAsar(buildAsarOption);
741
- log.info(`build update asar to '${buildAsarOption.gzipPath}' => ${readableSize(buffer.length)}`, { timestamp: true });
742
- await buildVersion(buildVersionOption, buffer);
743
- log.info(`build version info to '${buildVersionOption.versionPath}'`, { timestamp: true });
739
+ if (buildVersionJson) {
740
+ await buildVersion(buildVersionOption, buffer);
741
+ }
744
742
  }
745
743
  }
746
744
  ],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.4",
4
+ "version": "2.0.0-beta.5",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "author": "subframe7536",
7
7
  "license": "MIT",
@@ -60,6 +60,7 @@
60
60
  "@babel/core": "^7.24.7",
61
61
  "@babel/plugin-transform-arrow-functions": "^7.24.7",
62
62
  "@subframe7536/type-utils": "^0.1.6",
63
+ "ci-info": "^4.0.0",
63
64
  "local-pkg": "^0.5.0",
64
65
  "selfsigned": "^2.4.1",
65
66
  "vite-plugin-electron": "^0.28.7"
@@ -78,4 +79,4 @@
78
79
  "vite-plugin-electron": "^0.28.7",
79
80
  "vitest": "^2.0.3"
80
81
  }
81
- }
82
+ }