electron-incremental-update 0.7.7 → 0.7.8
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/{chunk-Q2K52LOG.mjs → chunk-2XHZMWRR.mjs} +8 -1
- package/dist/{chunk-67MCNA7W.mjs → chunk-SWXNCK6H.mjs} +27 -2
- package/dist/index.d.mts +89 -72
- package/dist/index.d.ts +89 -72
- package/dist/index.js +72 -32
- package/dist/index.mjs +55 -35
- package/dist/updateJson-7e45d9e1.d.ts +11 -0
- package/dist/utils.d.mts +12 -1
- package/dist/utils.d.ts +12 -1
- package/dist/utils.js +28 -1
- package/dist/utils.mjs +5 -1
- package/dist/vite.d.mts +20 -6
- package/dist/vite.d.ts +20 -6
- package/dist/vite.js +78 -20
- package/dist/vite.mjs +58 -16
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isUpdateJSON,
|
|
2
3
|
verify
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2XHZMWRR.mjs";
|
|
4
5
|
import {
|
|
5
6
|
__require,
|
|
6
7
|
getEntryVersion,
|
|
7
8
|
getProductAsarPath,
|
|
9
|
+
getProductVersion,
|
|
10
|
+
parseVersion,
|
|
8
11
|
unzipFile,
|
|
9
12
|
waitAppReady
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-SWXNCK6H.mjs";
|
|
11
14
|
|
|
12
15
|
// src/index.ts
|
|
13
16
|
import { resolve } from "node:path";
|
|
@@ -23,13 +26,6 @@ import { rm, writeFile } from "node:fs/promises";
|
|
|
23
26
|
// src/updater/defaultFunctions.ts
|
|
24
27
|
import { Buffer } from "node:buffer";
|
|
25
28
|
import { net } from "electron";
|
|
26
|
-
|
|
27
|
-
// src/updater/types.ts
|
|
28
|
-
function isUpdateJSON(json) {
|
|
29
|
-
return "signature" in json && "version" in json && "size" in json;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// src/updater/defaultFunctions.ts
|
|
33
29
|
async function downloadJSONDefault(url, updater, headers) {
|
|
34
30
|
await waitAppReady();
|
|
35
31
|
return new Promise((resolve2, reject) => {
|
|
@@ -92,20 +88,6 @@ async function downloadBufferDefault(url, updater, headers) {
|
|
|
92
88
|
});
|
|
93
89
|
}
|
|
94
90
|
var compareVersionDefault = (oldVersion, newVersion) => {
|
|
95
|
-
if (!oldVersion || !newVersion || typeof oldVersion !== "string" || typeof newVersion !== "string") {
|
|
96
|
-
throw new TypeError("invalid version");
|
|
97
|
-
}
|
|
98
|
-
const parseVersion = (version) => {
|
|
99
|
-
const [versionNumber, stage] = version.split("-", 2);
|
|
100
|
-
if (!versionNumber || !versionNumber.includes(".")) {
|
|
101
|
-
throw new TypeError("invalid version");
|
|
102
|
-
}
|
|
103
|
-
const [major, minor, patch] = versionNumber.split(".").map(Number);
|
|
104
|
-
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
105
|
-
throw new TypeError("invalid version");
|
|
106
|
-
}
|
|
107
|
-
return { major, minor, patch, stage };
|
|
108
|
-
};
|
|
109
91
|
const oldV = parseVersion(oldVersion);
|
|
110
92
|
const newV = parseVersion(newVersion);
|
|
111
93
|
if (oldV.major < newV.major || oldV.major === newV.major && oldV.minor < newV.minor || oldV.major === newV.major && oldV.minor === newV.minor && oldV.patch < newV.patch) {
|
|
@@ -118,6 +100,24 @@ var compareVersionDefault = (oldVersion, newVersion) => {
|
|
|
118
100
|
};
|
|
119
101
|
|
|
120
102
|
// src/updater/index.ts
|
|
103
|
+
var MinimumVersionError = class extends Error {
|
|
104
|
+
currentVersion;
|
|
105
|
+
minVersion;
|
|
106
|
+
constructor(version, minimumVersion) {
|
|
107
|
+
super(`current entry version is ${version}, less than the minimumVersion ${minimumVersion}`);
|
|
108
|
+
this.currentVersion = version;
|
|
109
|
+
this.minVersion = minimumVersion;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var VerifyFailedError = class extends Error {
|
|
113
|
+
signature;
|
|
114
|
+
cert;
|
|
115
|
+
constructor(signature, cert) {
|
|
116
|
+
super("verify failed, invalid signature or certificate");
|
|
117
|
+
this.signature = signature;
|
|
118
|
+
this.cert = cert;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
121
|
function createUpdater(updaterOptions) {
|
|
122
122
|
const {
|
|
123
123
|
SIGNATURE_CERT,
|
|
@@ -126,6 +126,7 @@ function createUpdater(updaterOptions) {
|
|
|
126
126
|
releaseAsarURL: _release,
|
|
127
127
|
updateJsonURL: _update,
|
|
128
128
|
debug = false,
|
|
129
|
+
receiveBeta = false,
|
|
129
130
|
downloadConfig: { extraHeader, userAgent } = {},
|
|
130
131
|
overrideFunctions: {
|
|
131
132
|
compareVersion,
|
|
@@ -143,11 +144,15 @@ function createUpdater(updaterOptions) {
|
|
|
143
144
|
function log(msg) {
|
|
144
145
|
debug && updater.emit("debug", msg);
|
|
145
146
|
}
|
|
146
|
-
function needUpdate(version2) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
147
|
+
async function needUpdate(version2, minVersion) {
|
|
148
|
+
const compare = compareVersion ?? compareVersionDefault;
|
|
149
|
+
const productVersion = getProductVersion(productName);
|
|
150
|
+
const entryVersion = getEntryVersion();
|
|
151
|
+
if (await compare(entryVersion, minVersion)) {
|
|
152
|
+
throw new MinimumVersionError(entryVersion, minVersion);
|
|
153
|
+
}
|
|
154
|
+
log(`check update: current version is ${productVersion}, new version is ${version2}`);
|
|
155
|
+
return await compare(productVersion, version2);
|
|
151
156
|
}
|
|
152
157
|
async function parseData(format, data, version2) {
|
|
153
158
|
if (existsSync(tmpFilePath)) {
|
|
@@ -162,7 +167,7 @@ function createUpdater(updaterOptions) {
|
|
|
162
167
|
if (format === "json" && isUpdateJSON(data) || format === "buffer" && Buffer2.isBuffer(data)) {
|
|
163
168
|
return data;
|
|
164
169
|
} else {
|
|
165
|
-
throw new
|
|
170
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
166
171
|
}
|
|
167
172
|
} else if (["string", "undefined"].includes(typeof data)) {
|
|
168
173
|
const ua = userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
|
|
@@ -202,16 +207,29 @@ function createUpdater(updaterOptions) {
|
|
|
202
207
|
}
|
|
203
208
|
return ret;
|
|
204
209
|
} else {
|
|
205
|
-
throw new
|
|
210
|
+
throw new TypeError(`invalid type at format '${format}': ${data}`);
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
updater.productName = productName;
|
|
209
|
-
updater.
|
|
214
|
+
updater.debug = debug;
|
|
215
|
+
updater.receiveBeta = receiveBeta;
|
|
210
216
|
updater.checkUpdate = async (data) => {
|
|
211
217
|
try {
|
|
212
|
-
|
|
218
|
+
let {
|
|
219
|
+
signature: _sig,
|
|
220
|
+
size,
|
|
221
|
+
version: _ver,
|
|
222
|
+
minimumVersion,
|
|
223
|
+
beta
|
|
224
|
+
} = await parseData("json", data);
|
|
225
|
+
if (receiveBeta) {
|
|
226
|
+
_ver = beta.version;
|
|
227
|
+
_sig = beta.signature;
|
|
228
|
+
minimumVersion = beta.minimumVersion;
|
|
229
|
+
size = beta.size;
|
|
230
|
+
}
|
|
213
231
|
log(`checked version: ${_ver}, size: ${size}, signature: ${_sig}`);
|
|
214
|
-
if (!needUpdate(_ver)) {
|
|
232
|
+
if (!await needUpdate(_ver, minimumVersion)) {
|
|
215
233
|
log(`update unavailable: ${_ver}`);
|
|
216
234
|
return void 0;
|
|
217
235
|
} else {
|
|
@@ -234,9 +252,9 @@ function createUpdater(updaterOptions) {
|
|
|
234
252
|
const buffer = await parseData("buffer", data, version);
|
|
235
253
|
log("verify start");
|
|
236
254
|
const _verify = verifySignaure ?? verify;
|
|
237
|
-
const _ver = _verify(buffer, _sig, SIGNATURE_CERT);
|
|
255
|
+
const _ver = await _verify(buffer, _sig, SIGNATURE_CERT);
|
|
238
256
|
if (!_ver) {
|
|
239
|
-
throw new
|
|
257
|
+
throw new VerifyFailedError(_sig, SIGNATURE_CERT);
|
|
240
258
|
}
|
|
241
259
|
log("verify success");
|
|
242
260
|
log(`write to ${gzipPath}`);
|
|
@@ -297,6 +315,8 @@ function initApp(appOptions) {
|
|
|
297
315
|
};
|
|
298
316
|
}
|
|
299
317
|
export {
|
|
318
|
+
MinimumVersionError,
|
|
319
|
+
VerifyFailedError,
|
|
300
320
|
createUpdater,
|
|
301
321
|
initApp
|
|
302
322
|
};
|
package/dist/utils.d.mts
CHANGED
|
@@ -12,9 +12,14 @@ declare function getEntryVersion(): string;
|
|
|
12
12
|
* @param name - The name of the application
|
|
13
13
|
*/
|
|
14
14
|
declare function getProductVersion(name: string): string;
|
|
15
|
+
declare class NoSuchNativeModuleError extends Error {
|
|
16
|
+
moduleName: string;
|
|
17
|
+
constructor(moduleName: string);
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* require native package from app.asar
|
|
17
21
|
* @param packageName native package name
|
|
22
|
+
* @throws error: {@link NoSuchNativeModuleError}
|
|
18
23
|
*/
|
|
19
24
|
declare function requireNative<T = any>(packageName: string): T;
|
|
20
25
|
/**
|
|
@@ -40,5 +45,11 @@ declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
|
40
45
|
declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
|
|
41
46
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
42
47
|
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
48
|
+
declare function parseVersion(version: string): {
|
|
49
|
+
major: number;
|
|
50
|
+
minor: number;
|
|
51
|
+
patch: number;
|
|
52
|
+
stage: string;
|
|
53
|
+
};
|
|
43
54
|
|
|
44
|
-
export { getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
|
55
|
+
export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
package/dist/utils.d.ts
CHANGED
|
@@ -12,9 +12,14 @@ declare function getEntryVersion(): string;
|
|
|
12
12
|
* @param name - The name of the application
|
|
13
13
|
*/
|
|
14
14
|
declare function getProductVersion(name: string): string;
|
|
15
|
+
declare class NoSuchNativeModuleError extends Error {
|
|
16
|
+
moduleName: string;
|
|
17
|
+
constructor(moduleName: string);
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* require native package from app.asar
|
|
17
21
|
* @param packageName native package name
|
|
22
|
+
* @throws error: {@link NoSuchNativeModuleError}
|
|
18
23
|
*/
|
|
19
24
|
declare function requireNative<T = any>(packageName: string): T;
|
|
20
25
|
/**
|
|
@@ -40,5 +45,11 @@ declare function waitAppReady(duration?: number): Promise<unknown>;
|
|
|
40
45
|
declare function unzipFile(gzipPath: string, targetFilePath: string): Promise<unknown>;
|
|
41
46
|
declare function zipFile(filePath: string, targetFilePath?: string): Promise<unknown>;
|
|
42
47
|
declare function handleUnexpectedErrors(callback: (err: Error) => void): void;
|
|
48
|
+
declare function parseVersion(version: string): {
|
|
49
|
+
major: number;
|
|
50
|
+
minor: number;
|
|
51
|
+
patch: number;
|
|
52
|
+
stage: string;
|
|
53
|
+
};
|
|
43
54
|
|
|
44
|
-
export { getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
|
55
|
+
export { NoSuchNativeModuleError, getEntryVersion, getGithubFileCdnGroup, getGithubReleaseCdnGroup, getProductAsarPath, getProductVersion, handleUnexpectedErrors, parseGithubCdnURL, parseVersion, requireNative, restartApp, unzipFile, waitAppReady, zipFile };
|
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
|
-
|
|
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/")) {
|
|
@@ -141,8 +154,21 @@ 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
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
165
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
166
|
+
}
|
|
167
|
+
return { major, minor, patch, stage: match[4] };
|
|
168
|
+
}
|
|
144
169
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
170
|
0 && (module.exports = {
|
|
171
|
+
NoSuchNativeModuleError,
|
|
146
172
|
getEntryVersion,
|
|
147
173
|
getGithubFileCdnGroup,
|
|
148
174
|
getGithubReleaseCdnGroup,
|
|
@@ -150,6 +176,7 @@ function handleUnexpectedErrors(callback) {
|
|
|
150
176
|
getProductVersion,
|
|
151
177
|
handleUnexpectedErrors,
|
|
152
178
|
parseGithubCdnURL,
|
|
179
|
+
parseVersion,
|
|
153
180
|
requireNative,
|
|
154
181
|
restartApp,
|
|
155
182
|
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,15 @@ 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-
|
|
16
|
+
} from "./chunk-SWXNCK6H.mjs";
|
|
15
17
|
export {
|
|
18
|
+
NoSuchNativeModuleError,
|
|
16
19
|
getEntryVersion,
|
|
17
20
|
getGithubFileCdnGroup,
|
|
18
21
|
getGithubReleaseCdnGroup,
|
|
@@ -20,6 +23,7 @@ export {
|
|
|
20
23
|
getProductVersion,
|
|
21
24
|
handleUnexpectedErrors,
|
|
22
25
|
parseGithubCdnURL,
|
|
26
|
+
parseVersion,
|
|
23
27
|
requireNative,
|
|
24
28
|
restartApp,
|
|
25
29
|
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 { U as UpdateJSON } from './updateJson-7e45d9e1.js';
|
|
3
4
|
|
|
4
5
|
type DistinguishedName = {
|
|
5
6
|
countryName?: string;
|
|
@@ -14,7 +15,8 @@ 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 FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
|
|
19
|
+
type FunctionGenerateVersionJson = (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
|
|
18
20
|
type Options = {
|
|
19
21
|
/**
|
|
20
22
|
* whether is in build mode
|
|
@@ -32,6 +34,11 @@ type Options = {
|
|
|
32
34
|
* you can set as 'version' in `package.json`
|
|
33
35
|
*/
|
|
34
36
|
version: string;
|
|
37
|
+
/**
|
|
38
|
+
* mini version of entry
|
|
39
|
+
* @default version
|
|
40
|
+
*/
|
|
41
|
+
minimumVersion?: string;
|
|
35
42
|
/**
|
|
36
43
|
* Whether to minify entry file
|
|
37
44
|
*/
|
|
@@ -55,6 +62,11 @@ type Options = {
|
|
|
55
62
|
* @default `release/${productName}.asar`
|
|
56
63
|
*/
|
|
57
64
|
asarOutputPath?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Path to version info output, content is {@link UpdateJSON}
|
|
67
|
+
* @default `version.json`
|
|
68
|
+
*/
|
|
69
|
+
versionPath?: string;
|
|
58
70
|
/**
|
|
59
71
|
* Path to gzipped asar file
|
|
60
72
|
* @default `release/${productName}-${version}.asar.gz`
|
|
@@ -70,11 +82,6 @@ type Options = {
|
|
|
70
82
|
* @default `dist`
|
|
71
83
|
*/
|
|
72
84
|
rendererDistPath?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Path to version info output
|
|
75
|
-
* @default `version.json`
|
|
76
|
-
*/
|
|
77
|
-
versionPath?: string;
|
|
78
85
|
};
|
|
79
86
|
/**
|
|
80
87
|
* signature config
|
|
@@ -124,6 +131,13 @@ type Options = {
|
|
|
124
131
|
* @param cert certificate
|
|
125
132
|
*/
|
|
126
133
|
generateSignature?: FunctionGenerateSignature;
|
|
134
|
+
/**
|
|
135
|
+
* custom signature generate function {@link FunctionGenerateVersionJson}
|
|
136
|
+
* @param signature generated signature
|
|
137
|
+
* @param version currentVersion
|
|
138
|
+
* @param cert certificate
|
|
139
|
+
*/
|
|
140
|
+
generateVersionJson?: FunctionGenerateVersionJson;
|
|
127
141
|
};
|
|
128
142
|
};
|
|
129
143
|
};
|
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 { U as UpdateJSON } from './updateJson-7e45d9e1.js';
|
|
3
4
|
|
|
4
5
|
type DistinguishedName = {
|
|
5
6
|
countryName?: string;
|
|
@@ -14,7 +15,8 @@ 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 FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string | Promise<string>;
|
|
19
|
+
type FunctionGenerateVersionJson = (existingJson: UpdateJSON, buffer: Buffer, signature: string, version: string, minVersion: string) => UpdateJSON | Promise<UpdateJSON>;
|
|
18
20
|
type Options = {
|
|
19
21
|
/**
|
|
20
22
|
* whether is in build mode
|
|
@@ -32,6 +34,11 @@ type Options = {
|
|
|
32
34
|
* you can set as 'version' in `package.json`
|
|
33
35
|
*/
|
|
34
36
|
version: string;
|
|
37
|
+
/**
|
|
38
|
+
* mini version of entry
|
|
39
|
+
* @default version
|
|
40
|
+
*/
|
|
41
|
+
minimumVersion?: string;
|
|
35
42
|
/**
|
|
36
43
|
* Whether to minify entry file
|
|
37
44
|
*/
|
|
@@ -55,6 +62,11 @@ type Options = {
|
|
|
55
62
|
* @default `release/${productName}.asar`
|
|
56
63
|
*/
|
|
57
64
|
asarOutputPath?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Path to version info output, content is {@link UpdateJSON}
|
|
67
|
+
* @default `version.json`
|
|
68
|
+
*/
|
|
69
|
+
versionPath?: string;
|
|
58
70
|
/**
|
|
59
71
|
* Path to gzipped asar file
|
|
60
72
|
* @default `release/${productName}-${version}.asar.gz`
|
|
@@ -70,11 +82,6 @@ type Options = {
|
|
|
70
82
|
* @default `dist`
|
|
71
83
|
*/
|
|
72
84
|
rendererDistPath?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Path to version info output
|
|
75
|
-
* @default `version.json`
|
|
76
|
-
*/
|
|
77
|
-
versionPath?: string;
|
|
78
85
|
};
|
|
79
86
|
/**
|
|
80
87
|
* signature config
|
|
@@ -124,6 +131,13 @@ type Options = {
|
|
|
124
131
|
* @param cert certificate
|
|
125
132
|
*/
|
|
126
133
|
generateSignature?: FunctionGenerateSignature;
|
|
134
|
+
/**
|
|
135
|
+
* custom signature generate function {@link FunctionGenerateVersionJson}
|
|
136
|
+
* @param signature generated signature
|
|
137
|
+
* @param version currentVersion
|
|
138
|
+
* @param cert certificate
|
|
139
|
+
*/
|
|
140
|
+
generateVersionJson?: FunctionGenerateVersionJson;
|
|
127
141
|
};
|
|
128
142
|
};
|
|
129
143
|
};
|
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,24 @@ 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
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
80
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
81
|
+
}
|
|
82
|
+
return { major, minor, patch, stage: match[4] };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/updateJson.ts
|
|
86
|
+
function isUpdateJSON(json) {
|
|
87
|
+
const is = (j) => "signature" in j && "version" in j && "size" in j && "minimumVersion" in j;
|
|
88
|
+
return is(json) && "beta" in json && is(json.beta);
|
|
89
|
+
}
|
|
71
90
|
|
|
72
91
|
// src/build-plugins/build.ts
|
|
73
92
|
async function buildAsar({
|
|
@@ -88,15 +107,51 @@ async function buildVersion({
|
|
|
88
107
|
privateKey,
|
|
89
108
|
cert,
|
|
90
109
|
version,
|
|
91
|
-
|
|
110
|
+
minimumVersion,
|
|
111
|
+
generateSignature,
|
|
112
|
+
generateVersionJson
|
|
92
113
|
}) {
|
|
114
|
+
let _json = {
|
|
115
|
+
beta: {
|
|
116
|
+
minimumVersion: version,
|
|
117
|
+
signature: "",
|
|
118
|
+
size: 0,
|
|
119
|
+
version
|
|
120
|
+
},
|
|
121
|
+
minimumVersion: version,
|
|
122
|
+
signature: "",
|
|
123
|
+
size: 0,
|
|
124
|
+
version
|
|
125
|
+
};
|
|
126
|
+
if ((0, import_node_fs2.existsSync)(versionPath)) {
|
|
127
|
+
try {
|
|
128
|
+
_json = JSON.parse(await (0, import_promises.readFile)(versionPath, "utf-8"));
|
|
129
|
+
} catch (error) {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!isUpdateJSON(_json)) {
|
|
133
|
+
throw new Error("invalid version file");
|
|
134
|
+
}
|
|
93
135
|
const buffer = await (0, import_promises.readFile)(gzipPath);
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
136
|
+
const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
|
|
137
|
+
if (generateVersionJson) {
|
|
138
|
+
_json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
|
|
139
|
+
if (!isUpdateJSON(_json)) {
|
|
140
|
+
throw new Error("invalid version info");
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
_json.beta.version = version;
|
|
144
|
+
_json.beta.minimumVersion = minimumVersion;
|
|
145
|
+
_json.beta.signature = sig;
|
|
146
|
+
_json.beta.size = buffer.length;
|
|
147
|
+
if (!parseVersion(version).stage) {
|
|
148
|
+
_json.version = version;
|
|
149
|
+
_json.minimumVersion = minimumVersion;
|
|
150
|
+
_json.signature = sig;
|
|
151
|
+
_json.size = buffer.length;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
await (0, import_promises.writeFile)(versionPath, JSON.stringify(_json, null, 2));
|
|
100
155
|
}
|
|
101
156
|
async function buildEntry({
|
|
102
157
|
entryPath,
|
|
@@ -117,25 +172,25 @@ async function buildEntry({
|
|
|
117
172
|
var import_ci_info = require("ci-info");
|
|
118
173
|
|
|
119
174
|
// src/build-plugins/key.ts
|
|
120
|
-
var
|
|
175
|
+
var import_node_fs3 = require("fs");
|
|
121
176
|
var import_node_path2 = require("path");
|
|
122
177
|
var import_node_os = require("os");
|
|
123
178
|
var import_selfsigned = require("selfsigned");
|
|
124
179
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
125
180
|
const privateKeyDir = (0, import_node_path2.dirname)(privateKeyPath);
|
|
126
|
-
(0,
|
|
181
|
+
(0, import_node_fs3.existsSync)(privateKeyDir) || (0, import_node_fs3.mkdirSync)(privateKeyDir, { recursive: true });
|
|
127
182
|
const certDir = (0, import_node_path2.dirname)(certPath);
|
|
128
|
-
(0,
|
|
183
|
+
(0, import_node_fs3.existsSync)(certDir) || (0, import_node_fs3.mkdirSync)(certDir, { recursive: true });
|
|
129
184
|
const { cert, private: privateKey } = (0, import_selfsigned.generate)(subject, {
|
|
130
185
|
keySize: keyLength,
|
|
131
186
|
algorithm: "sha256",
|
|
132
187
|
days
|
|
133
188
|
});
|
|
134
|
-
(0,
|
|
135
|
-
(0,
|
|
189
|
+
(0, import_node_fs3.writeFileSync)(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
190
|
+
(0, import_node_fs3.writeFileSync)(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
136
191
|
}
|
|
137
192
|
function writeCertToMain(entryPath, cert) {
|
|
138
|
-
const file = (0,
|
|
193
|
+
const file = (0, import_node_fs3.readFileSync)(entryPath, "utf-8");
|
|
139
194
|
const regex = /const SIGNATURE_CERT = ['`][\s\S]*?['`]/;
|
|
140
195
|
const replacement = `const SIGNATURE_CERT = \`${cert}\``;
|
|
141
196
|
let replaced = file;
|
|
@@ -157,7 +212,7 @@ function writeCertToMain(entryPath, cert) {
|
|
|
157
212
|
!isMatched && lines.push(r);
|
|
158
213
|
replaced = lines.join(import_node_os.EOL);
|
|
159
214
|
}
|
|
160
|
-
(0,
|
|
215
|
+
(0, import_node_fs3.writeFileSync)(entryPath, replaced.replace(/\r\n?/g, "\n"));
|
|
161
216
|
}
|
|
162
217
|
function parseKeys({
|
|
163
218
|
keyLength,
|
|
@@ -168,12 +223,12 @@ function parseKeys({
|
|
|
168
223
|
days
|
|
169
224
|
}) {
|
|
170
225
|
const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
|
|
171
|
-
!(0,
|
|
172
|
-
if (!(0,
|
|
226
|
+
!(0, import_node_fs3.existsSync)(keysDir) && (0, import_node_fs3.mkdirSync)(keysDir);
|
|
227
|
+
if (!(0, import_node_fs3.existsSync)(privateKeyPath) || !(0, import_node_fs3.existsSync)(certPath)) {
|
|
173
228
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
174
229
|
}
|
|
175
|
-
const privateKey = (0,
|
|
176
|
-
const cert = (0,
|
|
230
|
+
const privateKey = (0, import_node_fs3.readFileSync)(privateKeyPath, "utf-8");
|
|
231
|
+
const cert = (0, import_node_fs3.readFileSync)(certPath, "utf-8");
|
|
177
232
|
writeCertToMain(entryPath, cert);
|
|
178
233
|
return {
|
|
179
234
|
privateKey,
|
|
@@ -195,6 +250,7 @@ function parseOptions(options) {
|
|
|
195
250
|
isBuild,
|
|
196
251
|
productName,
|
|
197
252
|
version,
|
|
253
|
+
minimumVersion = version,
|
|
198
254
|
minify = false,
|
|
199
255
|
paths: {
|
|
200
256
|
entryPath = "electron/app.ts",
|
|
@@ -213,7 +269,7 @@ function parseOptions(options) {
|
|
|
213
269
|
overrideFunctions = {}
|
|
214
270
|
} = {}
|
|
215
271
|
} = options;
|
|
216
|
-
const { generateSignature } = overrideFunctions;
|
|
272
|
+
const { generateSignature, generateVersionJson } = overrideFunctions;
|
|
217
273
|
let {
|
|
218
274
|
subject = {
|
|
219
275
|
commonName: productName,
|
|
@@ -245,11 +301,13 @@ function parseOptions(options) {
|
|
|
245
301
|
});
|
|
246
302
|
buildVersionOption = {
|
|
247
303
|
version,
|
|
304
|
+
minimumVersion,
|
|
248
305
|
gzipPath,
|
|
249
306
|
privateKey,
|
|
250
307
|
cert,
|
|
251
308
|
versionPath,
|
|
252
|
-
generateSignature
|
|
309
|
+
generateSignature,
|
|
310
|
+
generateVersionJson
|
|
253
311
|
};
|
|
254
312
|
}
|
|
255
313
|
return { isBuild, buildAsarOption, buildEntryOption, buildVersionOption };
|