electron-incremental-update 0.7.1 → 0.7.2

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.
@@ -1,5 +1,5 @@
1
1
  // src/crypto.ts
2
- import { constants, createCipheriv, createDecipheriv, createHash, createSign, createVerify } from "node:crypto";
2
+ import { createCipheriv, createDecipheriv, createHash, createPrivateKey, createSign, createVerify } from "node:crypto";
3
3
  import { Buffer } from "node:buffer";
4
4
  function encrypt(plainText, key2, iv) {
5
5
  const cipher = createCipheriv("aes-256-cbc", key2, iv);
@@ -18,11 +18,7 @@ function key(data, length) {
18
18
  return Buffer.from(hash).subarray(0, length);
19
19
  }
20
20
  var signature = (buffer, privateKey, cert, version) => {
21
- const sig = createSign("RSA-SHA256").update(buffer).sign({
22
- key: privateKey,
23
- padding: constants.RSA_PKCS1_PADDING,
24
- saltLength: constants.RSA_PSS_SALTLEN_DIGEST
25
- }, "base64");
21
+ const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
26
22
  return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
27
23
  };
28
24
  var verify = (buffer, signature2, cert) => {
package/dist/index.js CHANGED
@@ -210,24 +210,24 @@ function createUpdater({
210
210
  } = {}
211
211
  }) {
212
212
  const updater = new import_node_events.EventEmitter();
213
- let signature = "";
213
+ let signature, version;
214
214
  const asarPath = getProductAsarPath(productName);
215
215
  const gzipPath = `${asarPath}.gz`;
216
216
  const tmpFilePath = gzipPath.replace(".asar.gz", ".tmp.asar");
217
217
  function log(msg) {
218
218
  debug && updater.emit("debug", msg);
219
219
  }
220
- function needUpdate(version) {
220
+ function needUpdate(version2) {
221
221
  if (!import_electron3.app.isPackaged) {
222
222
  log("in dev mode, no need to update");
223
223
  return false;
224
224
  }
225
225
  const currentVersion = getEntryVersion();
226
- log(`check update: current version is ${currentVersion}, new version is ${version}`);
226
+ log(`check update: current version is ${currentVersion}, new version is ${version2}`);
227
227
  const _compare = compareVersion ?? compareVersionDefault;
228
- return _compare(currentVersion, version);
228
+ return _compare(currentVersion, version2);
229
229
  }
230
- async function parseData(format, data) {
230
+ async function parseData(format, data, version2) {
231
231
  if ((0, import_node_fs2.existsSync)(tmpFilePath)) {
232
232
  log(`remove tmp file: ${tmpFilePath}`);
233
233
  await (0, import_promises.rm)(tmpFilePath);
@@ -258,7 +258,7 @@ function createUpdater({
258
258
  } : {
259
259
  name: "releaseAsarURL",
260
260
  url: _release,
261
- repoFallback: `${repository}/releases/download/latest/${productName}.asar.gz`,
261
+ repoFallback: `${repository}/releases/download/v${version2}/${productName}-${version2}.asar.gz`,
262
262
  fn: downloadBuffer ?? downloadBufferDefault
263
263
  };
264
264
  data ??= info.url;
@@ -267,6 +267,9 @@ function createUpdater({
267
267
  if (!repository) {
268
268
  throw new Error(`${info.name} or repository are not set`);
269
269
  }
270
+ if (format === "buffer" && !version2) {
271
+ throw new Error("version are not set");
272
+ }
270
273
  data = info.repoFallback;
271
274
  }
272
275
  log(`download ${format} from ${data}`);
@@ -280,15 +283,16 @@ function createUpdater({
280
283
  updater.setDebug = (isDebug) => debug = isDebug;
281
284
  updater.checkUpdate = async (data) => {
282
285
  try {
283
- const { signature: _sig, size, version } = await parseData("json", data);
284
- log(`checked version: ${version}, size: ${size}, signature: ${_sig}`);
285
- if (!needUpdate(version)) {
286
- log(`update unavailable: ${version}`);
286
+ const { signature: _sig, size, version: _ver } = await parseData("json", data);
287
+ log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
288
+ if (!needUpdate(_ver)) {
289
+ log(`update unavailable: ${_ver}`);
287
290
  return void 0;
288
291
  } else {
289
- log(`update available: ${version}`);
292
+ log(`update available: ${_ver}`);
290
293
  signature = _sig;
291
- return { size, version };
294
+ version = _ver;
295
+ return { size, version: _ver };
292
296
  }
293
297
  } catch (error) {
294
298
  log(error);
@@ -301,29 +305,29 @@ function createUpdater({
301
305
  if (!_sig) {
302
306
  throw new Error("signature are not set, please checkUpdate first or set the second parameter");
303
307
  }
304
- const buffer = await parseData("buffer", data);
308
+ const buffer = await parseData("buffer", data, version);
305
309
  log("verify start");
306
310
  const _verify = verifySignaure ?? verify;
307
- const version = _verify(buffer, _sig, SIGNATURE_CERT);
308
- if (!version) {
311
+ const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
312
+ if (!_ver) {
309
313
  throw new Error("verify failed, invalid signature");
310
314
  }
311
315
  log("verify success");
312
- if (!needUpdate(version)) {
313
- throw new Error(`update unavailable: ${version}`);
316
+ if (!needUpdate(_ver)) {
317
+ throw new Error(`update unavailable: ${_ver}`);
314
318
  }
315
319
  log(`write file: ${gzipPath}`);
316
320
  await (0, import_promises.writeFile)(gzipPath, buffer);
317
321
  log(`extract file: ${gzipPath}`);
318
322
  await unzipFile(gzipPath, tmpFilePath);
319
323
  const asarVersion = await (0, import_promises.readFile)((0, import_node_path2.resolve)(tmpFilePath, "version"), "utf8");
320
- if (asarVersion !== version) {
324
+ if (asarVersion !== _ver) {
321
325
  (0, import_node_fs2.rmSync)(tmpFilePath);
322
- throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${version}`);
326
+ throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${_ver}`);
323
327
  } else {
324
328
  await (0, import_promises.rename)(tmpFilePath, asarPath);
325
329
  }
326
- log(`update success, version: ${version}`);
330
+ log(`update success, version: ${_ver}`);
327
331
  signature = "";
328
332
  return true;
329
333
  } catch (error) {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  verify
3
- } from "./chunk-3YKEHZAU.mjs";
3
+ } from "./chunk-Q2K52LOG.mjs";
4
4
  import {
5
5
  __require,
6
6
  getEntryVersion,
@@ -132,24 +132,24 @@ function createUpdater({
132
132
  } = {}
133
133
  }) {
134
134
  const updater = new EventEmitter();
135
- let signature = "";
135
+ let signature, version;
136
136
  const asarPath = getProductAsarPath(productName);
137
137
  const gzipPath = `${asarPath}.gz`;
138
138
  const tmpFilePath = gzipPath.replace(".asar.gz", ".tmp.asar");
139
139
  function log(msg) {
140
140
  debug && updater.emit("debug", msg);
141
141
  }
142
- function needUpdate(version) {
142
+ function needUpdate(version2) {
143
143
  if (!app.isPackaged) {
144
144
  log("in dev mode, no need to update");
145
145
  return false;
146
146
  }
147
147
  const currentVersion = getEntryVersion();
148
- log(`check update: current version is ${currentVersion}, new version is ${version}`);
148
+ log(`check update: current version is ${currentVersion}, new version is ${version2}`);
149
149
  const _compare = compareVersion ?? compareVersionDefault;
150
- return _compare(currentVersion, version);
150
+ return _compare(currentVersion, version2);
151
151
  }
152
- async function parseData(format, data) {
152
+ async function parseData(format, data, version2) {
153
153
  if (existsSync(tmpFilePath)) {
154
154
  log(`remove tmp file: ${tmpFilePath}`);
155
155
  await rm(tmpFilePath);
@@ -180,7 +180,7 @@ function createUpdater({
180
180
  } : {
181
181
  name: "releaseAsarURL",
182
182
  url: _release,
183
- repoFallback: `${repository}/releases/download/latest/${productName}.asar.gz`,
183
+ repoFallback: `${repository}/releases/download/v${version2}/${productName}-${version2}.asar.gz`,
184
184
  fn: downloadBuffer ?? downloadBufferDefault
185
185
  };
186
186
  data ??= info.url;
@@ -189,6 +189,9 @@ function createUpdater({
189
189
  if (!repository) {
190
190
  throw new Error(`${info.name} or repository are not set`);
191
191
  }
192
+ if (format === "buffer" && !version2) {
193
+ throw new Error("version are not set");
194
+ }
192
195
  data = info.repoFallback;
193
196
  }
194
197
  log(`download ${format} from ${data}`);
@@ -202,15 +205,16 @@ function createUpdater({
202
205
  updater.setDebug = (isDebug) => debug = isDebug;
203
206
  updater.checkUpdate = async (data) => {
204
207
  try {
205
- const { signature: _sig, size, version } = await parseData("json", data);
206
- log(`checked version: ${version}, size: ${size}, signature: ${_sig}`);
207
- if (!needUpdate(version)) {
208
- log(`update unavailable: ${version}`);
208
+ const { signature: _sig, size, version: _ver } = await parseData("json", data);
209
+ log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
210
+ if (!needUpdate(_ver)) {
211
+ log(`update unavailable: ${_ver}`);
209
212
  return void 0;
210
213
  } else {
211
- log(`update available: ${version}`);
214
+ log(`update available: ${_ver}`);
212
215
  signature = _sig;
213
- return { size, version };
216
+ version = _ver;
217
+ return { size, version: _ver };
214
218
  }
215
219
  } catch (error) {
216
220
  log(error);
@@ -223,29 +227,29 @@ function createUpdater({
223
227
  if (!_sig) {
224
228
  throw new Error("signature are not set, please checkUpdate first or set the second parameter");
225
229
  }
226
- const buffer = await parseData("buffer", data);
230
+ const buffer = await parseData("buffer", data, version);
227
231
  log("verify start");
228
232
  const _verify = verifySignaure ?? verify;
229
- const version = _verify(buffer, _sig, SIGNATURE_CERT);
230
- if (!version) {
233
+ const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
234
+ if (!_ver) {
231
235
  throw new Error("verify failed, invalid signature");
232
236
  }
233
237
  log("verify success");
234
- if (!needUpdate(version)) {
235
- throw new Error(`update unavailable: ${version}`);
238
+ if (!needUpdate(_ver)) {
239
+ throw new Error(`update unavailable: ${_ver}`);
236
240
  }
237
241
  log(`write file: ${gzipPath}`);
238
242
  await writeFile(gzipPath, buffer);
239
243
  log(`extract file: ${gzipPath}`);
240
244
  await unzipFile(gzipPath, tmpFilePath);
241
245
  const asarVersion = await readFile(resolve(tmpFilePath, "version"), "utf8");
242
- if (asarVersion !== version) {
246
+ if (asarVersion !== _ver) {
243
247
  rmSync(tmpFilePath);
244
- throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${version}`);
248
+ throw new Error(`update failed: asar version is ${asarVersion}, but it should be ${_ver}`);
245
249
  } else {
246
250
  await rename(tmpFilePath, asarPath);
247
251
  }
248
- log(`update success, version: ${version}`);
252
+ log(`update success, version: ${_ver}`);
249
253
  signature = "";
250
254
  return true;
251
255
  } catch (error) {
package/dist/vite.d.mts CHANGED
@@ -47,6 +47,11 @@ type Options = {
47
47
  * @default `release/${productName}.asar`
48
48
  */
49
49
  asarOutputPath?: string;
50
+ /**
51
+ * Path to gzipped asar file
52
+ * @default `release/${productName}-${version}.asar.gz`
53
+ */
54
+ gzipPath?: string;
50
55
  /**
51
56
  * Path to electron build output
52
57
  * @default `dist-electron`
package/dist/vite.d.ts CHANGED
@@ -47,6 +47,11 @@ type Options = {
47
47
  * @default `release/${productName}.asar`
48
48
  */
49
49
  asarOutputPath?: string;
50
+ /**
51
+ * Path to gzipped asar file
52
+ * @default `release/${productName}-${version}.asar.gz`
53
+ */
54
+ gzipPath?: string;
50
55
  /**
51
56
  * Path to electron build output
52
57
  * @default `dist-electron`
package/dist/vite.js CHANGED
@@ -53,11 +53,7 @@ function key(data, length) {
53
53
  return import_node_buffer.Buffer.from(hash).subarray(0, length);
54
54
  }
55
55
  var signature = (buffer, privateKey, cert, version) => {
56
- const sig = (0, import_node_crypto.createSign)("RSA-SHA256").update(buffer).sign({
57
- key: privateKey,
58
- padding: import_node_crypto.constants.RSA_PKCS1_PADDING,
59
- saltLength: import_node_crypto.constants.RSA_PSS_SALTLEN_DIGEST
60
- }, "base64");
56
+ const sig = (0, import_node_crypto.createSign)("RSA-SHA256").update(buffer).sign((0, import_node_crypto.createPrivateKey)(privateKey), "base64");
61
57
  return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
62
58
  };
63
59
 
@@ -99,23 +95,24 @@ async function pack(dir, target) {
99
95
  async function buildAsar({
100
96
  version,
101
97
  asarOutputPath,
98
+ gzipPath,
102
99
  electronDistPath,
103
100
  rendererDistPath
104
101
  }) {
105
102
  await (0, import_promises.rename)(rendererDistPath, `${electronDistPath}/renderer`);
106
103
  await (0, import_promises.writeFile)(`${electronDistPath}/version`, version);
107
104
  await pack(electronDistPath, asarOutputPath);
108
- await zipFile(asarOutputPath);
105
+ await zipFile(asarOutputPath, gzipPath);
109
106
  }
110
107
  async function buildVersion({
111
- asarOutputPath,
108
+ gzipPath,
112
109
  versionPath,
113
110
  privateKey,
114
111
  cert,
115
112
  version,
116
113
  generateSignature
117
114
  }) {
118
- const buffer = await (0, import_promises.readFile)(`${asarOutputPath}.gz`);
115
+ const buffer = await (0, import_promises.readFile)(gzipPath);
119
116
  const _func = generateSignature ?? signature;
120
117
  await (0, import_promises.writeFile)(versionPath, JSON.stringify({
121
118
  signature: _func(buffer, privateKey, cert, version),
@@ -138,6 +135,9 @@ async function buildEntry({
138
135
  });
139
136
  }
140
137
 
138
+ // src/build-plugins/option.ts
139
+ var import_ci_info = require("ci-info");
140
+
141
141
  // src/build-plugins/key.ts
142
142
  var import_node_fs2 = require("fs");
143
143
  var import_node_path2 = require("path");
@@ -182,7 +182,7 @@ function writeCertToMain(entryPath, cert) {
182
182
  }
183
183
  (0, import_node_fs2.writeFileSync)(entryPath, replaced);
184
184
  }
185
- function getKeys({
185
+ function parseKeys({
186
186
  keyLength,
187
187
  privateKeyPath,
188
188
  certPath,
@@ -213,7 +213,6 @@ function getKeys({
213
213
  }
214
214
 
215
215
  // src/build-plugins/option.ts
216
- var import_ci_info = require("ci-info");
217
216
  function parseOptions(options) {
218
217
  const {
219
218
  isBuild,
@@ -223,7 +222,8 @@ function parseOptions(options) {
223
222
  paths: {
224
223
  entryPath = "electron/app.ts",
225
224
  entryOutputPath = "app.js",
226
- asarOutputPath = `release/${productName}-${version}.asar`,
225
+ asarOutputPath = `release/${productName}.asar`,
226
+ gzipPath = `release/${productName}-${version}.asar.gz`,
227
227
  electronDistPath = "dist-electron",
228
228
  rendererDistPath = "dist",
229
229
  versionPath = "version.json"
@@ -250,6 +250,7 @@ function parseOptions(options) {
250
250
  const buildAsarOption = {
251
251
  version,
252
252
  asarOutputPath,
253
+ gzipPath,
253
254
  electronDistPath,
254
255
  rendererDistPath
255
256
  };
@@ -263,7 +264,7 @@ function parseOptions(options) {
263
264
  if (typeof expires === "number") {
264
265
  expires = new Date(Date.now() + expires);
265
266
  }
266
- const { privateKey, cert } = getKeys({
267
+ const { privateKey, cert } = parseKeys({
267
268
  keyLength,
268
269
  privateKeyPath,
269
270
  certPath,
@@ -274,7 +275,7 @@ function parseOptions(options) {
274
275
  });
275
276
  buildVersionOption = {
276
277
  version,
277
- asarOutputPath,
278
+ gzipPath,
278
279
  privateKey,
279
280
  cert,
280
281
  versionPath,
package/dist/vite.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  signature
3
- } from "./chunk-3YKEHZAU.mjs";
3
+ } from "./chunk-Q2K52LOG.mjs";
4
4
  import {
5
5
  zipFile
6
6
  } from "./chunk-CRBEZBU5.mjs";
@@ -31,23 +31,24 @@ async function pack(dir, target) {
31
31
  async function buildAsar({
32
32
  version,
33
33
  asarOutputPath,
34
+ gzipPath,
34
35
  electronDistPath,
35
36
  rendererDistPath
36
37
  }) {
37
38
  await rename(rendererDistPath, `${electronDistPath}/renderer`);
38
39
  await writeFile(`${electronDistPath}/version`, version);
39
40
  await pack(electronDistPath, asarOutputPath);
40
- await zipFile(asarOutputPath);
41
+ await zipFile(asarOutputPath, gzipPath);
41
42
  }
42
43
  async function buildVersion({
43
- asarOutputPath,
44
+ gzipPath,
44
45
  versionPath,
45
46
  privateKey,
46
47
  cert,
47
48
  version,
48
49
  generateSignature
49
50
  }) {
50
- const buffer = await readFile(`${asarOutputPath}.gz`);
51
+ const buffer = await readFile(gzipPath);
51
52
  const _func = generateSignature ?? signature;
52
53
  await writeFile(versionPath, JSON.stringify({
53
54
  signature: _func(buffer, privateKey, cert, version),
@@ -70,6 +71,9 @@ async function buildEntry({
70
71
  });
71
72
  }
72
73
 
74
+ // src/build-plugins/option.ts
75
+ import { isCI } from "ci-info";
76
+
73
77
  // src/build-plugins/key.ts
74
78
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
75
79
  import { dirname } from "node:path";
@@ -114,7 +118,7 @@ function writeCertToMain(entryPath, cert) {
114
118
  }
115
119
  writeFileSync(entryPath, replaced);
116
120
  }
117
- function getKeys({
121
+ function parseKeys({
118
122
  keyLength,
119
123
  privateKeyPath,
120
124
  certPath,
@@ -145,7 +149,6 @@ function getKeys({
145
149
  }
146
150
 
147
151
  // src/build-plugins/option.ts
148
- import { isCI } from "ci-info";
149
152
  function parseOptions(options) {
150
153
  const {
151
154
  isBuild,
@@ -155,7 +158,8 @@ function parseOptions(options) {
155
158
  paths: {
156
159
  entryPath = "electron/app.ts",
157
160
  entryOutputPath = "app.js",
158
- asarOutputPath = `release/${productName}-${version}.asar`,
161
+ asarOutputPath = `release/${productName}.asar`,
162
+ gzipPath = `release/${productName}-${version}.asar.gz`,
159
163
  electronDistPath = "dist-electron",
160
164
  rendererDistPath = "dist",
161
165
  versionPath = "version.json"
@@ -182,6 +186,7 @@ function parseOptions(options) {
182
186
  const buildAsarOption = {
183
187
  version,
184
188
  asarOutputPath,
189
+ gzipPath,
185
190
  electronDistPath,
186
191
  rendererDistPath
187
192
  };
@@ -195,7 +200,7 @@ function parseOptions(options) {
195
200
  if (typeof expires === "number") {
196
201
  expires = new Date(Date.now() + expires);
197
202
  }
198
- const { privateKey, cert } = getKeys({
203
+ const { privateKey, cert } = parseKeys({
199
204
  keyLength,
200
205
  privateKeyPath,
201
206
  certPath,
@@ -206,7 +211,7 @@ function parseOptions(options) {
206
211
  });
207
212
  buildVersionOption = {
208
213
  version,
209
- asarOutputPath,
214
+ gzipPath,
210
215
  privateKey,
211
216
  cert,
212
217
  versionPath,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",
@@ -50,7 +50,6 @@
50
50
  "bumpp": "^9.1.1",
51
51
  "electron": "^25.2.0",
52
52
  "eslint": "^8.43.0",
53
- "fs-jetpack": "^5.1.0",
54
53
  "tsup": "^7.1.0",
55
54
  "typescript": "^5.1.5",
56
55
  "vite": "^4.3.9",