electron-incremental-update 1.0.3 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "1.0.3",
3
+ "type": "module",
4
+ "version": "1.2.0",
4
5
  "description": "electron incremental update tools, powered by vite",
5
6
  "author": "subframe7536",
6
7
  "license": "MIT",
@@ -8,24 +9,24 @@
8
9
  "keywords": [
9
10
  "electron",
10
11
  "incremental update",
11
- "updater"
12
+ "updater",
13
+ "bytecode"
12
14
  ],
13
15
  "exports": {
14
16
  ".": {
15
- "import": "./dist/index.mjs",
16
- "require": "./dist/index.js"
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
17
19
  },
18
20
  "./vite": {
19
- "import": "./dist/vite.mjs",
20
- "require": "./dist/vite.js"
21
+ "import": "./dist/vite.js"
21
22
  },
22
23
  "./utils": {
23
- "import": "./dist/utils.mjs",
24
- "require": "./dist/utils.js"
24
+ "import": "./dist/utils.js",
25
+ "require": "./dist/utils.cjs"
25
26
  }
26
27
  },
27
- "main": "dist/index.js",
28
- "module": "dist/index.mjs",
28
+ "main": "dist/index.cjs",
29
+ "module": "dist/index.js",
29
30
  "files": [
30
31
  "dist",
31
32
  "utils.d.ts",
@@ -35,39 +36,40 @@
35
36
  ],
36
37
  "scripts": {
37
38
  "dev": "tsup --watch",
38
- "build": "tsup && node fix-module.js",
39
+ "build": "tsup && esno fix-module.cjs",
39
40
  "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
40
41
  "test": "vitest --run",
41
- "lint": "eslint . --fix"
42
+ "format": "eslint . --fix"
42
43
  },
43
44
  "publishConfig": {
44
45
  "access": "public",
45
46
  "registry": "https://registry.npmjs.org/"
46
47
  },
47
48
  "peerDependencies": {
49
+ "@babel/core": "^7.24.7",
50
+ "@babel/plugin-transform-arrow-functions": "^7.24.7",
51
+ "@electron/asar": "*",
48
52
  "esbuild": "*",
53
+ "magic-string": "*",
49
54
  "vite-plugin-electron": "^0.15.6 || ^0.28"
50
55
  },
51
56
  "dependencies": {
52
- "@electron/asar": "^3.2.9",
53
57
  "@subframe7536/type-utils": "^0.1.6",
58
+ "local-pkg": "^0.5.0",
54
59
  "selfsigned": "^2.4.1"
55
60
  },
56
61
  "devDependencies": {
57
- "@subframe7536/eslint-config": "^0.6.0",
58
- "@types/node": "^20.12.5",
59
- "bumpp": "^9.4.0",
60
- "electron": "28.1.1",
61
- "eslint": "^8.57.0",
62
- "tsup": "^8.0.2",
63
- "typescript": "^5.4.4",
64
- "vite": "^5.2.8",
65
- "vite-plugin-electron": "^0.28.4",
66
- "vitest": "^1.4.0"
67
- },
68
- "pnpm": {
69
- "overrides": {
70
- "has": "npm:@nolyfill/has@latest"
71
- }
62
+ "@subframe7536/eslint-config": "^0.6.6",
63
+ "@types/babel__core": "^7.20.5",
64
+ "@types/node": "^20.14.7",
65
+ "bumpp": "^9.4.1",
66
+ "electron": "28.2.10",
67
+ "eslint": "^9.5.0",
68
+ "esno": "^4.7.0",
69
+ "tsup": "^8.1.0",
70
+ "typescript": "^5.5.2",
71
+ "vite": "^5.3.1",
72
+ "vite-plugin-electron": "^0.28.7",
73
+ "vitest": "^1.6.0"
72
74
  }
73
75
  }
package/utils.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/utils.js')
1
+ module.exports = require('./dist/utils.cjs')
@@ -1,95 +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/utils/zip.ts
10
- import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
11
- import { gunzip, gzip } from "node:zlib";
12
- async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
13
- if (!existsSync(gzipPath)) {
14
- throw new Error(`path to zipped file not exist: ${gzipPath}`);
15
- }
16
- const compressedBuffer = readFileSync(gzipPath);
17
- return new Promise((resolve, reject) => {
18
- gunzip(compressedBuffer, (err, buffer) => {
19
- rmSync(gzipPath);
20
- if (err) {
21
- reject(err);
22
- }
23
- writeFileSync(targetFilePath, buffer);
24
- resolve(null);
25
- });
26
- });
27
- }
28
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
29
- if (!existsSync(filePath)) {
30
- throw new Error(`path to be zipped not exist: ${filePath}`);
31
- }
32
- const buffer = readFileSync(filePath);
33
- return new Promise((resolve, reject) => {
34
- gzip(buffer, (err, buffer2) => {
35
- if (err) {
36
- reject(err);
37
- }
38
- writeFileSync(targetFilePath, buffer2);
39
- resolve(null);
40
- });
41
- });
42
- }
43
-
44
- // src/utils/noDep.ts
45
- function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
46
- if (!originRepoURL.startsWith("https://github.com/")) {
47
- throw new Error("origin url must start with https://github.com/");
48
- }
49
- originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
50
- relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
51
- cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
52
- return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
53
- }
54
- function handleUnexpectedErrors(callback) {
55
- process.on("uncaughtException", callback);
56
- process.on("unhandledRejection", callback);
57
- }
58
- function parseVersion(version) {
59
- const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
60
- const match = semver.exec(version);
61
- if (!match) {
62
- throw new TypeError(`invalid version: ${version}`);
63
- }
64
- const [major, minor, patch] = match.slice(1, 4).map(Number);
65
- const ret = {
66
- major,
67
- minor,
68
- patch,
69
- stage: "",
70
- stageVersion: -1
71
- };
72
- if (match[4]) {
73
- let [stage, _v] = match[4].split(".");
74
- ret.stage = stage;
75
- ret.stageVersion = Number(_v) || -1;
76
- }
77
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
78
- throw new TypeError(`invalid version: ${version}`);
79
- }
80
- return ret;
81
- }
82
- function isUpdateJSON(json) {
83
- const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
84
- return is(json) && is(json?.beta);
85
- }
86
-
87
- export {
88
- __require,
89
- unzipFile,
90
- zipFile,
91
- parseGithubCdnURL,
92
- handleUnexpectedErrors,
93
- parseVersion,
94
- isUpdateJSON
95
- };
@@ -1,36 +0,0 @@
1
- // src/crypto.ts
2
- import { createCipheriv, createDecipheriv, createHash, createPrivateKey, createSign, createVerify } from "node:crypto";
3
- function encrypt(plainText, key2, iv) {
4
- const cipher = createCipheriv("aes-256-cbc", key2, iv);
5
- let encrypted = cipher.update(plainText, "utf8", "base64url");
6
- encrypted += cipher.final("base64url");
7
- return encrypted;
8
- }
9
- function decrypt(encryptedText, key2, iv) {
10
- const decipher = createDecipheriv("aes-256-cbc", key2, iv);
11
- let decrypted = decipher.update(encryptedText, "base64url", "utf8");
12
- decrypted += decipher.final("utf8");
13
- return decrypted;
14
- }
15
- function key(data, length) {
16
- const hash = createHash("SHA256").update(data).digest("binary");
17
- return Buffer.from(hash).subarray(0, length);
18
- }
19
- var signature = (buffer, privateKey, cert, version) => {
20
- const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
21
- return encrypt(`${sig}%${version}`, key(cert, 32), key(buffer, 16));
22
- };
23
- var verify = (buffer, signature2, cert) => {
24
- try {
25
- const [sig, version] = decrypt(signature2, key(cert, 32), key(buffer, 16)).split("%");
26
- const result = createVerify("RSA-SHA256").update(buffer).verify(cert, sig, "base64");
27
- return result ? version : false;
28
- } catch (error) {
29
- return false;
30
- }
31
- };
32
-
33
- export {
34
- signature,
35
- verify
36
- };
package/dist/utils.mjs DELETED
@@ -1,40 +0,0 @@
1
- import {
2
- disableHWAccForWin7,
3
- getPathFromAppNameAsar,
4
- getPaths,
5
- getVersions,
6
- is,
7
- loadNativeModuleFromEntry,
8
- restartApp,
9
- setAppUserModelId,
10
- setPortableAppDataPath,
11
- singleInstance,
12
- waitAppReady
13
- } from "./chunk-OUZLSVQC.mjs";
14
- import {
15
- handleUnexpectedErrors,
16
- isUpdateJSON,
17
- parseGithubCdnURL,
18
- parseVersion,
19
- unzipFile,
20
- zipFile
21
- } from "./chunk-GB6VLKJZ.mjs";
22
- export {
23
- disableHWAccForWin7,
24
- getPathFromAppNameAsar,
25
- getPaths,
26
- getVersions,
27
- handleUnexpectedErrors,
28
- is,
29
- isUpdateJSON,
30
- loadNativeModuleFromEntry,
31
- parseGithubCdnURL,
32
- parseVersion,
33
- restartApp,
34
- setAppUserModelId,
35
- setPortableAppDataPath,
36
- singleInstance,
37
- unzipFile,
38
- waitAppReady,
39
- zipFile
40
- };
package/dist/vite.d.mts DELETED
@@ -1,329 +0,0 @@
1
- import * as vite from 'vite';
2
- import { Plugin } from 'vite';
3
- import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
4
- import { Promisable } from '@subframe7536/type-utils';
5
- import { BuildOptions } from 'esbuild';
6
- import { a as UpdateJSON } from './noDep-TvZoKVF8.mjs';
7
-
8
- type PKG = {
9
- name: string;
10
- version: string;
11
- main: string;
12
- };
13
- type DistinguishedName = {
14
- countryName?: string;
15
- stateOrProvinceName?: string;
16
- localityName?: string;
17
- organizationName?: string;
18
- organizationalUnitName?: string;
19
- commonName?: string;
20
- serialNumber?: string;
21
- title?: string;
22
- description?: string;
23
- businessCategory?: string;
24
- emailAddress?: string;
25
- };
26
- type BuildEntryOption = {
27
- /**
28
- * whether to minify
29
- * @default isBuild
30
- */
31
- minify?: boolean;
32
- /**
33
- * whether to generate sourcemap
34
- * @default isBuild
35
- */
36
- sourcemap?: boolean;
37
- /**
38
- * path to app entry output file
39
- * @default 'dist-entry'
40
- */
41
- entryOutputDirPath?: string;
42
- /**
43
- * path to app entry file
44
- * @default 'electron/entry.ts'
45
- */
46
- appEntryPath?: string;
47
- /**
48
- * esbuild path map of native modules in entry directory
49
- *
50
- * @default {}
51
- * @example
52
- * { db: './electron/native/db.ts' }
53
- */
54
- nativeModuleEntryMap?: Record<string, string>;
55
- /**
56
- * custom options for esbuild
57
- * ```ts
58
- * // default options
59
- * const options = {
60
- * entryPoints: {
61
- * entry: appEntryPath,
62
- * ...moduleEntryMap,
63
- * },
64
- * bundle: true,
65
- * platform: 'node',
66
- * outdir: entryOutputDirPath,
67
- * minify,
68
- * sourcemap,
69
- * entryNames: '[dir]/[name]',
70
- * assetNames: '[dir]/[name]',
71
- * external: ['electron', 'original-fs'],
72
- * loader: {
73
- * '.node': 'empty',
74
- * },
75
- * }
76
- * ```
77
- */
78
- overrideEsbuildOptions?: BuildOptions;
79
- /**
80
- * resolve extra files on startup, such as `.node`
81
- * @remark won't trigger will reload
82
- */
83
- postBuild?: (args: {
84
- /**
85
- * get path from `entryOutputDirPath`
86
- */
87
- getPathFromEntryOutputDir: (...paths: string[]) => string;
88
- /**
89
- * copy file to `entryOutputDirPath`
90
- *
91
- * if `to` absent, set to `basename(from)`
92
- *
93
- * if `skipIfExist` absent, skip copy if `to` exist
94
- */
95
- existsAndCopyToEntryOutputDir: (options: {
96
- from: string;
97
- to?: string;
98
- /**
99
- * skip copy if `to` exist
100
- * @default true
101
- */
102
- skipIfExist?: boolean;
103
- }) => void;
104
- }) => Promisable<void>;
105
- };
106
- type GeneratorOverrideFunctions = {
107
- /**
108
- * custom signature generate function
109
- * @param buffer file buffer
110
- * @param privateKey private key
111
- * @param cert certificate string, **EOL must be '\n'**
112
- * @param version current version
113
- */
114
- generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
115
- /**
116
- * custom generate version json function
117
- * @param existingJson The existing JSON object.
118
- * @param buffer file buffer
119
- * @param signature generated signature
120
- * @param version current version
121
- * @param minVersion The minimum version
122
- * @returns The updated version json
123
- */
124
- generateVersionJson?: (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
125
- };
126
- type ElectronUpdaterOptions = {
127
- /**
128
- * mini version of entry
129
- * @default '0.0.0'
130
- */
131
- minimumVersion?: string;
132
- /**
133
- * config for entry (app.asar)
134
- */
135
- entry?: BuildEntryOption;
136
- /**
137
- * paths config
138
- */
139
- paths?: {
140
- /**
141
- * Path to asar file
142
- * @default `release/${app.name}.asar`
143
- */
144
- asarOutputPath?: string;
145
- /**
146
- * Path to version info output, content is {@link UpdateJSON}
147
- * @default `version.json`
148
- */
149
- versionPath?: string;
150
- /**
151
- * Path to gzipped asar file
152
- * @default `release/${app.name}-${version}.asar.gz`
153
- */
154
- gzipPath?: string;
155
- /**
156
- * Path to electron build output
157
- * @default `dist-electron`
158
- */
159
- electronDistPath?: string;
160
- /**
161
- * Path to renderer build output
162
- * @default `dist`
163
- */
164
- rendererDistPath?: string;
165
- };
166
- /**
167
- * signature config
168
- */
169
- keys?: {
170
- /**
171
- * path to the pem file that contains private key
172
- * if not ended with .pem, it will be appended
173
- *
174
- * **if `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
175
- * @default 'keys/private.pem'
176
- */
177
- privateKeyPath?: string;
178
- /**
179
- * path to the pem file that contains public key
180
- * if not ended with .pem, it will be appended
181
- *
182
- * **if `UPDATER_CERT` is set, will read it instead of read from `certPath`**
183
- * @default 'keys/cert.pem'
184
- */
185
- certPath?: string;
186
- /**
187
- * length of the key
188
- * @default 2048
189
- */
190
- keyLength?: number;
191
- /**
192
- * X509 certificate info
193
- *
194
- * only generate simple **self-signed** certificate **without extensions**
195
- */
196
- certInfo?: {
197
- /**
198
- * the subject of the certificate
199
- *
200
- * @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
201
- */
202
- subject?: DistinguishedName;
203
- /**
204
- * expire days of the certificate
205
- *
206
- * @default 3650
207
- */
208
- days?: number;
209
- };
210
- overrideGenerator?: GeneratorOverrideFunctions;
211
- };
212
- };
213
-
214
- type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
215
- [P in K]-?: T[P];
216
- };
217
- type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
218
- [P in NewKey]: T[Key];
219
- };
220
- type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
221
- /**
222
- * startup function for debug (see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template})
223
- * @example
224
- * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
225
- * const options = buildElectronPluginOptions({
226
- * // ...
227
- * main: {
228
- * // ...
229
- * startup: debugStartup
230
- * },
231
- * })
232
- */
233
- declare function debugStartup(args: {
234
- startup: (argv?: string[]) => Promise<void>;
235
- reload: () => void;
236
- }): void;
237
- type ElectronWithUpdaterOptions = {
238
- /**
239
- * whether is in build mode
240
- * ```ts
241
- * export default defineConfig(({ command }) => {
242
- * const isBuild = command === 'build'
243
- * })
244
- * ```
245
- */
246
- isBuild: boolean;
247
- /**
248
- * name, version and main in `package.json`
249
- * ```ts
250
- * import pkg from './package.json'
251
- * ```
252
- */
253
- pkg: PKG;
254
- /**
255
- * main options
256
- */
257
- main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'>;
258
- /**
259
- * preload options
260
- */
261
- preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'>;
262
- /**
263
- * updater options
264
- */
265
- updater?: ElectronUpdaterOptions;
266
- /**
267
- * use NotBundle() plugin in main
268
- * @default true
269
- */
270
- useNotBundle?: boolean;
271
- /**
272
- * Whether to log parsed options
273
- */
274
- logParsedOptions?: boolean;
275
- };
276
- declare const log: vite.Logger;
277
- /**
278
- * build options for `vite-plugin-electron/simple`
279
- * - integrate with updater
280
- * - only contains `main` and `preload` configs
281
- * - remove old electron files
282
- * - externalize dependencies
283
- * - auto restart when entry file changes
284
- * - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
285
- * - no `vite-plugin-electron-renderer` config
286
- *
287
- * you can override all the configs
288
- *
289
- * **Limitation**: entry file change cannot trigger auto restart
290
- *
291
- * @example
292
- * import { defineConfig } from 'vite'
293
- * import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
294
- * import pkg from './package.json'
295
- *
296
- * export default defineConfig(async ({ command }) => {
297
- * const isBuild = command === 'build'
298
- * return {
299
- * plugins: [
300
- * electronWithUpdater({
301
- * pkg,
302
- * isBuild,
303
- * logParsedOptions: true,
304
- * main: {
305
- * files: ['./electron/main/index.ts', './electron/main/worker.ts'],
306
- * // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
307
- * onstart: debugStartup,
308
- * },
309
- * preload: {
310
- * files: './electron/preload/index.ts',
311
- * },
312
- * updater: {
313
- * // options
314
- * }
315
- * }),
316
- * ],
317
- * server: process.env.VSCODE_DEBUG && (() => {
318
- * const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
319
- * return {
320
- * host: url.hostname,
321
- * port: +url.port,
322
- * }
323
- * })(),
324
- * }
325
- * })
326
- */
327
- declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[];
328
-
329
- export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater, log };