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

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.
@@ -40,14 +40,16 @@ function aesDecrypt(encryptedText, key, iv) {
40
40
  const decipher = createDecipheriv("aes-256-cbc", key, iv);
41
41
  return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
42
42
  }
43
- function defaultVerify(buffer, signature, cert) {
43
+ function defaultVerifySignature(buffer, version, signature, cert) {
44
44
  try {
45
- const [sig, version] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
46
- const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
47
- return result ? version : void 0;
45
+ const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
46
+ if (ver !== version) {
47
+ return false;
48
+ }
49
+ return createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
48
50
  } catch {
49
- return void 0;
51
+ return false;
50
52
  }
51
53
  }
52
54
 
53
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer };
55
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer };
@@ -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-C5P0h_bB.js';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-CItP6bL-.js';
3
3
 
4
4
  declare const ErrorInfo: {
5
5
  readonly download: "Download failed";
@@ -110,9 +110,9 @@ declare class Updater extends EventEmitter<{
110
110
  /**
111
111
  * download update using existing `asar.gz` buffer and signature
112
112
  * @param data existing `asar.gz` buffer
113
- * @param sig signature
113
+ * @param info update info
114
114
  */
115
- downloadUpdate(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
115
+ downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
116
116
  /**
117
117
  * quit App and install
118
118
  */
@@ -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-C5P0h_bB.cjs';
2
+ import { a as UpdateJSON, U as UpdateInfo, D as DownloadingInfo, I as IProvider, c as URLHandler } from './types-CItP6bL-.cjs';
3
3
 
4
4
  declare const ErrorInfo: {
5
5
  readonly download: "Download failed";
@@ -110,9 +110,9 @@ declare class Updater extends EventEmitter<{
110
110
  /**
111
111
  * download update using existing `asar.gz` buffer and signature
112
112
  * @param data existing `asar.gz` buffer
113
- * @param sig signature
113
+ * @param info update info
114
114
  */
115
- downloadUpdate(data: Uint8Array | Buffer, sig: string): Promise<boolean>;
115
+ downloadUpdate(data: Uint8Array, info: Omit<UpdateInfo, 'minimumVersion'>): Promise<boolean>;
116
116
  /**
117
117
  * quit App and install
118
118
  */
package/dist/index.cjs CHANGED
@@ -153,10 +153,11 @@ var Updater = class extends events.EventEmitter {
153
153
  this.emit("update-available", this.info);
154
154
  return true;
155
155
  }
156
- async downloadUpdate(data, sig) {
157
- const _sig = sig ?? this.info?.signature;
158
- if (!_sig) {
159
- this.err("download failed", "param", "no update signature, please call `checkUpdate` first");
156
+ async downloadUpdate(data, info) {
157
+ const _sig = info?.signature ?? this.info?.signature;
158
+ const _version = info?.version ?? this.info?.version;
159
+ if (!_sig || !_version) {
160
+ this.err("download failed", "param", "no update signature, please call `checkUpdate` first or manually setup params");
160
161
  return false;
161
162
  }
162
163
  const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
@@ -165,8 +166,7 @@ var Updater = class extends events.EventEmitter {
165
166
  return false;
166
167
  }
167
168
  this.logger?.debug("verify start");
168
- const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
169
- if (!_ver) {
169
+ if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
170
170
  this.err("download failed", "validate", "invalid signature / certificate pair");
171
171
  return false;
172
172
  }
@@ -175,7 +175,7 @@ var Updater = class extends events.EventEmitter {
175
175
  const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
176
176
  this.logger?.debug(`install to ${tmpFilePath}`);
177
177
  fs.writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
178
- this.logger?.info(`download success, version: ${_ver}`);
178
+ this.logger?.info(`download success, version: ${_version}`);
179
179
  this.info = void 0;
180
180
  this.emit("update-downloaded");
181
181
  return true;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
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';
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-ZUlLHadf.cjs';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-ZUlLHadf.cjs';
3
+ import { I as IProvider } from './types-CItP6bL-.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-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';
1
+ import { U as Updater, a as UpdaterOption, L as Logger } from './core-DJdvtwvU.js';
2
+ export { C as CheckResult, D as DownloadResult, E as ErrorInfo, b as UpdaterError } from './core-DJdvtwvU.js';
3
+ import { I as IProvider } from './types-CItP6bL-.js';
4
4
  import 'node:events';
5
5
  import '@subframe7536/type-utils';
6
6
 
package/dist/index.js CHANGED
@@ -123,10 +123,11 @@ var Updater = class extends EventEmitter {
123
123
  this.emit("update-available", this.info);
124
124
  return true;
125
125
  }
126
- async downloadUpdate(data, sig) {
127
- const _sig = sig ?? this.info?.signature;
128
- if (!_sig) {
129
- this.err("download failed", "param", "no update signature, please call `checkUpdate` first");
126
+ async downloadUpdate(data, info) {
127
+ const _sig = info?.signature ?? this.info?.signature;
128
+ const _version = info?.version ?? this.info?.version;
129
+ if (!_sig || !_version) {
130
+ this.err("download failed", "param", "no update signature, please call `checkUpdate` first or manually setup params");
130
131
  return false;
131
132
  }
132
133
  const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
@@ -135,8 +136,7 @@ var Updater = class extends EventEmitter {
135
136
  return false;
136
137
  }
137
138
  this.logger?.debug("verify start");
138
- const _ver = await this.provider.verifySignaure(buffer, _sig, this.CERT);
139
- if (!_ver) {
139
+ if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
140
140
  this.err("download failed", "validate", "invalid signature / certificate pair");
141
141
  return false;
142
142
  }
@@ -145,7 +145,7 @@ var Updater = class extends EventEmitter {
145
145
  const tmpFilePath = getPathFromAppNameAsar() + ".tmp";
146
146
  this.logger?.debug(`install to ${tmpFilePath}`);
147
147
  writeFileSync(tmpFilePath, await this.provider.unzipFile(buffer));
148
- this.logger?.info(`download success, version: ${_ver}`);
148
+ this.logger?.info(`download success, version: ${_version}`);
149
149
  this.info = void 0;
150
150
  this.emit("update-downloaded");
151
151
  return true;
package/dist/provider.cjs CHANGED
@@ -104,14 +104,15 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
104
104
  const total = getHeader(resp.headers, "content-length") || -1;
105
105
  let data = [];
106
106
  resp.on("data", (chunk) => {
107
- transferred += chunk.length;
107
+ const delta = chunk.length;
108
+ transferred += delta;
108
109
  const current = Date.now();
109
110
  onDownloading?.({
110
111
  percent: +(transferred / total).toFixed(2) * 100,
111
112
  total,
112
113
  transferred,
113
- delta: chunk.length,
114
- bps: chunk.length / ((current - time) * 1e3)
114
+ delta,
115
+ bps: delta / ((current - time) * 1e3)
115
116
  });
116
117
  time = current;
117
118
  data.push(chunk);
@@ -127,13 +128,15 @@ function aesDecrypt(encryptedText, key, iv) {
127
128
  const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
128
129
  return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
129
130
  }
130
- function defaultVerify(buffer, signature, cert) {
131
+ function defaultVerifySignature(buffer, version, signature, cert) {
131
132
  try {
132
- const [sig, version] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
133
- const result = crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
134
- return result ? version : void 0;
133
+ const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
134
+ if (ver !== version) {
135
+ return false;
136
+ }
137
+ return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
135
138
  } catch {
136
- return void 0;
139
+ return false;
137
140
  }
138
141
  }
139
142
  async function defaultUnzipFile(buffer) {
@@ -152,7 +155,7 @@ async function defaultUnzipFile(buffer) {
152
155
  var BaseProvider = class {
153
156
  name = "BaseProvider";
154
157
  isLowerVersion = defaultIsLowerVersion;
155
- verifySignaure = defaultVerify;
158
+ verifySignaure = defaultVerifySignature;
156
159
  unzipFile = defaultUnzipFile;
157
160
  };
158
161
 
@@ -187,7 +190,7 @@ var GitHubProvider = class extends BaseProvider {
187
190
  }
188
191
  async downloadJSON(versionPath) {
189
192
  return await defaultDownloadUpdateJSON(
190
- await this.parseURL(false, `HEAD/${versionPath}`),
193
+ await this.parseURL(false, `${this.options.branch ?? "HEAD"}/${versionPath}`),
191
194
  { accept: "application/json", ...this.options.extraHeaders }
192
195
  );
193
196
  }
@@ -1,11 +1,11 @@
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
- import { f as defaultVerify, a as defaultUnzipFile } from './zip-WRrEMkgp.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-CItP6bL-.cjs';
2
+ import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.cjs';
3
3
  import { Arrayable } from '@subframe7536/type-utils';
4
4
 
5
5
  declare abstract class BaseProvider implements IProvider {
6
6
  name: string;
7
7
  isLowerVersion: typeof defaultIsLowerVersion;
8
- verifySignaure: typeof defaultVerify;
8
+ verifySignaure: typeof defaultVerifySignature;
9
9
  unzipFile: typeof defaultUnzipFile;
10
10
  abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
11
11
  abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
@@ -20,6 +20,11 @@ interface GitHubProviderOptions {
20
20
  * github repo name
21
21
  */
22
22
  repo: string;
23
+ /**
24
+ * github branch name that fetch version
25
+ * @default 'HEAD'
26
+ */
27
+ branch?: string;
23
28
  /**
24
29
  * extra headers
25
30
  */
@@ -59,7 +64,13 @@ declare class GitHubProvider extends BaseProvider {
59
64
  }
60
65
 
61
66
  declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
67
+ /**
68
+ * download json and parse UpdateJson
69
+ */
62
70
  declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
71
+ /**
72
+ * download asar buffer, get total size from `Content-Length` header
73
+ */
63
74
  declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
64
75
 
65
76
  export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
@@ -1,11 +1,11 @@
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
- import { f as defaultVerify, a as defaultUnzipFile } from './zip-WRrEMkgp.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-CItP6bL-.js';
2
+ import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-DPF5IFkK.js';
3
3
  import { Arrayable } from '@subframe7536/type-utils';
4
4
 
5
5
  declare abstract class BaseProvider implements IProvider {
6
6
  name: string;
7
7
  isLowerVersion: typeof defaultIsLowerVersion;
8
- verifySignaure: typeof defaultVerify;
8
+ verifySignaure: typeof defaultVerifySignature;
9
9
  unzipFile: typeof defaultUnzipFile;
10
10
  abstract downloadJSON(versionPath: string): Promise<UpdateJSON>;
11
11
  abstract downloadAsar(name: string, info: UpdateInfo, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
@@ -20,6 +20,11 @@ interface GitHubProviderOptions {
20
20
  * github repo name
21
21
  */
22
22
  repo: string;
23
+ /**
24
+ * github branch name that fetch version
25
+ * @default 'HEAD'
26
+ */
27
+ branch?: string;
23
28
  /**
24
29
  * extra headers
25
30
  */
@@ -59,7 +64,13 @@ declare class GitHubProvider extends BaseProvider {
59
64
  }
60
65
 
61
66
  declare function getHeader(response: Record<string, Arrayable<string>>, headerKey: any): any;
67
+ /**
68
+ * download json and parse UpdateJson
69
+ */
62
70
  declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>): Promise<UpdateJSON>;
71
+ /**
72
+ * download asar buffer, get total size from `Content-Length` header
73
+ */
63
74
  declare function defaultDownloadAsar(url: string, headers: Record<string, any>, onDownloading?: OnDownloading): Promise<Buffer>;
64
75
 
65
76
  export { BaseProvider, DownloadingInfo, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, defaultDownloadAsar, defaultDownloadUpdateJSON, getHeader };
package/dist/provider.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defaultVerify, defaultUnzipFile } from './chunk-JSYIRKTR.js';
1
+ import { defaultVerifySignature, defaultUnzipFile } from './chunk-N77WQ5WB.js';
2
2
  import { defaultIsLowerVersion, isUpdateJSON } from './chunk-72ZAJ7AF.js';
3
3
  import { URL } from 'node:url';
4
4
  import { app, net } from 'electron';
@@ -50,14 +50,15 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
50
50
  const total = getHeader(resp.headers, "content-length") || -1;
51
51
  let data = [];
52
52
  resp.on("data", (chunk) => {
53
- transferred += chunk.length;
53
+ const delta = chunk.length;
54
+ transferred += delta;
54
55
  const current = Date.now();
55
56
  onDownloading?.({
56
57
  percent: +(transferred / total).toFixed(2) * 100,
57
58
  total,
58
59
  transferred,
59
- delta: chunk.length,
60
- bps: chunk.length / ((current - time) * 1e3)
60
+ delta,
61
+ bps: delta / ((current - time) * 1e3)
61
62
  });
62
63
  time = current;
63
64
  data.push(chunk);
@@ -70,7 +71,7 @@ async function defaultDownloadAsar(url, headers, onDownloading) {
70
71
  var BaseProvider = class {
71
72
  name = "BaseProvider";
72
73
  isLowerVersion = defaultIsLowerVersion;
73
- verifySignaure = defaultVerify;
74
+ verifySignaure = defaultVerifySignature;
74
75
  unzipFile = defaultUnzipFile;
75
76
  };
76
77
 
@@ -105,7 +106,7 @@ var GitHubProvider = class extends BaseProvider {
105
106
  }
106
107
  async downloadJSON(versionPath) {
107
108
  return await defaultDownloadUpdateJSON(
108
- await this.parseURL(false, `HEAD/${versionPath}`),
109
+ await this.parseURL(false, `${this.options.branch ?? "HEAD"}/${versionPath}`),
109
110
  { accept: "application/json", ...this.options.extraHeaders }
110
111
  );
111
112
  }
@@ -93,11 +93,12 @@ interface IProvider {
93
93
  /**
94
94
  * verify asar signature
95
95
  * @param buffer file buffer
96
+ * @param version target version
96
97
  * @param signature signature
97
98
  * @param cert certificate
98
99
  * @returns if signature is valid, returns the version, otherwise returns `undefined`
99
100
  */
100
- verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
101
+ verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
101
102
  }
102
103
 
103
104
  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 };
@@ -93,11 +93,12 @@ interface IProvider {
93
93
  /**
94
94
  * verify asar signature
95
95
  * @param buffer file buffer
96
+ * @param version target version
96
97
  * @param signature signature
97
98
  * @param cert certificate
98
99
  * @returns if signature is valid, returns the version, otherwise returns `undefined`
99
100
  */
100
- verifySignaure: (buffer: Buffer, signature: string, cert: string) => Promisable<string | undefined>;
101
+ verifySignaure: (buffer: Buffer, version: string, signature: string, cert: string) => Promisable<boolean>;
101
102
  }
102
103
 
103
104
  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
@@ -186,13 +186,15 @@ function aesDecrypt(encryptedText, key, iv) {
186
186
  const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
187
187
  return decipher.update(encryptedText, "base64url", "utf8") + decipher.final("utf8");
188
188
  }
189
- function defaultVerify(buffer, signature, cert) {
189
+ function defaultVerifySignature(buffer, version, signature, cert) {
190
190
  try {
191
- const [sig, version] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
192
- const result = crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
193
- return result ? version : void 0;
191
+ const [sig, ver] = aesDecrypt(signature, hashBuffer(cert, 32), hashBuffer(buffer, 16)).split("%");
192
+ if (ver !== version) {
193
+ return false;
194
+ }
195
+ return crypto.createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
194
196
  } catch {
195
- return void 0;
197
+ return false;
196
198
  }
197
199
  }
198
200
 
@@ -209,7 +211,7 @@ exports.autoUpdate = autoUpdate;
209
211
  exports.defaultIsLowerVersion = defaultIsLowerVersion;
210
212
  exports.defaultSignature = defaultSignature;
211
213
  exports.defaultUnzipFile = defaultUnzipFile;
212
- exports.defaultVerify = defaultVerify;
214
+ exports.defaultVerifySignature = defaultVerifySignature;
213
215
  exports.defaultVersionJsonGenerator = defaultVersionJsonGenerator;
214
216
  exports.defaultZipFile = defaultZipFile;
215
217
  exports.disableHWAccForWin7 = disableHWAccForWin7;
package/dist/utils.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BrowserWindow } from 'electron';
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, i as isUpdateJSON, p as parseVersion } from './types-C5P0h_bB.cjs';
4
- import { U as Updater } from './core-DmU2Vk_S.cjs';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-DPF5IFkK.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-CItP6bL-.cjs';
4
+ import { U as Updater } from './core-ZUlLHadf.cjs';
5
5
  import '@subframe7536/type-utils';
6
6
  import 'node:events';
7
7
 
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BrowserWindow } from 'electron';
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, i as isUpdateJSON, p as parseVersion } from './types-C5P0h_bB.js';
4
- import { U as Updater } from './core-CXETH_bb.js';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-DPF5IFkK.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-CItP6bL-.js';
4
+ import { U as Updater } from './core-DJdvtwvU.js';
5
5
  import '@subframe7536/type-utils';
6
6
  import 'node:events';
7
7
 
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
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
- export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerify, defaultZipFile, hashBuffer } from './chunk-JSYIRKTR.js';
2
+ export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-N77WQ5WB.js';
3
3
  export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-72ZAJ7AF.js';
4
4
 
5
5
  // src/utils/updater.ts
package/dist/vite.d.ts CHANGED
@@ -2,6 +2,7 @@ import { PluginOption } from 'vite';
2
2
  import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
3
3
  import { Promisable } from '@subframe7536/type-utils';
4
4
  import { BuildOptions } from 'esbuild';
5
+ export { isCI } from 'ci-info';
5
6
 
6
7
  /**
7
8
  * update info json
package/dist/vite.js CHANGED
@@ -6,6 +6,7 @@ import { startup } from 'vite-plugin-electron';
6
6
  import { notBundle } from 'vite-plugin-electron/plugin';
7
7
  import { getPackageInfoSync, loadPackageJSON } from 'local-pkg';
8
8
  import { isCI } from 'ci-info';
9
+ export { isCI } from 'ci-info';
9
10
  import Asar from '@electron/asar';
10
11
  import { build } from 'esbuild';
11
12
  import { spawn } from 'node:child_process';
@@ -102,7 +103,7 @@ function toRelativePath(filename, importer) {
102
103
  }
103
104
  function compileToBytecode(code) {
104
105
  let data = Buffer.from([]);
105
- const logErr = (...args) => log.error(args.join(" "), { timestamp: true });
106
+ const logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
106
107
  const electronPath = getElectronPath();
107
108
  const bytecodePath = getBytecodeCompilerPath();
108
109
  return new Promise((resolve2, reject) => {
@@ -151,11 +152,11 @@ function convertString(code, strings, sourcemap) {
151
152
  map: sourcemap ? s.generateMap({ hires: "boundary" }) : null
152
153
  } : { code };
153
154
  }
155
+ var decodeFn = "function(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))}";
154
156
  function obfuscateString(input) {
155
- const offset = Math.floor(Math.random() * 2 << 4) + 1;
156
- const hexArray = Array.from(input).map((c) => "0x" + (c.charCodeAt(0) + offset).toString(16));
157
- const decodeFn = `function(a,b){return String.fromCharCode.apply(null,a.map(x=>+x-b))}`;
158
- return `(${decodeFn})([${hexArray.join(",")}],${offset})`;
157
+ const offset = Math.random() << 4 | 0;
158
+ const hexArray = input.split("").map((c) => "0x" + (c.charCodeAt(0) + offset).toString(16));
159
+ return `(${decodeFn})(${JSON.stringify(hexArray)},${offset})`;
159
160
  }
160
161
 
161
162
  // src/build-plugins/utils.ts
@@ -247,6 +248,7 @@ async function buildEntry({
247
248
  entryNames: "[dir]/[name]",
248
249
  assetNames: "[dir]/[name]",
249
250
  external: ["electron", "original-fs"],
251
+ treeShaking: true,
250
252
  loader: {
251
253
  ".node": "empty"
252
254
  },
@@ -280,7 +282,7 @@ async function buildEntry({
280
282
  `${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
281
283
  );
282
284
  bytecodeLog.info(
283
- `${filePath} => ${(buffer.byteLength / 1e3).toFixed(2)} kB`,
285
+ `${filePath} [${(buffer.byteLength / 1e3).toFixed(2)} kB]`,
284
286
  { timestamp: true }
285
287
  );
286
288
  }
@@ -431,8 +433,8 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
431
433
  };
432
434
  return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
433
435
  }
434
- function bytecodePlugin(isBuild, env, options = {}) {
435
- if (!isBuild) {
436
+ function bytecodePlugin(enable, env, options = {}) {
437
+ if (!enable) {
436
438
  return null;
437
439
  }
438
440
  const {
@@ -577,8 +579,6 @@ ${bytecodeLoaderBlock}`) : _code;
577
579
  }
578
580
  };
579
581
  }
580
-
581
- // src/vite.ts
582
582
  function debugStartup(args) {
583
583
  if (process.env.VSCODE_DEBUG) {
584
584
  console.log("[startup] Electron App");
@@ -616,7 +616,7 @@ async function electronWithUpdater(options) {
616
616
  preload: _preload,
617
617
  sourcemap = !isBuild,
618
618
  minify = isBuild,
619
- buildVersionJson = isCI,
619
+ buildVersionJson,
620
620
  updater,
621
621
  bytecode,
622
622
  useNotBundle = true,
@@ -685,7 +685,8 @@ async function electronWithUpdater(options) {
685
685
  };
686
686
  let isInit = false;
687
687
  const rollupOptions = {
688
- external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src)
688
+ external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src),
689
+ treeshake: true
689
690
  };
690
691
  const electronPluginOptions = {
691
692
  main: {
@@ -706,7 +707,7 @@ async function electronWithUpdater(options) {
706
707
  {
707
708
  plugins: [
708
709
  !isBuild && useNotBundle ? notBundle() : void 0,
709
- bytecodeOptions && bytecodePlugin(isBuild, "main", bytecodeOptions)
710
+ bytecodeOptions && bytecodePlugin(!!bytecode, "main", bytecodeOptions)
710
711
  ],
711
712
  build: {
712
713
  sourcemap,
@@ -725,7 +726,7 @@ async function electronWithUpdater(options) {
725
726
  vite: mergeConfig(
726
727
  {
727
728
  plugins: [
728
- bytecodeOptions && bytecodePlugin(isBuild, "preload", bytecodeOptions),
729
+ bytecodeOptions && bytecodePlugin(!!bytecode, "preload", bytecodeOptions),
729
730
  {
730
731
  name: `${id}-build`,
731
732
  enforce: "post",
@@ -736,7 +737,9 @@ async function electronWithUpdater(options) {
736
737
  await _buildEntry();
737
738
  await _postBuild();
738
739
  const buffer = await buildAsar(buildAsarOption);
739
- if (buildVersionJson) {
740
+ if (!buildVersionJson && !isCI) {
741
+ log.warn("no `buildVersionJson` setup, skip build version json. Will build in CI by default", { timestamp: true });
742
+ } else {
740
743
  await buildVersion(buildVersionOption, buffer);
741
744
  }
742
745
  }
@@ -2,9 +2,9 @@ declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
2
  declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
3
  declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
4
4
  declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
5
- declare function defaultVerify(buffer: Buffer, signature: string, cert: string): string | undefined;
5
+ declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
6
6
 
7
7
  declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
8
8
  declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
9
9
 
10
- export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerify as f, hashBuffer as h };
10
+ export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
@@ -2,9 +2,9 @@ declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
2
  declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
3
  declare function defaultSignature(buffer: Buffer, privateKey: string, cert: string, version: string): string;
4
4
  declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): string;
5
- declare function defaultVerify(buffer: Buffer, signature: string, cert: string): string | undefined;
5
+ declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
6
6
 
7
7
  declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
8
8
  declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
9
9
 
10
- export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerify as f, hashBuffer as h };
10
+ export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
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.5",
4
+ "version": "2.0.0-beta.7",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "author": "subframe7536",
7
7
  "license": "MIT",