electron-incremental-update 0.7.5 → 0.7.7

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.d.mts CHANGED
@@ -4,6 +4,7 @@ type CheckResultType = Omit<UpdateJSON, 'signature'> | undefined | Error;
4
4
  type InstallResult = true | Error;
5
5
  type UpdateEvents = {
6
6
  downloading: [progress: number];
7
+ downloadBuffer: [buffer: Buffer];
7
8
  debug: [msg: string | Error];
8
9
  };
9
10
  type UpdateJSON = {
@@ -40,7 +41,7 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
40
41
  * - `Error`: fail
41
42
  */
42
43
  download(data?: string | Buffer, sig?: string): Promise<InstallResult>;
43
- setDebugMode(debug: boolean): void;
44
+ debugMode: boolean;
44
45
  productName: string;
45
46
  }
46
47
  type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ type CheckResultType = Omit<UpdateJSON, 'signature'> | undefined | Error;
4
4
  type InstallResult = true | Error;
5
5
  type UpdateEvents = {
6
6
  downloading: [progress: number];
7
+ downloadBuffer: [buffer: Buffer];
7
8
  debug: [msg: string | Error];
8
9
  };
9
10
  type UpdateJSON = {
@@ -40,7 +41,7 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
40
41
  * - `Error`: fail
41
42
  */
42
43
  download(data?: string | Buffer, sig?: string): Promise<InstallResult>;
43
- setDebugMode(debug: boolean): void;
44
+ debugMode: boolean;
44
45
  productName: string;
45
46
  }
46
47
  type FunctionVerifySignature = (buffer: Buffer, signature: string, cert: string) => string | false;
package/dist/index.js CHANGED
@@ -26,14 +26,13 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
  var import_node_path2 = require("path");
28
28
  var import_node_fs3 = require("fs");
29
- var import_electron4 = require("electron");
29
+ var import_electron3 = require("electron");
30
30
 
31
31
  // src/updater/index.ts
32
32
  var import_node_events = require("events");
33
33
  var import_node_buffer3 = require("buffer");
34
34
  var import_node_fs2 = require("fs");
35
35
  var import_promises = require("fs/promises");
36
- var import_electron3 = require("electron");
37
36
 
38
37
  // src/crypto.ts
39
38
  var import_node_crypto = require("crypto");
@@ -214,18 +213,13 @@ function createUpdater(updaterOptions) {
214
213
  const updater = new import_node_events.EventEmitter();
215
214
  let signature;
216
215
  let version;
217
- let _debug = debug;
218
216
  const asarPath = getProductAsarPath(productName);
219
217
  const gzipPath = `${asarPath}.gz`;
220
218
  const tmpFilePath = `${asarPath}.tmp`;
221
219
  function log(msg) {
222
- _debug && updater.emit("debug", msg);
220
+ debug && updater.emit("debug", msg);
223
221
  }
224
222
  function needUpdate(version2) {
225
- if (!import_electron3.app.isPackaged) {
226
- log("in dev mode, no need to update");
227
- return false;
228
- }
229
223
  const currentVersion = getEntryVersion();
230
224
  log(`check update: current version is ${currentVersion}, new version is ${version2}`);
231
225
  const _compare = compareVersion ?? compareVersionDefault;
@@ -279,13 +273,16 @@ function createUpdater(updaterOptions) {
279
273
  log(`download ${format} from ${data}`);
280
274
  const ret = await info.fn(data, updater, headers);
281
275
  log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
276
+ if (format === "buffer") {
277
+ updater.emit("downloadBuffer", ret);
278
+ }
282
279
  return ret;
283
280
  } else {
284
281
  throw new Error(`invalid type at format '${format}': ${data}`);
285
282
  }
286
283
  }
287
284
  updater.productName = productName;
288
- updater.setDebugMode = (isDebug) => _debug = isDebug;
285
+ updater.debugMode = debug;
289
286
  updater.checkUpdate = async (data) => {
290
287
  try {
291
288
  const { signature: _sig, size, version: _ver } = await parseData("json", data);
@@ -343,7 +340,7 @@ function initApp(appOptions) {
343
340
  } = appOptions || {};
344
341
  function handleError(msg) {
345
342
  onStartError?.(new Error(msg));
346
- import_electron4.app.quit();
343
+ import_electron3.app.quit();
347
344
  }
348
345
  function startup(updater) {
349
346
  try {
@@ -351,7 +348,7 @@ function initApp(appOptions) {
351
348
  if ((0, import_node_fs3.existsSync)(`${asarPath}.tmp`)) {
352
349
  (0, import_node_fs3.renameSync)(`${asarPath}.tmp`, asarPath);
353
350
  }
354
- const mainDir = import_electron4.app.isPackaged ? asarPath : electronDevDistPath;
351
+ const mainDir = import_electron3.app.isPackaged ? asarPath : electronDevDistPath;
355
352
  const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
356
353
  onStart?.(entry);
357
354
  require(entry)(updater);
package/dist/index.mjs CHANGED
@@ -12,14 +12,13 @@ import {
12
12
  // src/index.ts
13
13
  import { resolve } from "node:path";
14
14
  import { existsSync as existsSync2, renameSync } from "node:fs";
15
- import { app as app2 } from "electron";
15
+ import { app } from "electron";
16
16
 
17
17
  // src/updater/index.ts
18
18
  import { EventEmitter } from "node:events";
19
19
  import { Buffer as Buffer2 } from "node:buffer";
20
20
  import { existsSync } from "node:fs";
21
21
  import { rm, writeFile } from "node:fs/promises";
22
- import { app } from "electron";
23
22
 
24
23
  // src/updater/defaultFunctions.ts
25
24
  import { Buffer } from "node:buffer";
@@ -138,18 +137,13 @@ function createUpdater(updaterOptions) {
138
137
  const updater = new EventEmitter();
139
138
  let signature;
140
139
  let version;
141
- let _debug = debug;
142
140
  const asarPath = getProductAsarPath(productName);
143
141
  const gzipPath = `${asarPath}.gz`;
144
142
  const tmpFilePath = `${asarPath}.tmp`;
145
143
  function log(msg) {
146
- _debug && updater.emit("debug", msg);
144
+ debug && updater.emit("debug", msg);
147
145
  }
148
146
  function needUpdate(version2) {
149
- if (!app.isPackaged) {
150
- log("in dev mode, no need to update");
151
- return false;
152
- }
153
147
  const currentVersion = getEntryVersion();
154
148
  log(`check update: current version is ${currentVersion}, new version is ${version2}`);
155
149
  const _compare = compareVersion ?? compareVersionDefault;
@@ -203,13 +197,16 @@ function createUpdater(updaterOptions) {
203
197
  log(`download ${format} from ${data}`);
204
198
  const ret = await info.fn(data, updater, headers);
205
199
  log(`download ${format} success${format === "buffer" ? `, file size: ${ret.length}` : ""}`);
200
+ if (format === "buffer") {
201
+ updater.emit("downloadBuffer", ret);
202
+ }
206
203
  return ret;
207
204
  } else {
208
205
  throw new Error(`invalid type at format '${format}': ${data}`);
209
206
  }
210
207
  }
211
208
  updater.productName = productName;
212
- updater.setDebugMode = (isDebug) => _debug = isDebug;
209
+ updater.debugMode = debug;
213
210
  updater.checkUpdate = async (data) => {
214
211
  try {
215
212
  const { signature: _sig, size, version: _ver } = await parseData("json", data);
@@ -267,7 +264,7 @@ function initApp(appOptions) {
267
264
  } = appOptions || {};
268
265
  function handleError(msg) {
269
266
  onStartError?.(new Error(msg));
270
- app2.quit();
267
+ app.quit();
271
268
  }
272
269
  function startup(updater) {
273
270
  try {
@@ -275,7 +272,7 @@ function initApp(appOptions) {
275
272
  if (existsSync2(`${asarPath}.tmp`)) {
276
273
  renameSync(`${asarPath}.tmp`, asarPath);
277
274
  }
278
- const mainDir = app2.isPackaged ? asarPath : electronDevDistPath;
275
+ const mainDir = app.isPackaged ? asarPath : electronDevDistPath;
279
276
  const entry = resolve(__dirname, mainDir, mainPath);
280
277
  onStart?.(entry);
281
278
  __require(entry)(updater);
package/dist/vite.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,14 +15,6 @@ 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
20
  // src/vite.ts
@@ -37,6 +27,7 @@ var import_vite = require("vite");
37
27
 
38
28
  // src/build-plugins/build.ts
39
29
  var import_promises = require("fs/promises");
30
+ var import_asar = require("@electron/asar");
40
31
  var import_esbuild = require("esbuild");
41
32
 
42
33
  // src/crypto.ts
@@ -79,23 +70,6 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
79
70
  }
80
71
 
81
72
  // src/build-plugins/build.ts
82
- async function pack(dir, target) {
83
- let asar = null;
84
- try {
85
- asar = await import("asar");
86
- } catch (ignore) {
87
- }
88
- if (!asar) {
89
- try {
90
- asar = await import("@electron/asar");
91
- } catch (ignore) {
92
- }
93
- }
94
- if (!asar) {
95
- throw new Error("no asar, please install @electron/asar");
96
- }
97
- await asar.createPackage(dir, target);
98
- }
99
73
  async function buildAsar({
100
74
  version,
101
75
  asarOutputPath,
@@ -105,7 +79,7 @@ async function buildAsar({
105
79
  }) {
106
80
  await (0, import_promises.rename)(rendererDistPath, `${electronDistPath}/renderer`);
107
81
  await (0, import_promises.writeFile)(`${electronDistPath}/version`, version);
108
- await pack(electronDistPath, asarOutputPath);
82
+ await (0, import_asar.createPackage)(electronDistPath, asarOutputPath);
109
83
  await zipFile(asarOutputPath, gzipPath);
110
84
  }
111
85
  async function buildVersion({
@@ -135,7 +109,7 @@ async function buildEntry({
135
109
  platform: "node",
136
110
  outfile,
137
111
  minify,
138
- external: ["electron"]
112
+ external: ["electron", "original-fs"]
139
113
  });
140
114
  }
141
115
 
@@ -146,44 +120,19 @@ var import_ci_info = require("ci-info");
146
120
  var import_node_fs2 = require("fs");
147
121
  var import_node_path2 = require("path");
148
122
  var import_node_os = require("os");
149
- var import_node_child_process = require("child_process");
123
+ var import_selfsigned = require("selfsigned");
150
124
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
151
- const starter = `try {
152
- require('selfsigned')
153
- } catch (e) {
154
- console.error('to generate private key, please run "npm install --dev selfsigned"')
155
- }
156
- try {
157
- const { existsSync, mkdirSync, writeFileSync } = require('node:fs')
158
- const { dirname } = require('node:path')
159
- const { generate } = require('selfsigned')
160
- const privateKeyPath = '${privateKeyPath.replace(/\\/g, "/")}'
161
- const certPath = '${certPath.replace(/\\/g, "/")}'
162
- const privateKeyDir = dirname(privateKeyPath)
163
- existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true })
164
- const certDir = dirname(certPath)
165
- existsSync(certDir) || mkdirSync(certDir, { recursive: true })
166
-
167
- const { cert, private: privateKey } = generate(${JSON.stringify(subject)}, {
168
- keySize: ${keyLength}, algorithm: 'sha256', days: ${days},
169
- })
170
-
171
- writeFileSync(privateKeyPath, privateKey.replace(/\\r\\n?/g, '\\n'))
172
- writeFileSync(certPath, cert.replace(/\\r\\n?/g, '\\n'))
173
- } catch (e) {
174
- console.error(e)
175
- process.exit(-1)
176
- } finally {
177
- process.exit(0)
178
- }
179
- `;
180
- const fileName = "key-gen.js";
181
- (0, import_node_fs2.writeFileSync)(`./${fileName}`, starter);
182
- try {
183
- (0, import_node_child_process.execSync)(`npx electron ${fileName}`, { stdio: "inherit" });
184
- } finally {
185
- (0, import_node_fs2.rmSync)(`./${fileName}`);
186
- }
125
+ const privateKeyDir = (0, import_node_path2.dirname)(privateKeyPath);
126
+ (0, import_node_fs2.existsSync)(privateKeyDir) || (0, import_node_fs2.mkdirSync)(privateKeyDir, { recursive: true });
127
+ const certDir = (0, import_node_path2.dirname)(certPath);
128
+ (0, import_node_fs2.existsSync)(certDir) || (0, import_node_fs2.mkdirSync)(certDir, { recursive: true });
129
+ const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
130
+ keySize: keyLength,
131
+ algorithm: "sha256",
132
+ days
133
+ });
134
+ (0, import_node_fs2.writeFileSync)(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
135
+ (0, import_node_fs2.writeFileSync)(certPath, cert.replace(/\r\n?/g, "\n"));
187
136
  }
188
137
  function writeCertToMain(entryPath, cert) {
189
138
  const file = (0, import_node_fs2.readFileSync)(entryPath, "utf-8");
@@ -208,7 +157,7 @@ function writeCertToMain(entryPath, cert) {
208
157
  !isMatched && lines.push(r);
209
158
  replaced = lines.join(import_node_os.EOL);
210
159
  }
211
- (0, import_node_fs2.writeFileSync)(entryPath, replaced);
160
+ (0, import_node_fs2.writeFileSync)(entryPath, replaced.replace(/\r\n?/g, "\n"));
212
161
  }
213
162
  function parseKeys({
214
163
  keyLength,
package/dist/vite.mjs CHANGED
@@ -10,24 +10,8 @@ import { createLogger } from "vite";
10
10
 
11
11
  // src/build-plugins/build.ts
12
12
  import { readFile, rename, writeFile } from "node:fs/promises";
13
+ import { createPackage } from "@electron/asar";
13
14
  import { build } from "esbuild";
14
- async function pack(dir, target) {
15
- let asar = null;
16
- try {
17
- asar = await import("asar");
18
- } catch (ignore) {
19
- }
20
- if (!asar) {
21
- try {
22
- asar = await import("@electron/asar");
23
- } catch (ignore) {
24
- }
25
- }
26
- if (!asar) {
27
- throw new Error("no asar, please install @electron/asar");
28
- }
29
- await asar.createPackage(dir, target);
30
- }
31
15
  async function buildAsar({
32
16
  version,
33
17
  asarOutputPath,
@@ -37,7 +21,7 @@ async function buildAsar({
37
21
  }) {
38
22
  await rename(rendererDistPath, `${electronDistPath}/renderer`);
39
23
  await writeFile(`${electronDistPath}/version`, version);
40
- await pack(electronDistPath, asarOutputPath);
24
+ await createPackage(electronDistPath, asarOutputPath);
41
25
  await zipFile(asarOutputPath, gzipPath);
42
26
  }
43
27
  async function buildVersion({
@@ -67,7 +51,7 @@ async function buildEntry({
67
51
  platform: "node",
68
52
  outfile,
69
53
  minify,
70
- external: ["electron"]
54
+ external: ["electron", "original-fs"]
71
55
  });
72
56
  }
73
57
 
@@ -75,47 +59,22 @@ async function buildEntry({
75
59
  import { isCI } from "ci-info";
76
60
 
77
61
  // src/build-plugins/key.ts
78
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
62
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
79
63
  import { dirname } from "node:path";
80
64
  import { EOL } from "node:os";
81
- import { execSync } from "node:child_process";
65
+ import { generate } from "selfsigned";
82
66
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
83
- const starter = `try {
84
- require('selfsigned')
85
- } catch (e) {
86
- console.error('to generate private key, please run "npm install --dev selfsigned"')
87
- }
88
- try {
89
- const { existsSync, mkdirSync, writeFileSync } = require('node:fs')
90
- const { dirname } = require('node:path')
91
- const { generate } = require('selfsigned')
92
- const privateKeyPath = '${privateKeyPath.replace(/\\/g, "/")}'
93
- const certPath = '${certPath.replace(/\\/g, "/")}'
94
- const privateKeyDir = dirname(privateKeyPath)
95
- existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true })
96
- const certDir = dirname(certPath)
97
- existsSync(certDir) || mkdirSync(certDir, { recursive: true })
98
-
99
- const { cert, private: privateKey } = generate(${JSON.stringify(subject)}, {
100
- keySize: ${keyLength}, algorithm: 'sha256', days: ${days},
101
- })
102
-
103
- writeFileSync(privateKeyPath, privateKey.replace(/\\r\\n?/g, '\\n'))
104
- writeFileSync(certPath, cert.replace(/\\r\\n?/g, '\\n'))
105
- } catch (e) {
106
- console.error(e)
107
- process.exit(-1)
108
- } finally {
109
- process.exit(0)
110
- }
111
- `;
112
- const fileName = "key-gen.js";
113
- writeFileSync(`./${fileName}`, starter);
114
- try {
115
- execSync(`npx electron ${fileName}`, { stdio: "inherit" });
116
- } finally {
117
- rmSync(`./${fileName}`);
118
- }
67
+ const privateKeyDir = dirname(privateKeyPath);
68
+ existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true });
69
+ const certDir = dirname(certPath);
70
+ existsSync(certDir) || mkdirSync(certDir, { recursive: true });
71
+ const { cert, private: privateKey } = generate(subject, {
72
+ keySize: keyLength,
73
+ algorithm: "sha256",
74
+ days
75
+ });
76
+ writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
77
+ writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
119
78
  }
120
79
  function writeCertToMain(entryPath, cert) {
121
80
  const file = readFileSync(entryPath, "utf-8");
@@ -140,7 +99,7 @@ function writeCertToMain(entryPath, cert) {
140
99
  !isMatched && lines.push(r);
141
100
  replaced = lines.join(EOL);
142
101
  }
143
- writeFileSync(entryPath, replaced);
102
+ writeFileSync(entryPath, replaced.replace(/\r\n?/g, "\n"));
144
103
  }
145
104
  function parseKeys({
146
105
  keyLength,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.7.5",
4
+ "version": "0.7.7",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",
@@ -43,10 +43,8 @@
43
43
  "updater"
44
44
  ],
45
45
  "devDependencies": {
46
- "@electron/asar": "^3.2.4",
47
46
  "@subframe7536/eslint-config": "^0.1.9",
48
47
  "@types/node": "^20.3.2",
49
- "asar": "^3.2.0",
50
48
  "bumpp": "^9.1.1",
51
49
  "electron": "^25.2.0",
52
50
  "eslint": "^8.43.0",
@@ -56,9 +54,8 @@
56
54
  "vitest": "^0.32.2"
57
55
  },
58
56
  "dependencies": {
59
- "ci-info": "^3.8.0"
60
- },
61
- "peerDependencies": {
57
+ "@electron/asar": "^3.2.4",
58
+ "ci-info": "^3.8.0",
62
59
  "selfsigned": "^2.1.1"
63
60
  }
64
61
  }