electron-incremental-update 2.0.0 → 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/README.md +20 -1
- 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.d.ts +4 -0
- package/dist/vite.js +83 -405
- package/package.json +10 -10
- package/dist/chunk-IABBXJFB.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,219 +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) {
|
|
105
|
-
let data = Buffer.from([]);
|
|
106
|
-
const logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
107
|
-
const electronPath = getElectronPath();
|
|
108
|
-
const bytecodePath = getBytecodeCompilerPath();
|
|
109
|
-
return new Promise((resolve, reject) => {
|
|
110
|
-
const proc = cp.spawn(electronPath, [bytecodePath], {
|
|
111
|
-
env: { ELECTRON_RUN_AS_NODE: "1" },
|
|
112
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
113
|
-
});
|
|
114
|
-
if (proc.stdin) {
|
|
115
|
-
proc.stdin.write(code);
|
|
116
|
-
proc.stdin.end();
|
|
117
|
-
}
|
|
118
|
-
if (proc.stdout) {
|
|
119
|
-
proc.stdout.on("data", (chunk) => data = Buffer.concat([data, chunk]));
|
|
120
|
-
proc.stdout.on("error", (err) => logErr(err));
|
|
121
|
-
proc.stdout.on("end", () => resolve(data));
|
|
122
|
-
}
|
|
123
|
-
if (proc.stderr) {
|
|
124
|
-
proc.stderr.on("data", (chunk) => logErr("Error: ", chunk.toString()));
|
|
125
|
-
proc.stderr.on("error", (err) => logErr("Error: ", err));
|
|
126
|
-
}
|
|
127
|
-
proc.addListener("error", (err) => logErr(err));
|
|
128
|
-
proc.on("error", (err) => reject(err));
|
|
129
|
-
proc.on("exit", () => resolve(data));
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function convertArrowFunctionAndTemplate(code) {
|
|
133
|
-
const result = babel.transform(code, {
|
|
134
|
-
plugins: ["@babel/plugin-transform-arrow-functions", "@babel/plugin-transform-template-literals"]
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
code: result?.code || code,
|
|
138
|
-
map: result?.map
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
|
|
142
|
-
function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
|
|
143
|
-
const hexArray = input.split("").map((c) => `0x${(c.charCodeAt(0) + offset).toString(16)}`);
|
|
144
|
-
return `_0xstr_([${hexArray.join(",")}],${offset})`;
|
|
145
|
-
}
|
|
146
|
-
function convertLiteral(code, sourcemap, offset) {
|
|
147
|
-
const s = new MagicString(code);
|
|
148
|
-
let hasTransformed = false;
|
|
149
|
-
const ast = babel.parse(code, { ast: true });
|
|
150
|
-
if (!ast) {
|
|
151
|
-
throw new Error("Cannot parse code");
|
|
152
|
-
}
|
|
153
|
-
babel.traverse(ast, {
|
|
154
|
-
StringLiteral(path6) {
|
|
155
|
-
const parent = path6.parent;
|
|
156
|
-
const node = path6.node;
|
|
157
|
-
if (parent.type === "CallExpression") {
|
|
158
|
-
if (parent.callee.type === "Identifier" && parent.callee.name === "require") {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (parent.callee.type === "Import") {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (parent.type.startsWith("Export")) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (parent.type.startsWith("Import")) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (parent.type === "ObjectMethod" && parent.key === node) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (parent.type === "ObjectProperty" && parent.key === node) {
|
|
175
|
-
const result2 = `[${obfuscateString(node.value, offset)}]`;
|
|
176
|
-
const start2 = node.start;
|
|
177
|
-
const end2 = node.end;
|
|
178
|
-
if (start2 && end2) {
|
|
179
|
-
s.overwrite(start2, end2, result2);
|
|
180
|
-
hasTransformed = true;
|
|
181
|
-
}
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (!node.value.trim()) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const result = obfuscateString(node.value, offset);
|
|
188
|
-
const start = node.start;
|
|
189
|
-
const end = node.end;
|
|
190
|
-
if (start && end) {
|
|
191
|
-
s.overwrite(start, end, result);
|
|
192
|
-
hasTransformed = true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
if (hasTransformed) {
|
|
197
|
-
s.append("\n").append(decodeFn);
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
code: s.toString(),
|
|
201
|
-
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// src/vite/utils.ts
|
|
206
|
-
function readableSize(size) {
|
|
207
|
-
const units = ["B", "KB", "MB", "GB"];
|
|
208
|
-
let i = 0;
|
|
209
|
-
while (size >= 1024 && i < units.length - 1) {
|
|
210
|
-
size /= 1024;
|
|
211
|
-
i++;
|
|
212
|
-
}
|
|
213
|
-
return `${size.toFixed(2)} ${units[i]}`;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/vite/build.ts
|
|
217
19
|
async function buildAsar({
|
|
218
20
|
version,
|
|
219
21
|
asarOutputPath,
|
|
@@ -222,11 +24,11 @@ async function buildAsar({
|
|
|
222
24
|
rendererDistPath,
|
|
223
25
|
generateGzipFile
|
|
224
26
|
}) {
|
|
225
|
-
|
|
226
|
-
|
|
27
|
+
fs.renameSync(rendererDistPath, path3.join(electronDistPath, "renderer"));
|
|
28
|
+
fs.writeFileSync(path3.join(electronDistPath, "version"), version);
|
|
227
29
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
228
|
-
const buf = await generateGzipFile(
|
|
229
|
-
|
|
30
|
+
const buf = await generateGzipFile(fs.readFileSync(asarOutputPath));
|
|
31
|
+
fs.writeFileSync(gzipPath, buf);
|
|
230
32
|
log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
|
|
231
33
|
return buf;
|
|
232
34
|
}
|
|
@@ -249,9 +51,9 @@ async function buildVersion({
|
|
|
249
51
|
signature: "",
|
|
250
52
|
version
|
|
251
53
|
};
|
|
252
|
-
if (
|
|
54
|
+
if (fs.existsSync(versionPath)) {
|
|
253
55
|
try {
|
|
254
|
-
const oldVersionJson = JSON.parse(
|
|
56
|
+
const oldVersionJson = JSON.parse(fs.readFileSync(versionPath, "utf-8"));
|
|
255
57
|
if (isUpdateJSON(oldVersionJson)) {
|
|
256
58
|
_json = oldVersionJson;
|
|
257
59
|
} else {
|
|
@@ -265,7 +67,7 @@ async function buildVersion({
|
|
|
265
67
|
if (!isUpdateJSON(_json)) {
|
|
266
68
|
throw new Error("Invalid version info");
|
|
267
69
|
}
|
|
268
|
-
|
|
70
|
+
fs.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
269
71
|
log.info(`build version info to '${versionPath}'`, { timestamp: true });
|
|
270
72
|
}
|
|
271
73
|
async function buildEntry({
|
|
@@ -296,7 +98,26 @@ async function buildEntry({
|
|
|
296
98
|
".node": "empty"
|
|
297
99
|
},
|
|
298
100
|
define,
|
|
299
|
-
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
|
|
300
121
|
},
|
|
301
122
|
overrideEsbuildOptions ?? {}
|
|
302
123
|
);
|
|
@@ -305,9 +126,16 @@ async function buildEntry({
|
|
|
305
126
|
return;
|
|
306
127
|
}
|
|
307
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');
|
|
308
136
|
for (const filePath of filePaths) {
|
|
309
|
-
let code =
|
|
310
|
-
const fileName =
|
|
137
|
+
let code = fs.readFileSync(filePath, "utf-8");
|
|
138
|
+
const fileName = path3.basename(filePath);
|
|
311
139
|
const isEntry = fileName.endsWith("entry.js");
|
|
312
140
|
let transformedCode = convertLiteral(convertArrowFunctionAndTemplate(code).code).code;
|
|
313
141
|
if (bytecodeOptions.beforeCompile) {
|
|
@@ -316,12 +144,12 @@ async function buildEntry({
|
|
|
316
144
|
transformedCode = result;
|
|
317
145
|
}
|
|
318
146
|
}
|
|
319
|
-
const buffer = await compileToBytecode(transformedCode);
|
|
320
|
-
|
|
147
|
+
const buffer = await compileToBytecode(transformedCode, bytecodeOptions.electronPath);
|
|
148
|
+
fs.writeFileSync(
|
|
321
149
|
filePath,
|
|
322
150
|
`${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
|
|
323
151
|
);
|
|
324
|
-
|
|
152
|
+
fs.writeFileSync(`${filePath}c`, buffer);
|
|
325
153
|
bytecodeLog.info(
|
|
326
154
|
`${filePath} [${(buffer.byteLength / 1e3).toFixed(2)} kB]`,
|
|
327
155
|
{ timestamp: true }
|
|
@@ -353,21 +181,21 @@ function defaultSignature(buffer, privateKey, cert, version) {
|
|
|
353
181
|
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
354
182
|
}
|
|
355
183
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
356
|
-
const privateKeyDir =
|
|
357
|
-
if (!
|
|
358
|
-
|
|
184
|
+
const privateKeyDir = path3.dirname(privateKeyPath);
|
|
185
|
+
if (!fs.existsSync(privateKeyDir)) {
|
|
186
|
+
fs.mkdirSync(privateKeyDir, { recursive: true });
|
|
359
187
|
}
|
|
360
|
-
const certDir =
|
|
361
|
-
if (!
|
|
362
|
-
|
|
188
|
+
const certDir = path3.dirname(certPath);
|
|
189
|
+
if (!fs.existsSync(certDir)) {
|
|
190
|
+
fs.mkdirSync(certDir, { recursive: true });
|
|
363
191
|
}
|
|
364
192
|
const { cert, private: privateKey } = generate(subject, {
|
|
365
193
|
keySize: keyLength,
|
|
366
194
|
algorithm: "sha256",
|
|
367
195
|
days
|
|
368
196
|
});
|
|
369
|
-
|
|
370
|
-
|
|
197
|
+
fs.writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
198
|
+
fs.writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
371
199
|
}
|
|
372
200
|
function parseKeys({
|
|
373
201
|
keyLength,
|
|
@@ -376,22 +204,22 @@ function parseKeys({
|
|
|
376
204
|
subject,
|
|
377
205
|
days
|
|
378
206
|
}) {
|
|
379
|
-
const keysDir =
|
|
207
|
+
const keysDir = path3.dirname(privateKeyPath);
|
|
380
208
|
let privateKey = process.env.UPDATER_PK;
|
|
381
209
|
let cert = process.env.UPDATER_CERT;
|
|
382
210
|
if (privateKey && cert) {
|
|
383
211
|
log.info("Use `UPDATER_PK` and `UPDATER_CERT` from environment variables", { timestamp: true });
|
|
384
212
|
return { privateKey, cert };
|
|
385
213
|
}
|
|
386
|
-
if (!
|
|
387
|
-
|
|
214
|
+
if (!fs.existsSync(keysDir)) {
|
|
215
|
+
fs.mkdirSync(keysDir);
|
|
388
216
|
}
|
|
389
|
-
if (!
|
|
217
|
+
if (!fs.existsSync(privateKeyPath) || !fs.existsSync(certPath)) {
|
|
390
218
|
log.info("No key pair found, generate new key pair", { timestamp: true });
|
|
391
219
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
392
220
|
}
|
|
393
|
-
privateKey =
|
|
394
|
-
cert =
|
|
221
|
+
privateKey = fs.readFileSync(privateKeyPath, "utf-8");
|
|
222
|
+
cert = fs.readFileSync(certPath, "utf-8");
|
|
395
223
|
return { privateKey, cert };
|
|
396
224
|
}
|
|
397
225
|
function parseSubjects(subject) {
|
|
@@ -470,159 +298,6 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
470
298
|
};
|
|
471
299
|
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
|
|
472
300
|
}
|
|
473
|
-
function bytecodePlugin(env, options) {
|
|
474
|
-
const {
|
|
475
|
-
enable,
|
|
476
|
-
preload = false,
|
|
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);
|
|
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() {
|