electron-incremental-update 0.1.3 → 0.1.4

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.cjs CHANGED
@@ -42,53 +42,17 @@ module.exports = __toCommonJS(src_exports);
42
42
  var import_node_path2 = require("path");
43
43
  var import_electron3 = require("electron");
44
44
 
45
- // src/utils.ts
46
- var import_node_fs = require("fs");
47
- var import_node_path = require("path");
48
- var import_electron = require("electron");
49
- function getAppAsarPath(name) {
50
- return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
51
- }
52
- function getElectronVersion() {
53
- return import_electron.app.getVersion();
54
- }
55
- function getAppVersion(name) {
56
- return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getAppAsarPath(name), "version"), "utf-8").trim() : getElectronVersion();
57
- }
58
- function requireNative(packageName) {
59
- const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
60
- return require(path);
61
- }
62
- function getReleaseDnsPrefix() {
63
- const hub = "https://github.com";
64
- return [
65
- { urlPrefix: `https://gh.gh2233.ml/${hub}`, maintainer: "@X.I.U/XIU2" },
66
- { urlPrefix: `https://ghproxy.com/${hub}`, maintainer: "gh-proxy" },
67
- { urlPrefix: `https://gh.ddlc.top/${hub}`, maintainer: "@mtr-static-official" },
68
- { urlPrefix: `https://ghdl.feizhuqwq.cf/${hub}`, maintainer: "feizhuqwq.com" },
69
- { urlPrefix: `https://slink.ltd/${hub}`, maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
70
- { urlPrefix: `https://git.xfj0.cn/${hub}`, maintainer: "anonymous1" },
71
- { urlPrefix: `https://gh.con.sh/${hub}`, maintainer: "anonymous2" },
72
- { urlPrefix: `https://ghps.cc/${hub}`, maintainer: "anonymous3" },
73
- { urlPrefix: "https://cors.isteed.cc/github.com", maintainer: "Lufs's" },
74
- { urlPrefix: `https://hub.gitmirror.com/${hub}`, maintainer: "GitMirror" },
75
- { urlPrefix: `https://js.xxooo.ml/${hub}`, maintainer: "\u996D\u592A\u786C" },
76
- { urlPrefix: `https://proxy.freecdn.ml/?url=${hub}`, maintainer: "anonymous4" },
77
- { urlPrefix: "https://download.njuu.cf", maintainer: "LibraryCloud-njuu" },
78
- { urlPrefix: "https://download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
79
- { urlPrefix: "https://download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
80
- ];
81
- }
82
-
83
- // src/updater.ts
45
+ // src/updater/index.ts
84
46
  var import_node_events = require("events");
85
- var import_node_buffer = require("buffer");
86
47
  var import_node_crypto = require("crypto");
87
48
  var import_node_zlib = require("zlib");
88
49
  var import_node_fs2 = require("fs");
89
50
  var import_promises = require("fs/promises");
90
- var import_node_https = __toESM(require("https"), 1);
91
51
  var import_electron2 = require("electron");
52
+
53
+ // src/updater/download.ts
54
+ var import_node_buffer = require("buffer");
55
+ var import_node_https = __toESM(require("https"), 1);
92
56
  function downloadJSONDefault(url, updater, headers) {
93
57
  return new Promise((resolve2, reject) => {
94
58
  import_node_https.default.get(url, (res) => {
@@ -132,6 +96,46 @@ function downloadBufferDefault(url, updater, headers) {
132
96
  });
133
97
  });
134
98
  }
99
+
100
+ // src/updater/utils.ts
101
+ var import_node_fs = require("fs");
102
+ var import_node_path = require("path");
103
+ var import_electron = require("electron");
104
+ function getAppAsarPath(name) {
105
+ return import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "dev";
106
+ }
107
+ function getElectronVersion() {
108
+ return import_electron.app.getVersion();
109
+ }
110
+ function getAppVersion(name) {
111
+ return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getAppAsarPath(name), "version"), "utf-8").trim() : getElectronVersion();
112
+ }
113
+ function requireNative(packageName) {
114
+ const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
115
+ return require(path);
116
+ }
117
+ function getReleaseDnsPrefix() {
118
+ const hub = "https://github.com";
119
+ return [
120
+ { urlPrefix: `https://gh.gh2233.ml/${hub}`, maintainer: "@X.I.U/XIU2" },
121
+ { urlPrefix: `https://ghproxy.com/${hub}`, maintainer: "gh-proxy" },
122
+ { urlPrefix: `https://gh.ddlc.top/${hub}`, maintainer: "@mtr-static-official" },
123
+ { urlPrefix: `https://ghdl.feizhuqwq.cf/${hub}`, maintainer: "feizhuqwq.com" },
124
+ { urlPrefix: `https://slink.ltd/${hub}`, maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
125
+ { urlPrefix: `https://git.xfj0.cn/${hub}`, maintainer: "anonymous1" },
126
+ { urlPrefix: `https://gh.con.sh/${hub}`, maintainer: "anonymous2" },
127
+ { urlPrefix: `https://ghps.cc/${hub}`, maintainer: "anonymous3" },
128
+ { urlPrefix: "https://cors.isteed.cc/github.com", maintainer: "Lufs's" },
129
+ { urlPrefix: `https://hub.gitmirror.com/${hub}`, maintainer: "GitMirror" },
130
+ { urlPrefix: `https://js.xxooo.ml/${hub}`, maintainer: "\u996D\u592A\u786C" },
131
+ { urlPrefix: `https://proxy.freecdn.ml/?url=${hub}`, maintainer: "anonymous4" },
132
+ { urlPrefix: "https://download.njuu.cf", maintainer: "LibraryCloud-njuu" },
133
+ { urlPrefix: "https://download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
134
+ { urlPrefix: "https://download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
135
+ ];
136
+ }
137
+
138
+ // src/updater/index.ts
135
139
  function createUpdater({
136
140
  SIGNATURE_PUB,
137
141
  repository,
@@ -187,11 +191,13 @@ function createUpdater({
187
191
  updateJsonURL = _update,
188
192
  releaseAsarURL = _release
189
193
  } = option || {};
190
- if ((!updateJsonURL || !releaseAsarURL) && !repository) {
191
- throw new Error("updateJsonURL or releaseAsarURL are not set");
194
+ if (!updateJsonURL || !releaseAsarURL) {
195
+ if (!repository) {
196
+ throw new Error("updateJsonURL or releaseAsarURL are not set");
197
+ }
198
+ updateJsonURL = `${repository.replace("github.com", "raw.githubusercontent.com")}/version.json`;
199
+ releaseAsarURL = `${repository}/releases/download/latest/${productName}.asar.gz`;
192
200
  }
193
- updateJsonURL ??= `${repository}/version.json`;
194
- releaseAsarURL ??= `${repository}/releases/download/latest/${productName}.asar.gz`;
195
201
  const gzipPath = `../${productName}.asar.gz`;
196
202
  const tmpFile = gzipPath.replace(".asar.gz", ".tmp.gz");
197
203
  if ((0, import_node_fs2.existsSync)(tmpFile)) {
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ?
18
18
  interface UpdateOption {
19
19
  /**
20
20
  * URL of version info json
21
- * @default `${repository}/version.json`
21
+ * @default `${repository.replace('github.com', 'raw.githubusercontent.com')}/version.json`
22
22
  * @throws if `updateJsonURL` and `repository` are all not set
23
23
  */
24
24
  updateJsonURL?: string;
@@ -100,7 +100,6 @@ interface Options extends UpdateOption {
100
100
  downloadBuffer?: (url: string, updater: Updater, headers: Record<string, any>) => Promise<Buffer>;
101
101
  };
102
102
  }
103
- declare function createUpdater({ SIGNATURE_PUB, repository, productName, releaseAsarURL: _release, updateJsonURL: _update, downloadConfig, }: Options): Updater;
104
103
 
105
104
  declare function getAppAsarPath(name: string): string;
106
105
  declare function getElectronVersion(): string;
@@ -111,6 +110,8 @@ declare function getReleaseDnsPrefix(): {
111
110
  maintainer: string;
112
111
  }[];
113
112
 
113
+ declare function createUpdater({ SIGNATURE_PUB, repository, productName, releaseAsarURL: _release, updateJsonURL: _update, downloadConfig, }: Options): Updater;
114
+
114
115
  interface PathConfig {
115
116
  /**
116
117
  * path of electron output dist
@@ -132,4 +133,4 @@ interface PathConfig {
132
133
  */
133
134
  declare function initApp(productName: string, updater: Updater, option?: PathConfig): any;
134
135
 
135
- export { Options, Updater, createUpdater, getAppAsarPath, getAppVersion, getElectronVersion, getReleaseDnsPrefix, initApp, requireNative };
136
+ export { CheckResultType, Options, UpdateJSON, UpdateOption, Updater, createUpdater, getAppAsarPath, getAppVersion, getElectronVersion, getReleaseDnsPrefix, initApp, requireNative };
package/dist/index.mjs CHANGED
@@ -6,53 +6,17 @@ import {
6
6
  import { resolve } from "node:path";
7
7
  import { app as app3 } from "electron";
8
8
 
9
- // src/utils.ts
10
- import { readFileSync } from "node:fs";
11
- import { dirname, join } from "node:path";
12
- import { app } from "electron";
13
- function getAppAsarPath(name) {
14
- return app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "dev";
15
- }
16
- function getElectronVersion() {
17
- return app.getVersion();
18
- }
19
- function getAppVersion(name) {
20
- return app.isPackaged ? readFileSync(join(getAppAsarPath(name), "version"), "utf-8").trim() : getElectronVersion();
21
- }
22
- function requireNative(packageName) {
23
- const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
24
- return __require(path);
25
- }
26
- function getReleaseDnsPrefix() {
27
- const hub = "https://github.com";
28
- return [
29
- { urlPrefix: `https://gh.gh2233.ml/${hub}`, maintainer: "@X.I.U/XIU2" },
30
- { urlPrefix: `https://ghproxy.com/${hub}`, maintainer: "gh-proxy" },
31
- { urlPrefix: `https://gh.ddlc.top/${hub}`, maintainer: "@mtr-static-official" },
32
- { urlPrefix: `https://ghdl.feizhuqwq.cf/${hub}`, maintainer: "feizhuqwq.com" },
33
- { urlPrefix: `https://slink.ltd/${hub}`, maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
34
- { urlPrefix: `https://git.xfj0.cn/${hub}`, maintainer: "anonymous1" },
35
- { urlPrefix: `https://gh.con.sh/${hub}`, maintainer: "anonymous2" },
36
- { urlPrefix: `https://ghps.cc/${hub}`, maintainer: "anonymous3" },
37
- { urlPrefix: "https://cors.isteed.cc/github.com", maintainer: "Lufs's" },
38
- { urlPrefix: `https://hub.gitmirror.com/${hub}`, maintainer: "GitMirror" },
39
- { urlPrefix: `https://js.xxooo.ml/${hub}`, maintainer: "\u996D\u592A\u786C" },
40
- { urlPrefix: `https://proxy.freecdn.ml/?url=${hub}`, maintainer: "anonymous4" },
41
- { urlPrefix: "https://download.njuu.cf", maintainer: "LibraryCloud-njuu" },
42
- { urlPrefix: "https://download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
43
- { urlPrefix: "https://download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
44
- ];
45
- }
46
-
47
- // src/updater.ts
9
+ // src/updater/index.ts
48
10
  import { EventEmitter } from "node:events";
49
- import { Buffer } from "node:buffer";
50
11
  import { createVerify } from "node:crypto";
51
12
  import { createGunzip } from "node:zlib";
52
13
  import { createReadStream, createWriteStream, existsSync } from "node:fs";
53
14
  import { rm, writeFile } from "node:fs/promises";
54
- import https from "node:https";
55
15
  import { app as app2 } from "electron";
16
+
17
+ // src/updater/download.ts
18
+ import { Buffer } from "node:buffer";
19
+ import https from "node:https";
56
20
  function downloadJSONDefault(url, updater, headers) {
57
21
  return new Promise((resolve2, reject) => {
58
22
  https.get(url, (res) => {
@@ -96,6 +60,46 @@ function downloadBufferDefault(url, updater, headers) {
96
60
  });
97
61
  });
98
62
  }
63
+
64
+ // src/updater/utils.ts
65
+ import { readFileSync } from "node:fs";
66
+ import { dirname, join } from "node:path";
67
+ import { app } from "electron";
68
+ function getAppAsarPath(name) {
69
+ return app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "dev";
70
+ }
71
+ function getElectronVersion() {
72
+ return app.getVersion();
73
+ }
74
+ function getAppVersion(name) {
75
+ return app.isPackaged ? readFileSync(join(getAppAsarPath(name), "version"), "utf-8").trim() : getElectronVersion();
76
+ }
77
+ function requireNative(packageName) {
78
+ const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
79
+ return __require(path);
80
+ }
81
+ function getReleaseDnsPrefix() {
82
+ const hub = "https://github.com";
83
+ return [
84
+ { urlPrefix: `https://gh.gh2233.ml/${hub}`, maintainer: "@X.I.U/XIU2" },
85
+ { urlPrefix: `https://ghproxy.com/${hub}`, maintainer: "gh-proxy" },
86
+ { urlPrefix: `https://gh.ddlc.top/${hub}`, maintainer: "@mtr-static-official" },
87
+ { urlPrefix: `https://ghdl.feizhuqwq.cf/${hub}`, maintainer: "feizhuqwq.com" },
88
+ { urlPrefix: `https://slink.ltd/${hub}`, maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
89
+ { urlPrefix: `https://git.xfj0.cn/${hub}`, maintainer: "anonymous1" },
90
+ { urlPrefix: `https://gh.con.sh/${hub}`, maintainer: "anonymous2" },
91
+ { urlPrefix: `https://ghps.cc/${hub}`, maintainer: "anonymous3" },
92
+ { urlPrefix: "https://cors.isteed.cc/github.com", maintainer: "Lufs's" },
93
+ { urlPrefix: `https://hub.gitmirror.com/${hub}`, maintainer: "GitMirror" },
94
+ { urlPrefix: `https://js.xxooo.ml/${hub}`, maintainer: "\u996D\u592A\u786C" },
95
+ { urlPrefix: `https://proxy.freecdn.ml/?url=${hub}`, maintainer: "anonymous4" },
96
+ { urlPrefix: "https://download.njuu.cf", maintainer: "LibraryCloud-njuu" },
97
+ { urlPrefix: "https://download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
98
+ { urlPrefix: "https://download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
99
+ ];
100
+ }
101
+
102
+ // src/updater/index.ts
99
103
  function createUpdater({
100
104
  SIGNATURE_PUB,
101
105
  repository,
@@ -151,11 +155,13 @@ function createUpdater({
151
155
  updateJsonURL = _update,
152
156
  releaseAsarURL = _release
153
157
  } = option || {};
154
- if ((!updateJsonURL || !releaseAsarURL) && !repository) {
155
- throw new Error("updateJsonURL or releaseAsarURL are not set");
158
+ if (!updateJsonURL || !releaseAsarURL) {
159
+ if (!repository) {
160
+ throw new Error("updateJsonURL or releaseAsarURL are not set");
161
+ }
162
+ updateJsonURL = `${repository.replace("github.com", "raw.githubusercontent.com")}/version.json`;
163
+ releaseAsarURL = `${repository}/releases/download/latest/${productName}.asar.gz`;
156
164
  }
157
- updateJsonURL ??= `${repository}/version.json`;
158
- releaseAsarURL ??= `${repository}/releases/download/latest/${productName}.asar.gz`;
159
165
  const gzipPath = `../${productName}.asar.gz`;
160
166
  const tmpFile = gzipPath.replace(".asar.gz", ".tmp.gz");
161
167
  if (existsSync(tmpFile)) {
package/dist/vite.cjs CHANGED
@@ -35,23 +35,85 @@ __export(vite_exports, {
35
35
  module.exports = __toCommonJS(vite_exports);
36
36
  var import_vite = require("vite");
37
37
 
38
- // src/build-entry.ts
38
+ // src/build-plugins/asar.ts
39
+ var import_node_crypto = require("crypto");
39
40
  var import_node_fs = require("fs");
40
41
  var import_promises = require("fs/promises");
41
- var import_node_crypto = require("crypto");
42
- var import_node_os = require("os");
42
+ var import_node_zlib = __toESM(require("zlib"), 1);
43
43
  var import_ci_info = require("ci-info");
44
+ function gzipFile(filePath) {
45
+ return new Promise((resolve, reject) => {
46
+ const gzip = import_node_zlib.default.createGzip();
47
+ const input = (0, import_node_fs.createReadStream)(filePath);
48
+ const output = (0, import_node_fs.createWriteStream)(`${filePath}.gz`);
49
+ input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
50
+ });
51
+ }
52
+ function generateSignature(buffer, privateKey) {
53
+ return (0, import_node_crypto.createSign)("RSA-SHA256").update(buffer).sign({
54
+ key: privateKey,
55
+ padding: import_node_crypto.constants.RSA_PKCS1_PADDING,
56
+ saltLength: import_node_crypto.constants.RSA_PSS_SALTLEN_DIGEST
57
+ }, "base64");
58
+ }
59
+ async function pack(dir, target) {
60
+ let asar = null;
61
+ try {
62
+ asar = await import("asar");
63
+ } catch (ignore) {
64
+ }
65
+ if (!asar) {
66
+ try {
67
+ asar = await import("@electron/asar");
68
+ } catch (ignore) {
69
+ }
70
+ }
71
+ if (!asar) {
72
+ throw new Error("no asar, please install @electron/asar");
73
+ }
74
+ await asar.createPackage(dir, target);
75
+ }
76
+ async function buildAsar({
77
+ version,
78
+ asarOutputPath,
79
+ privateKeyPath,
80
+ electronDistPath,
81
+ rendererDistPath,
82
+ versionPath
83
+ }) {
84
+ await (0, import_promises.rename)(rendererDistPath, `${electronDistPath}/renderer`);
85
+ await (0, import_promises.writeFile)(`${electronDistPath}/version`, version);
86
+ await pack(electronDistPath, asarOutputPath);
87
+ if (import_ci_info.isCI) {
88
+ return;
89
+ }
90
+ await gzipFile(asarOutputPath);
91
+ const buffer = await (0, import_promises.readFile)(`${asarOutputPath}.gz`);
92
+ const signature = generateSignature(buffer, await (0, import_promises.readFile)(privateKeyPath, "utf-8"));
93
+ await (0, import_promises.writeFile)(versionPath, JSON.stringify({
94
+ signature,
95
+ version,
96
+ size: buffer.length
97
+ }, null, 2));
98
+ }
99
+
100
+ // src/build-plugins/entry.ts
101
+ var import_node_fs2 = require("fs");
102
+ var import_promises2 = require("fs/promises");
103
+ var import_node_crypto2 = require("crypto");
104
+ var import_node_os = require("os");
105
+ var import_ci_info2 = require("ci-info");
44
106
  var import_esbuild = require("esbuild");
45
107
  async function generateKey(privateKeyPath, publicKeyPath, length) {
46
- const pair = (0, import_node_crypto.generateKeyPairSync)("rsa", { modulusLength: length });
108
+ const pair = (0, import_node_crypto2.generateKeyPairSync)("rsa", { modulusLength: length });
47
109
  const privateKey = pair.privateKey.export({ type: "pkcs1", format: "pem" });
48
110
  const publicKey = pair.publicKey.export({ type: "pkcs1", format: "pem" });
49
- await (0, import_promises.writeFile)(privateKeyPath, privateKey);
50
- await (0, import_promises.writeFile)(publicKeyPath, publicKey);
111
+ await (0, import_promises2.writeFile)(privateKeyPath, privateKey);
112
+ await (0, import_promises2.writeFile)(publicKeyPath, publicKey);
51
113
  }
52
114
  async function writePublicKeyToMain(updatePath, publicKeyPath) {
53
- const file = await (0, import_promises.readFile)(updatePath, "utf-8");
54
- const key = await (0, import_promises.readFile)(publicKeyPath, "utf-8");
115
+ const file = await (0, import_promises2.readFile)(updatePath, "utf-8");
116
+ const key = await (0, import_promises2.readFile)(publicKeyPath, "utf-8");
55
117
  const regex = /const SIGNATURE_PUB = ['`][\s\S]*?['`]/;
56
118
  const replacement = `const SIGNATURE_PUB = \`${key}\``;
57
119
  let replaced = file;
@@ -73,7 +135,7 @@ async function writePublicKeyToMain(updatePath, publicKeyPath) {
73
135
  !isMatched && lines.push(r);
74
136
  replaced = lines.join(import_node_os.EOL);
75
137
  }
76
- await (0, import_promises.writeFile)(updatePath, replaced);
138
+ await (0, import_promises2.writeFile)(updatePath, replaced);
77
139
  }
78
140
  async function buildEntry({
79
141
  privateKeyPath,
@@ -83,8 +145,8 @@ async function buildEntry({
83
145
  minify,
84
146
  keyLength
85
147
  }) {
86
- if (!import_ci_info.isCI) {
87
- !(0, import_node_fs.existsSync)(privateKeyPath) && await generateKey(privateKeyPath, publicKeyPath, keyLength);
148
+ if (!import_ci_info2.isCI) {
149
+ !(0, import_node_fs2.existsSync)(privateKeyPath) && await generateKey(privateKeyPath, publicKeyPath, keyLength);
88
150
  await writePublicKeyToMain(entryPath, publicKeyPath);
89
151
  }
90
152
  await (0, import_esbuild.build)({
@@ -97,69 +159,7 @@ async function buildEntry({
97
159
  });
98
160
  }
99
161
 
100
- // src/build-asar.ts
101
- var import_node_crypto2 = require("crypto");
102
- var import_node_fs2 = require("fs");
103
- var import_promises2 = require("fs/promises");
104
- var import_node_zlib = __toESM(require("zlib"), 1);
105
- var import_ci_info2 = require("ci-info");
106
- function gzipFile(filePath) {
107
- return new Promise((resolve, reject) => {
108
- const gzip = import_node_zlib.default.createGzip();
109
- const input = (0, import_node_fs2.createReadStream)(filePath);
110
- const output = (0, import_node_fs2.createWriteStream)(`${filePath}.gz`);
111
- input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
112
- });
113
- }
114
- function generateSignature(buffer, privateKey) {
115
- return (0, import_node_crypto2.createSign)("RSA-SHA256").update(buffer).sign({
116
- key: privateKey,
117
- padding: import_node_crypto2.constants.RSA_PKCS1_PADDING,
118
- saltLength: import_node_crypto2.constants.RSA_PSS_SALTLEN_DIGEST
119
- }, "base64");
120
- }
121
- async function pack(dir, target) {
122
- let asar = null;
123
- try {
124
- asar = await import("asar");
125
- } catch (ignore) {
126
- }
127
- if (!asar) {
128
- try {
129
- asar = await import("@electron/asar");
130
- } catch (ignore) {
131
- }
132
- }
133
- if (!asar) {
134
- throw new Error("no asar, please install @electron/asar");
135
- }
136
- await asar.createPackage(dir, target);
137
- }
138
- async function buildAsar({
139
- version,
140
- asarOutputPath,
141
- privateKeyPath,
142
- electronDistPath,
143
- rendererDistPath,
144
- versionPath
145
- }) {
146
- await (0, import_promises2.rename)(rendererDistPath, `${electronDistPath}/renderer`);
147
- await (0, import_promises2.writeFile)(`${electronDistPath}/version`, version);
148
- await pack(electronDistPath, asarOutputPath);
149
- if (import_ci_info2.isCI) {
150
- return;
151
- }
152
- await gzipFile(asarOutputPath);
153
- const buffer = await (0, import_promises2.readFile)(`${asarOutputPath}.gz`);
154
- const signature = generateSignature(buffer, await (0, import_promises2.readFile)(privateKeyPath, "utf-8"));
155
- await (0, import_promises2.writeFile)(versionPath, JSON.stringify({
156
- signature,
157
- version,
158
- size: buffer.length
159
- }, null, 2));
160
- }
161
-
162
- // src/option.ts
162
+ // src/build-plugins/option.ts
163
163
  function parseOptions(options) {
164
164
  const { isBuild, productName, version, minify = false, paths = {}, keys = {} } = options;
165
165
  const {
package/dist/vite.mjs CHANGED
@@ -3,74 +3,12 @@ import "./chunk-AKU6F3WT.mjs";
3
3
  // src/vite.ts
4
4
  import { createLogger } from "vite";
5
5
 
6
- // src/build-entry.ts
7
- import { existsSync } from "node:fs";
8
- import { readFile, writeFile } from "node:fs/promises";
9
- import { generateKeyPairSync } from "node:crypto";
10
- import { EOL } from "node:os";
11
- import { isCI } from "ci-info";
12
- import { build } from "esbuild";
13
- async function generateKey(privateKeyPath, publicKeyPath, length) {
14
- const pair = generateKeyPairSync("rsa", { modulusLength: length });
15
- const privateKey = pair.privateKey.export({ type: "pkcs1", format: "pem" });
16
- const publicKey = pair.publicKey.export({ type: "pkcs1", format: "pem" });
17
- await writeFile(privateKeyPath, privateKey);
18
- await writeFile(publicKeyPath, publicKey);
19
- }
20
- async function writePublicKeyToMain(updatePath, publicKeyPath) {
21
- const file = await readFile(updatePath, "utf-8");
22
- const key = await readFile(publicKeyPath, "utf-8");
23
- const regex = /const SIGNATURE_PUB = ['`][\s\S]*?['`]/;
24
- const replacement = `const SIGNATURE_PUB = \`${key}\``;
25
- let replaced = file;
26
- const signaturePubExists = regex.test(file);
27
- if (signaturePubExists) {
28
- replaced = file.replace(regex, replacement);
29
- } else {
30
- const lines = file.split(EOL);
31
- const r = `${EOL}${replacement}${EOL}`;
32
- let isMatched = false;
33
- for (let i = 0; i < lines.length; i++) {
34
- const line = lines[i];
35
- if (!line.startsWith("import") && !line.startsWith("/")) {
36
- lines.splice(i, 0, r);
37
- isMatched = true;
38
- break;
39
- }
40
- }
41
- !isMatched && lines.push(r);
42
- replaced = lines.join(EOL);
43
- }
44
- await writeFile(updatePath, replaced);
45
- }
46
- async function buildEntry({
47
- privateKeyPath,
48
- publicKeyPath,
49
- entryPath,
50
- entryOutputPath: outfile,
51
- minify,
52
- keyLength
53
- }) {
54
- if (!isCI) {
55
- !existsSync(privateKeyPath) && await generateKey(privateKeyPath, publicKeyPath, keyLength);
56
- await writePublicKeyToMain(entryPath, publicKeyPath);
57
- }
58
- await build({
59
- entryPoints: [entryPath],
60
- bundle: true,
61
- platform: "node",
62
- outfile,
63
- minify,
64
- external: ["electron"]
65
- });
66
- }
67
-
68
- // src/build-asar.ts
6
+ // src/build-plugins/asar.ts
69
7
  import { constants, createSign } from "node:crypto";
70
8
  import { createReadStream, createWriteStream } from "node:fs";
71
- import { readFile as readFile2, rename, writeFile as writeFile2 } from "node:fs/promises";
9
+ import { readFile, rename, writeFile } from "node:fs/promises";
72
10
  import zlib from "node:zlib";
73
- import { isCI as isCI2 } from "ci-info";
11
+ import { isCI } from "ci-info";
74
12
  function gzipFile(filePath) {
75
13
  return new Promise((resolve, reject) => {
76
14
  const gzip = zlib.createGzip();
@@ -112,22 +50,84 @@ async function buildAsar({
112
50
  versionPath
113
51
  }) {
114
52
  await rename(rendererDistPath, `${electronDistPath}/renderer`);
115
- await writeFile2(`${electronDistPath}/version`, version);
53
+ await writeFile(`${electronDistPath}/version`, version);
116
54
  await pack(electronDistPath, asarOutputPath);
117
- if (isCI2) {
55
+ if (isCI) {
118
56
  return;
119
57
  }
120
58
  await gzipFile(asarOutputPath);
121
- const buffer = await readFile2(`${asarOutputPath}.gz`);
122
- const signature = generateSignature(buffer, await readFile2(privateKeyPath, "utf-8"));
123
- await writeFile2(versionPath, JSON.stringify({
59
+ const buffer = await readFile(`${asarOutputPath}.gz`);
60
+ const signature = generateSignature(buffer, await readFile(privateKeyPath, "utf-8"));
61
+ await writeFile(versionPath, JSON.stringify({
124
62
  signature,
125
63
  version,
126
64
  size: buffer.length
127
65
  }, null, 2));
128
66
  }
129
67
 
130
- // src/option.ts
68
+ // src/build-plugins/entry.ts
69
+ import { existsSync } from "node:fs";
70
+ import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
71
+ import { generateKeyPairSync } from "node:crypto";
72
+ import { EOL } from "node:os";
73
+ import { isCI as isCI2 } from "ci-info";
74
+ import { build } from "esbuild";
75
+ async function generateKey(privateKeyPath, publicKeyPath, length) {
76
+ const pair = generateKeyPairSync("rsa", { modulusLength: length });
77
+ const privateKey = pair.privateKey.export({ type: "pkcs1", format: "pem" });
78
+ const publicKey = pair.publicKey.export({ type: "pkcs1", format: "pem" });
79
+ await writeFile2(privateKeyPath, privateKey);
80
+ await writeFile2(publicKeyPath, publicKey);
81
+ }
82
+ async function writePublicKeyToMain(updatePath, publicKeyPath) {
83
+ const file = await readFile2(updatePath, "utf-8");
84
+ const key = await readFile2(publicKeyPath, "utf-8");
85
+ const regex = /const SIGNATURE_PUB = ['`][\s\S]*?['`]/;
86
+ const replacement = `const SIGNATURE_PUB = \`${key}\``;
87
+ let replaced = file;
88
+ const signaturePubExists = regex.test(file);
89
+ if (signaturePubExists) {
90
+ replaced = file.replace(regex, replacement);
91
+ } else {
92
+ const lines = file.split(EOL);
93
+ const r = `${EOL}${replacement}${EOL}`;
94
+ let isMatched = false;
95
+ for (let i = 0; i < lines.length; i++) {
96
+ const line = lines[i];
97
+ if (!line.startsWith("import") && !line.startsWith("/")) {
98
+ lines.splice(i, 0, r);
99
+ isMatched = true;
100
+ break;
101
+ }
102
+ }
103
+ !isMatched && lines.push(r);
104
+ replaced = lines.join(EOL);
105
+ }
106
+ await writeFile2(updatePath, replaced);
107
+ }
108
+ async function buildEntry({
109
+ privateKeyPath,
110
+ publicKeyPath,
111
+ entryPath,
112
+ entryOutputPath: outfile,
113
+ minify,
114
+ keyLength
115
+ }) {
116
+ if (!isCI2) {
117
+ !existsSync(privateKeyPath) && await generateKey(privateKeyPath, publicKeyPath, keyLength);
118
+ await writePublicKeyToMain(entryPath, publicKeyPath);
119
+ }
120
+ await build({
121
+ entryPoints: [entryPath],
122
+ bundle: true,
123
+ platform: "node",
124
+ outfile,
125
+ minify,
126
+ external: ["electron"]
127
+ });
128
+ }
129
+
130
+ // src/build-plugins/option.ts
131
131
  function parseOptions(options) {
132
132
  const { isBuild, productName, version, minify = false, paths = {}, keys = {} } = options;
133
133
  const {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "electron incremental update tools, powered by vite",
5
5
  "scripts": {
6
6
  "build": "tsup",