electron-incremental-update 0.7.7 → 0.7.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/dist/utils.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
+ NoSuchNativeModuleError: () => NoSuchNativeModuleError,
23
24
  getEntryVersion: () => getEntryVersion,
24
25
  getGithubFileCdnGroup: () => getGithubFileCdnGroup,
25
26
  getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
@@ -27,6 +28,7 @@ __export(utils_exports, {
27
28
  getProductVersion: () => getProductVersion,
28
29
  handleUnexpectedErrors: () => handleUnexpectedErrors,
29
30
  parseGithubCdnURL: () => parseGithubCdnURL,
31
+ parseVersion: () => parseVersion,
30
32
  requireNative: () => requireNative,
31
33
  restartApp: () => restartApp,
32
34
  unzipFile: () => unzipFile,
@@ -47,9 +49,20 @@ function getEntryVersion() {
47
49
  function getProductVersion(name) {
48
50
  return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getProductAsarPath(name), "version"), "utf-8") : getEntryVersion();
49
51
  }
52
+ var NoSuchNativeModuleError = class extends Error {
53
+ moduleName;
54
+ constructor(moduleName) {
55
+ super(`no such native module: ${moduleName}`);
56
+ this.moduleName = moduleName;
57
+ }
58
+ };
50
59
  function requireNative(packageName) {
51
60
  const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
52
- return require(path);
61
+ try {
62
+ return require(path);
63
+ } catch (error) {
64
+ throw new NoSuchNativeModuleError(packageName);
65
+ }
53
66
  }
54
67
  function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
55
68
  if (!repository.startsWith("https://github.com/")) {
@@ -98,11 +111,11 @@ function waitAppReady(duration = 1e3) {
98
111
  }, duration);
99
112
  import_electron.app.whenReady().then(() => {
100
113
  clearTimeout(timeout);
101
- resolve(null);
114
+ resolve();
102
115
  });
103
116
  });
104
117
  }
105
- async function unzipFile(gzipPath, targetFilePath) {
118
+ async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
106
119
  if (!(0, import_node_fs.existsSync)(gzipPath)) {
107
120
  throw new Error(`path to zipped file not exist: ${gzipPath}`);
108
121
  }
@@ -141,8 +154,33 @@ function handleUnexpectedErrors(callback) {
141
154
  process.on("uncaughtException", listener);
142
155
  process.on("unhandledRejection", listener);
143
156
  }
157
+ function parseVersion(version) {
158
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
159
+ const match = semver.exec(version);
160
+ if (!match) {
161
+ throw new TypeError(`invalid version: ${version}`);
162
+ }
163
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
164
+ const ret = {
165
+ major,
166
+ minor,
167
+ patch,
168
+ stage: "",
169
+ stageVersion: -1
170
+ };
171
+ if (match[4]) {
172
+ let [stage, _v] = match[4].split(".");
173
+ ret.stage = stage;
174
+ ret.stageVersion = Number(_v) || -1;
175
+ }
176
+ if (isNaN(major) || isNaN(minor) || isNaN(patch) || isNaN(ret.stageVersion)) {
177
+ throw new TypeError(`invalid version: ${version}`);
178
+ }
179
+ return ret;
180
+ }
144
181
  // Annotate the CommonJS export names for ESM import in node:
145
182
  0 && (module.exports = {
183
+ NoSuchNativeModuleError,
146
184
  getEntryVersion,
147
185
  getGithubFileCdnGroup,
148
186
  getGithubReleaseCdnGroup,
@@ -150,6 +188,7 @@ function handleUnexpectedErrors(callback) {
150
188
  getProductVersion,
151
189
  handleUnexpectedErrors,
152
190
  parseGithubCdnURL,
191
+ parseVersion,
153
192
  requireNative,
154
193
  restartApp,
155
194
  unzipFile,
package/dist/utils.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ NoSuchNativeModuleError,
2
3
  getEntryVersion,
3
4
  getGithubFileCdnGroup,
4
5
  getGithubReleaseCdnGroup,
@@ -6,13 +7,16 @@ import {
6
7
  getProductVersion,
7
8
  handleUnexpectedErrors,
8
9
  parseGithubCdnURL,
10
+ parseVersion,
9
11
  requireNative,
10
12
  restartApp,
11
13
  unzipFile,
12
14
  waitAppReady,
13
15
  zipFile
14
- } from "./chunk-67MCNA7W.mjs";
16
+ } from "./chunk-4TION32M.mjs";
17
+ import "./chunk-ZFXKCRJC.mjs";
15
18
  export {
19
+ NoSuchNativeModuleError,
16
20
  getEntryVersion,
17
21
  getGithubFileCdnGroup,
18
22
  getGithubReleaseCdnGroup,
@@ -20,6 +24,7 @@ export {
20
24
  getProductVersion,
21
25
  handleUnexpectedErrors,
22
26
  parseGithubCdnURL,
27
+ parseVersion,
23
28
  requireNative,
24
29
  restartApp,
25
30
  unzipFile,
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { Buffer } from 'node:buffer';
3
+ import { UpdateJSON } from './updateJson.mjs';
3
4
 
4
5
  type DistinguishedName = {
5
6
  countryName?: string;
@@ -14,7 +15,26 @@ type DistinguishedName = {
14
15
  businessCategory?: string;
15
16
  emailAddress?: string;
16
17
  };
17
- type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string;
18
+ type GeneratorOverrideFunctions = {
19
+ /**
20
+ * custom signature generate function
21
+ * @param buffer file buffer
22
+ * @param privateKey private key
23
+ * @param cert certificate string, **EOL must be '\n'**
24
+ * @param version current version
25
+ */
26
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
27
+ /**
28
+ * custom generate version json function
29
+ * @param existingJson The existing JSON object.
30
+ * @param buffer file buffer
31
+ * @param signature generated signature
32
+ * @param version current version
33
+ * @param minVersion The minimum version
34
+ * @returns The updated version json
35
+ */
36
+ generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
37
+ };
18
38
  type Options = {
19
39
  /**
20
40
  * whether is in build mode
@@ -32,6 +52,11 @@ type Options = {
32
52
  * you can set as 'version' in `package.json`
33
53
  */
34
54
  version: string;
55
+ /**
56
+ * mini version of entry
57
+ * @default version
58
+ */
59
+ minimumVersion?: string;
35
60
  /**
36
61
  * Whether to minify entry file
37
62
  */
@@ -55,6 +80,11 @@ type Options = {
55
80
  * @default `release/${productName}.asar`
56
81
  */
57
82
  asarOutputPath?: string;
83
+ /**
84
+ * Path to version info output, content is {@link UpdateJSON}
85
+ * @default `version.json`
86
+ */
87
+ versionPath?: string;
58
88
  /**
59
89
  * Path to gzipped asar file
60
90
  * @default `release/${productName}-${version}.asar.gz`
@@ -70,11 +100,6 @@ type Options = {
70
100
  * @default `dist`
71
101
  */
72
102
  rendererDistPath?: string;
73
- /**
74
- * Path to version info output
75
- * @default `version.json`
76
- */
77
- versionPath?: string;
78
103
  };
79
104
  /**
80
105
  * signature config
@@ -116,15 +141,7 @@ type Options = {
116
141
  */
117
142
  days?: number;
118
143
  };
119
- overrideFunctions?: {
120
- /**
121
- * custom signature generate function {@link FunctionGenerateSignature}
122
- * @param buffer file buffer
123
- * @param privateKey private key
124
- * @param cert certificate
125
- */
126
- generateSignature?: FunctionGenerateSignature;
127
- };
144
+ overrideFunctions?: GeneratorOverrideFunctions;
128
145
  };
129
146
  };
130
147
 
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { Buffer } from 'node:buffer';
3
+ import { UpdateJSON } from './updateJson.js';
3
4
 
4
5
  type DistinguishedName = {
5
6
  countryName?: string;
@@ -14,7 +15,26 @@ type DistinguishedName = {
14
15
  businessCategory?: string;
15
16
  emailAddress?: string;
16
17
  };
17
- type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string;
18
+ type GeneratorOverrideFunctions = {
19
+ /**
20
+ * custom signature generate function
21
+ * @param buffer file buffer
22
+ * @param privateKey private key
23
+ * @param cert certificate string, **EOL must be '\n'**
24
+ * @param version current version
25
+ */
26
+ generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
27
+ /**
28
+ * custom generate version json function
29
+ * @param existingJson The existing JSON object.
30
+ * @param buffer file buffer
31
+ * @param signature generated signature
32
+ * @param version current version
33
+ * @param minVersion The minimum version
34
+ * @returns The updated version json
35
+ */
36
+ generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
37
+ };
18
38
  type Options = {
19
39
  /**
20
40
  * whether is in build mode
@@ -32,6 +52,11 @@ type Options = {
32
52
  * you can set as 'version' in `package.json`
33
53
  */
34
54
  version: string;
55
+ /**
56
+ * mini version of entry
57
+ * @default version
58
+ */
59
+ minimumVersion?: string;
35
60
  /**
36
61
  * Whether to minify entry file
37
62
  */
@@ -55,6 +80,11 @@ type Options = {
55
80
  * @default `release/${productName}.asar`
56
81
  */
57
82
  asarOutputPath?: string;
83
+ /**
84
+ * Path to version info output, content is {@link UpdateJSON}
85
+ * @default `version.json`
86
+ */
87
+ versionPath?: string;
58
88
  /**
59
89
  * Path to gzipped asar file
60
90
  * @default `release/${productName}-${version}.asar.gz`
@@ -70,11 +100,6 @@ type Options = {
70
100
  * @default `dist`
71
101
  */
72
102
  rendererDistPath?: string;
73
- /**
74
- * Path to version info output
75
- * @default `version.json`
76
- */
77
- versionPath?: string;
78
103
  };
79
104
  /**
80
105
  * signature config
@@ -116,15 +141,7 @@ type Options = {
116
141
  */
117
142
  days?: number;
118
143
  };
119
- overrideFunctions?: {
120
- /**
121
- * custom signature generate function {@link FunctionGenerateSignature}
122
- * @param buffer file buffer
123
- * @param privateKey private key
124
- * @param cert certificate
125
- */
126
- generateSignature?: FunctionGenerateSignature;
127
- };
144
+ overrideFunctions?: GeneratorOverrideFunctions;
128
145
  };
129
146
  };
130
147
 
package/dist/vite.js CHANGED
@@ -27,6 +27,7 @@ var import_vite = require("vite");
27
27
 
28
28
  // src/build-plugins/build.ts
29
29
  var import_promises = require("fs/promises");
30
+ var import_node_fs2 = require("fs");
30
31
  var import_asar = require("@electron/asar");
31
32
  var import_esbuild = require("esbuild");
32
33
 
@@ -68,6 +69,36 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
68
69
  });
69
70
  });
70
71
  }
72
+ function parseVersion(version) {
73
+ const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
74
+ const match = semver.exec(version);
75
+ if (!match) {
76
+ throw new TypeError(`invalid version: ${version}`);
77
+ }
78
+ const [major, minor, patch] = match.slice(1, 4).map(Number);
79
+ const ret = {
80
+ major,
81
+ minor,
82
+ patch,
83
+ stage: "",
84
+ stageVersion: -1
85
+ };
86
+ if (match[4]) {
87
+ let [stage, _v] = match[4].split(".");
88
+ ret.stage = stage;
89
+ ret.stageVersion = Number(_v) || -1;
90
+ }
91
+ if (isNaN(major) || isNaN(minor) || isNaN(patch) || isNaN(ret.stageVersion)) {
92
+ throw new TypeError(`invalid version: ${version}`);
93
+ }
94
+ return ret;
95
+ }
96
+
97
+ // src/updateJson.ts
98
+ function isUpdateJSON(json) {
99
+ const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
100
+ return is(json) && "beta" in json && is(json.beta);
101
+ }
71
102
 
72
103
  // src/build-plugins/build.ts
73
104
  async function buildAsar({
@@ -88,15 +119,51 @@ async function buildVersion({
88
119
  privateKey,
89
120
  cert,
90
121
  version,
91
- generateSignature
122
+ minimumVersion,
123
+ generateSignature,
124
+ generateVersionJson
92
125
  }) {
126
+ let _json = {
127
+ beta: {
128
+ minimumVersion: version,
129
+ signature: "",
130
+ size: 0,
131
+ version
132
+ },
133
+ minimumVersion: version,
134
+ signature: "",
135
+ size: 0,
136
+ version
137
+ };
138
+ if ((0, import_node_fs2.existsSync)(versionPath)) {
139
+ try {
140
+ _json = JSON.parse(await (0, import_promises.readFile)(versionPath, "utf-8"));
141
+ } catch (error) {
142
+ }
143
+ }
144
+ if (!isUpdateJSON(_json)) {
145
+ throw new Error("invalid version file");
146
+ }
93
147
  const buffer = await (0, import_promises.readFile)(gzipPath);
94
- const _func = generateSignature ?? signature;
95
- await (0, import_promises.writeFile)(versionPath, JSON.stringify({
96
- signature: _func(buffer, privateKey, cert, version),
97
- version,
98
- size: buffer.length
99
- }, null, 2));
148
+ const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
149
+ if (generateVersionJson) {
150
+ _json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
151
+ if (!isUpdateJSON(_json)) {
152
+ throw new Error("invalid version info");
153
+ }
154
+ } else {
155
+ _json.beta.version = version;
156
+ _json.beta.minimumVersion = minimumVersion;
157
+ _json.beta.signature = sig;
158
+ _json.beta.size = buffer.length;
159
+ if (!parseVersion(version).stage) {
160
+ _json.version = version;
161
+ _json.minimumVersion = minimumVersion;
162
+ _json.signature = sig;
163
+ _json.size = buffer.length;
164
+ }
165
+ }
166
+ await (0, import_promises.writeFile)(versionPath, JSON.stringify(_json, null, 2));
100
167
  }
101
168
  async function buildEntry({
102
169
  entryPath,
@@ -117,25 +184,25 @@ async function buildEntry({
117
184
  var import_ci_info = require("ci-info");
118
185
 
119
186
  // src/build-plugins/key.ts
120
- var import_node_fs2 = require("fs");
187
+ var import_node_fs3 = require("fs");
121
188
  var import_node_path2 = require("path");
122
189
  var import_node_os = require("os");
123
190
  var import_selfsigned = require("selfsigned");
124
191
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
125
192
  const privateKeyDir = (0, import_node_path2.dirname)(privateKeyPath);
126
- (0, import_node_fs2.existsSync)(privateKeyDir) || (0, import_node_fs2.mkdirSync)(privateKeyDir, { recursive: true });
193
+ (0, import_node_fs3.existsSync)(privateKeyDir) || (0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
127
194
  const certDir = (0, import_node_path2.dirname)(certPath);
128
- (0, import_node_fs2.existsSync)(certDir) || (0, import_node_fs2.mkdirSync)(certDir, { recursive: true });
195
+ (0, import_node_fs3.existsSync)(certDir) || (0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
129
196
  const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
130
197
  keySize: keyLength,
131
198
  algorithm: "sha256",
132
199
  days
133
200
  });
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"));
201
+ (0, import_node_fs3.writeFileSync)(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
202
+ (0, import_node_fs3.writeFileSync)(certPath, cert.replace(/\r\n?/g, "\n"));
136
203
  }
137
204
  function writeCertToMain(entryPath, cert) {
138
- const file = (0, import_node_fs2.readFileSync)(entryPath, "utf-8");
205
+ const file = (0, import_node_fs3.readFileSync)(entryPath, "utf-8");
139
206
  const regex = /const SIGNATURE_CERT = ['`][\s\S]*?['`]/;
140
207
  const replacement = `const SIGNATURE_CERT = \`${cert}\``;
141
208
  let replaced = file;
@@ -157,7 +224,7 @@ function writeCertToMain(entryPath, cert) {
157
224
  !isMatched && lines.push(r);
158
225
  replaced = lines.join(import_node_os.EOL);
159
226
  }
160
- (0, import_node_fs2.writeFileSync)(entryPath, replaced.replace(/\r\n?/g, "\n"));
227
+ (0, import_node_fs3.writeFileSync)(entryPath, replaced.replace(/\r\n?/g, "\n"));
161
228
  }
162
229
  function parseKeys({
163
230
  keyLength,
@@ -168,12 +235,12 @@ function parseKeys({
168
235
  days
169
236
  }) {
170
237
  const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
171
- !(0, import_node_fs2.existsSync)(keysDir) && (0, import_node_fs2.mkdirSync)(keysDir);
172
- if (!(0, import_node_fs2.existsSync)(privateKeyPath) || !(0, import_node_fs2.existsSync)(certPath)) {
238
+ !(0, import_node_fs3.existsSync)(keysDir) && (0, import_node_fs3.mkdirSync)(keysDir);
239
+ if (!(0, import_node_fs3.existsSync)(privateKeyPath) || !(0, import_node_fs3.existsSync)(certPath)) {
173
240
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
174
241
  }
175
- const privateKey = (0, import_node_fs2.readFileSync)(privateKeyPath, "utf-8");
176
- const cert = (0, import_node_fs2.readFileSync)(certPath, "utf-8");
242
+ const privateKey = (0, import_node_fs3.readFileSync)(privateKeyPath, "utf-8");
243
+ const cert = (0, import_node_fs3.readFileSync)(certPath, "utf-8");
177
244
  writeCertToMain(entryPath, cert);
178
245
  return {
179
246
  privateKey,
@@ -195,6 +262,7 @@ function parseOptions(options) {
195
262
  isBuild,
196
263
  productName,
197
264
  version,
265
+ minimumVersion = version,
198
266
  minify = false,
199
267
  paths: {
200
268
  entryPath = "electron/app.ts",
@@ -213,7 +281,7 @@ function parseOptions(options) {
213
281
  overrideFunctions = {}
214
282
  } = {}
215
283
  } = options;
216
- const { generateSignature } = overrideFunctions;
284
+ const { generateSignature, generateVersionJson } = overrideFunctions;
217
285
  let {
218
286
  subject = {
219
287
  commonName: productName,
@@ -245,11 +313,13 @@ function parseOptions(options) {
245
313
  });
246
314
  buildVersionOption = {
247
315
  version,
316
+ minimumVersion,
248
317
  gzipPath,
249
318
  privateKey,
250
319
  cert,
251
320
  versionPath,
252
- generateSignature
321
+ generateSignature,
322
+ generateVersionJson
253
323
  };
254
324
  }
255
325
  return { isBuild, buildAsarOption, buildEntryOption, buildVersionOption };
package/dist/vite.mjs CHANGED
@@ -2,14 +2,20 @@ import {
2
2
  signature
3
3
  } from "./chunk-Q2K52LOG.mjs";
4
4
  import {
5
+ parseVersion,
5
6
  zipFile
6
- } from "./chunk-67MCNA7W.mjs";
7
+ } from "./chunk-4TION32M.mjs";
8
+ import {
9
+ isUpdateJSON
10
+ } from "./chunk-2JVXVTC5.mjs";
11
+ import "./chunk-ZFXKCRJC.mjs";
7
12
 
8
13
  // src/vite.ts
9
14
  import { createLogger } from "vite";
10
15
 
11
16
  // src/build-plugins/build.ts
12
17
  import { readFile, rename, writeFile } from "node:fs/promises";
18
+ import { existsSync } from "node:fs";
13
19
  import { createPackage } from "@electron/asar";
14
20
  import { build } from "esbuild";
15
21
  async function buildAsar({
@@ -30,15 +36,51 @@ async function buildVersion({
30
36
  privateKey,
31
37
  cert,
32
38
  version,
33
- generateSignature
39
+ minimumVersion,
40
+ generateSignature,
41
+ generateVersionJson
34
42
  }) {
43
+ let _json = {
44
+ beta: {
45
+ minimumVersion: version,
46
+ signature: "",
47
+ size: 0,
48
+ version
49
+ },
50
+ minimumVersion: version,
51
+ signature: "",
52
+ size: 0,
53
+ version
54
+ };
55
+ if (existsSync(versionPath)) {
56
+ try {
57
+ _json = JSON.parse(await readFile(versionPath, "utf-8"));
58
+ } catch (error) {
59
+ }
60
+ }
61
+ if (!isUpdateJSON(_json)) {
62
+ throw new Error("invalid version file");
63
+ }
35
64
  const buffer = await readFile(gzipPath);
36
- const _func = generateSignature ?? signature;
37
- await writeFile(versionPath, JSON.stringify({
38
- signature: _func(buffer, privateKey, cert, version),
39
- version,
40
- size: buffer.length
41
- }, null, 2));
65
+ const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
66
+ if (generateVersionJson) {
67
+ _json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
68
+ if (!isUpdateJSON(_json)) {
69
+ throw new Error("invalid version info");
70
+ }
71
+ } else {
72
+ _json.beta.version = version;
73
+ _json.beta.minimumVersion = minimumVersion;
74
+ _json.beta.signature = sig;
75
+ _json.beta.size = buffer.length;
76
+ if (!parseVersion(version).stage) {
77
+ _json.version = version;
78
+ _json.minimumVersion = minimumVersion;
79
+ _json.signature = sig;
80
+ _json.size = buffer.length;
81
+ }
82
+ }
83
+ await writeFile(versionPath, JSON.stringify(_json, null, 2));
42
84
  }
43
85
  async function buildEntry({
44
86
  entryPath,
@@ -59,15 +101,15 @@ async function buildEntry({
59
101
  import { isCI } from "ci-info";
60
102
 
61
103
  // src/build-plugins/key.ts
62
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
104
+ import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
63
105
  import { dirname } from "node:path";
64
106
  import { EOL } from "node:os";
65
107
  import { generate } from "selfsigned";
66
108
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
67
109
  const privateKeyDir = dirname(privateKeyPath);
68
- existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true });
110
+ existsSync2(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true });
69
111
  const certDir = dirname(certPath);
70
- existsSync(certDir) || mkdirSync(certDir, { recursive: true });
112
+ existsSync2(certDir) || mkdirSync(certDir, { recursive: true });
71
113
  const { cert, private: privateKey } = generate(subject, {
72
114
  keySize: keyLength,
73
115
  algorithm: "sha256",
@@ -110,8 +152,8 @@ function parseKeys({
110
152
  days
111
153
  }) {
112
154
  const keysDir = dirname(privateKeyPath);
113
- !existsSync(keysDir) && mkdirSync(keysDir);
114
- if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
155
+ !existsSync2(keysDir) && mkdirSync(keysDir);
156
+ if (!existsSync2(privateKeyPath) || !existsSync2(certPath)) {
115
157
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
116
158
  }
117
159
  const privateKey = readFileSync(privateKeyPath, "utf-8");
@@ -137,6 +179,7 @@ function parseOptions(options) {
137
179
  isBuild,
138
180
  productName,
139
181
  version,
182
+ minimumVersion = version,
140
183
  minify = false,
141
184
  paths: {
142
185
  entryPath = "electron/app.ts",
@@ -155,7 +198,7 @@ function parseOptions(options) {
155
198
  overrideFunctions = {}
156
199
  } = {}
157
200
  } = options;
158
- const { generateSignature } = overrideFunctions;
201
+ const { generateSignature, generateVersionJson } = overrideFunctions;
159
202
  let {
160
203
  subject = {
161
204
  commonName: productName,
@@ -187,11 +230,13 @@ function parseOptions(options) {
187
230
  });
188
231
  buildVersionOption = {
189
232
  version,
233
+ minimumVersion,
190
234
  gzipPath,
191
235
  privateKey,
192
236
  cert,
193
237
  versionPath,
194
- generateSignature
238
+ generateSignature,
239
+ generateVersionJson
195
240
  };
196
241
  }
197
242
  return { isBuild, buildAsarOption, buildEntryOption, buildVersionOption };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.7.7",
4
+ "version": "0.7.9",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",
@@ -58,4 +58,4 @@
58
58
  "ci-info": "^3.8.0",
59
59
  "selfsigned": "^2.1.1"
60
60
  }
61
- }
61
+ }