electron-incremental-update 0.8.5 → 0.8.6

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/README.md CHANGED
@@ -121,7 +121,7 @@ export default defineConfig(({ command }) => {
121
121
  ```json
122
122
  {
123
123
  // ...
124
- "main": "app.js" // <- app entry file
124
+ "main": "app.js" // <- app entry file path
125
125
  }
126
126
  ```
127
127
 
@@ -174,7 +174,7 @@ However, you have the option to customize the download function when creating th
174
174
  ```ts
175
175
  // electron/main/index.ts
176
176
  import type { StartupWithUpdater, Updater } from 'electron-incremental-update'
177
- import { getEntryVersion, getProductAsarPath, getProductVersion } from 'electron-incremental-update'
177
+ import { getAppVersion, getElectronVersion, getProductAsarPath } from 'electron-incremental-update/utils'
178
178
  import { app } from 'electron'
179
179
  import { name } from '../../package.json'
180
180
 
@@ -182,8 +182,8 @@ const startup: StartupWithUpdater = (updater: Updater) => {
182
182
  await app.whenReady()
183
183
  console.log('\ncurrent:')
184
184
  console.log(`\tasar path: ${getProductAsarPath(name)}`)
185
- console.log(`\tentry: ${getEntryVersion()}`)
186
- console.log(`\tapp: ${getProductVersion(name)}`)
185
+ console.log(`\tapp: ${getAppVersion(name)}`)
186
+ console.log(`\telectron: ${getElectronVersion()}`)
187
187
  updater.onDownloading = ({ percent }) => {
188
188
  console.log(percent)
189
189
  }
@@ -209,11 +209,18 @@ export default startup
209
209
 
210
210
  ### use native modules
211
211
 
212
+ the native modules is packed in `app.asar`, so you cannot directly access it when in production
213
+
214
+ to use it, you can prebundle native modules, or use `requireNative` to load.
215
+
212
216
  ```ts
213
217
  // db.ts
214
- import { requireNative } from 'electron-incremental-update'
218
+ import { isNoSuchNativeModuleError, requireNative } from 'electron-incremental-update/utils'
215
219
 
216
220
  const Database = requireNative<typeof import('better-sqlite3')>('better-sqlite3')
221
+ if (isNoSuchNativeModuleError(Database)) {
222
+ // ...
223
+ }
217
224
  const db = new Database(':memory:')
218
225
  db.exec(
219
226
  'DROP TABLE IF EXISTS employees; '
@@ -30,7 +30,14 @@ var verify = (buffer, signature2, cert) => {
30
30
  }
31
31
  };
32
32
 
33
+ // src/updateJson.ts
34
+ function isUpdateJSON(json) {
35
+ const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
36
+ return is(json) && "beta" in json && is(json.beta);
37
+ }
38
+
33
39
  export {
34
40
  signature,
35
- verify
41
+ verify,
42
+ isUpdateJSON
36
43
  };
@@ -0,0 +1,75 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/utils/version.ts
10
+ function parseVersion(version) {
11
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
12
+ const match = semver.exec(version);
13
+ if (!match) {
14
+ throw new TypeError(`invalid version: ${version}`);
15
+ }
16
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
17
+ const ret = {
18
+ major,
19
+ minor,
20
+ patch,
21
+ stage: "",
22
+ stageVersion: -1
23
+ };
24
+ if (match[4]) {
25
+ let [stage, _v] = match[4].split(".");
26
+ ret.stage = stage;
27
+ ret.stageVersion = Number(_v) || -1;
28
+ }
29
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
30
+ throw new TypeError(`invalid version: ${version}`);
31
+ }
32
+ return ret;
33
+ }
34
+
35
+ // src/utils/zip.ts
36
+ import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
37
+ import { gunzip, gzip } from "node:zlib";
38
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
39
+ if (!existsSync(gzipPath)) {
40
+ throw new Error(`path to zipped file not exist: ${gzipPath}`);
41
+ }
42
+ const compressedBuffer = readFileSync(gzipPath);
43
+ return new Promise((resolve, reject) => {
44
+ gunzip(compressedBuffer, (err, buffer) => {
45
+ rmSync(gzipPath);
46
+ if (err) {
47
+ reject(err);
48
+ }
49
+ writeFileSync(targetFilePath, buffer);
50
+ resolve(null);
51
+ });
52
+ });
53
+ }
54
+ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
55
+ if (!existsSync(filePath)) {
56
+ throw new Error(`path to be zipped not exist: ${filePath}`);
57
+ }
58
+ const buffer = readFileSync(filePath);
59
+ return new Promise((resolve, reject) => {
60
+ gzip(buffer, (err, buffer2) => {
61
+ if (err) {
62
+ reject(err);
63
+ }
64
+ writeFileSync(targetFilePath, buffer2);
65
+ resolve(null);
66
+ });
67
+ });
68
+ }
69
+
70
+ export {
71
+ __require,
72
+ parseVersion,
73
+ unzipFile,
74
+ zipFile
75
+ };
@@ -0,0 +1,118 @@
1
+ import {
2
+ __require
3
+ } from "./chunk-CMBFI77K.mjs";
4
+
5
+ // src/utils/core.ts
6
+ import { readFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { release } from "node:os";
9
+ import { app } from "electron";
10
+ function getAppInfo() {
11
+ return {
12
+ dev: !app.isPackaged,
13
+ win: process.platform === "win32",
14
+ mac: process.platform === "darwin",
15
+ linux: process.platform === "linux",
16
+ electronVersion: getElectronVersion(),
17
+ system: release(),
18
+ locale: app.isReady() ? app.getLocale() : void 0
19
+ };
20
+ }
21
+ function getProductAsarPath(name) {
22
+ return !app.isPackaged ? "DEV.asar" : join(dirname(app.getAppPath()), `${name}.asar`);
23
+ }
24
+ function getElectronVersion() {
25
+ return app.getVersion();
26
+ }
27
+ function getAppVersion(name) {
28
+ return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
29
+ }
30
+ var NoSuchNativeModuleError = class extends Error {
31
+ moduleName;
32
+ constructor(moduleName) {
33
+ super(`no such native module: ${moduleName}`);
34
+ this.moduleName = moduleName;
35
+ }
36
+ };
37
+ function isNoSuchNativeModuleError(e) {
38
+ return e instanceof NoSuchNativeModuleError;
39
+ }
40
+ function requireNative(packageName) {
41
+ const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
42
+ try {
43
+ return __require(path);
44
+ } catch (error) {
45
+ return new NoSuchNativeModuleError(packageName);
46
+ }
47
+ }
48
+ function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
49
+ if (!repository.startsWith("https://github.com/")) {
50
+ throw new Error("url must start with https://github.com/");
51
+ }
52
+ repository = repository.trim().replace(/\/?$/, "/").trim();
53
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
54
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
55
+ return repository.replace("github.com", cdnPrefix) + relativeFilePath;
56
+ }
57
+ function getGithubFileCdnGroup() {
58
+ return [
59
+ { cdnPrefix: "cdn.jsdelivr.net/gh", source: "jsdelivr" },
60
+ { cdnPrefix: "fastly.jsdelivr.net/gh", source: "jsdelivr-fastly" },
61
+ { cdnPrefix: "cdn.statically.io/gh", source: "statically" },
62
+ { cdnPrefix: "rawcdn.githack.com/gh", source: "githack" },
63
+ { cdnPrefix: "raw.githack.com/gh", source: "githack-dev" }
64
+ ];
65
+ }
66
+ function getGithubReleaseCdnGroup() {
67
+ return [
68
+ { cdnPrefix: "gh.gh2233.ml", source: "@X.I.U/XIU2" },
69
+ { cdnPrefix: "ghproxy.com", source: "gh-proxy" },
70
+ { cdnPrefix: "gh.ddlc.top", source: "@mtr-static-official" },
71
+ { cdnPrefix: "ghdl.feizhuqwq.cf", source: "feizhuqwq.com" },
72
+ { cdnPrefix: "slink.ltd", source: "\u77E5\u4E86\u5C0F\u7AD9" },
73
+ { cdnPrefix: "git.xfj0.cn", source: "anonymous1" },
74
+ { cdnPrefix: "gh.con.sh", source: "anonymous2" },
75
+ { cdnPrefix: "ghps.cc", source: "anonymous3" },
76
+ { cdnPrefix: "cors.isteed.cc/github.com", source: "Lufs's" },
77
+ { cdnPrefix: "hub.gitmirror.com", source: "GitMirror" },
78
+ { cdnPrefix: "js.xxooo.ml", source: "\u996D\u592A\u786C" },
79
+ { cdnPrefix: "download.njuu.cf", source: "LibraryCloud-njuu" },
80
+ { cdnPrefix: "download.yzuu.cf", source: "LibraryCloud-yzuu" },
81
+ { cdnPrefix: "download.nuaa.cf", source: "LibraryCloud-nuaa" }
82
+ ];
83
+ }
84
+ function restartApp() {
85
+ app.relaunch();
86
+ app.quit();
87
+ }
88
+ function waitAppReady(duration = 1e3) {
89
+ return new Promise((resolve, reject) => {
90
+ const timeout = setTimeout(() => {
91
+ reject(new Error("app is not ready"));
92
+ }, duration);
93
+ app.whenReady().then(() => {
94
+ clearTimeout(timeout);
95
+ resolve();
96
+ });
97
+ });
98
+ }
99
+ function handleUnexpectedErrors(callback) {
100
+ process.on("uncaughtException", callback);
101
+ process.on("unhandledRejection", callback);
102
+ }
103
+
104
+ export {
105
+ getAppInfo,
106
+ getProductAsarPath,
107
+ getElectronVersion,
108
+ getAppVersion,
109
+ NoSuchNativeModuleError,
110
+ isNoSuchNativeModuleError,
111
+ requireNative,
112
+ parseGithubCdnURL,
113
+ getGithubFileCdnGroup,
114
+ getGithubReleaseCdnGroup,
115
+ restartApp,
116
+ waitAppReady,
117
+ handleUnexpectedErrors
118
+ };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { UpdateJSON } from './updateJson.mjs';
1
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
2
2
 
3
3
  declare class MinimumVersionError extends Error {
4
4
  currentVersion: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UpdateJSON } from './updateJson.js';
1
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
2
2
 
3
3
  declare class MinimumVersionError extends Error {
4
4
  currentVersion: string;
package/dist/index.js CHANGED
@@ -36,59 +36,40 @@ __export(src_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(src_exports);
38
38
  var import_node_path2 = require("path");
39
- var import_node_fs3 = require("fs");
39
+ var import_node_fs4 = require("fs");
40
40
  var import_electron3 = __toESM(require("electron"));
41
41
 
42
42
  // src/updater/index.ts
43
- var import_node_fs2 = require("fs");
43
+ var import_node_fs3 = require("fs");
44
44
  var import_promises = require("fs/promises");
45
45
 
46
- // src/utils.ts
46
+ // src/utils/core.ts
47
47
  var import_node_fs = require("fs");
48
48
  var import_node_path = require("path");
49
- var import_node_zlib = require("zlib");
50
- var import_electron = __toESM(require("electron"));
51
- var info = {
52
- dev: !import_electron.default.app?.isPackaged,
53
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
54
- appPath: import_electron.default.app?.getAppPath()
55
- };
49
+ var import_node_os = require("os");
50
+ var import_electron = require("electron");
56
51
  function getProductAsarPath(name) {
57
- return info.dev ? "dev.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`);
52
+ return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
58
53
  }
59
- function getEntryVersion() {
60
- return import_electron.default.app.getVersion();
54
+ function getElectronVersion() {
55
+ return import_electron.app.getVersion();
61
56
  }
62
- function getProductVersion(name) {
63
- return info.dev ? getEntryVersion() : (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8");
57
+ function getAppVersion(name) {
58
+ return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
64
59
  }
65
60
  function waitAppReady(duration = 1e3) {
66
61
  return new Promise((resolve2, reject) => {
67
62
  const timeout = setTimeout(() => {
68
63
  reject(new Error("app is not ready"));
69
64
  }, duration);
70
- import_electron.default.app.whenReady().then(() => {
65
+ import_electron.app.whenReady().then(() => {
71
66
  clearTimeout(timeout);
72
67
  resolve2();
73
68
  });
74
69
  });
75
70
  }
76
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
77
- if (!(0, import_node_fs.existsSync)(gzipPath)) {
78
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
79
- }
80
- const compressedBuffer = (0, import_node_fs.readFileSync)(gzipPath);
81
- return new Promise((resolve2, reject) => {
82
- (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
83
- (0, import_node_fs.rmSync)(gzipPath);
84
- if (err) {
85
- reject(err);
86
- }
87
- (0, import_node_fs.writeFileSync)(targetFilePath, buffer);
88
- resolve2(null);
89
- });
90
- });
91
- }
71
+
72
+ // src/utils/version.ts
92
73
  function parseVersion(version) {
93
74
  const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
94
75
  const match = semver.exec(version);
@@ -114,6 +95,26 @@ function parseVersion(version) {
114
95
  return ret;
115
96
  }
116
97
 
98
+ // src/utils/zip.ts
99
+ var import_node_fs2 = require("fs");
100
+ var import_node_zlib = require("zlib");
101
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
102
+ if (!(0, import_node_fs2.existsSync)(gzipPath)) {
103
+ throw new Error(`path to zipped file not exist: ${gzipPath}`);
104
+ }
105
+ const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
106
+ return new Promise((resolve2, reject) => {
107
+ (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
108
+ (0, import_node_fs2.rmSync)(gzipPath);
109
+ if (err) {
110
+ reject(err);
111
+ }
112
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
113
+ resolve2(null);
114
+ });
115
+ });
116
+ }
117
+
117
118
  // src/crypto.ts
118
119
  var import_node_crypto = require("crypto");
119
120
  function decrypt(encryptedText, key2, iv) {
@@ -168,11 +169,11 @@ var DownloadError = class extends Error {
168
169
  };
169
170
 
170
171
  // src/updater/defaultFunctions.ts
171
- var import_electron2 = __toESM(require("electron"));
172
+ var import_electron2 = require("electron");
172
173
  var downloadJSONDefault = async (url, headers) => {
173
174
  await waitAppReady();
174
175
  return new Promise((resolve2, reject) => {
175
- const request = import_electron2.default.net.request({
176
+ const request = import_electron2.net.request({
176
177
  url,
177
178
  method: "GET",
178
179
  redirect: "follow"
@@ -206,7 +207,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
206
207
  await waitAppReady();
207
208
  let current = 0;
208
209
  return new Promise((resolve2, reject) => {
209
- const request = import_electron2.default.net.request({
210
+ const request = import_electron2.net.request({
210
211
  url,
211
212
  method: "GET",
212
213
  redirect: "follow"
@@ -284,8 +285,8 @@ var IncrementalUpdater = class {
284
285
  }
285
286
  async needUpdate(version, minVersion) {
286
287
  const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
287
- const productVersion = getProductVersion(this.option.productName);
288
- const entryVersion = getEntryVersion();
288
+ const productVersion = getAppVersion(this.option.productName);
289
+ const entryVersion = getElectronVersion();
289
290
  if (await compare(entryVersion, minVersion)) {
290
291
  throw new MinimumVersionError(entryVersion, minVersion);
291
292
  }
@@ -293,11 +294,11 @@ var IncrementalUpdater = class {
293
294
  return await compare(productVersion, version);
294
295
  }
295
296
  async parseData(format, data) {
296
- if ((0, import_node_fs2.existsSync)(this.tmpFilePath)) {
297
+ if ((0, import_node_fs3.existsSync)(this.tmpFilePath)) {
297
298
  this.logger?.warn(`remove tmp file: ${this.tmpFilePath}`);
298
299
  await (0, import_promises.rm)(this.tmpFilePath);
299
300
  }
300
- if ((0, import_node_fs2.existsSync)(this.gzipPath)) {
301
+ if ((0, import_node_fs3.existsSync)(this.gzipPath)) {
301
302
  this.logger?.warn(`remove .gz file: ${this.gzipPath}`);
302
303
  await (0, import_promises.rm)(this.gzipPath);
303
304
  }
@@ -427,9 +428,9 @@ function initApp(appOptions) {
427
428
  try {
428
429
  const asarPath = getProductAsarPath(updater.productName);
429
430
  const updateAsarPath = `${asarPath}.tmp`;
430
- if ((0, import_node_fs3.existsSync)(updateAsarPath)) {
431
+ if ((0, import_node_fs4.existsSync)(updateAsarPath)) {
431
432
  await beforeDoUpdate?.(asarPath, updateAsarPath);
432
- (0, import_node_fs3.renameSync)(updateAsarPath, asarPath);
433
+ (0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
433
434
  }
434
435
  const mainDir = import_electron3.default.app.isPackaged ? asarPath : electronDevDistPath;
435
436
  const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
package/dist/index.mjs CHANGED
@@ -1,25 +1,23 @@
1
1
  import {
2
+ isUpdateJSON,
2
3
  verify
3
- } from "./chunk-GXZSAUBR.mjs";
4
+ } from "./chunk-5BZLJPHJ.mjs";
4
5
  import {
5
- getEntryVersion,
6
+ getAppVersion,
7
+ getElectronVersion,
6
8
  getProductAsarPath,
7
- getProductVersion,
8
- parseVersion,
9
- unzipFile,
10
9
  waitAppReady
11
- } from "./chunk-CR6HTU6P.mjs";
12
- import {
13
- isUpdateJSON
14
- } from "./chunk-2JVXVTC5.mjs";
10
+ } from "./chunk-MFFH2NRM.mjs";
15
11
  import {
16
- __require
17
- } from "./chunk-ZFXKCRJC.mjs";
12
+ __require,
13
+ parseVersion,
14
+ unzipFile
15
+ } from "./chunk-CMBFI77K.mjs";
18
16
 
19
17
  // src/index.ts
20
18
  import { resolve } from "node:path";
21
19
  import { existsSync as existsSync2, renameSync } from "node:fs";
22
- import Electron2 from "electron";
20
+ import Electron from "electron";
23
21
 
24
22
  // src/updater/index.ts
25
23
  import { existsSync } from "node:fs";
@@ -51,11 +49,11 @@ var DownloadError = class extends Error {
51
49
  };
52
50
 
53
51
  // src/updater/defaultFunctions.ts
54
- import Electron from "electron";
52
+ import { net } from "electron";
55
53
  var downloadJSONDefault = async (url, headers) => {
56
54
  await waitAppReady();
57
55
  return new Promise((resolve2, reject) => {
58
- const request = Electron.net.request({
56
+ const request = net.request({
59
57
  url,
60
58
  method: "GET",
61
59
  redirect: "follow"
@@ -89,7 +87,7 @@ var downloadBufferDefault = async (url, headers, total, onDownloading) => {
89
87
  await waitAppReady();
90
88
  let current = 0;
91
89
  return new Promise((resolve2, reject) => {
92
- const request = Electron.net.request({
90
+ const request = net.request({
93
91
  url,
94
92
  method: "GET",
95
93
  redirect: "follow"
@@ -167,8 +165,8 @@ var IncrementalUpdater = class {
167
165
  }
168
166
  async needUpdate(version, minVersion) {
169
167
  const compare = this.option.overrideFunctions?.compareVersion ?? compareVersionDefault;
170
- const productVersion = getProductVersion(this.option.productName);
171
- const entryVersion = getEntryVersion();
168
+ const productVersion = getAppVersion(this.option.productName);
169
+ const entryVersion = getElectronVersion();
172
170
  if (await compare(entryVersion, minVersion)) {
173
171
  throw new MinimumVersionError(entryVersion, minVersion);
174
172
  }
@@ -304,7 +302,7 @@ function initApp(appOptions) {
304
302
  } = hooks || {};
305
303
  function handleError(msg) {
306
304
  onStartError?.(new Error(msg));
307
- Electron2.app.quit();
305
+ Electron.app.quit();
308
306
  }
309
307
  async function startup(updater) {
310
308
  try {
@@ -314,7 +312,7 @@ function initApp(appOptions) {
314
312
  await beforeDoUpdate?.(asarPath, updateAsarPath);
315
313
  renameSync(updateAsarPath, asarPath);
316
314
  }
317
- const mainDir = Electron2.app.isPackaged ? asarPath : electronDevDistPath;
315
+ const mainDir = Electron.app.isPackaged ? asarPath : electronDevDistPath;
318
316
  const entry = resolve(__dirname, mainDir, mainPath);
319
317
  await beforeStart?.(entry);
320
318
  __require(entry)(updater);
@@ -7,6 +7,5 @@ type UpdateInfo = {
7
7
  type UpdateJSON = UpdateInfo & {
8
8
  beta: UpdateInfo;
9
9
  };
10
- declare function isUpdateJSON(json: any): json is UpdateJSON;
11
10
 
12
- export { UpdateInfo, UpdateJSON, isUpdateJSON };
11
+ export { UpdateJSON as U };
package/dist/utils.d.mts CHANGED
@@ -1,36 +1,49 @@
1
1
  type Info = {
2
2
  dev: boolean;
3
- platform: 'win' | 'mac' | 'linux';
4
- appPath: string;
3
+ win: boolean;
4
+ mac: boolean;
5
+ linux: boolean;
6
+ electronVersion: string;
7
+ /**
8
+ * `os.release()`
9
+ */
10
+ system: string;
11
+ /**
12
+ * system locale, `undefined` when `!app.isReady()`
13
+ */
14
+ locale: string | undefined;
5
15
  };
6
- declare const info: Info;
7
16
  /**
8
- * get the application asar absolute path
17
+ * get app info
18
+ */
19
+ declare function getAppInfo(): Info;
20
+ /**
21
+ * get the application asar absolute path (not `app.asar`),
22
+ * if is in dev, return `'DEV.asar'`
9
23
  * @param name The name of the application
10
- * @todo support v8 bytecode
11
24
  */
12
25
  declare function getProductAsarPath(name: string): string;
13
26
  /**
14
- * get the version of entry (app.asar)
27
+ * get the version of Electron runtime
15
28
  */
16
- declare function getEntryVersion(): string;
29
+ declare function getElectronVersion(): string;
17
30
  /**
18
31
  * get the version of application (name.asar)
19
32
  *
20
- * if is dev, return {@link getEntryVersion}
33
+ * if is dev, return {@link getElectronVersion}
21
34
  * @param name - The name of the application
22
35
  */
23
- declare function getProductVersion(name: string): string;
36
+ declare function getAppVersion(name: string): string;
24
37
  declare class NoSuchNativeModuleError extends Error {
25
38
  moduleName: string;
26
39
  constructor(moduleName: string);
27
40
  }
41
+ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleError;
28
42
  /**
29
- * require native package from app.asar
43
+ * require native package, if not found, return {@link NoSuchNativeModuleError}
30
44
  * @param packageName native package name
31
- * @throws error: {@link NoSuchNativeModuleError}
32
45
  */
33
- declare function requireNative<T = any>(packageName: string): T;
46
+ declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
34
47
  /**
35
48
  * parse Github CDN URL for accelerating the speed of downloading
36
49
  */
@@ -57,9 +70,8 @@ declare function restartApp(): void;
57
70
  * ensure app is ready.
58
71
  */
59
72
  declare function waitAppReady(duration?: number): Promise<void>;
60
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
61
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
62
- declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
+
63
75
  interface Version {
64
76
  major: number;
65
77
  minor: number;
@@ -69,4 +81,7 @@ interface Version {
69
81
  }
70
82
  declare function parseVersion(version: string): Version;
71
83
 
72
- export { NoSuchNativeModuleError, Version, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, info, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
84
+ declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
85
+ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
86
+
87
+ export { NoSuchNativeModuleError, Version, getAppInfo, getAppVersion, getElectronVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.d.ts CHANGED
@@ -1,36 +1,49 @@
1
1
  type Info = {
2
2
  dev: boolean;
3
- platform: 'win' | 'mac' | 'linux';
4
- appPath: string;
3
+ win: boolean;
4
+ mac: boolean;
5
+ linux: boolean;
6
+ electronVersion: string;
7
+ /**
8
+ * `os.release()`
9
+ */
10
+ system: string;
11
+ /**
12
+ * system locale, `undefined` when `!app.isReady()`
13
+ */
14
+ locale: string | undefined;
5
15
  };
6
- declare const info: Info;
7
16
  /**
8
- * get the application asar absolute path
17
+ * get app info
18
+ */
19
+ declare function getAppInfo(): Info;
20
+ /**
21
+ * get the application asar absolute path (not `app.asar`),
22
+ * if is in dev, return `'DEV.asar'`
9
23
  * @param name The name of the application
10
- * @todo support v8 bytecode
11
24
  */
12
25
  declare function getProductAsarPath(name: string): string;
13
26
  /**
14
- * get the version of entry (app.asar)
27
+ * get the version of Electron runtime
15
28
  */
16
- declare function getEntryVersion(): string;
29
+ declare function getElectronVersion(): string;
17
30
  /**
18
31
  * get the version of application (name.asar)
19
32
  *
20
- * if is dev, return {@link getEntryVersion}
33
+ * if is dev, return {@link getElectronVersion}
21
34
  * @param name - The name of the application
22
35
  */
23
- declare function getProductVersion(name: string): string;
36
+ declare function getAppVersion(name: string): string;
24
37
  declare class NoSuchNativeModuleError extends Error {
25
38
  moduleName: string;
26
39
  constructor(moduleName: string);
27
40
  }
41
+ declare function isNoSuchNativeModuleError(e: unknown): e is NoSuchNativeModuleError;
28
42
  /**
29
- * require native package from app.asar
43
+ * require native package, if not found, return {@link NoSuchNativeModuleError}
30
44
  * @param packageName native package name
31
- * @throws error: {@link NoSuchNativeModuleError}
32
45
  */
33
- declare function requireNative<T = any>(packageName: string): T;
46
+ declare function requireNative<T = any>(packageName: string): T | NoSuchNativeModuleError;
34
47
  /**
35
48
  * parse Github CDN URL for accelerating the speed of downloading
36
49
  */
@@ -57,9 +70,8 @@ declare function restartApp(): void;
57
70
  * ensure app is ready.
58
71
  */
59
72
  declare function waitAppReady(duration?: number): Promise<void>;
60
- declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
61
- declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
62
- declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
73
+ declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
+
63
75
  interface Version {
64
76
  major: number;
65
77
  minor: number;
@@ -69,4 +81,7 @@ interface Version {
69
81
  }
70
82
  declare function parseVersion(version: string): Version;
71
83
 
72
- export { NoSuchNativeModuleError, Version, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, info, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
84
+ declare function unzipFile(gzipPath: string, targetFilePath?: string): Promise<unknown>;
85
+ declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
86
+
87
+ export { NoSuchNativeModuleError, Version, getAppInfo, getAppVersion, getElectronVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,27 +15,20 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
- // src/utils.ts
20
+ // src/utils/index.ts
31
21
  var utils_exports = {};
32
22
  __export(utils_exports, {
33
23
  NoSuchNativeModuleError: () => NoSuchNativeModuleError,
34
- getEntryVersion: () => getEntryVersion,
24
+ getAppInfo: () => getAppInfo,
25
+ getAppVersion: () => getAppVersion,
26
+ getElectronVersion: () => getElectronVersion,
35
27
  getGithubFileCdnGroup: () => getGithubFileCdnGroup,
36
28
  getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
37
29
  getProductAsarPath: () => getProductAsarPath,
38
- getProductVersion: () => getProductVersion,
39
30
  handleUnexpectedErrors: () => handleUnexpectedErrors,
40
- info: () => info,
31
+ isNoSuchNativeModuleError: () => isNoSuchNativeModuleError,
41
32
  parseGithubCdnURL: () => parseGithubCdnURL,
42
33
  parseVersion: () => parseVersion,
43
34
  requireNative: () => requireNative,
@@ -47,23 +38,31 @@ __export(utils_exports, {
47
38
  zipFile: () => zipFile
48
39
  });
49
40
  module.exports = __toCommonJS(utils_exports);
41
+
42
+ // src/utils/core.ts
50
43
  var import_node_fs = require("fs");
51
44
  var import_node_path = require("path");
52
- var import_node_zlib = require("zlib");
53
- var import_electron = __toESM(require("electron"));
54
- var info = {
55
- dev: !import_electron.default.app?.isPackaged,
56
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
57
- appPath: import_electron.default.app?.getAppPath()
58
- };
45
+ var import_node_os = require("os");
46
+ var import_electron = require("electron");
47
+ function getAppInfo() {
48
+ return {
49
+ dev: !import_electron.app.isPackaged,
50
+ win: process.platform === "win32",
51
+ mac: process.platform === "darwin",
52
+ linux: process.platform === "linux",
53
+ electronVersion: getElectronVersion(),
54
+ system: (0, import_node_os.release)(),
55
+ locale: import_electron.app.isReady() ? import_electron.app.getLocale() : void 0
56
+ };
57
+ }
59
58
  function getProductAsarPath(name) {
60
- return info.dev ? "dev.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(info.appPath), `${name}.asar`);
59
+ return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
61
60
  }
62
- function getEntryVersion() {
63
- return import_electron.default.app.getVersion();
61
+ function getElectronVersion() {
62
+ return import_electron.app.getVersion();
64
63
  }
65
- function getProductVersion(name) {
66
- return info.dev ? getEntryVersion() : (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8");
64
+ function getAppVersion(name) {
65
+ return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
67
66
  }
68
67
  var NoSuchNativeModuleError = class extends Error {
69
68
  moduleName;
@@ -72,12 +71,15 @@ var NoSuchNativeModuleError = class extends Error {
72
71
  this.moduleName = moduleName;
73
72
  }
74
73
  };
74
+ function isNoSuchNativeModuleError(e) {
75
+ return e instanceof NoSuchNativeModuleError;
76
+ }
75
77
  function requireNative(packageName) {
76
- const path = info.dev ? packageName : (0, import_node_path.join)(info.appPath, "node_modules", packageName);
78
+ const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
77
79
  try {
78
80
  return require(path);
79
81
  } catch (error) {
80
- throw new NoSuchNativeModuleError(packageName);
82
+ return new NoSuchNativeModuleError(packageName);
81
83
  }
82
84
  }
83
85
  function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
@@ -117,59 +119,26 @@ function getGithubReleaseCdnGroup() {
117
119
  ];
118
120
  }
119
121
  function restartApp() {
120
- import_electron.default.app.relaunch();
121
- import_electron.default.app.quit();
122
+ import_electron.app.relaunch();
123
+ import_electron.app.quit();
122
124
  }
123
125
  function waitAppReady(duration = 1e3) {
124
126
  return new Promise((resolve, reject) => {
125
127
  const timeout = setTimeout(() => {
126
128
  reject(new Error("app is not ready"));
127
129
  }, duration);
128
- import_electron.default.app.whenReady().then(() => {
130
+ import_electron.app.whenReady().then(() => {
129
131
  clearTimeout(timeout);
130
132
  resolve();
131
133
  });
132
134
  });
133
135
  }
134
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
135
- if (!(0, import_node_fs.existsSync)(gzipPath)) {
136
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
137
- }
138
- const compressedBuffer = (0, import_node_fs.readFileSync)(gzipPath);
139
- return new Promise((resolve, reject) => {
140
- (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
141
- (0, import_node_fs.rmSync)(gzipPath);
142
- if (err) {
143
- reject(err);
144
- }
145
- (0, import_node_fs.writeFileSync)(targetFilePath, buffer);
146
- resolve(null);
147
- });
148
- });
149
- }
150
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
151
- if (!(0, import_node_fs.existsSync)(filePath)) {
152
- throw new Error(`path to be zipped not exist: ${filePath}`);
153
- }
154
- const buffer = (0, import_node_fs.readFileSync)(filePath);
155
- return new Promise((resolve, reject) => {
156
- (0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
157
- if (err) {
158
- reject(err);
159
- }
160
- (0, import_node_fs.writeFileSync)(targetFilePath, buffer2);
161
- resolve(null);
162
- });
163
- });
164
- }
165
136
  function handleUnexpectedErrors(callback) {
166
- const listener = (err) => {
167
- const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
168
- callback(e);
169
- };
170
- process.on("uncaughtException", listener);
171
- process.on("unhandledRejection", listener);
137
+ process.on("uncaughtException", callback);
138
+ process.on("unhandledRejection", callback);
172
139
  }
140
+
141
+ // src/utils/version.ts
173
142
  function parseVersion(version) {
174
143
  const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
175
144
  const match = semver.exec(version);
@@ -194,16 +163,52 @@ function parseVersion(version) {
194
163
  }
195
164
  return ret;
196
165
  }
166
+
167
+ // src/utils/zip.ts
168
+ var import_node_fs2 = require("fs");
169
+ var import_node_zlib = require("zlib");
170
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
171
+ if (!(0, import_node_fs2.existsSync)(gzipPath)) {
172
+ throw new Error(`path to zipped file not exist: ${gzipPath}`);
173
+ }
174
+ const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
175
+ return new Promise((resolve, reject) => {
176
+ (0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
177
+ (0, import_node_fs2.rmSync)(gzipPath);
178
+ if (err) {
179
+ reject(err);
180
+ }
181
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
182
+ resolve(null);
183
+ });
184
+ });
185
+ }
186
+ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
187
+ if (!(0, import_node_fs2.existsSync)(filePath)) {
188
+ throw new Error(`path to be zipped not exist: ${filePath}`);
189
+ }
190
+ const buffer = (0, import_node_fs2.readFileSync)(filePath);
191
+ return new Promise((resolve, reject) => {
192
+ (0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
193
+ if (err) {
194
+ reject(err);
195
+ }
196
+ (0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
197
+ resolve(null);
198
+ });
199
+ });
200
+ }
197
201
  // Annotate the CommonJS export names for ESM import in node:
198
202
  0 && (module.exports = {
199
203
  NoSuchNativeModuleError,
200
- getEntryVersion,
204
+ getAppInfo,
205
+ getAppVersion,
206
+ getElectronVersion,
201
207
  getGithubFileCdnGroup,
202
208
  getGithubReleaseCdnGroup,
203
209
  getProductAsarPath,
204
- getProductVersion,
205
210
  handleUnexpectedErrors,
206
- info,
211
+ isNoSuchNativeModuleError,
207
212
  parseGithubCdnURL,
208
213
  parseVersion,
209
214
  requireNative,
package/dist/utils.mjs CHANGED
@@ -1,30 +1,33 @@
1
1
  import {
2
2
  NoSuchNativeModuleError,
3
- getEntryVersion,
3
+ getAppInfo,
4
+ getAppVersion,
5
+ getElectronVersion,
4
6
  getGithubFileCdnGroup,
5
7
  getGithubReleaseCdnGroup,
6
8
  getProductAsarPath,
7
- getProductVersion,
8
9
  handleUnexpectedErrors,
9
- info,
10
+ isNoSuchNativeModuleError,
10
11
  parseGithubCdnURL,
11
- parseVersion,
12
12
  requireNative,
13
13
  restartApp,
14
+ waitAppReady
15
+ } from "./chunk-MFFH2NRM.mjs";
16
+ import {
17
+ parseVersion,
14
18
  unzipFile,
15
- waitAppReady,
16
19
  zipFile
17
- } from "./chunk-CR6HTU6P.mjs";
18
- import "./chunk-ZFXKCRJC.mjs";
20
+ } from "./chunk-CMBFI77K.mjs";
19
21
  export {
20
22
  NoSuchNativeModuleError,
21
- getEntryVersion,
23
+ getAppInfo,
24
+ getAppVersion,
25
+ getElectronVersion,
22
26
  getGithubFileCdnGroup,
23
27
  getGithubReleaseCdnGroup,
24
28
  getProductAsarPath,
25
- getProductVersion,
26
29
  handleUnexpectedErrors,
27
- info,
30
+ isNoSuchNativeModuleError,
28
31
  parseGithubCdnURL,
29
32
  parseVersion,
30
33
  requireNative,
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { UpdateJSON } from './updateJson.mjs';
2
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
3
3
 
4
4
  type DistinguishedName = {
5
5
  countryName?: string;
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { UpdateJSON } from './updateJson.js';
2
+ import { U as UpdateJSON } from './updateJson-7e45d9e1.js';
3
3
 
4
4
  type DistinguishedName = {
5
5
  countryName?: string;
package/dist/vite.js CHANGED
@@ -58,16 +58,9 @@ var signature = (buffer, privateKey, cert, version) => {
58
58
  return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
59
59
  };
60
60
 
61
- // src/utils.ts
61
+ // src/utils/zip.ts
62
62
  var import_node_fs = require("fs");
63
- var import_node_path = require("path");
64
63
  var import_node_zlib = require("zlib");
65
- var import_electron = __toESM(require("electron"));
66
- var info = {
67
- dev: !import_electron.default.app?.isPackaged,
68
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
69
- appPath: import_electron.default.app?.getAppPath()
70
- };
71
64
  async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
72
65
  if (!(0, import_node_fs.existsSync)(filePath)) {
73
66
  throw new Error(`path to be zipped not exist: ${filePath}`);
@@ -83,6 +76,8 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
83
76
  });
84
77
  });
85
78
  }
79
+
80
+ // src/utils/version.ts
86
81
  function parseVersion(version) {
87
82
  const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
88
83
  const match = semver.exec(version);
@@ -199,12 +194,12 @@ var import_ci_info = require("ci-info");
199
194
 
200
195
  // src/build-plugins/key.ts
201
196
  var import_node_fs3 = require("fs");
202
- var import_node_path2 = require("path");
197
+ var import_node_path = require("path");
203
198
  var import_selfsigned = require("selfsigned");
204
199
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
205
- const privateKeyDir = (0, import_node_path2.dirname)(privateKeyPath);
200
+ const privateKeyDir = (0, import_node_path.dirname)(privateKeyPath);
206
201
  (0, import_node_fs3.existsSync)(privateKeyDir) || (0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
207
- const certDir = (0, import_node_path2.dirname)(certPath);
202
+ const certDir = (0, import_node_path.dirname)(certPath);
208
203
  (0, import_node_fs3.existsSync)(certDir) || (0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
209
204
  const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
210
205
  keySize: keyLength,
@@ -251,7 +246,7 @@ function parseKeys({
251
246
  subject,
252
247
  days
253
248
  }) {
254
- const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
249
+ const keysDir = (0, import_node_path.dirname)(privateKeyPath);
255
250
  !(0, import_node_fs3.existsSync)(keysDir) && (0, import_node_fs3.mkdirSync)(keysDir);
256
251
  if (!(0, import_node_fs3.existsSync)(privateKeyPath) || !(0, import_node_fs3.existsSync)(certPath)) {
257
252
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
package/dist/vite.mjs CHANGED
@@ -1,14 +1,11 @@
1
1
  import {
2
+ isUpdateJSON,
2
3
  signature
3
- } from "./chunk-GXZSAUBR.mjs";
4
+ } from "./chunk-5BZLJPHJ.mjs";
4
5
  import {
5
6
  parseVersion,
6
7
  zipFile
7
- } from "./chunk-CR6HTU6P.mjs";
8
- import {
9
- isUpdateJSON
10
- } from "./chunk-2JVXVTC5.mjs";
11
- import "./chunk-ZFXKCRJC.mjs";
8
+ } from "./chunk-CMBFI77K.mjs";
12
9
 
13
10
  // src/vite.ts
14
11
  import { createLogger } from "vite";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.8.5",
4
+ "version": "0.8.6",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",
@@ -1,9 +0,0 @@
1
- // src/updateJson.ts
2
- function isUpdateJSON(json) {
3
- const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
4
- return is(json) && "beta" in json && is(json.beta);
5
- }
6
-
7
- export {
8
- isUpdateJSON
9
- };
@@ -1,170 +0,0 @@
1
- import {
2
- __require
3
- } from "./chunk-ZFXKCRJC.mjs";
4
-
5
- // src/utils.ts
6
- import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7
- import { dirname, join } from "node:path";
8
- import { gunzip, gzip } from "node:zlib";
9
- import Electron from "electron";
10
- var info = {
11
- dev: !Electron.app?.isPackaged,
12
- platform: process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux",
13
- appPath: Electron.app?.getAppPath()
14
- };
15
- function getProductAsarPath(name) {
16
- return info.dev ? "dev.asar" : join(dirname(info.appPath), `${name}.asar`);
17
- }
18
- function getEntryVersion() {
19
- return Electron.app.getVersion();
20
- }
21
- function getProductVersion(name) {
22
- return info.dev ? getEntryVersion() : readFileSync(join(getProductAsarPath(name), "version"), "utf-8");
23
- }
24
- var NoSuchNativeModuleError = class extends Error {
25
- moduleName;
26
- constructor(moduleName) {
27
- super(`no such native module: ${moduleName}`);
28
- this.moduleName = moduleName;
29
- }
30
- };
31
- function requireNative(packageName) {
32
- const path = info.dev ? packageName : join(info.appPath, "node_modules", packageName);
33
- try {
34
- return __require(path);
35
- } catch (error) {
36
- throw new NoSuchNativeModuleError(packageName);
37
- }
38
- }
39
- function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
40
- if (!repository.startsWith("https://github.com/")) {
41
- throw new Error("url must start with https://github.com/");
42
- }
43
- repository = repository.trim().replace(/\/?$/, "/").trim();
44
- relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
45
- cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
46
- return repository.replace("github.com", cdnPrefix) + relativeFilePath;
47
- }
48
- function getGithubFileCdnGroup() {
49
- return [
50
- { cdnPrefix: "cdn.jsdelivr.net/gh", source: "jsdelivr" },
51
- { cdnPrefix: "fastly.jsdelivr.net/gh", source: "jsdelivr-fastly" },
52
- { cdnPrefix: "cdn.statically.io/gh", source: "statically" },
53
- { cdnPrefix: "rawcdn.githack.com/gh", source: "githack" },
54
- { cdnPrefix: "raw.githack.com/gh", source: "githack-dev" }
55
- ];
56
- }
57
- function getGithubReleaseCdnGroup() {
58
- return [
59
- { cdnPrefix: "gh.gh2233.ml", source: "@X.I.U/XIU2" },
60
- { cdnPrefix: "ghproxy.com", source: "gh-proxy" },
61
- { cdnPrefix: "gh.ddlc.top", source: "@mtr-static-official" },
62
- { cdnPrefix: "ghdl.feizhuqwq.cf", source: "feizhuqwq.com" },
63
- { cdnPrefix: "slink.ltd", source: "\u77E5\u4E86\u5C0F\u7AD9" },
64
- { cdnPrefix: "git.xfj0.cn", source: "anonymous1" },
65
- { cdnPrefix: "gh.con.sh", source: "anonymous2" },
66
- { cdnPrefix: "ghps.cc", source: "anonymous3" },
67
- { cdnPrefix: "cors.isteed.cc/github.com", source: "Lufs's" },
68
- { cdnPrefix: "hub.gitmirror.com", source: "GitMirror" },
69
- { cdnPrefix: "js.xxooo.ml", source: "\u996D\u592A\u786C" },
70
- { cdnPrefix: "download.njuu.cf", source: "LibraryCloud-njuu" },
71
- { cdnPrefix: "download.yzuu.cf", source: "LibraryCloud-yzuu" },
72
- { cdnPrefix: "download.nuaa.cf", source: "LibraryCloud-nuaa" }
73
- ];
74
- }
75
- function restartApp() {
76
- Electron.app.relaunch();
77
- Electron.app.quit();
78
- }
79
- function waitAppReady(duration = 1e3) {
80
- return new Promise((resolve, reject) => {
81
- const timeout = setTimeout(() => {
82
- reject(new Error("app is not ready"));
83
- }, duration);
84
- Electron.app.whenReady().then(() => {
85
- clearTimeout(timeout);
86
- resolve();
87
- });
88
- });
89
- }
90
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
91
- if (!existsSync(gzipPath)) {
92
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
93
- }
94
- const compressedBuffer = readFileSync(gzipPath);
95
- return new Promise((resolve, reject) => {
96
- gunzip(compressedBuffer, (err, buffer) => {
97
- rmSync(gzipPath);
98
- if (err) {
99
- reject(err);
100
- }
101
- writeFileSync(targetFilePath, buffer);
102
- resolve(null);
103
- });
104
- });
105
- }
106
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
107
- if (!existsSync(filePath)) {
108
- throw new Error(`path to be zipped not exist: ${filePath}`);
109
- }
110
- const buffer = readFileSync(filePath);
111
- return new Promise((resolve, reject) => {
112
- gzip(buffer, (err, buffer2) => {
113
- if (err) {
114
- reject(err);
115
- }
116
- writeFileSync(targetFilePath, buffer2);
117
- resolve(null);
118
- });
119
- });
120
- }
121
- function handleUnexpectedErrors(callback) {
122
- const listener = (err) => {
123
- const e = err instanceof Error ? err : new Error(typeof err === "string" ? err : JSON.stringify(err));
124
- callback(e);
125
- };
126
- process.on("uncaughtException", listener);
127
- process.on("unhandledRejection", listener);
128
- }
129
- function parseVersion(version) {
130
- const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
131
- const match = semver.exec(version);
132
- if (!match) {
133
- throw new TypeError(`invalid version: ${version}`);
134
- }
135
- const [major, minor, patch] = match.slice(1, 4).map(Number);
136
- const ret = {
137
- major,
138
- minor,
139
- patch,
140
- stage: "",
141
- stageVersion: -1
142
- };
143
- if (match[4]) {
144
- let [stage, _v] = match[4].split(".");
145
- ret.stage = stage;
146
- ret.stageVersion = Number(_v) || -1;
147
- }
148
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
149
- throw new TypeError(`invalid version: ${version}`);
150
- }
151
- return ret;
152
- }
153
-
154
- export {
155
- info,
156
- getProductAsarPath,
157
- getEntryVersion,
158
- getProductVersion,
159
- NoSuchNativeModuleError,
160
- requireNative,
161
- parseGithubCdnURL,
162
- getGithubFileCdnGroup,
163
- getGithubReleaseCdnGroup,
164
- restartApp,
165
- waitAppReady,
166
- unzipFile,
167
- zipFile,
168
- handleUnexpectedErrors,
169
- parseVersion
170
- };
@@ -1,11 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- export {
10
- __require
11
- };
@@ -1,12 +0,0 @@
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 };
@@ -1,33 +0,0 @@
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
- });
@@ -1,7 +0,0 @@
1
- import {
2
- isUpdateJSON
3
- } from "./chunk-2JVXVTC5.mjs";
4
- import "./chunk-ZFXKCRJC.mjs";
5
- export {
6
- isUpdateJSON
7
- };