electron-incremental-update 0.8.7 → 0.8.9

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
@@ -75,11 +75,12 @@ initApp({ onStart: console.log })
75
75
  make sure the plugin is set in the **last** build task
76
76
 
77
77
  - for `vite-plugin-electron`, set it to `preload` (the second object in the plugin option array)
78
+ - cert is read from `process.env.UPDATER_CERT` first, then read config
79
+ - privatekey is read from `process.env.UPDATER_PK` first, then read config
78
80
 
79
81
  ```ts
80
82
  // vite.config.ts
81
83
  export default defineConfig(({ command }) => {
82
-
83
84
  const isBuild = command === 'build'
84
85
  // ...
85
86
 
@@ -13,15 +13,13 @@ var appInfo = {
13
13
  win: process.platform === "win32",
14
14
  mac: process.platform === "darwin",
15
15
  linux: process.platform === "linux",
16
- electronVersion: getElectronVersion(),
17
- appVersion: getAppVersion,
18
16
  systemVersion: release()
19
17
  };
20
18
  function getLocale() {
21
19
  return app.isReady() ? app.getLocale() : void 0;
22
20
  }
23
21
  function getProductAsarPath(name = DEFAULT_APP_NAME) {
24
- return !app.isPackaged ? "DEV.asar" : join(dirname(app.getAppPath()), `${name}.asar`);
22
+ return !app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "DEV.asar";
25
23
  }
26
24
  function getElectronVersion() {
27
25
  return app.getVersion();
@@ -63,16 +61,13 @@ function restartApp() {
63
61
  app2.relaunch();
64
62
  app2.quit();
65
63
  }
66
- function waitAppReady(duration = 1e3) {
67
- if (app2.isReady()) {
68
- return Promise.resolve();
69
- }
70
- return new Promise((resolve, reject) => {
71
- const timeout = setTimeout(() => {
64
+ function waitAppReady(timeout = 1e3) {
65
+ return app2.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
66
+ const _ = setTimeout(() => {
72
67
  reject(new Error("app is not ready"));
73
- }, duration);
68
+ }, timeout);
74
69
  app2.whenReady().then(() => {
75
- clearTimeout(timeout);
70
+ clearTimeout(_);
76
71
  resolve();
77
72
  });
78
73
  });
package/dist/index.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/index.ts
@@ -37,7 +27,7 @@ __export(src_exports, {
37
27
  module.exports = __toCommonJS(src_exports);
38
28
  var import_node_path2 = require("path");
39
29
  var import_node_fs4 = require("fs");
40
- var import_electron4 = __toESM(require("electron"));
30
+ var import_electron4 = require("electron");
41
31
 
42
32
  // src/updater/index.ts
43
33
  var import_node_fs3 = require("fs");
@@ -54,12 +44,10 @@ var appInfo = {
54
44
  win: process.platform === "win32",
55
45
  mac: process.platform === "darwin",
56
46
  linux: process.platform === "linux",
57
- electronVersion: getElectronVersion(),
58
- appVersion: getAppVersion,
59
47
  systemVersion: (0, import_node_os.release)()
60
48
  };
61
49
  function getProductAsarPath(name = DEFAULT_APP_NAME) {
62
- return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
50
+ return !import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "DEV.asar";
63
51
  }
64
52
  function getElectronVersion() {
65
53
  return import_electron.app.getVersion();
@@ -116,16 +104,13 @@ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
116
104
 
117
105
  // src/utils/utils.ts
118
106
  var import_electron2 = require("electron");
119
- function waitAppReady(duration = 1e3) {
120
- if (import_electron2.app.isReady()) {
121
- return Promise.resolve();
122
- }
123
- return new Promise((resolve2, reject) => {
124
- const timeout = setTimeout(() => {
107
+ function waitAppReady(timeout = 1e3) {
108
+ return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve2, reject) => {
109
+ const _ = setTimeout(() => {
125
110
  reject(new Error("app is not ready"));
126
- }, duration);
111
+ }, timeout);
127
112
  import_electron2.app.whenReady().then(() => {
128
- clearTimeout(timeout);
113
+ clearTimeout(_);
129
114
  resolve2();
130
115
  });
131
116
  });
@@ -438,7 +423,7 @@ function initApp(appOptions) {
438
423
  } = hooks || {};
439
424
  function handleError(msg) {
440
425
  onStartError?.(new Error(msg));
441
- import_electron4.default.app.quit();
426
+ import_electron4.app.quit();
442
427
  }
443
428
  async function startup(updater) {
444
429
  try {
@@ -448,7 +433,7 @@ function initApp(appOptions) {
448
433
  await beforeDoUpdate?.(asarPath, updateAsarPath);
449
434
  (0, import_node_fs4.renameSync)(updateAsarPath, asarPath);
450
435
  }
451
- const mainDir = import_electron4.default.app.isPackaged ? asarPath : electronDevDistPath;
436
+ const mainDir = import_electron4.app.isPackaged ? asarPath : electronDevDistPath;
452
437
  const entry = (0, import_node_path2.resolve)(__dirname, mainDir, mainPath);
453
438
  await beforeStart?.(entry);
454
439
  require(entry)(updater);
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  getElectronVersion,
9
9
  getProductAsarPath,
10
10
  waitAppReady
11
- } from "./chunk-OGAOUYV3.mjs";
11
+ } from "./chunk-6V5SXFGA.mjs";
12
12
  import {
13
13
  __require,
14
14
  parseVersion,
@@ -18,7 +18,7 @@ import {
18
18
  // src/index.ts
19
19
  import { resolve } from "node:path";
20
20
  import { existsSync as existsSync2, renameSync } from "node:fs";
21
- import Electron from "electron";
21
+ import { app } from "electron";
22
22
 
23
23
  // src/updater/index.ts
24
24
  import { existsSync } from "node:fs";
@@ -303,7 +303,7 @@ function initApp(appOptions) {
303
303
  } = hooks || {};
304
304
  function handleError(msg) {
305
305
  onStartError?.(new Error(msg));
306
- Electron.app.quit();
306
+ app.quit();
307
307
  }
308
308
  async function startup(updater) {
309
309
  try {
@@ -313,7 +313,7 @@ function initApp(appOptions) {
313
313
  await beforeDoUpdate?.(asarPath, updateAsarPath);
314
314
  renameSync(updateAsarPath, asarPath);
315
315
  }
316
- const mainDir = Electron.app.isPackaged ? asarPath : electronDevDistPath;
316
+ const mainDir = app.isPackaged ? asarPath : electronDevDistPath;
317
317
  const entry = resolve(__dirname, mainDir, mainPath);
318
318
  await beforeStart?.(entry);
319
319
  __require(entry)(updater);
package/dist/utils.d.mts CHANGED
@@ -4,8 +4,6 @@ type Info = {
4
4
  win: boolean;
5
5
  mac: boolean;
6
6
  linux: boolean;
7
- electronVersion: string;
8
- appVersion: (name?: string) => string;
9
7
  /**
10
8
  * `os.release()`
11
9
  */
@@ -68,8 +66,13 @@ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, rel
68
66
  declare function restartApp(): void;
69
67
  /**
70
68
  * ensure app is ready.
69
+ * @param timeout wait timeout, @default 1000
70
+ */
71
+ declare function waitAppReady(timeout?: number): Promise<void>;
72
+ /**
73
+ * handle all unhandled error
74
+ * @param callback callback function
71
75
  */
72
- declare function waitAppReady(duration?: number): Promise<void>;
73
76
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
77
 
75
78
  export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.d.ts CHANGED
@@ -4,8 +4,6 @@ type Info = {
4
4
  win: boolean;
5
5
  mac: boolean;
6
6
  linux: boolean;
7
- electronVersion: string;
8
- appVersion: (name?: string) => string;
9
7
  /**
10
8
  * `os.release()`
11
9
  */
@@ -68,8 +66,13 @@ declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, rel
68
66
  declare function restartApp(): void;
69
67
  /**
70
68
  * ensure app is ready.
69
+ * @param timeout wait timeout, @default 1000
70
+ */
71
+ declare function waitAppReady(timeout?: number): Promise<void>;
72
+ /**
73
+ * handle all unhandled error
74
+ * @param callback callback function
71
75
  */
72
- declare function waitAppReady(duration?: number): Promise<void>;
73
76
  declare function handleUnexpectedErrors(callback: (err: unknown) => void): void;
74
77
 
75
78
  export { DEFAULT_APP_NAME, NoSuchNativeModuleError, Version, appInfo, getAppVersion, getElectronVersion, getLocale, getProductAsarPath, handleUnexpectedErrors, isNoSuchNativeModuleError, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
package/dist/utils.js CHANGED
@@ -50,15 +50,13 @@ var appInfo = {
50
50
  win: process.platform === "win32",
51
51
  mac: process.platform === "darwin",
52
52
  linux: process.platform === "linux",
53
- electronVersion: getElectronVersion(),
54
- appVersion: getAppVersion,
55
53
  systemVersion: (0, import_node_os.release)()
56
54
  };
57
55
  function getLocale() {
58
56
  return import_electron.app.isReady() ? import_electron.app.getLocale() : void 0;
59
57
  }
60
58
  function getProductAsarPath(name = DEFAULT_APP_NAME) {
61
- return !import_electron.app.isPackaged ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`);
59
+ return !import_electron.app.isPackaged ? (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${name}.asar`) : "DEV.asar";
62
60
  }
63
61
  function getElectronVersion() {
64
62
  return import_electron.app.getVersion();
@@ -161,16 +159,13 @@ function restartApp() {
161
159
  import_electron2.app.relaunch();
162
160
  import_electron2.app.quit();
163
161
  }
164
- function waitAppReady(duration = 1e3) {
165
- if (import_electron2.app.isReady()) {
166
- return Promise.resolve();
167
- }
168
- return new Promise((resolve, reject) => {
169
- const timeout = setTimeout(() => {
162
+ function waitAppReady(timeout = 1e3) {
163
+ return import_electron2.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
164
+ const _ = setTimeout(() => {
170
165
  reject(new Error("app is not ready"));
171
- }, duration);
166
+ }, timeout);
172
167
  import_electron2.app.whenReady().then(() => {
173
- clearTimeout(timeout);
168
+ clearTimeout(_);
174
169
  resolve();
175
170
  });
176
171
  });
package/dist/utils.mjs CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  requireNative,
13
13
  restartApp,
14
14
  waitAppReady
15
- } from "./chunk-OGAOUYV3.mjs";
15
+ } from "./chunk-6V5SXFGA.mjs";
16
16
  import {
17
17
  parseVersion,
18
18
  unzipFile,
package/dist/vite.d.mts CHANGED
@@ -43,7 +43,7 @@ type Options = {
43
43
  * the name of you application
44
44
  *
45
45
  * you can set as 'name' in `package.json`
46
- */
46
+ */
47
47
  productName: string;
48
48
  /**
49
49
  * the version of you application
package/dist/vite.d.ts CHANGED
@@ -43,7 +43,7 @@ type Options = {
43
43
  * the name of you application
44
44
  *
45
45
  * you can set as 'name' in `package.json`
46
- */
46
+ */
47
47
  productName: string;
48
48
  /**
49
49
  * the version of you application
package/dist/vite.js CHANGED
@@ -189,9 +189,6 @@ async function buildEntry({
189
189
  });
190
190
  }
191
191
 
192
- // src/build-plugins/option.ts
193
- var import_ci_info = require("ci-info");
194
-
195
192
  // src/build-plugins/key.ts
196
193
  var import_node_fs3 = require("fs");
197
194
  var import_node_path = require("path");
@@ -250,8 +247,8 @@ function parseKeys({
250
247
  if (!(0, import_node_fs3.existsSync)(privateKeyPath) || !(0, import_node_fs3.existsSync)(certPath)) {
251
248
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
252
249
  }
253
- const privateKey = (0, import_node_fs3.readFileSync)(privateKeyPath, "utf-8");
254
- const cert = (0, import_node_fs3.readFileSync)(certPath, "utf-8");
250
+ const privateKey = process.env.UPDATER_PK || (0, import_node_fs3.readFileSync)(privateKeyPath, "utf-8");
251
+ const cert = process.env.UPDATER_CERT || (0, import_node_fs3.readFileSync)(certPath, "utf-8");
255
252
  writeCertToMain(entryPath, cert);
256
253
  return {
257
254
  privateKey,
@@ -312,27 +309,24 @@ function parseOptions(options) {
312
309
  entryOutputPath,
313
310
  minify
314
311
  };
315
- let buildVersionOption;
316
- if (!import_ci_info.isCI) {
317
- const { privateKey, cert } = parseKeys({
318
- keyLength,
319
- privateKeyPath,
320
- certPath,
321
- entryPath,
322
- subject,
323
- days
324
- });
325
- buildVersionOption = {
326
- version,
327
- minimumVersion,
328
- gzipPath,
329
- privateKey,
330
- cert,
331
- versionPath,
332
- generateSignature,
333
- generateVersionJson
334
- };
335
- }
312
+ const { privateKey, cert } = parseKeys({
313
+ keyLength,
314
+ privateKeyPath,
315
+ certPath,
316
+ entryPath,
317
+ subject,
318
+ days
319
+ });
320
+ const buildVersionOption = {
321
+ version,
322
+ minimumVersion,
323
+ gzipPath,
324
+ privateKey,
325
+ cert,
326
+ versionPath,
327
+ generateSignature,
328
+ generateVersionJson
329
+ };
336
330
  return { isBuild, buildAsarOption, buildEntryOption, buildVersionOption };
337
331
  }
338
332
 
@@ -347,16 +341,16 @@ function ElectronUpdater(options) {
347
341
  name: `vite-plugin-${id}`,
348
342
  enforce: "post",
349
343
  async closeBundle() {
350
- log.info("build entry start");
344
+ log.info("build entry start", { timestamp: true });
351
345
  await buildEntry(buildEntryOption);
352
- log.info(`build entry end, ${entryPath} -> ${entryOutputPath}`);
346
+ log.info(`build entry end, ${entryPath} -> ${entryOutputPath}`, { timestamp: true });
353
347
  if (!isBuild) {
354
348
  return;
355
349
  }
356
- log.info("build asar start");
350
+ log.info("build asar start", { timestamp: true });
357
351
  await buildAsar(buildAsarOption);
358
- buildVersionOption && await buildVersion(buildVersionOption);
359
- log.info(`build asar end, output to ${asarOutputPath}`);
352
+ await buildVersion(buildVersionOption);
353
+ log.info(`build asar end, output to ${asarOutputPath}`, { timestamp: true });
360
354
  }
361
355
  };
362
356
  }
package/dist/vite.mjs CHANGED
@@ -94,9 +94,6 @@ async function buildEntry({
94
94
  });
95
95
  }
96
96
 
97
- // src/build-plugins/option.ts
98
- import { isCI } from "ci-info";
99
-
100
97
  // src/build-plugins/key.ts
101
98
  import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
102
99
  import { dirname } from "node:path";
@@ -155,8 +152,8 @@ function parseKeys({
155
152
  if (!existsSync2(privateKeyPath) || !existsSync2(certPath)) {
156
153
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
157
154
  }
158
- const privateKey = readFileSync(privateKeyPath, "utf-8");
159
- const cert = readFileSync(certPath, "utf-8");
155
+ const privateKey = process.env.UPDATER_PK || readFileSync(privateKeyPath, "utf-8");
156
+ const cert = process.env.UPDATER_CERT || readFileSync(certPath, "utf-8");
160
157
  writeCertToMain(entryPath, cert);
161
158
  return {
162
159
  privateKey,
@@ -217,27 +214,24 @@ function parseOptions(options) {
217
214
  entryOutputPath,
218
215
  minify
219
216
  };
220
- let buildVersionOption;
221
- if (!isCI) {
222
- const { privateKey, cert } = parseKeys({
223
- keyLength,
224
- privateKeyPath,
225
- certPath,
226
- entryPath,
227
- subject,
228
- days
229
- });
230
- buildVersionOption = {
231
- version,
232
- minimumVersion,
233
- gzipPath,
234
- privateKey,
235
- cert,
236
- versionPath,
237
- generateSignature,
238
- generateVersionJson
239
- };
240
- }
217
+ const { privateKey, cert } = parseKeys({
218
+ keyLength,
219
+ privateKeyPath,
220
+ certPath,
221
+ entryPath,
222
+ subject,
223
+ days
224
+ });
225
+ const buildVersionOption = {
226
+ version,
227
+ minimumVersion,
228
+ gzipPath,
229
+ privateKey,
230
+ cert,
231
+ versionPath,
232
+ generateSignature,
233
+ generateVersionJson
234
+ };
241
235
  return { isBuild, buildAsarOption, buildEntryOption, buildVersionOption };
242
236
  }
243
237
 
@@ -252,16 +246,16 @@ function ElectronUpdater(options) {
252
246
  name: `vite-plugin-${id}`,
253
247
  enforce: "post",
254
248
  async closeBundle() {
255
- log.info("build entry start");
249
+ log.info("build entry start", { timestamp: true });
256
250
  await buildEntry(buildEntryOption);
257
- log.info(`build entry end, ${entryPath} -> ${entryOutputPath}`);
251
+ log.info(`build entry end, ${entryPath} -> ${entryOutputPath}`, { timestamp: true });
258
252
  if (!isBuild) {
259
253
  return;
260
254
  }
261
- log.info("build asar start");
255
+ log.info("build asar start", { timestamp: true });
262
256
  await buildAsar(buildAsarOption);
263
- buildVersionOption && await buildVersion(buildVersionOption);
264
- log.info(`build asar end, output to ${asarOutputPath}`);
257
+ await buildVersion(buildVersionOption);
258
+ log.info(`build asar end, output to ${asarOutputPath}`, { timestamp: true });
265
259
  }
266
260
  };
267
261
  }
package/package.json CHANGED
@@ -1,29 +1,15 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "author": "subframe7536",
4
- "version": "0.8.7",
3
+ "version": "0.8.9",
5
4
  "description": "electron incremental update tools, powered by vite",
6
- "scripts": {
7
- "build": "tsup && node fix-module.js",
8
- "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
9
- "test": "vitest --run",
10
- "lint": "eslint . --fix"
11
- },
12
- "publishConfig": {
13
- "access": "public",
14
- "registry": "https://registry.npmjs.org/"
15
- },
16
- "repository": "https://github.com/subframe7536/electron-incremental-update",
5
+ "author": "subframe7536",
17
6
  "license": "MIT",
18
- "files": [
19
- "dist",
20
- "vite.js",
21
- "vite.d.ts",
22
- "utils.js",
23
- "utils.d.ts"
7
+ "repository": "https://github.com/subframe7536/electron-incremental-update",
8
+ "keywords": [
9
+ "electron",
10
+ "incremental update",
11
+ "updater"
24
12
  ],
25
- "main": "dist/index.js",
26
- "module": "dist/index.mjs",
27
13
  "exports": {
28
14
  ".": {
29
15
  "import": "./dist/index.mjs",
@@ -38,25 +24,39 @@
38
24
  "require": "./dist/utils.js"
39
25
  }
40
26
  },
41
- "keywords": [
42
- "electron",
43
- "incremental update",
44
- "updater"
27
+ "main": "dist/index.js",
28
+ "module": "dist/index.mjs",
29
+ "files": [
30
+ "dist",
31
+ "utils.d.ts",
32
+ "utils.js",
33
+ "vite.d.ts",
34
+ "vite.js"
45
35
  ],
36
+ "scripts": {
37
+ "build": "tsup && node fix-module.js",
38
+ "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
39
+ "test": "vitest --run",
40
+ "lint": "eslint . --fix"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "registry": "https://registry.npmjs.org/"
45
+ },
46
+ "dependencies": {
47
+ "@electron/asar": "^3.2.8",
48
+ "ci-info": "^4.0.0",
49
+ "selfsigned": "^2.4.1",
50
+ "vite": "^4.5.0"
51
+ },
46
52
  "devDependencies": {
47
- "@subframe7536/eslint-config": "^0.2.9",
48
- "@types/node": "^20.6.0",
53
+ "@subframe7536/eslint-config": "^0.4.1",
54
+ "@types/node": "^20.9.0",
49
55
  "bumpp": "^9.2.0",
50
- "electron": "^26.2.0",
51
- "eslint": "^8.49.0",
56
+ "electron": "^27.0.4",
57
+ "eslint": "^8.53.0",
52
58
  "tsup": "^7.2.0",
53
59
  "typescript": "^5.2.2",
54
- "vitest": "^0.34.4"
55
- },
56
- "dependencies": {
57
- "@electron/asar": "^3.2.4",
58
- "ci-info": "^3.8.0",
59
- "selfsigned": "^2.1.1",
60
- "vite": "^4.4.9"
60
+ "vitest": "^0.34.6"
61
61
  }
62
62
  }