electron-incremental-update 0.7.8 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,16 +1,20 @@
1
1
  import {
2
- isUpdateJSON,
3
2
  verify
4
- } from "./chunk-2XHZMWRR.mjs";
3
+ } from "./chunk-Q2K52LOG.mjs";
5
4
  import {
6
- __require,
7
5
  getEntryVersion,
8
6
  getProductAsarPath,
9
7
  getProductVersion,
10
8
  parseVersion,
11
9
  unzipFile,
12
10
  waitAppReady
13
- } from "./chunk-SWXNCK6H.mjs";
11
+ } from "./chunk-4TION32M.mjs";
12
+ import {
13
+ isUpdateJSON
14
+ } from "./chunk-2JVXVTC5.mjs";
15
+ import {
16
+ __require
17
+ } from "./chunk-ZFXKCRJC.mjs";
14
18
 
15
19
  // src/index.ts
16
20
  import { resolve } from "node:path";
@@ -18,15 +22,14 @@ import { existsSync as existsSync2, renameSync } from "node:fs";
18
22
  import { app } from "electron";
19
23
 
20
24
  // src/updater/index.ts
21
- import { EventEmitter } from "node:events";
22
- import { Buffer as Buffer2 } from "node:buffer";
23
25
  import { existsSync } from "node:fs";
26
+ import { Buffer as Buffer2 } from "node:buffer";
24
27
  import { rm, writeFile } from "node:fs/promises";
25
28
 
26
29
  // src/updater/defaultFunctions.ts
27
30
  import { Buffer } from "node:buffer";
28
31
  import { net } from "electron";
29
- async function downloadJSONDefault(url, updater, headers) {
32
+ var downloadJSONDefault = async (url, headers) => {
30
33
  await waitAppReady();
31
34
  return new Promise((resolve2, reject) => {
32
35
  const request = net.request({
@@ -58,10 +61,10 @@ async function downloadJSONDefault(url, updater, headers) {
58
61
  });
59
62
  request.end();
60
63
  });
61
- }
62
- async function downloadBufferDefault(url, updater, headers) {
64
+ };
65
+ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
63
66
  await waitAppReady();
64
- let progress = 0;
67
+ let current = 0;
65
68
  return new Promise((resolve2, reject) => {
66
69
  const request = net.request({
67
70
  url,
@@ -74,8 +77,12 @@ async function downloadBufferDefault(url, updater, headers) {
74
77
  request.on("response", (res) => {
75
78
  let data = [];
76
79
  res.on("data", (chunk) => {
77
- progress += chunk.length;
78
- updater.emit("downloading", progress);
80
+ current += chunk.length;
81
+ onDownloading?.({
82
+ percent: `${+(current / total).toFixed(2) * 100}%`,
83
+ total,
84
+ current
85
+ });
79
86
  data.push(chunk);
80
87
  });
81
88
  res.on("end", () => {
@@ -86,15 +93,24 @@ async function downloadBufferDefault(url, updater, headers) {
86
93
  });
87
94
  request.end();
88
95
  });
89
- }
90
- var compareVersionDefault = (oldVersion, newVersion) => {
91
- const oldV = parseVersion(oldVersion);
92
- const newV = parseVersion(newVersion);
93
- if (oldV.major < newV.major || oldV.major === newV.major && oldV.minor < newV.minor || oldV.major === newV.major && oldV.minor === newV.minor && oldV.patch < newV.patch) {
94
- return true;
96
+ };
97
+ var compareVersionDefault = (version1, version2) => {
98
+ const oldV = parseVersion(version1);
99
+ const newV = parseVersion(version2);
100
+ function compareStrings(str1, str2) {
101
+ if (str1 === "") {
102
+ return str2 !== "";
103
+ } else if (str2 === "") {
104
+ return true;
105
+ }
106
+ return str1 < str2;
95
107
  }
96
- if (oldV.stage < newV.stage || !newV.stage && oldV.stage) {
97
- return true;
108
+ for (let key of Object.keys(oldV)) {
109
+ if (key === "stage" && compareStrings(oldV[key], newV[key])) {
110
+ return true;
111
+ } else if (oldV[key] !== newV[key]) {
112
+ return oldV[key] < newV[key];
113
+ }
98
114
  }
99
115
  return false;
100
116
  };
@@ -118,158 +134,151 @@ var VerifyFailedError = class extends Error {
118
134
  this.cert = cert;
119
135
  }
120
136
  };
121
- function createUpdater(updaterOptions) {
122
- const {
123
- SIGNATURE_CERT,
124
- repository,
125
- productName,
126
- releaseAsarURL: _release,
127
- updateJsonURL: _update,
128
- debug = false,
129
- receiveBeta = false,
130
- downloadConfig: { extraHeader, userAgent } = {},
131
- overrideFunctions: {
132
- compareVersion,
133
- verifySignaure,
134
- downloadBuffer,
135
- downloadJSON
136
- } = {}
137
- } = updaterOptions;
138
- const updater = new EventEmitter();
139
- let signature;
140
- let version;
141
- const asarPath = getProductAsarPath(productName);
142
- const gzipPath = `${asarPath}.gz`;
143
- const tmpFilePath = `${asarPath}.tmp`;
144
- function log(msg) {
145
- debug && updater.emit("debug", msg);
137
+ var IncrementalUpdater = class {
138
+ info;
139
+ option;
140
+ asarPath;
141
+ gzipPath;
142
+ tmpFilePath;
143
+ logger;
144
+ onDownloading;
145
+ get productName() {
146
+ return this.option.productName;
147
+ }
148
+ set productName(name) {
149
+ this.option.productName = name;
150
+ }
151
+ get receiveBeta() {
152
+ return !!this.option.receiveBeta;
153
+ }
154
+ set receiveBeta(receiveBeta) {
155
+ this.option.receiveBeta = receiveBeta;
146
156
  }
147
- async function needUpdate(version2, minVersion) {
148
- const compare = compareVersion ?? compareVersionDefault;
149
- const productVersion = getProductVersion(productName);
157
+ constructor(option) {
158
+ this.option = option;
159
+ this.asarPath = getProductAsarPath(this.productName);
160
+ this.gzipPath = `${this.asarPath}.gz`;
161
+ this.tmpFilePath = `${this.asarPath}.tmp`;
162
+ }
163
+ async needUpdate(version, minVersion) {
164
+ const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
165
+ const productVersion = getProductVersion(this.option.productName);
150
166
  const entryVersion = getEntryVersion();
151
167
  if (await compare(entryVersion, minVersion)) {
152
168
  throw new MinimumVersionError(entryVersion, minVersion);
153
169
  }
154
- log(`check update: current version is ${productVersion}, new version is ${version2}`);
155
- return await compare(productVersion, version2);
170
+ this.logger?.info(`check update: current version is ${productVersion}, new version is ${version}`);
171
+ return await compare(productVersion, version);
156
172
  }
157
- async function parseData(format, data, version2) {
158
- if (existsSync(tmpFilePath)) {
159
- log(`remove tmp file: ${tmpFilePath}`);
160
- await rm(tmpFilePath);
173
+ async parseData(format, data) {
174
+ if (existsSync(this.tmpFilePath)) {
175
+ this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
176
+ await rm(this.tmpFilePath);
177
+ }
178
+ if (existsSync(this.gzipPath)) {
179
+ this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
180
+ await rm(this.gzipPath);
181
+ }
182
+ if (!["string", "object", "undefined"].includes(typeof data)) {
183
+ throw new TypeError(`invalid type at format '${format}': ${data}`);
161
184
  }
162
- if (existsSync(gzipPath)) {
163
- log(`remove .gz file: ${gzipPath}`);
164
- await rm(gzipPath);
185
+ if (typeof data === "object" && (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer2.isBuffer(data))) {
186
+ return data;
165
187
  }
166
188
  if (typeof data === "object") {
167
- if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer2.isBuffer(data)) {
168
- return data;
169
- } else {
170
- throw new TypeError(`invalid type at format '${format}': ${data}`);
171
- }
172
- } else if (["string", "undefined"].includes(typeof data)) {
173
- const ua = userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
174
- const headers = {
175
- Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
176
- UserAgent: ua,
177
- ...extraHeader
178
- };
179
- log(`download headers: ${JSON.stringify(headers, null, 2)}`);
180
- const info = format === "json" ? {
181
- name: "updateJsonURL",
182
- url: _update,
183
- repoFallback: `${repository.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
184
- fn: downloadJSON ?? downloadJSONDefault
185
- } : {
186
- name: "releaseAsarURL",
187
- url: _release,
188
- repoFallback: `${repository}/releases/download/v${version2}/${productName}-${version2}.asar.gz`,
189
- fn: downloadBuffer ?? downloadBufferDefault
190
- };
191
- data ??= info.url;
192
- if (!data) {
193
- log(`no ${info.name}, fallback to use repository`);
194
- if (!repository) {
195
- throw new Error(`${info.name} or repository are not set`);
196
- }
197
- if (format === "buffer" && !version2) {
198
- throw new Error("version are not set");
199
- }
200
- data = info.repoFallback;
189
+ throw new TypeError(`invalid type at format '${format}': ${data}`);
190
+ }
191
+ const ua = this.option.downloadConfig?.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
192
+ const headers = {
193
+ Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
194
+ UserAgent: ua,
195
+ ...this.option.downloadConfig?.extraHeader
196
+ };
197
+ this.logger?.info(`download headers: ${JSON.stringify(headers, null, 2)}`);
198
+ const config = format === "json" ? {
199
+ name: "updateJsonURL",
200
+ url: this.option.updateJsonURL,
201
+ repoFallback: `${this.option.repository.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
202
+ fn: this.option.overrideFunctions?.downloadJSON ?? downloadJSONDefault
203
+ } : {
204
+ name: "releaseAsarURL",
205
+ url: this.option.releaseAsarURL,
206
+ repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${this.productName}-${this.info?.version}.asar.gz`,
207
+ fn: this.option.overrideFunctions?.downloadBuffer ?? downloadBufferDefault
208
+ };
209
+ data ??= config.url;
210
+ if (!data) {
211
+ this.logger?.debug(`no ${config.name}, fallback to use repository`);
212
+ if (!this.option.repository) {
213
+ throw new Error(`${config.name} or repository are not set`);
201
214
  }
202
- log(`download ${format} from ${data}`);
203
- const ret = await info.fn(data, updater, headers);
204
- log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
205
- if (format === "buffer") {
206
- updater.emit("downloadBuffer", ret);
215
+ if (format === "buffer" && !this.info?.version) {
216
+ throw new Error("version are not set");
207
217
  }
208
- return ret;
209
- } else {
210
- throw new TypeError(`invalid type at format '${format}': ${data}`);
218
+ data = config.repoFallback;
211
219
  }
220
+ this.logger?.info(`download ${format} from ${data}`);
221
+ const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
222
+ this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
223
+ return ret;
212
224
  }
213
- updater.productName = productName;
214
- updater.debug = debug;
215
- updater.receiveBeta = receiveBeta;
216
- updater.checkUpdate = async (data) => {
225
+ async checkUpdate(data) {
217
226
  try {
218
- let {
219
- signature: _sig,
220
- size,
221
- version: _ver,
222
- minimumVersion,
223
- beta
224
- } = await parseData("json", data);
225
- if (receiveBeta) {
226
- _ver = beta.version;
227
- _sig = beta.signature;
227
+ let { signature, size, version, minimumVersion, beta } = await this.parseData("json", data);
228
+ if (this.receiveBeta) {
229
+ version = beta.version;
230
+ signature = beta.signature;
228
231
  minimumVersion = beta.minimumVersion;
229
232
  size = beta.size;
230
233
  }
231
- log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
232
- if (!await needUpdate(_ver, minimumVersion)) {
233
- log(`update unavailable: ${_ver}`);
234
+ this.logger?.info(`checked version: ${version}, size: ${size}, signature: ${signature}`);
235
+ if (!await this.needUpdate(version, minimumVersion)) {
236
+ this.logger?.info(`update unavailable: ${version} is the latest version`);
234
237
  return void 0;
235
238
  } else {
236
- log(`update available: ${_ver}`);
237
- signature = _sig;
238
- version = _ver;
239
- return { size, version: _ver };
239
+ this.logger?.info(`update available: ${version}`);
240
+ this.info = {
241
+ signature,
242
+ minimumVersion,
243
+ version,
244
+ size
245
+ };
246
+ return { size, version };
240
247
  }
241
248
  } catch (error) {
242
- log(error);
249
+ this.logger?.error("check update failed", error);
243
250
  return error;
244
251
  }
245
- };
246
- updater.download = async (data, sig) => {
252
+ }
253
+ async download(data, sig) {
247
254
  try {
248
- const _sig = sig ?? signature;
255
+ const _sig = sig ?? this.info?.signature;
249
256
  if (!_sig) {
250
257
  throw new Error("signature are not set, please checkUpdate first or set the second parameter");
251
258
  }
252
- const buffer = await parseData("buffer", data, version);
253
- log("verify start");
254
- const _verify = verifySignaure ?? verify;
255
- const _ver = await _verify(buffer, _sig, SIGNATURE_CERT);
259
+ const buffer = await this.parseData("buffer", data);
260
+ this.logger?.info("verify start");
261
+ const _verify = this.option.overrideFunctions?.verifySignaure ?? verify;
262
+ const _ver = await _verify(buffer, _sig, this.option.SIGNATURE_CERT);
256
263
  if (!_ver) {
257
- throw new VerifyFailedError(_sig, SIGNATURE_CERT);
264
+ throw new VerifyFailedError(_sig, this.option.SIGNATURE_CERT);
258
265
  }
259
- log("verify success");
260
- log(`write to ${gzipPath}`);
261
- await writeFile(gzipPath, buffer);
262
- log(`extract to ${tmpFilePath}`);
263
- await unzipFile(gzipPath, tmpFilePath);
264
- log(`download success, version: ${_ver}`);
265
- signature = "";
266
+ this.logger?.info("verify success");
267
+ this.logger?.info(`write to ${this.gzipPath}`);
268
+ await writeFile(this.gzipPath, buffer);
269
+ this.logger?.info(`extract to ${this.tmpFilePath}`);
270
+ await unzipFile(this.gzipPath, this.tmpFilePath);
271
+ this.logger?.info(`download success${typeof _ver === "string" ? `, version: ${_ver}` : ""}`);
272
+ this.info = void 0;
266
273
  return true;
267
274
  } catch (error) {
268
- log(error);
275
+ this.logger?.error("download asar failed", error);
269
276
  return error;
270
277
  }
271
- };
272
- return updater;
278
+ }
279
+ };
280
+ function createUpdater(option) {
281
+ return new IncrementalUpdater(option);
273
282
  }
274
283
 
275
284
  // src/index.ts
@@ -315,6 +324,7 @@ function initApp(appOptions) {
315
324
  };
316
325
  }
317
326
  export {
327
+ IncrementalUpdater,
318
328
  MinimumVersionError,
319
329
  VerifyFailedError,
320
330
  createUpdater,
@@ -7,5 +7,6 @@ type UpdateInfo = {
7
7
  type UpdateJSON = UpdateInfo & {
8
8
  beta: UpdateInfo;
9
9
  };
10
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
10
11
 
11
- export { UpdateJSON as U };
12
+ export { UpdateInfo, UpdateJSON, isUpdateJSON };
@@ -0,0 +1,12 @@
1
+ type UpdateInfo = {
2
+ signature: string;
3
+ minimumVersion: string;
4
+ version: string;
5
+ size: number;
6
+ };
7
+ type UpdateJSON = UpdateInfo & {
8
+ beta: UpdateInfo;
9
+ };
10
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
11
+
12
+ export { UpdateInfo, UpdateJSON, isUpdateJSON };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/updateJson.ts
21
+ var updateJson_exports = {};
22
+ __export(updateJson_exports, {
23
+ isUpdateJSON: () => isUpdateJSON
24
+ });
25
+ module.exports = __toCommonJS(updateJson_exports);
26
+ function isUpdateJSON(json) {
27
+ const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
28
+ return is(json) && "beta" in json && is(json.beta);
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ isUpdateJSON
33
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ isUpdateJSON
3
+ } from "./chunk-2JVXVTC5.mjs";
4
+ import "./chunk-ZFXKCRJC.mjs";
5
+ export {
6
+ isUpdateJSON
7
+ };
package/dist/utils.d.mts CHANGED
@@ -9,6 +9,8 @@ declare function getProductAsarPath(name: string): string;
9
9
  declare function getEntryVersion(): string;
10
10
  /**
11
11
  * get the version of application (name.asar)
12
+ *
13
+ * if is dev, return {@link getEntryVersion}
12
14
  * @param name - The name of the application
13
15
  */
14
16
  declare function getProductVersion(name: string): string;
@@ -23,11 +25,11 @@ declare class NoSuchNativeModuleError extends Error {
23
25
  */
24
26
  declare function requireNative<T = any>(packageName: string): T;
25
27
  /**
26
- * get github version.json CDN URL for accelerating the speed of downloading version info
28
+ * parse Github CDN URL for accelerating the speed of downloading
27
29
  */
28
30
  declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
29
31
  /**
30
- * get group of github file CDN prefix for accelerating the speed of downloading release
32
+ * get group of Github file CDN prefix for accelerating the speed of downloading project files
31
33
  */
32
34
  declare function getGithubFileCdnGroup(): {
33
35
  cdnPrefix: string;
@@ -40,16 +42,24 @@ declare function getGithubReleaseCdnGroup(): {
40
42
  cdnPrefix: string;
41
43
  source: string;
42
44
  }[];
45
+ /**
46
+ * Restarts the Electron app.
47
+ */
43
48
  declare function restartApp(): void;
44
- declare function waitAppReady(duration?: number): Promise<unknown>;
45
- declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
49
+ /**
50
+ * ensure app is ready.
51
+ */
52
+ declare function waitAppReady(duration?: number): Promise<void>;
53
+ declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
46
54
  declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
47
55
  declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
48
- declare function parseVersion(version: string): {
56
+ interface Version {
49
57
  major: number;
50
58
  minor: number;
51
59
  patch: number;
52
60
  stage: string;
53
- };
61
+ stageVersion: number;
62
+ }
63
+ declare function parseVersion(version: string): Version;
54
64
 
55
- export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
65
+ export { NoSuchNativeModuleError, Version, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.d.ts CHANGED
@@ -9,6 +9,8 @@ declare function getProductAsarPath(name: string): string;
9
9
  declare function getEntryVersion(): string;
10
10
  /**
11
11
  * get the version of application (name.asar)
12
+ *
13
+ * if is dev, return {@link getEntryVersion}
12
14
  * @param name - The name of the application
13
15
  */
14
16
  declare function getProductVersion(name: string): string;
@@ -23,11 +25,11 @@ declare class NoSuchNativeModuleError extends Error {
23
25
  */
24
26
  declare function requireNative<T = any>(packageName: string): T;
25
27
  /**
26
- * get github version.json CDN URL for accelerating the speed of downloading version info
28
+ * parse Github CDN URL for accelerating the speed of downloading
27
29
  */
28
30
  declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
29
31
  /**
30
- * get group of github file CDN prefix for accelerating the speed of downloading release
32
+ * get group of Github file CDN prefix for accelerating the speed of downloading project files
31
33
  */
32
34
  declare function getGithubFileCdnGroup(): {
33
35
  cdnPrefix: string;
@@ -40,16 +42,24 @@ declare function getGithubReleaseCdnGroup(): {
40
42
  cdnPrefix: string;
41
43
  source: string;
42
44
  }[];
45
+ /**
46
+ * Restarts the Electron app.
47
+ */
43
48
  declare function restartApp(): void;
44
- declare function waitAppReady(duration?: number): Promise<unknown>;
45
- declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
49
+ /**
50
+ * ensure app is ready.
51
+ */
52
+ declare function waitAppReady(duration?: number): Promise<void>;
53
+ declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
46
54
  declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
47
55
  declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
48
- declare function parseVersion(version: string): {
56
+ interface Version {
49
57
  major: number;
50
58
  minor: number;
51
59
  patch: number;
52
60
  stage: string;
53
- };
61
+ stageVersion: number;
62
+ }
63
+ declare function parseVersion(version: string): Version;
54
64
 
55
- export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
65
+ export { NoSuchNativeModuleError, Version, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.js CHANGED
@@ -111,11 +111,11 @@ function waitAppReady(duration = 1e3) {
111
111
  }, duration);
112
112
  import_electron.app.whenReady().then(() => {
113
113
  clearTimeout(timeout);
114
- resolve(null);
114
+ resolve();
115
115
  });
116
116
  });
117
117
  }
118
- async function unzipFile(gzipPath, targetFilePath) {
118
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
119
119
  if (!(0, import_node_fs.existsSync)(gzipPath)) {
120
120
  throw new Error(`path to zipped file not exist: ${gzipPath}`);
121
121
  }
@@ -161,10 +161,22 @@ function parseVersion(version) {
161
161
  throw new TypeError(`invalid version: ${version}`);
162
162
  }
163
163
  const [major, minor, patch] = match.slice(1, 4).map(Number);
164
- if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
164
+ const ret = {
165
+ major,
166
+ minor,
167
+ patch,
168
+ stage: "",
169
+ stageVersion: -1
170
+ };
171
+ if (match[4]) {
172
+ let [stage, _v] = match[4].split(".");
173
+ ret.stage = stage;
174
+ ret.stageVersion = Number(_v) || -1;
175
+ }
176
+ if (isNaN(major) || isNaN(minor) || isNaN(patch) || isNaN(ret.stageVersion)) {
165
177
  throw new TypeError(`invalid version: ${version}`);
166
178
  }
167
- return { major, minor, patch, stage: match[4] };
179
+ return ret;
168
180
  }
169
181
  // Annotate the CommonJS export names for ESM import in node:
170
182
  0 && (module.exports = {
package/dist/utils.mjs CHANGED
@@ -13,7 +13,8 @@ import {
13
13
  unzipFile,
14
14
  waitAppReady,
15
15
  zipFile
16
- } from "./chunk-SWXNCK6H.mjs";
16
+ } from "./chunk-4TION32M.mjs";
17
+ import "./chunk-ZFXKCRJC.mjs";
17
18
  export {
18
19
  NoSuchNativeModuleError,
19
20
  getEntryVersion,
package/dist/vite.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { Buffer } from 'node:buffer';
3
- import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
3
+ import { UpdateJSON } from './updateJson.mjs';
4
4
 
5
5
  type DistinguishedName = {
6
6
  countryName?: string;
@@ -15,8 +15,26 @@ type DistinguishedName = {
15
15
  businessCategory?: string;
16
16
  emailAddress?: string;
17
17
  };
18
- type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
19
- type FunctionGenerateVersionJson = (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
18
+ type GeneratorOverrideFunctions = {
19
+ /**
20
+ * custom signature generate function
21
+ * @param buffer file buffer
22
+ * @param privateKey private key
23
+ * @param cert certificate string, **EOL must be '\n'**
24
+ * @param version current version
25
+ */
26
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
27
+ /**
28
+ * custom generate version json function
29
+ * @param existingJson The existing JSON object.
30
+ * @param buffer file buffer
31
+ * @param signature generated signature
32
+ * @param version current version
33
+ * @param minVersion The minimum version
34
+ * @returns The updated version json
35
+ */
36
+ generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
37
+ };
20
38
  type Options = {
21
39
  /**
22
40
  * whether is in build mode
@@ -123,22 +141,7 @@ type Options = {
123
141
  */
124
142
  days?: number;
125
143
  };
126
- overrideFunctions?: {
127
- /**
128
- * custom signature generate function {@link FunctionGenerateSignature}
129
- * @param buffer file buffer
130
- * @param privateKey private key
131
- * @param cert certificate
132
- */
133
- generateSignature?: FunctionGenerateSignature;
134
- /**
135
- * custom signature generate function {@link FunctionGenerateVersionJson}
136
- * @param signature generated signature
137
- * @param version currentVersion
138
- * @param cert certificate
139
- */
140
- generateVersionJson?: FunctionGenerateVersionJson;
141
- };
144
+ overrideFunctions?: GeneratorOverrideFunctions;
142
145
  };
143
146
  };
144
147