electron-incremental-update 2.0.1 → 2.1.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/dist/bytecode-I4PMYUGT.js +166 -0
- package/dist/chunk-5CE27A6G.js +44 -0
- package/dist/chunk-5NKEXGI3.js +10 -0
- package/dist/chunk-7IRGAAL2.js +5 -0
- package/dist/chunk-7M7DIMDN.js +43 -0
- package/dist/chunk-AUY7A2FL.js +147 -0
- package/dist/chunk-WYQ5DRO7.js +12 -0
- package/dist/chunk-ZM5CIZ4L.js +106 -0
- package/dist/code-P5OANH3Q.js +1 -0
- package/dist/constant-ME27JB5D.js +1 -0
- package/dist/esm-ZFXJ56BN.js +26 -0
- package/dist/index.cjs +36 -36
- package/dist/index.d.cts +7 -44
- package/dist/index.d.ts +7 -44
- package/dist/index.js +39 -38
- package/dist/provider.cjs +140 -18
- package/dist/provider.d.cts +67 -10
- package/dist/provider.d.ts +67 -10
- package/dist/provider.js +140 -20
- package/dist/types-1Hc4F8aC.d.ts +117 -0
- package/dist/types-jAPZkKmv.d.cts +117 -0
- package/dist/utils-JZ4CMTJG.js +4 -0
- package/dist/utils-KPSYP7HQ.js +5 -0
- package/dist/utils.cjs +23 -2
- package/dist/utils.d.cts +14 -2
- package/dist/utils.d.ts +14 -2
- package/dist/utils.js +1 -1
- package/dist/{version-BYVQ367i.d.ts → version-DcFMG3pT.d.cts} +1 -1
- package/dist/{version-BYVQ367i.d.cts → version-DcFMG3pT.d.ts} +1 -1
- package/dist/vite.js +82 -404
- package/package.json +10 -10
- package/dist/chunk-GTDMND3I.js +0 -87
- package/dist/types-BLdN9rkY.d.ts +0 -72
- package/dist/types-DkCn03M3.d.cts +0 -72
package/dist/vite.js
CHANGED
|
@@ -1,218 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { readableSize } from './chunk-WYQ5DRO7.js';
|
|
2
|
+
import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-7M7DIMDN.js';
|
|
3
|
+
import { log, id, bytecodeLog } from './chunk-5NKEXGI3.js';
|
|
4
|
+
import path3 from 'node:path';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { normalizePath, mergeConfig } from 'vite';
|
|
4
7
|
import ElectronSimple from 'vite-plugin-electron/simple';
|
|
5
8
|
import { startup } from 'vite-plugin-electron';
|
|
6
9
|
import { notBundle } from 'vite-plugin-electron/plugin';
|
|
7
|
-
import {
|
|
10
|
+
import { loadPackageJSON } from 'local-pkg';
|
|
8
11
|
import { isCI } from 'ci-info';
|
|
9
12
|
export { isCI } from 'ci-info';
|
|
10
13
|
import Asar from '@electron/asar';
|
|
11
14
|
import { build } from 'esbuild';
|
|
12
|
-
import cp from 'node:child_process';
|
|
13
|
-
import * as babel from '@babel/core';
|
|
14
|
-
import MagicString from 'magic-string';
|
|
15
15
|
import zlib from 'node:zlib';
|
|
16
16
|
import crypto from 'node:crypto';
|
|
17
17
|
import { generate } from 'selfsigned';
|
|
18
18
|
|
|
19
|
-
// src/vite/index.ts
|
|
20
|
-
|
|
21
|
-
// src/utils/version.ts
|
|
22
|
-
function parseVersion(version) {
|
|
23
|
-
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
24
|
-
if (!match) {
|
|
25
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
26
|
-
}
|
|
27
|
-
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
28
|
-
const ret = {
|
|
29
|
-
major,
|
|
30
|
-
minor,
|
|
31
|
-
patch,
|
|
32
|
-
stage: "",
|
|
33
|
-
stageVersion: -1
|
|
34
|
-
};
|
|
35
|
-
if (match[4]) {
|
|
36
|
-
let [stage, _v] = match[4].split(".");
|
|
37
|
-
ret.stage = stage;
|
|
38
|
-
ret.stageVersion = Number(_v) || -1;
|
|
39
|
-
}
|
|
40
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
41
|
-
throw new TypeError(`Invalid version: ${version}`);
|
|
42
|
-
}
|
|
43
|
-
return ret;
|
|
44
|
-
}
|
|
45
|
-
function isUpdateJSON(json) {
|
|
46
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
47
|
-
return is(json) && is(json?.beta);
|
|
48
|
-
}
|
|
49
|
-
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
|
50
|
-
existingJson.beta = {
|
|
51
|
-
version,
|
|
52
|
-
minimumVersion,
|
|
53
|
-
signature
|
|
54
|
-
};
|
|
55
|
-
if (!parseVersion(version).stage) {
|
|
56
|
-
existingJson.version = version;
|
|
57
|
-
existingJson.minimumVersion = minimumVersion;
|
|
58
|
-
existingJson.signature = signature;
|
|
59
|
-
}
|
|
60
|
-
return existingJson;
|
|
61
|
-
}
|
|
62
|
-
var id = "electron-incremental-updater";
|
|
63
|
-
var bytecodeId = `${id}-bytecode`;
|
|
64
|
-
var log = createLogger("info", { prefix: `[${id}]` });
|
|
65
|
-
var bytecodeLog = createLogger("info", { prefix: `[${bytecodeId}]` });
|
|
66
|
-
|
|
67
|
-
// src/vite/bytecode/code.ts
|
|
68
|
-
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";
|
|
69
|
-
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';
|
|
70
|
-
var electronModulePath = getPackageInfoSync("electron")?.rootPath;
|
|
71
|
-
var useStrict = "'use strict';";
|
|
72
|
-
var bytecodeModuleLoader = "__loader__.js";
|
|
73
|
-
function getElectronPath() {
|
|
74
|
-
let electronExecPath = process.env.ELECTRON_EXEC_PATH || "";
|
|
75
|
-
if (!electronExecPath) {
|
|
76
|
-
if (!electronModulePath) {
|
|
77
|
-
throw new Error("Electron is not installed");
|
|
78
|
-
}
|
|
79
|
-
const pathFile = path5.join(electronModulePath, "path.txt");
|
|
80
|
-
let executablePath;
|
|
81
|
-
if (fs3.existsSync(pathFile)) {
|
|
82
|
-
executablePath = fs3.readFileSync(pathFile, "utf-8");
|
|
83
|
-
}
|
|
84
|
-
if (executablePath) {
|
|
85
|
-
electronExecPath = path5.join(electronModulePath, "dist", executablePath);
|
|
86
|
-
process.env.ELECTRON_EXEC_PATH = electronExecPath;
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error("Electron executable file is not existed");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return electronExecPath;
|
|
92
|
-
}
|
|
93
|
-
function getBytecodeCompilerPath() {
|
|
94
|
-
const scriptPath = path5.join(electronModulePath, "EIU_bytenode.cjs");
|
|
95
|
-
if (!fs3.existsSync(scriptPath)) {
|
|
96
|
-
fs3.writeFileSync(scriptPath, bytecodeGeneratorScript);
|
|
97
|
-
}
|
|
98
|
-
return scriptPath;
|
|
99
|
-
}
|
|
100
|
-
function toRelativePath(filename, importer) {
|
|
101
|
-
const relPath = path5.posix.relative(path5.dirname(importer), filename);
|
|
102
|
-
return relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
103
|
-
}
|
|
104
|
-
function compileToBytecode(code, electronPath = getElectronPath()) {
|
|
105
|
-
let data = Buffer.from([]);
|
|
106
|
-
const logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
107
|
-
const bytecodePath = getBytecodeCompilerPath();
|
|
108
|
-
return new Promise((resolve, reject) => {
|
|
109
|
-
const proc = cp.spawn(electronPath, [bytecodePath], {
|
|
110
|
-
env: { ELECTRON_RUN_AS_NODE: "1" },
|
|
111
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
112
|
-
});
|
|
113
|
-
if (proc.stdin) {
|
|
114
|
-
proc.stdin.write(code);
|
|
115
|
-
proc.stdin.end();
|
|
116
|
-
}
|
|
117
|
-
if (proc.stdout) {
|
|
118
|
-
proc.stdout.on("data", (chunk) => data = Buffer.concat([data, chunk]));
|
|
119
|
-
proc.stdout.on("error", (err) => logErr(err));
|
|
120
|
-
proc.stdout.on("end", () => resolve(data));
|
|
121
|
-
}
|
|
122
|
-
if (proc.stderr) {
|
|
123
|
-
proc.stderr.on("data", (chunk) => logErr("Error: ", chunk.toString()));
|
|
124
|
-
proc.stderr.on("error", (err) => logErr("Error: ", err));
|
|
125
|
-
}
|
|
126
|
-
proc.addListener("error", (err) => logErr(err));
|
|
127
|
-
proc.on("error", (err) => reject(err));
|
|
128
|
-
proc.on("exit", () => resolve(data));
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
function convertArrowFunctionAndTemplate(code) {
|
|
132
|
-
const result = babel.transform(code, {
|
|
133
|
-
plugins: ["@babel/plugin-transform-arrow-functions", "@babel/plugin-transform-template-literals"]
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
code: result?.code || code,
|
|
137
|
-
map: result?.map
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
|
|
141
|
-
function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
|
|
142
|
-
const hexArray = input.split("").map((c) => `0x${(c.charCodeAt(0) + offset).toString(16)}`);
|
|
143
|
-
return `_0xstr_([${hexArray.join(",")}],${offset})`;
|
|
144
|
-
}
|
|
145
|
-
function convertLiteral(code, sourcemap, offset) {
|
|
146
|
-
const s = new MagicString(code);
|
|
147
|
-
let hasTransformed = false;
|
|
148
|
-
const ast = babel.parse(code, { ast: true });
|
|
149
|
-
if (!ast) {
|
|
150
|
-
throw new Error("Cannot parse code");
|
|
151
|
-
}
|
|
152
|
-
babel.traverse(ast, {
|
|
153
|
-
StringLiteral(path6) {
|
|
154
|
-
const parent = path6.parent;
|
|
155
|
-
const node = path6.node;
|
|
156
|
-
if (parent.type === "CallExpression") {
|
|
157
|
-
if (parent.callee.type === "Identifier" && parent.callee.name === "require") {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (parent.callee.type === "Import") {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (parent.type.startsWith("Export")) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (parent.type.startsWith("Import")) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (parent.type === "ObjectMethod" && parent.key === node) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (parent.type === "ObjectProperty" && parent.key === node) {
|
|
174
|
-
const result2 = `[${obfuscateString(node.value, offset)}]`;
|
|
175
|
-
const start2 = node.start;
|
|
176
|
-
const end2 = node.end;
|
|
177
|
-
if (start2 && end2) {
|
|
178
|
-
s.overwrite(start2, end2, result2);
|
|
179
|
-
hasTransformed = true;
|
|
180
|
-
}
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (!node.value.trim()) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const result = obfuscateString(node.value, offset);
|
|
187
|
-
const start = node.start;
|
|
188
|
-
const end = node.end;
|
|
189
|
-
if (start && end) {
|
|
190
|
-
s.overwrite(start, end, result);
|
|
191
|
-
hasTransformed = true;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
if (hasTransformed) {
|
|
196
|
-
s.append("\n").append(decodeFn);
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
code: s.toString(),
|
|
200
|
-
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// src/vite/utils.ts
|
|
205
|
-
function readableSize(size) {
|
|
206
|
-
const units = ["B", "KB", "MB", "GB"];
|
|
207
|
-
let i = 0;
|
|
208
|
-
while (size >= 1024 && i < units.length - 1) {
|
|
209
|
-
size /= 1024;
|
|
210
|
-
i++;
|
|
211
|
-
}
|
|
212
|
-
return `${size.toFixed(2)} ${units[i]}`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/vite/build.ts
|
|
216
19
|
async function buildAsar({
|
|
217
20
|
version,
|
|
218
21
|
asarOutputPath,
|
|
@@ -221,11 +24,11 @@ async function buildAsar({
|
|
|
221
24
|
rendererDistPath,
|
|
222
25
|
generateGzipFile
|
|
223
26
|
}) {
|
|
224
|
-
|
|
225
|
-
|
|
27
|
+
fs.renameSync(rendererDistPath, path3.join(electronDistPath, "renderer"));
|
|
28
|
+
fs.writeFileSync(path3.join(electronDistPath, "version"), version);
|
|
226
29
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
227
|
-
const buf = await generateGzipFile(
|
|
228
|
-
|
|
30
|
+
const buf = await generateGzipFile(fs.readFileSync(asarOutputPath));
|
|
31
|
+
fs.writeFileSync(gzipPath, buf);
|
|
229
32
|
log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
|
|
230
33
|
return buf;
|
|
231
34
|
}
|
|
@@ -248,9 +51,9 @@ async function buildVersion({
|
|
|
248
51
|
signature: "",
|
|
249
52
|
version
|
|
250
53
|
};
|
|
251
|
-
if (
|
|
54
|
+
if (fs.existsSync(versionPath)) {
|
|
252
55
|
try {
|
|
253
|
-
const oldVersionJson = JSON.parse(
|
|
56
|
+
const oldVersionJson = JSON.parse(fs.readFileSync(versionPath, "utf-8"));
|
|
254
57
|
if (isUpdateJSON(oldVersionJson)) {
|
|
255
58
|
_json = oldVersionJson;
|
|
256
59
|
} else {
|
|
@@ -264,7 +67,7 @@ async function buildVersion({
|
|
|
264
67
|
if (!isUpdateJSON(_json)) {
|
|
265
68
|
throw new Error("Invalid version info");
|
|
266
69
|
}
|
|
267
|
-
|
|
70
|
+
fs.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
268
71
|
log.info(`build version info to '${versionPath}'`, { timestamp: true });
|
|
269
72
|
}
|
|
270
73
|
async function buildEntry({
|
|
@@ -295,7 +98,26 @@ async function buildEntry({
|
|
|
295
98
|
".node": "empty"
|
|
296
99
|
},
|
|
297
100
|
define,
|
|
298
|
-
format: isESM ? "esm" : "cjs"
|
|
101
|
+
format: isESM ? "esm" : "cjs",
|
|
102
|
+
write: !isESM,
|
|
103
|
+
plugins: isESM ? [
|
|
104
|
+
{
|
|
105
|
+
name: "entry-esm-shim",
|
|
106
|
+
setup(build2) {
|
|
107
|
+
build2.onEnd(async ({ outputFiles }) => {
|
|
108
|
+
const parse = (await import('./utils-KPSYP7HQ.js')).insertCJSShim;
|
|
109
|
+
fs.mkdirSync(entryOutputDirPath, { recursive: true });
|
|
110
|
+
outputFiles?.filter((file) => file.path.endsWith(".js")).forEach((file) => {
|
|
111
|
+
const output = parse(file.text, sourcemap);
|
|
112
|
+
fs.writeFileSync(file.path, output?.code || file.text, "utf-8");
|
|
113
|
+
if (sourcemap && output?.map) {
|
|
114
|
+
fs.writeFileSync(`${file.path}.map`, output.map.toString(), "utf-8");
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
] : void 0
|
|
299
121
|
},
|
|
300
122
|
overrideEsbuildOptions ?? {}
|
|
301
123
|
);
|
|
@@ -304,9 +126,16 @@ async function buildEntry({
|
|
|
304
126
|
return;
|
|
305
127
|
}
|
|
306
128
|
const filePaths = Object.keys(metafile?.outputs ?? []).filter((filePath) => filePath.endsWith("js"));
|
|
129
|
+
const {
|
|
130
|
+
compileToBytecode,
|
|
131
|
+
convertArrowFunctionAndTemplate,
|
|
132
|
+
convertLiteral,
|
|
133
|
+
useStrict
|
|
134
|
+
} = await import('./utils-JZ4CMTJG.js');
|
|
135
|
+
const { bytecodeModuleLoaderCode } = await import('./code-P5OANH3Q.js');
|
|
307
136
|
for (const filePath of filePaths) {
|
|
308
|
-
let code =
|
|
309
|
-
const fileName =
|
|
137
|
+
let code = fs.readFileSync(filePath, "utf-8");
|
|
138
|
+
const fileName = path3.basename(filePath);
|
|
310
139
|
const isEntry = fileName.endsWith("entry.js");
|
|
311
140
|
let transformedCode = convertLiteral(convertArrowFunctionAndTemplate(code).code).code;
|
|
312
141
|
if (bytecodeOptions.beforeCompile) {
|
|
@@ -316,11 +145,11 @@ async function buildEntry({
|
|
|
316
145
|
}
|
|
317
146
|
}
|
|
318
147
|
const buffer = await compileToBytecode(transformedCode, bytecodeOptions.electronPath);
|
|
319
|
-
|
|
148
|
+
fs.writeFileSync(
|
|
320
149
|
filePath,
|
|
321
150
|
`${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
|
|
322
151
|
);
|
|
323
|
-
|
|
152
|
+
fs.writeFileSync(`${filePath}c`, buffer);
|
|
324
153
|
bytecodeLog.info(
|
|
325
154
|
`${filePath} [${(buffer.byteLength / 1e3).toFixed(2)} kB]`,
|
|
326
155
|
{ timestamp: true }
|
|
@@ -352,21 +181,21 @@ function defaultSignature(buffer, privateKey, cert, version) {
|
|
|
352
181
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
353
182
|
}
|
|
354
183
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
355
|
-
const privateKeyDir =
|
|
356
|
-
if (!
|
|
357
|
-
|
|
184
|
+
const privateKeyDir = path3.dirname(privateKeyPath);
|
|
185
|
+
if (!fs.existsSync(privateKeyDir)) {
|
|
186
|
+
fs.mkdirSync(privateKeyDir, { recursive: true });
|
|
358
187
|
}
|
|
359
|
-
const certDir =
|
|
360
|
-
if (!
|
|
361
|
-
|
|
188
|
+
const certDir = path3.dirname(certPath);
|
|
189
|
+
if (!fs.existsSync(certDir)) {
|
|
190
|
+
fs.mkdirSync(certDir, { recursive: true });
|
|
362
191
|
}
|
|
363
192
|
const { cert, private: privateKey } = generate(subject, {
|
|
364
193
|
keySize: keyLength,
|
|
365
194
|
algorithm: "sha256",
|
|
366
195
|
days
|
|
367
196
|
});
|
|
368
|
-
|
|
369
|
-
|
|
197
|
+
fs.writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
198
|
+
fs.writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
370
199
|
}
|
|
371
200
|
function parseKeys({
|
|
372
201
|
keyLength,
|
|
@@ -375,22 +204,22 @@ function parseKeys({
|
|
|
375
204
|
subject,
|
|
376
205
|
days
|
|
377
206
|
}) {
|
|
378
|
-
const keysDir =
|
|
207
|
+
const keysDir = path3.dirname(privateKeyPath);
|
|
379
208
|
let privateKey = process.env.UPDATER_PK;
|
|
380
209
|
let cert = process.env.UPDATER_CERT;
|
|
381
210
|
if (privateKey && cert) {
|
|
382
211
|
log.info("Use `UPDATER_PK` and `UPDATER_CERT` from environment variables", { timestamp: true });
|
|
383
212
|
return { privateKey, cert };
|
|
384
213
|
}
|
|
385
|
-
if (!
|
|
386
|
-
|
|
214
|
+
if (!fs.existsSync(keysDir)) {
|
|
215
|
+
fs.mkdirSync(keysDir);
|
|
387
216
|
}
|
|
388
|
-
if (!
|
|
217
|
+
if (!fs.existsSync(privateKeyPath) || !fs.existsSync(certPath)) {
|
|
389
218
|
log.info("No key pair found, generate new key pair", { timestamp: true });
|
|
390
219
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
391
220
|
}
|
|
392
|
-
privateKey =
|
|
393
|
-
cert =
|
|
221
|
+
privateKey = fs.readFileSync(privateKeyPath, "utf-8");
|
|
222
|
+
cert = fs.readFileSync(certPath, "utf-8");
|
|
394
223
|
return { privateKey, cert };
|
|
395
224
|
}
|
|
396
225
|
function parseSubjects(subject) {
|
|
@@ -469,160 +298,6 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
469
298
|
};
|
|
470
299
|
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
|
|
471
300
|
}
|
|
472
|
-
function bytecodePlugin(env, options) {
|
|
473
|
-
const {
|
|
474
|
-
enable,
|
|
475
|
-
preload = false,
|
|
476
|
-
electronPath,
|
|
477
|
-
beforeCompile
|
|
478
|
-
} = options;
|
|
479
|
-
if (!enable) {
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
if (!preload && env === "preload") {
|
|
483
|
-
bytecodeLog.warn('`bytecodePlugin` is skiped in preload. To enable in preload, please manually set the "enablePreload" option to true and set `sandbox: false` when creating the window', { timestamp: true });
|
|
484
|
-
return null;
|
|
485
|
-
}
|
|
486
|
-
const filter = createFilter(/\.(m?[jt]s|[jt]sx)$/);
|
|
487
|
-
let config;
|
|
488
|
-
let bytecodeRequired = false;
|
|
489
|
-
let bytecodeFiles = [];
|
|
490
|
-
return {
|
|
491
|
-
name: `${bytecodeId}-${env}`,
|
|
492
|
-
apply: "build",
|
|
493
|
-
enforce: "post",
|
|
494
|
-
configResolved(resolvedConfig) {
|
|
495
|
-
config = resolvedConfig;
|
|
496
|
-
},
|
|
497
|
-
transform(code, id2) {
|
|
498
|
-
if (!filter(id2)) {
|
|
499
|
-
return convertLiteral(code, !!config.build.sourcemap);
|
|
500
|
-
}
|
|
501
|
-
},
|
|
502
|
-
generateBundle(options2) {
|
|
503
|
-
if (options2.format !== "es" && bytecodeRequired) {
|
|
504
|
-
this.emitFile({
|
|
505
|
-
type: "asset",
|
|
506
|
-
source: `${bytecodeModuleLoaderCode}
|
|
507
|
-
`,
|
|
508
|
-
name: "Bytecode Loader File",
|
|
509
|
-
fileName: bytecodeModuleLoader
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
},
|
|
513
|
-
renderChunk(code, chunk, options2) {
|
|
514
|
-
if (options2.format === "es") {
|
|
515
|
-
bytecodeLog.warn(
|
|
516
|
-
'`bytecodePlugin` does not support ES module, please set "build.rollupOptions.output.format" option to "cjs"',
|
|
517
|
-
{ timestamp: true }
|
|
518
|
-
);
|
|
519
|
-
return null;
|
|
520
|
-
}
|
|
521
|
-
if (chunk.type === "chunk") {
|
|
522
|
-
bytecodeRequired = true;
|
|
523
|
-
return convertArrowFunctionAndTemplate(code);
|
|
524
|
-
}
|
|
525
|
-
return null;
|
|
526
|
-
},
|
|
527
|
-
async writeBundle(options2, output) {
|
|
528
|
-
if (options2.format === "es" || !bytecodeRequired) {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
const outDir = options2.dir;
|
|
532
|
-
bytecodeFiles = [];
|
|
533
|
-
const bundles = Object.keys(output);
|
|
534
|
-
const chunks = Object.values(output).filter(
|
|
535
|
-
(chunk) => chunk.type === "chunk" && chunk.fileName !== bytecodeModuleLoader
|
|
536
|
-
);
|
|
537
|
-
const bytecodeChunks = chunks.map((chunk) => chunk.fileName);
|
|
538
|
-
const nonEntryChunks = chunks.filter((chunk) => !chunk.isEntry).map((chunk) => path5.basename(chunk.fileName));
|
|
539
|
-
const pattern = nonEntryChunks.map((chunk) => `(${chunk})`).join("|");
|
|
540
|
-
const bytecodeRE = pattern ? new RegExp(`require\\(\\S*(?=(${pattern})\\S*\\))`, "g") : null;
|
|
541
|
-
const getBytecodeLoaderBlock = (chunkFileName) => {
|
|
542
|
-
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
543
|
-
};
|
|
544
|
-
await Promise.all(
|
|
545
|
-
bundles.map(async (name) => {
|
|
546
|
-
const chunk = output[name];
|
|
547
|
-
if (chunk.type === "chunk") {
|
|
548
|
-
let _code = chunk.code;
|
|
549
|
-
const chunkFilePath = path5.resolve(outDir, name);
|
|
550
|
-
if (beforeCompile) {
|
|
551
|
-
const cbResult = await beforeCompile(_code, chunkFilePath);
|
|
552
|
-
if (cbResult) {
|
|
553
|
-
_code = cbResult;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (bytecodeRE && _code.match(bytecodeRE)) {
|
|
557
|
-
let match;
|
|
558
|
-
const s = new MagicString(_code);
|
|
559
|
-
while (match = bytecodeRE.exec(_code)) {
|
|
560
|
-
const [prefix, chunkName] = match;
|
|
561
|
-
const len = prefix.length + chunkName.length;
|
|
562
|
-
s.overwrite(match.index, match.index + len, `${prefix + chunkName}c`, {
|
|
563
|
-
contentOnly: true
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
_code = s.toString();
|
|
567
|
-
}
|
|
568
|
-
if (bytecodeChunks.includes(name)) {
|
|
569
|
-
const bytecodeBuffer = await compileToBytecode(_code, electronPath);
|
|
570
|
-
fs3.writeFileSync(`${chunkFilePath}c`, bytecodeBuffer);
|
|
571
|
-
if (chunk.isEntry) {
|
|
572
|
-
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
573
|
-
const bytecodeModuleBlock = `require("./${`${path5.basename(name)}c`}");`;
|
|
574
|
-
const code = `${useStrict}
|
|
575
|
-
${bytecodeLoaderBlock}
|
|
576
|
-
module.exports=${bytecodeModuleBlock}
|
|
577
|
-
`;
|
|
578
|
-
fs3.writeFileSync(chunkFilePath, code);
|
|
579
|
-
} else {
|
|
580
|
-
fs3.unlinkSync(chunkFilePath);
|
|
581
|
-
}
|
|
582
|
-
bytecodeFiles.push({ name: `${name}c`, size: bytecodeBuffer.length });
|
|
583
|
-
} else {
|
|
584
|
-
if (chunk.isEntry) {
|
|
585
|
-
let hasBytecodeMoudle = false;
|
|
586
|
-
const idsToHandle = /* @__PURE__ */ new Set([...chunk.imports, ...chunk.dynamicImports]);
|
|
587
|
-
for (const moduleId of idsToHandle) {
|
|
588
|
-
if (bytecodeChunks.includes(moduleId)) {
|
|
589
|
-
hasBytecodeMoudle = true;
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
const moduleInfo = this.getModuleInfo(moduleId);
|
|
593
|
-
if (moduleInfo && !moduleInfo.isExternal) {
|
|
594
|
-
const { importers, dynamicImporters } = moduleInfo;
|
|
595
|
-
for (const importerId of importers) {
|
|
596
|
-
idsToHandle.add(importerId);
|
|
597
|
-
}
|
|
598
|
-
for (const importerId of dynamicImporters) {
|
|
599
|
-
idsToHandle.add(importerId);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
604
|
-
_code = hasBytecodeMoudle ? _code.replace(useStrict, `${useStrict}
|
|
605
|
-
${bytecodeLoaderBlock}`) : _code;
|
|
606
|
-
}
|
|
607
|
-
fs3.writeFileSync(chunkFilePath, _code);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
})
|
|
611
|
-
);
|
|
612
|
-
},
|
|
613
|
-
closeBundle() {
|
|
614
|
-
const outDir = `${normalizePath(path5.relative(config.root, path5.resolve(config.root, config.build.outDir)))}/`;
|
|
615
|
-
bytecodeFiles.forEach((file) => {
|
|
616
|
-
bytecodeLog.info(
|
|
617
|
-
`${outDir}${file.name} [${readableSize(file.size)}]`,
|
|
618
|
-
{ timestamp: true }
|
|
619
|
-
);
|
|
620
|
-
});
|
|
621
|
-
bytecodeLog.info(`${bytecodeFiles.length} bundles compiled into bytecode.`, { timestamp: true });
|
|
622
|
-
bytecodeFiles = [];
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
301
|
function debugStartup(args) {
|
|
627
302
|
if (process.env.VSCODE_DEBUG) {
|
|
628
303
|
console.log("[startup] Electron App");
|
|
@@ -633,9 +308,9 @@ function debugStartup(args) {
|
|
|
633
308
|
function getMainFilePath(options) {
|
|
634
309
|
let mainFilePath;
|
|
635
310
|
if (typeof options === "string") {
|
|
636
|
-
mainFilePath =
|
|
311
|
+
mainFilePath = path3.basename(options);
|
|
637
312
|
} else if (Array.isArray(options)) {
|
|
638
|
-
mainFilePath =
|
|
313
|
+
mainFilePath = path3.basename(options[0]);
|
|
639
314
|
} else {
|
|
640
315
|
const name = options?.index ?? options?.main;
|
|
641
316
|
if (!name) {
|
|
@@ -674,7 +349,7 @@ async function electronWithUpdater(options) {
|
|
|
674
349
|
const isESM = pkg.type === "module";
|
|
675
350
|
let bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { enable: true } : void 0;
|
|
676
351
|
if (isESM && bytecodeOptions?.enable) {
|
|
677
|
-
bytecodeLog.warn(
|
|
352
|
+
(await import('./constant-ME27JB5D.js')).bytecodeLog.warn(
|
|
678
353
|
'`bytecodePlugin` does not support ES module, please remove "type": "module" in package.json',
|
|
679
354
|
{ timestamp: true }
|
|
680
355
|
);
|
|
@@ -689,25 +364,25 @@ async function electronWithUpdater(options) {
|
|
|
689
364
|
} = parseOptions(pkg, sourcemap, minify, updater);
|
|
690
365
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
691
366
|
try {
|
|
692
|
-
|
|
693
|
-
|
|
367
|
+
fs.rmSync(buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
368
|
+
fs.rmSync(entryOutputDirPath, { recursive: true, force: true });
|
|
694
369
|
} catch {
|
|
695
370
|
}
|
|
696
371
|
log.info(`Clear cache files`, { timestamp: true });
|
|
697
372
|
sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
|
|
698
|
-
const _appPath = normalizePath(
|
|
699
|
-
if (
|
|
373
|
+
const _appPath = normalizePath(path3.join(entryOutputDirPath, "entry.js"));
|
|
374
|
+
if (path3.resolve(normalizePath(pkg.main)) !== path3.resolve(_appPath)) {
|
|
700
375
|
throw new Error(`Wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
701
376
|
}
|
|
702
377
|
const define = {
|
|
703
|
-
__EIU_ELECTRON_DIST_PATH__: JSON.stringify(buildAsarOption.electronDistPath),
|
|
704
|
-
__EIU_ENTRY_DIST_PATH__: JSON.stringify(buildEntryOption.entryOutputDirPath),
|
|
378
|
+
__EIU_ELECTRON_DIST_PATH__: JSON.stringify(normalizePath(buildAsarOption.electronDistPath)),
|
|
379
|
+
__EIU_ENTRY_DIST_PATH__: JSON.stringify(normalizePath(buildEntryOption.entryOutputDirPath)),
|
|
705
380
|
__EIU_IS_DEV__: JSON.stringify(!isBuild),
|
|
706
381
|
__EIU_IS_ESM__: JSON.stringify(isESM),
|
|
707
|
-
__EIU_MAIN_DEV_DIR__: JSON.stringify(buildAsarOption.electronDistPath),
|
|
382
|
+
__EIU_MAIN_DEV_DIR__: JSON.stringify(normalizePath(buildAsarOption.electronDistPath)),
|
|
708
383
|
__EIU_MAIN_FILE__: JSON.stringify(getMainFilePath(_main.files)),
|
|
709
384
|
__EIU_SIGNATURE_CERT__: JSON.stringify(cert),
|
|
710
|
-
__EIU_VERSION_PATH__: JSON.stringify(parseVersionPath(buildVersionOption.versionPath))
|
|
385
|
+
__EIU_VERSION_PATH__: JSON.stringify(parseVersionPath(normalizePath(buildVersionOption.versionPath)))
|
|
711
386
|
};
|
|
712
387
|
const _buildEntry = async () => {
|
|
713
388
|
await buildEntry(
|
|
@@ -720,14 +395,14 @@ async function electronWithUpdater(options) {
|
|
|
720
395
|
};
|
|
721
396
|
const _postBuild = postBuild ? async () => await postBuild({
|
|
722
397
|
getPathFromEntryOutputDir(...paths) {
|
|
723
|
-
return
|
|
398
|
+
return path3.join(entryOutputDirPath, ...paths);
|
|
724
399
|
},
|
|
725
400
|
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
726
|
-
if (
|
|
727
|
-
const target =
|
|
728
|
-
if (!skipIfExist || !
|
|
401
|
+
if (fs.existsSync(from)) {
|
|
402
|
+
const target = path3.join(entryOutputDirPath, to ?? path3.basename(from));
|
|
403
|
+
if (!skipIfExist || !fs.existsSync(target)) {
|
|
729
404
|
try {
|
|
730
|
-
|
|
405
|
+
fs.cpSync(from, target);
|
|
731
406
|
} catch (error) {
|
|
732
407
|
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
733
408
|
}
|
|
@@ -741,6 +416,7 @@ async function electronWithUpdater(options) {
|
|
|
741
416
|
external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src) || src === "original-fs",
|
|
742
417
|
treeshake: true
|
|
743
418
|
};
|
|
419
|
+
const esmShimPlugin = isESM ? (await import('./esm-ZFXJ56BN.js')).esm() : void 0;
|
|
744
420
|
const electronPluginOptions = {
|
|
745
421
|
main: {
|
|
746
422
|
entry: _main.files,
|
|
@@ -760,7 +436,8 @@ async function electronWithUpdater(options) {
|
|
|
760
436
|
{
|
|
761
437
|
plugins: [
|
|
762
438
|
!isBuild && useNotBundle ? notBundle() : void 0,
|
|
763
|
-
bytecodeOptions && bytecodePlugin("main", bytecodeOptions)
|
|
439
|
+
bytecodeOptions && (await import('./bytecode-I4PMYUGT.js')).bytecodePlugin("main", bytecodeOptions),
|
|
440
|
+
esmShimPlugin
|
|
764
441
|
],
|
|
765
442
|
build: {
|
|
766
443
|
sourcemap,
|
|
@@ -779,7 +456,8 @@ async function electronWithUpdater(options) {
|
|
|
779
456
|
vite: mergeConfig(
|
|
780
457
|
{
|
|
781
458
|
plugins: [
|
|
782
|
-
bytecodeOptions && bytecodePlugin("preload", bytecodeOptions),
|
|
459
|
+
bytecodeOptions && (await import('./bytecode-I4PMYUGT.js')).bytecodePlugin("preload", bytecodeOptions),
|
|
460
|
+
esmShimPlugin,
|
|
783
461
|
{
|
|
784
462
|
name: `${id}-build`,
|
|
785
463
|
enforce: "post",
|
|
@@ -791,7 +469,7 @@ async function electronWithUpdater(options) {
|
|
|
791
469
|
await _postBuild();
|
|
792
470
|
const buffer = await buildAsar(buildAsarOption);
|
|
793
471
|
if (!buildVersionJson && !isCI) {
|
|
794
|
-
log.warn("No `buildVersionJson` setup, skip build version json.
|
|
472
|
+
log.warn("No `buildVersionJson` option setup, skip build version json. Only build in CI by default", { timestamp: true });
|
|
795
473
|
} else {
|
|
796
474
|
await buildVersion(buildVersionOption, buffer);
|
|
797
475
|
}
|
|
@@ -828,7 +506,7 @@ async function electronWithUpdater(options) {
|
|
|
828
506
|
const files = [
|
|
829
507
|
...Object.values(nativeModuleEntryMap),
|
|
830
508
|
appEntryPath
|
|
831
|
-
].map((file) =>
|
|
509
|
+
].map((file) => path3.resolve(normalizePath(file)));
|
|
832
510
|
extraHmrPlugin = {
|
|
833
511
|
name: `${id}-dev`,
|
|
834
512
|
apply() {
|