electron-incremental-update 0.7.0 → 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.
package/dist/vite.js CHANGED
@@ -36,19 +36,16 @@ module.exports = __toCommonJS(vite_exports);
36
36
  var import_vite = require("vite");
37
37
 
38
38
  // src/build-plugins/build.ts
39
- var import_node_fs = require("fs");
40
39
  var import_promises = require("fs/promises");
41
- var import_node_zlib = __toESM(require("zlib"));
42
40
  var import_esbuild = require("esbuild");
43
41
 
44
42
  // src/crypto.ts
45
43
  var import_node_crypto = require("crypto");
46
44
  var import_node_buffer = require("buffer");
47
- var aesEncode = "base64url";
48
45
  function encrypt(plainText, key2, iv) {
49
46
  const cipher = (0, import_node_crypto.createCipheriv)("aes-256-cbc", key2, iv);
50
- let encrypted = cipher.update(plainText, "utf8", aesEncode);
51
- encrypted += cipher.final(aesEncode);
47
+ let encrypted = cipher.update(plainText, "utf8", "base64url");
48
+ encrypted += cipher.final("base64url");
52
49
  return encrypted;
53
50
  }
54
51
  function key(data, length) {
@@ -56,23 +53,28 @@ function key(data, length) {
56
53
  return import_node_buffer.Buffer.from(hash).subarray(0, length);
57
54
  }
58
55
  var signature = (buffer, privateKey, cert, version) => {
59
- const sig = (0, import_node_crypto.createSign)("RSA-SHA256").update(buffer).sign({
60
- key: privateKey,
61
- padding: import_node_crypto.constants.RSA_PKCS1_PADDING,
62
- saltLength: import_node_crypto.constants.RSA_PSS_SALTLEN_DIGEST
63
- }, "base64");
56
+ const sig = (0, import_node_crypto.createSign)("RSA-SHA256").update(buffer).sign((0, import_node_crypto.createPrivateKey)(privateKey), "base64");
64
57
  return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
65
58
  };
66
59
 
67
- // src/build-plugins/build.ts
68
- function gzipFile(filePath) {
60
+ // src/utils.ts
61
+ var import_node_fs = require("fs");
62
+ var import_node_path = require("path");
63
+ var import_node_zlib = require("zlib");
64
+ var import_electron = require("electron");
65
+ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
66
+ if (!(0, import_node_fs.existsSync)(filePath)) {
67
+ throw new Error(`path to be zipped not exist: ${filePath}`);
68
+ }
69
69
  return new Promise((resolve, reject) => {
70
- const gzip = import_node_zlib.default.createGzip();
70
+ const gzip = (0, import_node_zlib.createGzip)();
71
71
  const input = (0, import_node_fs.createReadStream)(filePath);
72
- const output = (0, import_node_fs.createWriteStream)(`${filePath}.gz`);
72
+ const output = (0, import_node_fs.createWriteStream)(targetFilePath);
73
73
  input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
74
74
  });
75
75
  }
76
+
77
+ // src/build-plugins/build.ts
76
78
  async function pack(dir, target) {
77
79
  let asar = null;
78
80
  try {
@@ -93,23 +95,24 @@ async function pack(dir, target) {
93
95
  async function buildAsar({
94
96
  version,
95
97
  asarOutputPath,
98
+ gzipPath,
96
99
  electronDistPath,
97
100
  rendererDistPath
98
101
  }) {
99
102
  await (0, import_promises.rename)(rendererDistPath, `${electronDistPath}/renderer`);
100
103
  await (0, import_promises.writeFile)(`${electronDistPath}/version`, version);
101
104
  await pack(electronDistPath, asarOutputPath);
102
- await gzipFile(asarOutputPath);
105
+ await zipFile(asarOutputPath, gzipPath);
103
106
  }
104
107
  async function buildVersion({
105
- asarOutputPath,
108
+ gzipPath,
106
109
  versionPath,
107
110
  privateKey,
108
111
  cert,
109
112
  version,
110
113
  generateSignature
111
114
  }) {
112
- const buffer = await (0, import_promises.readFile)(`${asarOutputPath}.gz`);
115
+ const buffer = await (0, import_promises.readFile)(gzipPath);
113
116
  const _func = generateSignature ?? signature;
114
117
  await (0, import_promises.writeFile)(versionPath, JSON.stringify({
115
118
  signature: _func(buffer, privateKey, cert, version),
@@ -132,9 +135,12 @@ async function buildEntry({
132
135
  });
133
136
  }
134
137
 
138
+ // src/build-plugins/option.ts
139
+ var import_ci_info = require("ci-info");
140
+
135
141
  // src/build-plugins/key.ts
136
142
  var import_node_fs2 = require("fs");
137
- var import_node_path = require("path");
143
+ var import_node_path2 = require("path");
138
144
  var import_node_os = require("os");
139
145
  var import_node_crypto2 = require("crypto");
140
146
  var import_jscert = require("@cyyynthia/jscert");
@@ -176,7 +182,7 @@ function writeCertToMain(entryPath, cert) {
176
182
  }
177
183
  (0, import_node_fs2.writeFileSync)(entryPath, replaced);
178
184
  }
179
- function getKeys({
185
+ function parseKeys({
180
186
  keyLength,
181
187
  privateKeyPath,
182
188
  certPath,
@@ -185,7 +191,7 @@ function getKeys({
185
191
  expires,
186
192
  generateKeyPair
187
193
  }) {
188
- const keysDir = (0, import_node_path.dirname)(privateKeyPath);
194
+ const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
189
195
  !(0, import_node_fs2.existsSync)(keysDir) && (0, import_node_fs2.mkdirSync)(keysDir);
190
196
  let privateKey, cert;
191
197
  if (!(0, import_node_fs2.existsSync)(privateKeyPath) || !(0, import_node_fs2.existsSync)(certPath)) {
@@ -207,7 +213,6 @@ function getKeys({
207
213
  }
208
214
 
209
215
  // src/build-plugins/option.ts
210
- var import_ci_info = require("ci-info");
211
216
  function parseOptions(options) {
212
217
  const {
213
218
  isBuild,
@@ -217,7 +222,8 @@ function parseOptions(options) {
217
222
  paths: {
218
223
  entryPath = "electron/app.ts",
219
224
  entryOutputPath = "app.js",
220
- asarOutputPath = `release/${productName}-${version}.asar`,
225
+ asarOutputPath = `release/${productName}.asar`,
226
+ gzipPath = `release/${productName}-${version}.asar.gz`,
221
227
  electronDistPath = "dist-electron",
222
228
  rendererDistPath = "dist",
223
229
  versionPath = "version.json"
@@ -244,6 +250,7 @@ function parseOptions(options) {
244
250
  const buildAsarOption = {
245
251
  version,
246
252
  asarOutputPath,
253
+ gzipPath,
247
254
  electronDistPath,
248
255
  rendererDistPath
249
256
  };
@@ -257,7 +264,7 @@ function parseOptions(options) {
257
264
  if (typeof expires === "number") {
258
265
  expires = new Date(Date.now() + expires);
259
266
  }
260
- const { privateKey, cert } = getKeys({
267
+ const { privateKey, cert } = parseKeys({
261
268
  keyLength,
262
269
  privateKeyPath,
263
270
  certPath,
@@ -268,7 +275,7 @@ function parseOptions(options) {
268
275
  });
269
276
  buildVersionOption = {
270
277
  version,
271
- asarOutputPath,
278
+ gzipPath,
272
279
  privateKey,
273
280
  cert,
274
281
  versionPath,
package/dist/vite.mjs CHANGED
@@ -1,23 +1,16 @@
1
1
  import {
2
2
  signature
3
- } from "./chunk-XQ4Z2OVN.mjs";
3
+ } from "./chunk-Q2K52LOG.mjs";
4
+ import {
5
+ zipFile
6
+ } from "./chunk-CRBEZBU5.mjs";
4
7
 
5
8
  // src/vite.ts
6
9
  import { createLogger } from "vite";
7
10
 
8
11
  // src/build-plugins/build.ts
9
- import { createReadStream, createWriteStream } from "node:fs";
10
12
  import { readFile, rename, writeFile } from "node:fs/promises";
11
- import zlib from "node:zlib";
12
13
  import { build } from "esbuild";
13
- function gzipFile(filePath) {
14
- return new Promise((resolve, reject) => {
15
- const gzip = zlib.createGzip();
16
- const input = createReadStream(filePath);
17
- const output = createWriteStream(`${filePath}.gz`);
18
- input.pipe(gzip).pipe(output).on("finish", () => resolve(null)).on("error", (err) => reject(err));
19
- });
20
- }
21
14
  async function pack(dir, target) {
22
15
  let asar = null;
23
16
  try {
@@ -38,23 +31,24 @@ async function pack(dir, target) {
38
31
  async function buildAsar({
39
32
  version,
40
33
  asarOutputPath,
34
+ gzipPath,
41
35
  electronDistPath,
42
36
  rendererDistPath
43
37
  }) {
44
38
  await rename(rendererDistPath, `${electronDistPath}/renderer`);
45
39
  await writeFile(`${electronDistPath}/version`, version);
46
40
  await pack(electronDistPath, asarOutputPath);
47
- await gzipFile(asarOutputPath);
41
+ await zipFile(asarOutputPath, gzipPath);
48
42
  }
49
43
  async function buildVersion({
50
- asarOutputPath,
44
+ gzipPath,
51
45
  versionPath,
52
46
  privateKey,
53
47
  cert,
54
48
  version,
55
49
  generateSignature
56
50
  }) {
57
- const buffer = await readFile(`${asarOutputPath}.gz`);
51
+ const buffer = await readFile(gzipPath);
58
52
  const _func = generateSignature ?? signature;
59
53
  await writeFile(versionPath, JSON.stringify({
60
54
  signature: _func(buffer, privateKey, cert, version),
@@ -77,6 +71,9 @@ async function buildEntry({
77
71
  });
78
72
  }
79
73
 
74
+ // src/build-plugins/option.ts
75
+ import { isCI } from "ci-info";
76
+
80
77
  // src/build-plugins/key.ts
81
78
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
82
79
  import { dirname } from "node:path";
@@ -121,7 +118,7 @@ function writeCertToMain(entryPath, cert) {
121
118
  }
122
119
  writeFileSync(entryPath, replaced);
123
120
  }
124
- function getKeys({
121
+ function parseKeys({
125
122
  keyLength,
126
123
  privateKeyPath,
127
124
  certPath,
@@ -152,7 +149,6 @@ function getKeys({
152
149
  }
153
150
 
154
151
  // src/build-plugins/option.ts
155
- import { isCI } from "ci-info";
156
152
  function parseOptions(options) {
157
153
  const {
158
154
  isBuild,
@@ -162,7 +158,8 @@ function parseOptions(options) {
162
158
  paths: {
163
159
  entryPath = "electron/app.ts",
164
160
  entryOutputPath = "app.js",
165
- asarOutputPath = `release/${productName}-${version}.asar`,
161
+ asarOutputPath = `release/${productName}.asar`,
162
+ gzipPath = `release/${productName}-${version}.asar.gz`,
166
163
  electronDistPath = "dist-electron",
167
164
  rendererDistPath = "dist",
168
165
  versionPath = "version.json"
@@ -189,6 +186,7 @@ function parseOptions(options) {
189
186
  const buildAsarOption = {
190
187
  version,
191
188
  asarOutputPath,
189
+ gzipPath,
192
190
  electronDistPath,
193
191
  rendererDistPath
194
192
  };
@@ -202,7 +200,7 @@ function parseOptions(options) {
202
200
  if (typeof expires === "number") {
203
201
  expires = new Date(Date.now() + expires);
204
202
  }
205
- const { privateKey, cert } = getKeys({
203
+ const { privateKey, cert } = parseKeys({
206
204
  keyLength,
207
205
  privateKeyPath,
208
206
  certPath,
@@ -213,7 +211,7 @@ function parseOptions(options) {
213
211
  });
214
212
  buildVersionOption = {
215
213
  version,
216
- asarOutputPath,
214
+ gzipPath,
217
215
  privateKey,
218
216
  cert,
219
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.0",
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",
@@ -17,7 +17,9 @@
17
17
  "files": [
18
18
  "dist",
19
19
  "vite.js",
20
- "vite.d.ts"
20
+ "vite.d.ts",
21
+ "utils.js",
22
+ "utils.d.ts"
21
23
  ],
22
24
  "main": "dist/index.js",
23
25
  "module": "dist/index.mjs",
@@ -29,6 +31,10 @@
29
31
  "./vite": {
30
32
  "import": "./dist/vite.mjs",
31
33
  "require": "./dist/vite.js"
34
+ },
35
+ "./utils": {
36
+ "import": "./dist/utils.mjs",
37
+ "require": "./dist/utils.js"
32
38
  }
33
39
  },
34
40
  "keywords": [
@@ -44,7 +50,6 @@
44
50
  "bumpp": "^9.1.1",
45
51
  "electron": "^25.2.0",
46
52
  "eslint": "^8.43.0",
47
- "fs-jetpack": "^5.1.0",
48
53
  "tsup": "^7.1.0",
49
54
  "typescript": "^5.1.5",
50
55
  "vite": "^4.3.9",
package/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/utils'
package/utils.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/utils.js')
@@ -1,51 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/crypto.ts
10
- import { constants, createCipheriv, createDecipheriv, createHash, createSign, createVerify } from "node:crypto";
11
- import { Buffer as Buffer2 } from "node:buffer";
12
- var aesEncode = "base64url";
13
- function encrypt(plainText, key2, iv) {
14
- const cipher = createCipheriv("aes-256-cbc", key2, iv);
15
- let encrypted = cipher.update(plainText, "utf8", aesEncode);
16
- encrypted += cipher.final(aesEncode);
17
- return encrypted;
18
- }
19
- function decrypt(encryptedText, key2, iv) {
20
- const decipher = createDecipheriv("aes-256-cbc", key2, iv);
21
- let decrypted = decipher.update(encryptedText, aesEncode, "utf8");
22
- decrypted += decipher.final("utf8");
23
- return decrypted;
24
- }
25
- function key(data, length) {
26
- const hash = createHash("SHA256").update(data).digest("binary");
27
- return Buffer2.from(hash).subarray(0, length);
28
- }
29
- var signature = (buffer, privateKey, cert, version) => {
30
- const sig = createSign("RSA-SHA256").update(buffer).sign({
31
- key: privateKey,
32
- padding: constants.RSA_PKCS1_PADDING,
33
- saltLength: constants.RSA_PSS_SALTLEN_DIGEST
34
- }, "base64");
35
- return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
36
- };
37
- var verify = (buffer, signature2, cert) => {
38
- try {
39
- const [sig, version] = decrypt(signature2, key(cert, 32), key(buffer, 16)).split("%");
40
- const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
41
- return result ? version : false;
42
- } catch (error) {
43
- return false;
44
- }
45
- };
46
-
47
- export {
48
- __require,
49
- signature,
50
- verify
51
- };