electron-incremental-update 0.7.8 → 0.7.10

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,160 @@ 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 DownloadError = class extends Error {
138
+ constructor() {
139
+ super("download update error");
140
+ }
141
+ };
142
+ var IncrementalUpdater = class {
143
+ info;
144
+ option;
145
+ asarPath;
146
+ gzipPath;
147
+ tmpFilePath;
148
+ logger;
149
+ onDownloading;
150
+ get productName() {
151
+ return this.option.productName;
152
+ }
153
+ set productName(name) {
154
+ this.option.productName = name;
155
+ }
156
+ get receiveBeta() {
157
+ return !!this.option.receiveBeta;
158
+ }
159
+ set receiveBeta(receiveBeta) {
160
+ this.option.receiveBeta = receiveBeta;
146
161
  }
147
- async function needUpdate(version2, minVersion) {
148
- const compare = compareVersion ?? compareVersionDefault;
149
- const productVersion = getProductVersion(productName);
162
+ constructor(option) {
163
+ this.option = option;
164
+ this.asarPath = getProductAsarPath(this.productName);
165
+ this.gzipPath = `${this.asarPath}.gz`;
166
+ this.tmpFilePath = `${this.asarPath}.tmp`;
167
+ }
168
+ async needUpdate(version, minVersion) {
169
+ const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
170
+ const productVersion = getProductVersion(this.option.productName);
150
171
  const entryVersion = getEntryVersion();
151
172
  if (await compare(entryVersion, minVersion)) {
152
173
  throw new MinimumVersionError(entryVersion, minVersion);
153
174
  }
154
- log(`check update: current version is ${productVersion}, new version is ${version2}`);
155
- return await compare(productVersion, version2);
175
+ this.logger?.info(`check update: current version is ${productVersion}, new version is ${version}`);
176
+ return await compare(productVersion, version);
156
177
  }
157
- async function parseData(format, data, version2) {
158
- if (existsSync(tmpFilePath)) {
159
- log(`remove tmp file: ${tmpFilePath}`);
160
- await rm(tmpFilePath);
178
+ async parseData(format, data) {
179
+ if (existsSync(this.tmpFilePath)) {
180
+ this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
181
+ await rm(this.tmpFilePath);
182
+ }
183
+ if (existsSync(this.gzipPath)) {
184
+ this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
185
+ await rm(this.gzipPath);
161
186
  }
162
- if (existsSync(gzipPath)) {
163
- log(`remove .gz file: ${gzipPath}`);
164
- await rm(gzipPath);
187
+ if (!["string", "object", "undefined"].includes(typeof data)) {
188
+ throw new TypeError(`invalid type at format '${format}': ${data}`);
189
+ }
190
+ if (typeof data === "object" && (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer2.isBuffer(data))) {
191
+ return data;
165
192
  }
166
193
  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;
194
+ throw new TypeError(`invalid type at format '${format}': ${data}`);
195
+ }
196
+ 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";
197
+ const headers = {
198
+ Accept: `application/${format === "json" ? "json" : "octet-stream"}`,
199
+ UserAgent: ua,
200
+ ...this.option.downloadConfig?.extraHeader
201
+ };
202
+ this.logger?.info(`download headers: ${JSON.stringify(headers, null, 2)}`);
203
+ const config = format === "json" ? {
204
+ name: "updateJsonURL",
205
+ url: this.option.updateJsonURL,
206
+ repoFallback: `${this.option.repository.replace("github.com", "raw.githubusercontent.com")}/master/version.json`,
207
+ fn: this.option.overrideFunctions?.downloadJSON ?? downloadJSONDefault
208
+ } : {
209
+ name: "releaseAsarURL",
210
+ url: this.option.releaseAsarURL,
211
+ repoFallback: `${this.option.repository}/releases/download/v${this.info?.version}/${this.productName}-${this.info?.version}.asar.gz`,
212
+ fn: this.option.overrideFunctions?.downloadBuffer ?? downloadBufferDefault
213
+ };
214
+ data ??= config.url;
215
+ if (!data) {
216
+ this.logger?.debug(`no ${config.name}, fallback to use repository`);
217
+ if (!this.option.repository) {
218
+ throw new Error(`${config.name} or repository are not set`);
201
219
  }
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);
220
+ if (format === "buffer" && !this.info?.version) {
221
+ throw new Error("version are not set");
207
222
  }
223
+ data = config.repoFallback;
224
+ }
225
+ this.logger?.info(`download ${format} from ${data}`);
226
+ try {
227
+ const ret = format === "json" ? await config.fn(data, headers) : await config.fn(data, headers, this.info.size, this.onDownloading);
228
+ this.logger?.info(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
208
229
  return ret;
209
- } else {
210
- throw new TypeError(`invalid type at format '${format}': ${data}`);
230
+ } catch (e) {
231
+ throw new DownloadError();
211
232
  }
212
233
  }
213
- updater.productName = productName;
214
- updater.debug = debug;
215
- updater.receiveBeta = receiveBeta;
216
- updater.checkUpdate = async (data) => {
234
+ async checkUpdate(data) {
217
235
  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;
236
+ let { signature, size, version, minimumVersion, beta } = await this.parseData("json", data);
237
+ if (this.receiveBeta) {
238
+ version = beta.version;
239
+ signature = beta.signature;
228
240
  minimumVersion = beta.minimumVersion;
229
241
  size = beta.size;
230
242
  }
231
- log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
232
- if (!await needUpdate(_ver, minimumVersion)) {
233
- log(`update unavailable: ${_ver}`);
243
+ this.logger?.info(`checked version: ${version}, size: ${size}, signature: ${signature}`);
244
+ if (!await this.needUpdate(version, minimumVersion)) {
245
+ this.logger?.info(`update unavailable: ${version} is the latest version`);
234
246
  return void 0;
235
247
  } else {
236
- log(`update available: ${_ver}`);
237
- signature = _sig;
238
- version = _ver;
239
- return { size, version: _ver };
248
+ this.logger?.info(`update available: ${version}`);
249
+ this.info = {
250
+ signature,
251
+ minimumVersion,
252
+ version,
253
+ size
254
+ };
255
+ return { size, version };
240
256
  }
241
257
  } catch (error) {
242
- log(error);
258
+ this.logger?.error("check update failed", error);
243
259
  return error;
244
260
  }
245
- };
246
- updater.download = async (data, sig) => {
261
+ }
262
+ async download(data, sig) {
247
263
  try {
248
- const _sig = sig ?? signature;
264
+ const _sig = sig ?? this.info?.signature;
249
265
  if (!_sig) {
250
266
  throw new Error("signature are not set, please checkUpdate first or set the second parameter");
251
267
  }
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);
268
+ const buffer = await this.parseData("buffer", data);
269
+ this.logger?.info("verify start");
270
+ const _verify = this.option.overrideFunctions?.verifySignaure ?? verify;
271
+ const _ver = await _verify(buffer, _sig, this.option.SIGNATURE_CERT);
256
272
  if (!_ver) {
257
- throw new VerifyFailedError(_sig, SIGNATURE_CERT);
273
+ throw new VerifyFailedError(_sig, this.option.SIGNATURE_CERT);
258
274
  }
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 = "";
275
+ this.logger?.info("verify success");
276
+ this.logger?.info(`write to ${this.gzipPath}`);
277
+ await writeFile(this.gzipPath, buffer);
278
+ this.logger?.info(`extract to ${this.tmpFilePath}`);
279
+ await unzipFile(this.gzipPath, this.tmpFilePath);
280
+ this.logger?.info(`download success${typeof _ver === "string" ? `, version: ${_ver}` : ""}`);
281
+ this.info = void 0;
266
282
  return true;
267
283
  } catch (error) {
268
- log(error);
284
+ this.logger?.error("download asar failed", error);
269
285
  return error;
270
286
  }
271
- };
272
- return updater;
287
+ }
288
+ };
289
+ function createUpdater(option) {
290
+ return new IncrementalUpdater(option);
273
291
  }
274
292
 
275
293
  // src/index.ts
@@ -315,6 +333,8 @@ function initApp(appOptions) {
315
333
  };
316
334
  }
317
335
  export {
336
+ DownloadError,
337
+ IncrementalUpdater,
318
338
  MinimumVersionError,
319
339
  VerifyFailedError,
320
340
  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,