electron-incremental-update 1.2.0 → 2.0.0-beta.1
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 +131 -10
- package/dist/chunk-RSLOPAIZ.js +247 -0
- package/dist/decrypt-BNBcodiO.d.cts +4 -0
- package/dist/decrypt-BNBcodiO.d.ts +4 -0
- package/dist/index.cjs +131 -336
- package/dist/index.d.cts +96 -161
- package/dist/index.d.ts +96 -161
- package/dist/index.js +97 -269
- package/dist/provider.cjs +227 -0
- package/dist/provider.d.cts +37 -0
- package/dist/provider.d.ts +37 -0
- package/dist/provider.js +98 -0
- package/dist/types-DxPmQmaq.d.cts +61 -0
- package/dist/types-seJf3Wbc.d.ts +61 -0
- package/dist/utils.cjs +140 -117
- package/dist/utils.d.cts +31 -76
- package/dist/utils.d.ts +31 -76
- package/dist/utils.js +35 -11
- package/dist/{pure-GoN_3MEj.d.cts → version-CffZWDhZ.d.cts} +8 -7
- package/dist/{pure-GoN_3MEj.d.ts → version-CffZWDhZ.d.ts} +8 -7
- package/dist/vite.js +71 -119
- package/package.json +12 -6
- package/provider.d.ts +1 -0
- package/provider.js +1 -0
- package/dist/chunk-7ET4GMTZ.js +0 -236
- package/dist/chunk-CXHA5TF7.js +0 -236
- package/dist/chunk-HWUYTDEF.js +0 -236
- package/dist/chunk-RQCTJY4L.js +0 -236
- package/dist/vite.d.ts +0 -372
package/dist/utils.js
CHANGED
|
@@ -1,38 +1,62 @@
|
|
|
1
1
|
import {
|
|
2
|
+
decrypt,
|
|
2
3
|
disableHWAccForWin7,
|
|
4
|
+
encrypt,
|
|
5
|
+
getAppVersion,
|
|
6
|
+
getEntryVersion,
|
|
3
7
|
getPathFromAppNameAsar,
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
getPathFromEntryAsar,
|
|
9
|
+
getPathFromPreload,
|
|
10
|
+
getPathFromPublic,
|
|
6
11
|
handleUnexpectedErrors,
|
|
7
|
-
|
|
12
|
+
hashString,
|
|
13
|
+
isDev,
|
|
14
|
+
isLinux,
|
|
15
|
+
isLowerVersionDefault,
|
|
16
|
+
isMac,
|
|
8
17
|
isUpdateJSON,
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
isWin,
|
|
19
|
+
loadPage,
|
|
11
20
|
parseVersion,
|
|
21
|
+
requireNative,
|
|
12
22
|
restartApp,
|
|
13
23
|
setAppUserModelId,
|
|
14
24
|
setPortableAppDataPath,
|
|
25
|
+
signature,
|
|
15
26
|
singleInstance,
|
|
16
27
|
unzipFile,
|
|
28
|
+
verifySignatureDefault,
|
|
17
29
|
waitAppReady,
|
|
18
30
|
zipFile
|
|
19
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-RSLOPAIZ.js";
|
|
20
32
|
export {
|
|
33
|
+
decrypt,
|
|
21
34
|
disableHWAccForWin7,
|
|
35
|
+
encrypt,
|
|
36
|
+
getAppVersion,
|
|
37
|
+
getEntryVersion,
|
|
22
38
|
getPathFromAppNameAsar,
|
|
23
|
-
|
|
24
|
-
|
|
39
|
+
getPathFromEntryAsar,
|
|
40
|
+
getPathFromPreload,
|
|
41
|
+
getPathFromPublic,
|
|
25
42
|
handleUnexpectedErrors,
|
|
26
|
-
|
|
43
|
+
hashString,
|
|
44
|
+
isDev,
|
|
45
|
+
isLinux,
|
|
46
|
+
isLowerVersionDefault,
|
|
47
|
+
isMac,
|
|
27
48
|
isUpdateJSON,
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
isWin,
|
|
50
|
+
loadPage,
|
|
30
51
|
parseVersion,
|
|
52
|
+
requireNative,
|
|
31
53
|
restartApp,
|
|
32
54
|
setAppUserModelId,
|
|
33
55
|
setPortableAppDataPath,
|
|
56
|
+
signature,
|
|
34
57
|
singleInstance,
|
|
35
58
|
unzipFile,
|
|
59
|
+
verifySignatureDefault,
|
|
36
60
|
waitAppReady,
|
|
37
61
|
zipFile
|
|
38
62
|
};
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* parse Github CDN URL for accelerating the speed of downloading
|
|
3
|
-
*
|
|
4
|
-
* {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
|
|
5
|
-
*/
|
|
6
|
-
declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
7
1
|
/**
|
|
8
2
|
* handle all unhandled error
|
|
9
3
|
* @param callback callback function
|
|
@@ -17,15 +11,22 @@ interface Version {
|
|
|
17
11
|
stageVersion: number;
|
|
18
12
|
}
|
|
19
13
|
declare function parseVersion(version: string): Version;
|
|
14
|
+
declare function isLowerVersionDefault(oldVer: string, newVer: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* update info json
|
|
17
|
+
*/
|
|
20
18
|
type UpdateInfo = {
|
|
21
19
|
signature: string;
|
|
22
20
|
minimumVersion: string;
|
|
23
21
|
version: string;
|
|
24
22
|
size: number;
|
|
25
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* {@link UpdateInfo} with beta
|
|
26
|
+
*/
|
|
26
27
|
type UpdateJSON = UpdateInfo & {
|
|
27
28
|
beta: UpdateInfo;
|
|
28
29
|
};
|
|
29
30
|
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
30
31
|
|
|
31
|
-
export { type
|
|
32
|
+
export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, isUpdateJSON as b, handleUnexpectedErrors as h, isLowerVersionDefault as i, parseVersion as p };
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* parse Github CDN URL for accelerating the speed of downloading
|
|
3
|
-
*
|
|
4
|
-
* {@link https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L34 some public CDN links}
|
|
5
|
-
*/
|
|
6
|
-
declare function parseGithubCdnURL(originRepoURL: string, cdnPrefix: string, relativeFilePath: string): string;
|
|
7
1
|
/**
|
|
8
2
|
* handle all unhandled error
|
|
9
3
|
* @param callback callback function
|
|
@@ -17,15 +11,22 @@ interface Version {
|
|
|
17
11
|
stageVersion: number;
|
|
18
12
|
}
|
|
19
13
|
declare function parseVersion(version: string): Version;
|
|
14
|
+
declare function isLowerVersionDefault(oldVer: string, newVer: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* update info json
|
|
17
|
+
*/
|
|
20
18
|
type UpdateInfo = {
|
|
21
19
|
signature: string;
|
|
22
20
|
minimumVersion: string;
|
|
23
21
|
version: string;
|
|
24
22
|
size: number;
|
|
25
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* {@link UpdateInfo} with beta
|
|
26
|
+
*/
|
|
26
27
|
type UpdateJSON = UpdateInfo & {
|
|
27
28
|
beta: UpdateInfo;
|
|
28
29
|
};
|
|
29
30
|
declare function isUpdateJSON(json: any): json is UpdateJSON;
|
|
30
31
|
|
|
31
|
-
export { type
|
|
32
|
+
export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, isUpdateJSON as b, handleUnexpectedErrors as h, isLowerVersionDefault as i, parseVersion as p };
|
package/dist/vite.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/vite.ts
|
|
2
2
|
import { basename as basename2, join as join2, resolve } from "node:path";
|
|
3
|
-
import { cpSync, existsSync as existsSync4, rmSync
|
|
3
|
+
import { cpSync, existsSync as existsSync4, rmSync } from "node:fs";
|
|
4
4
|
import { mergeConfig as mergeConfig2, normalizePath as normalizePath2 } from "vite";
|
|
5
5
|
import ElectronSimple from "vite-plugin-electron/simple";
|
|
6
6
|
import { startup } from "vite-plugin-electron";
|
|
@@ -14,30 +14,9 @@ import Asar from "@electron/asar";
|
|
|
14
14
|
import { build } from "esbuild";
|
|
15
15
|
import { mergeConfig } from "vite";
|
|
16
16
|
|
|
17
|
-
// src/
|
|
18
|
-
import { createHash } from "node:crypto";
|
|
19
|
-
function hashString(data, length) {
|
|
20
|
-
const hash = createHash("SHA256").update(data).digest("binary");
|
|
21
|
-
return Buffer.from(hash).subarray(0, length);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/crypto/enc.ts
|
|
25
|
-
import { createCipheriv, createPrivateKey, createSign } from "node:crypto";
|
|
26
|
-
function encrypt(plainText, key, iv) {
|
|
27
|
-
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
28
|
-
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
29
|
-
encrypted += cipher.final("base64url");
|
|
30
|
-
return encrypted;
|
|
31
|
-
}
|
|
32
|
-
var signature = (buffer, privateKey, cert, version) => {
|
|
33
|
-
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
34
|
-
return encrypt(`${sig}%${version}`, hashString(cert, 32), hashString(buffer, 16));
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// src/utils/pure.ts
|
|
17
|
+
// src/utils/version.ts
|
|
38
18
|
function parseVersion(version) {
|
|
39
|
-
const
|
|
40
|
-
const match = semver.exec(version);
|
|
19
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
41
20
|
if (!match) {
|
|
42
21
|
throw new TypeError(`invalid version: ${version}`);
|
|
43
22
|
}
|
|
@@ -65,8 +44,8 @@ function isUpdateJSON(json) {
|
|
|
65
44
|
}
|
|
66
45
|
|
|
67
46
|
// src/utils/zip.ts
|
|
68
|
-
import { existsSync, readFileSync,
|
|
69
|
-
import { brotliCompress
|
|
47
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
48
|
+
import { brotliCompress } from "node:zlib";
|
|
70
49
|
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
71
50
|
if (!existsSync(filePath)) {
|
|
72
51
|
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
@@ -83,94 +62,36 @@ async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
|
83
62
|
});
|
|
84
63
|
}
|
|
85
64
|
|
|
86
|
-
// src/
|
|
87
|
-
import {
|
|
65
|
+
// src/utils/crypto/utils.ts
|
|
66
|
+
import { createHash } from "node:crypto";
|
|
67
|
+
function hashString(data, length) {
|
|
68
|
+
const hash = createHash("SHA256").update(data).digest("binary");
|
|
69
|
+
return Buffer.from(hash).subarray(0, length);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/utils/crypto/encrypt.ts
|
|
73
|
+
import { createCipheriv, createPrivateKey, createSign } from "node:crypto";
|
|
74
|
+
function encrypt(plainText, key, iv) {
|
|
75
|
+
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
76
|
+
let encrypted = cipher.update(plainText, "utf8", "base64url");
|
|
77
|
+
encrypted += cipher.final("base64url");
|
|
78
|
+
return encrypted;
|
|
79
|
+
}
|
|
80
|
+
function signature(buffer, privateKey, cert, version) {
|
|
81
|
+
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
82
|
+
return encrypt(`${sig}%${version}`, hashString(cert, 32), hashString(buffer, 16));
|
|
83
|
+
}
|
|
88
84
|
|
|
89
85
|
// src/build-plugins/constant.ts
|
|
86
|
+
import { createLogger } from "vite";
|
|
90
87
|
var id = "electron-incremental-updater";
|
|
91
88
|
var bytecodeId = `${id}-bytecode`;
|
|
92
|
-
var loaderId = `${id}-loader`;
|
|
93
|
-
|
|
94
|
-
// src/build-plugins/log.ts
|
|
95
89
|
var log = createLogger("info", { prefix: `[${id}]` });
|
|
96
90
|
var bytecodeLog = createLogger("info", { prefix: `[${bytecodeId}]` });
|
|
97
91
|
|
|
98
92
|
// src/build-plugins/bytecode/code.ts
|
|
99
93
|
var bytecodeGeneratorScript = "const vm = require('vm')\nconst v8 = require('v8')\nconst wrap = require('module').wrap\nv8.setFlagsFromString('--no-lazy')\nv8.setFlagsFromString('--no-flush-bytecode')\nlet code = ''\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('readable', () => {\n const data = process.stdin.read()\n if (data !== null) {\n code += data\n }\n})\nprocess.stdin.on('end', () => {\n try {\n if (typeof code !== 'string') {\n throw new Error('javascript code must be string.')\n }\n const script = new vm.Script(wrap(code), { produceCachedData: true })\n const bytecodeBuffer = script.createCachedData()\n process.stdout.write(bytecodeBuffer)\n } catch (error) {\n console.error(error)\n }\n})\n";
|
|
100
|
-
var bytecodeModuleLoaderCode = [
|
|
101
|
-
`"use strict";`,
|
|
102
|
-
`const fs = require("fs");`,
|
|
103
|
-
`const path = require("path");`,
|
|
104
|
-
`const vm = require("vm");`,
|
|
105
|
-
`const v8 = require("v8");`,
|
|
106
|
-
`const Module = require("module");`,
|
|
107
|
-
`v8.setFlagsFromString("--no-lazy");`,
|
|
108
|
-
`v8.setFlagsFromString("--no-flush-bytecode");`,
|
|
109
|
-
`const FLAG_HASH_OFFSET = 12;`,
|
|
110
|
-
`const SOURCE_HASH_OFFSET = 8;`,
|
|
111
|
-
`let dummyBytecode;`,
|
|
112
|
-
`function setFlagHashHeader(bytecodeBuffer) {`,
|
|
113
|
-
` if (!dummyBytecode) {`,
|
|
114
|
-
` const script = new vm.Script("", {`,
|
|
115
|
-
` produceCachedData: true`,
|
|
116
|
-
` });`,
|
|
117
|
-
` dummyBytecode = script.createCachedData();`,
|
|
118
|
-
` }`,
|
|
119
|
-
` dummyBytecode.slice(FLAG_HASH_OFFSET, FLAG_HASH_OFFSET + 4).copy(bytecodeBuffer, FLAG_HASH_OFFSET);`,
|
|
120
|
-
`};`,
|
|
121
|
-
`function getSourceHashHeader(bytecodeBuffer) {`,
|
|
122
|
-
` return bytecodeBuffer.slice(SOURCE_HASH_OFFSET, SOURCE_HASH_OFFSET + 4);`,
|
|
123
|
-
`};`,
|
|
124
|
-
`function buffer2Number(buffer) {`,
|
|
125
|
-
` let ret = 0;`,
|
|
126
|
-
` ret |= buffer[3] << 24;`,
|
|
127
|
-
` ret |= buffer[2] << 16;`,
|
|
128
|
-
` ret |= buffer[1] << 8;`,
|
|
129
|
-
` ret |= buffer[0];`,
|
|
130
|
-
` return ret;`,
|
|
131
|
-
`};`,
|
|
132
|
-
`Module._extensions[".jsc"] = Module._extensions[".cjsc"] = function (module, filename) {`,
|
|
133
|
-
` const bytecodeBuffer = fs.readFileSync(filename);`,
|
|
134
|
-
` if (!Buffer.isBuffer(bytecodeBuffer)) {`,
|
|
135
|
-
` throw new Error("BytecodeBuffer must be a buffer object.");`,
|
|
136
|
-
` }`,
|
|
137
|
-
` setFlagHashHeader(bytecodeBuffer);`,
|
|
138
|
-
` const length = buffer2Number(getSourceHashHeader(bytecodeBuffer));`,
|
|
139
|
-
` let dummyCode = "";`,
|
|
140
|
-
` if (length > 1) {`,
|
|
141
|
-
` dummyCode = "\\"" + "\\u200b".repeat(length - 2) + "\\"";`,
|
|
142
|
-
` }`,
|
|
143
|
-
` const script = new vm.Script(dummyCode, {`,
|
|
144
|
-
` filename: filename,`,
|
|
145
|
-
` lineOffset: 0,`,
|
|
146
|
-
` displayErrors: true,`,
|
|
147
|
-
` cachedData: bytecodeBuffer`,
|
|
148
|
-
` });`,
|
|
149
|
-
` if (script.cachedDataRejected) {`,
|
|
150
|
-
` throw new Error("Invalid or incompatible cached data (cachedDataRejected)");`,
|
|
151
|
-
` }`,
|
|
152
|
-
` const require = function (id) {`,
|
|
153
|
-
` return module.require(id);`,
|
|
154
|
-
` };`,
|
|
155
|
-
` require.resolve = function (request, options) {`,
|
|
156
|
-
` return Module._resolveFilename(request, module, false, options);`,
|
|
157
|
-
` };`,
|
|
158
|
-
` if (process.mainModule) {`,
|
|
159
|
-
` require.main = process.mainModule;`,
|
|
160
|
-
` }`,
|
|
161
|
-
` require.extensions = Module._extensions;`,
|
|
162
|
-
` require.cache = Module._cache;`,
|
|
163
|
-
` const compiledWrapper = script.runInThisContext({`,
|
|
164
|
-
` filename: filename,`,
|
|
165
|
-
` lineOffset: 0,`,
|
|
166
|
-
` columnOffset: 0,`,
|
|
167
|
-
` displayErrors: true`,
|
|
168
|
-
` });`,
|
|
169
|
-
` const dirname = path.dirname(filename);`,
|
|
170
|
-
` const args = [module.exports, require, module, filename, dirname, process, global];`,
|
|
171
|
-
` return compiledWrapper.apply(module.exports, args);`,
|
|
172
|
-
`};`
|
|
173
|
-
].join("\n");
|
|
94
|
+
var bytecodeModuleLoaderCode = '"use strict";\nconst fs = require("fs");\nconst path = require("path");\nconst vm = require("vm");\nconst v8 = require("v8");\nconst Module = require("module");\nv8.setFlagsFromString("--no-lazy");\nv8.setFlagsFromString("--no-flush-bytecode");\nconst FLAG_HASH_OFFSET = 12;\nconst SOURCE_HASH_OFFSET = 8;\nlet dummyBytecode;\nfunction setFlagHashHeader(bytecodeBuffer) {\n if (!dummyBytecode) {\n const script = new vm.Script("", {\n produceCachedData: true\n });\n dummyBytecode = script.createCachedData();\n }\n dummyBytecode.slice(FLAG_HASH_OFFSET, FLAG_HASH_OFFSET + 4).copy(bytecodeBuffer, FLAG_HASH_OFFSET);\n};\nfunction getSourceHashHeader(bytecodeBuffer) {\n return bytecodeBuffer.slice(SOURCE_HASH_OFFSET, SOURCE_HASH_OFFSET + 4);\n};\nfunction buffer2Number(buffer) {\n let ret = 0;\n ret |= buffer[3] << 24;\n ret |= buffer[2] << 16;\n ret |= buffer[1] << 8;\n ret |= buffer[0];\n return ret;\n};\nModule._extensions[".jsc"] = Module._extensions[".cjsc"] = function (module, filename) {\n const bytecodeBuffer = fs.readFileSync(filename);\n if (!Buffer.isBuffer(bytecodeBuffer)) {\n throw new Error("BytecodeBuffer must be a buffer object.");\n }\n setFlagHashHeader(bytecodeBuffer);\n const length = buffer2Number(getSourceHashHeader(bytecodeBuffer));\n let dummyCode = "";\n if (length > 1) {\n dummyCode = "\\"" + "\\u200b".repeat(length - 2) + "\\"";\n }\n const script = new vm.Script(dummyCode, {\n filename: filename,\n lineOffset: 0,\n displayErrors: true,\n cachedData: bytecodeBuffer\n });\n if (script.cachedDataRejected) {\n throw new Error("Invalid or incompatible cached data (cachedDataRejected)");\n }\n const require = function (id) {\n return module.require(id);\n };\n require.resolve = function (request, options) {\n return Module._resolveFilename(request, module, false, options);\n };\n if (process.mainModule) {\n require.main = process.mainModule;\n }\n require.extensions = Module._extensions;\n require.cache = Module._cache;\n const compiledWrapper = script.runInThisContext({\n filename: filename,\n lineOffset: 0,\n columnOffset: 0,\n displayErrors: true\n });\n const dirname = path.dirname(filename);\n const args = [module.exports, require, module, filename, dirname, process, global];\n return compiledWrapper.apply(module.exports, args);\n};\n';
|
|
174
95
|
|
|
175
96
|
// src/build-plugins/bytecode/utils.ts
|
|
176
97
|
import path from "node:path";
|
|
@@ -347,7 +268,7 @@ async function buildEntry({
|
|
|
347
268
|
entryOutputDirPath,
|
|
348
269
|
nativeModuleEntryMap,
|
|
349
270
|
overrideEsbuildOptions
|
|
350
|
-
},
|
|
271
|
+
}, define, protectedStrings) {
|
|
351
272
|
const option = mergeConfig(
|
|
352
273
|
{
|
|
353
274
|
entryPoints: {
|
|
@@ -366,9 +287,7 @@ async function buildEntry({
|
|
|
366
287
|
loader: {
|
|
367
288
|
".node": "empty"
|
|
368
289
|
},
|
|
369
|
-
define
|
|
370
|
-
__SIGNATURE_CERT__: JSON.stringify(cert)
|
|
371
|
-
}
|
|
290
|
+
define
|
|
372
291
|
},
|
|
373
292
|
overrideEsbuildOptions ?? {}
|
|
374
293
|
);
|
|
@@ -384,7 +303,7 @@ async function buildEntry({
|
|
|
384
303
|
if (isEntry) {
|
|
385
304
|
code = code.replace(
|
|
386
305
|
/(`-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\n`)/,
|
|
387
|
-
(_,
|
|
306
|
+
(_, cert) => `"${cert.slice(1, -1).replace(/\n/g, "\\n")}"`
|
|
388
307
|
);
|
|
389
308
|
}
|
|
390
309
|
const transformedCode = convertString(
|
|
@@ -679,6 +598,28 @@ ${bytecodeLoaderBlock}`) : _code;
|
|
|
679
598
|
function debugStartup(args) {
|
|
680
599
|
process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
|
|
681
600
|
}
|
|
601
|
+
function getMainFilePath(options) {
|
|
602
|
+
let mainFilePath;
|
|
603
|
+
if (typeof options === "string") {
|
|
604
|
+
mainFilePath = basename2(options);
|
|
605
|
+
} else if (Array.isArray(options)) {
|
|
606
|
+
mainFilePath = basename2(options[0]);
|
|
607
|
+
} else {
|
|
608
|
+
const name = options?.index ?? options?.main;
|
|
609
|
+
if (!name) {
|
|
610
|
+
throw new Error(`\`options.main.files\` (${options}) must have "index" or "main" key, like \`{ index: "..." }\``);
|
|
611
|
+
}
|
|
612
|
+
mainFilePath = options?.index ? "index.js" : "main.js";
|
|
613
|
+
}
|
|
614
|
+
return mainFilePath.replace(/\.[cm]?ts$/, ".js");
|
|
615
|
+
}
|
|
616
|
+
function parseVersionPath(versionPath) {
|
|
617
|
+
versionPath = normalizePath2(versionPath);
|
|
618
|
+
if (!versionPath.startsWith("./")) {
|
|
619
|
+
versionPath = "./" + versionPath;
|
|
620
|
+
}
|
|
621
|
+
return new URL(versionPath, "file://").pathname.slice(1);
|
|
622
|
+
}
|
|
682
623
|
async function electronWithUpdater(options) {
|
|
683
624
|
let {
|
|
684
625
|
isBuild,
|
|
@@ -706,8 +647,8 @@ async function electronWithUpdater(options) {
|
|
|
706
647
|
minify = false;
|
|
707
648
|
}
|
|
708
649
|
try {
|
|
709
|
-
|
|
710
|
-
|
|
650
|
+
rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
651
|
+
rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
711
652
|
} catch (ignore) {
|
|
712
653
|
}
|
|
713
654
|
log.info(`remove old files`, { timestamp: true });
|
|
@@ -718,8 +659,21 @@ async function electronWithUpdater(options) {
|
|
|
718
659
|
if (resolve(normalizePath2(pkg.main)) !== resolve(_appPath)) {
|
|
719
660
|
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
720
661
|
}
|
|
662
|
+
const define = {
|
|
663
|
+
__EIU_ELECTRON_DIST_PATH__: JSON.stringify(buildAsarOption.electronDistPath),
|
|
664
|
+
__EIU_ENTRY_DIST_PATH__: JSON.stringify(buildEntryOption.entryOutputDirPath),
|
|
665
|
+
__EIU_IS_DEV__: JSON.stringify(!isBuild),
|
|
666
|
+
__EIU_MAIN_DEV_DIR__: JSON.stringify(buildAsarOption.electronDistPath),
|
|
667
|
+
__EIU_MAIN_FILE__: JSON.stringify(getMainFilePath(_main.files)),
|
|
668
|
+
__EIU_SIGNATURE_CERT__: JSON.stringify(cert),
|
|
669
|
+
__EUI_VERSION_PATH__: JSON.stringify(parseVersionPath(buildVersionOption.versionPath))
|
|
670
|
+
};
|
|
721
671
|
const _buildEntry = async () => {
|
|
722
|
-
await buildEntry(
|
|
672
|
+
await buildEntry(
|
|
673
|
+
buildEntryOption,
|
|
674
|
+
define,
|
|
675
|
+
isBuild ? bytecodeOptions?.protectedStrings : void 0
|
|
676
|
+
);
|
|
723
677
|
log.info(`vite build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
724
678
|
};
|
|
725
679
|
const _postBuild = postBuild ? async () => await postBuild({
|
|
@@ -742,10 +696,6 @@ async function electronWithUpdater(options) {
|
|
|
742
696
|
};
|
|
743
697
|
let isInit = false;
|
|
744
698
|
const rollupOptions = {
|
|
745
|
-
// external: [
|
|
746
|
-
// /^node:/,
|
|
747
|
-
// ...Object.keys('dependencies' in pkg ? pkg.dependencies as object : {}),
|
|
748
|
-
// ],
|
|
749
699
|
external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src)
|
|
750
700
|
};
|
|
751
701
|
const electronPluginOptions = {
|
|
@@ -770,7 +720,8 @@ async function electronWithUpdater(options) {
|
|
|
770
720
|
minify,
|
|
771
721
|
outDir: `${buildAsarOption.electronDistPath}/main`,
|
|
772
722
|
rollupOptions
|
|
773
|
-
}
|
|
723
|
+
},
|
|
724
|
+
define
|
|
774
725
|
},
|
|
775
726
|
_main.vite ?? {}
|
|
776
727
|
)
|
|
@@ -803,7 +754,8 @@ async function electronWithUpdater(options) {
|
|
|
803
754
|
minify,
|
|
804
755
|
outDir: `${buildAsarOption.electronDistPath}/preload`,
|
|
805
756
|
rollupOptions
|
|
806
|
-
}
|
|
757
|
+
},
|
|
758
|
+
define
|
|
807
759
|
},
|
|
808
760
|
_preload.vite ?? {}
|
|
809
761
|
)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"author": "subframe7536",
|
|
7
7
|
"license": "MIT",
|
|
@@ -23,12 +23,18 @@
|
|
|
23
23
|
"./utils": {
|
|
24
24
|
"import": "./dist/utils.js",
|
|
25
25
|
"require": "./dist/utils.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./provider": {
|
|
28
|
+
"import": "./dist/provider.js",
|
|
29
|
+
"require": "./dist/provider.cjs"
|
|
26
30
|
}
|
|
27
31
|
},
|
|
28
32
|
"main": "dist/index.cjs",
|
|
29
33
|
"module": "dist/index.js",
|
|
30
34
|
"files": [
|
|
31
35
|
"dist",
|
|
36
|
+
"provider.d.ts",
|
|
37
|
+
"provider.js",
|
|
32
38
|
"utils.d.ts",
|
|
33
39
|
"utils.js",
|
|
34
40
|
"vite.d.ts",
|
|
@@ -61,15 +67,15 @@
|
|
|
61
67
|
"devDependencies": {
|
|
62
68
|
"@subframe7536/eslint-config": "^0.6.6",
|
|
63
69
|
"@types/babel__core": "^7.20.5",
|
|
64
|
-
"@types/node": "^20.14.
|
|
70
|
+
"@types/node": "^20.14.10",
|
|
65
71
|
"bumpp": "^9.4.1",
|
|
66
72
|
"electron": "28.2.10",
|
|
67
|
-
"eslint": "^9.
|
|
73
|
+
"eslint": "^9.7.0",
|
|
68
74
|
"esno": "^4.7.0",
|
|
69
75
|
"tsup": "^8.1.0",
|
|
70
|
-
"typescript": "^5.5.
|
|
71
|
-
"vite": "^5.3.
|
|
76
|
+
"typescript": "^5.5.3",
|
|
77
|
+
"vite": "^5.3.3",
|
|
72
78
|
"vite-plugin-electron": "^0.28.7",
|
|
73
|
-
"vitest": "^
|
|
79
|
+
"vitest": "^2.0.2"
|
|
74
80
|
}
|
|
75
81
|
}
|
package/provider.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/provider'
|
package/provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/provider.cjs')
|