electron-incremental-update 2.0.0-beta.2 → 2.0.0-beta.3
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-5WFXC5GU.js +43 -0
- package/dist/chunk-BVFQWBLK.js +76 -0
- package/dist/chunk-PNYRQYFC.js +77 -0
- package/dist/index.cjs +81 -144
- package/dist/index.d.cts +23 -18
- package/dist/index.d.ts +23 -18
- package/dist/index.js +56 -74
- package/dist/provider.cjs +78 -112
- package/dist/provider.d.cts +37 -11
- package/dist/provider.d.ts +37 -11
- package/dist/provider.js +42 -33
- package/dist/{types-CPq1MrYZ.d.ts → types-DxhNaNgR.d.ts} +8 -2
- package/dist/{types-COqp44eg.d.cts → types-Tequ_V2o.d.cts} +8 -2
- package/dist/unzip-JjYLjJkH.d.cts +9 -0
- package/dist/unzip-JjYLjJkH.d.ts +9 -0
- package/dist/utils.cjs +99 -173
- package/dist/utils.d.cts +4 -16
- package/dist/utils.d.ts +4 -16
- package/dist/utils.js +19 -62
- package/dist/{version-CffZWDhZ.d.cts → version-CemSHimT.d.cts} +3 -2
- package/dist/{version-CffZWDhZ.d.ts → version-CemSHimT.d.ts} +3 -2
- package/dist/vite.js +106 -139
- package/package.json +6 -6
- package/dist/chunk-BG22XZAB.js +0 -257
- package/dist/decrypt-D9WdXYjH.d.cts +0 -4
- package/dist/decrypt-D9WdXYjH.d.ts +0 -4
package/dist/vite.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
1
|
+
import path2, { join, resolve, basename, dirname } from 'node:path';
|
|
2
|
+
import fs, { rmSync, renameSync, writeFileSync, readFileSync, existsSync, cpSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { createLogger, normalizePath, mergeConfig, createFilter } from 'vite';
|
|
4
|
+
import ElectronSimple from 'vite-plugin-electron/simple';
|
|
5
|
+
import { startup } from 'vite-plugin-electron';
|
|
6
|
+
import { notBundle } from 'vite-plugin-electron/plugin';
|
|
7
|
+
import { getPackageInfoSync, loadPackageJSON } from 'local-pkg';
|
|
8
|
+
import Asar from '@electron/asar';
|
|
9
|
+
import { build } from 'esbuild';
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import * as babel from '@babel/core';
|
|
12
|
+
import MagicString from 'magic-string';
|
|
13
|
+
import { brotliCompress } from 'node:zlib';
|
|
14
|
+
import { createSign, createPrivateKey, createHash, createCipheriv } from 'node:crypto';
|
|
15
|
+
import { generate } from 'selfsigned';
|
|
9
16
|
|
|
10
|
-
// src/
|
|
11
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
12
|
-
import { basename, join } from "node:path";
|
|
13
|
-
import Asar from "@electron/asar";
|
|
14
|
-
import { build } from "esbuild";
|
|
15
|
-
import { mergeConfig } from "vite";
|
|
17
|
+
// src/vite.ts
|
|
16
18
|
|
|
17
19
|
// src/utils/version.ts
|
|
18
20
|
function parseVersion(version) {
|
|
@@ -42,48 +44,21 @@ function isUpdateJSON(json) {
|
|
|
42
44
|
const is = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
43
45
|
return is(json) && is(json?.beta);
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
function defaultVersionJsonGenerator(existingJson, buffer, signature, version, minimumVersion) {
|
|
48
|
+
existingJson.beta = {
|
|
49
|
+
version,
|
|
50
|
+
minimumVersion,
|
|
51
|
+
signature,
|
|
52
|
+
size: buffer.length
|
|
53
|
+
};
|
|
54
|
+
if (!parseVersion(version).stage) {
|
|
55
|
+
existingJson.version = version;
|
|
56
|
+
existingJson.minimumVersion = minimumVersion;
|
|
57
|
+
existingJson.signature = signature;
|
|
58
|
+
existingJson.size = buffer.length;
|
|
52
59
|
}
|
|
53
|
-
|
|
54
|
-
return new Promise((resolve2, reject) => {
|
|
55
|
-
brotliCompress(buffer, (err, buffer2) => {
|
|
56
|
-
if (err) {
|
|
57
|
-
reject(err);
|
|
58
|
-
}
|
|
59
|
-
writeFileSync(targetFilePath, buffer2);
|
|
60
|
-
resolve2();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
60
|
+
return existingJson;
|
|
63
61
|
}
|
|
64
|
-
|
|
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
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/build-plugins/constant.ts
|
|
86
|
-
import { createLogger } from "vite";
|
|
87
62
|
var id = "electron-incremental-updater";
|
|
88
63
|
var bytecodeId = `${id}-bytecode`;
|
|
89
64
|
var log = createLogger("info", { prefix: `[${id}]` });
|
|
@@ -92,14 +67,6 @@ var bytecodeLog = createLogger("info", { prefix: `[${bytecodeId}]` });
|
|
|
92
67
|
// src/build-plugins/bytecode/code.ts
|
|
93
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";
|
|
94
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';
|
|
95
|
-
|
|
96
|
-
// src/build-plugins/bytecode/utils.ts
|
|
97
|
-
import path from "node:path";
|
|
98
|
-
import fs from "node:fs";
|
|
99
|
-
import { spawn } from "node:child_process";
|
|
100
|
-
import * as babel from "@babel/core";
|
|
101
|
-
import MagicString from "magic-string";
|
|
102
|
-
import { getPackageInfoSync } from "local-pkg";
|
|
103
70
|
var electronModulePath = getPackageInfoSync("electron")?.rootPath;
|
|
104
71
|
var useStrict = "'use strict';";
|
|
105
72
|
var bytecodeModuleLoader = "__loader__.js";
|
|
@@ -109,13 +76,13 @@ function getElectronPath() {
|
|
|
109
76
|
if (!electronModulePath) {
|
|
110
77
|
throw new Error("Electron is not installed");
|
|
111
78
|
}
|
|
112
|
-
const pathFile =
|
|
79
|
+
const pathFile = path2.join(electronModulePath, "path.txt");
|
|
113
80
|
let executablePath;
|
|
114
81
|
if (fs.existsSync(pathFile)) {
|
|
115
82
|
executablePath = fs.readFileSync(pathFile, "utf-8");
|
|
116
83
|
}
|
|
117
84
|
if (executablePath) {
|
|
118
|
-
electronExecPath =
|
|
85
|
+
electronExecPath = path2.join(electronModulePath, "dist", executablePath);
|
|
119
86
|
process.env.ELECTRON_EXEC_PATH = electronExecPath;
|
|
120
87
|
} else {
|
|
121
88
|
throw new Error("Electron executable file is not existed");
|
|
@@ -124,14 +91,14 @@ function getElectronPath() {
|
|
|
124
91
|
return electronExecPath;
|
|
125
92
|
}
|
|
126
93
|
function getBytecodeCompilerPath() {
|
|
127
|
-
const scriptPath =
|
|
94
|
+
const scriptPath = path2.join(electronModulePath, "bytenode.cjs");
|
|
128
95
|
if (!fs.existsSync(scriptPath)) {
|
|
129
96
|
fs.writeFileSync(scriptPath, bytecodeGeneratorScript);
|
|
130
97
|
}
|
|
131
98
|
return scriptPath;
|
|
132
99
|
}
|
|
133
100
|
function toRelativePath(filename, importer) {
|
|
134
|
-
const relPath =
|
|
101
|
+
const relPath = path2.posix.relative(path2.dirname(importer), filename);
|
|
135
102
|
return relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
136
103
|
}
|
|
137
104
|
function compileToBytecode(code) {
|
|
@@ -198,12 +165,13 @@ async function buildAsar({
|
|
|
198
165
|
asarOutputPath,
|
|
199
166
|
gzipPath,
|
|
200
167
|
electronDistPath,
|
|
201
|
-
rendererDistPath
|
|
168
|
+
rendererDistPath,
|
|
169
|
+
generateGzipFile
|
|
202
170
|
}) {
|
|
203
171
|
renameSync(rendererDistPath, join(electronDistPath, "renderer"));
|
|
204
|
-
|
|
172
|
+
writeFileSync(join(electronDistPath, "version"), version);
|
|
205
173
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
206
|
-
await
|
|
174
|
+
await generateGzipFile(readFileSync(asarOutputPath), gzipPath);
|
|
207
175
|
}
|
|
208
176
|
async function buildVersion({
|
|
209
177
|
gzipPath,
|
|
@@ -227,9 +195,9 @@ async function buildVersion({
|
|
|
227
195
|
size: 0,
|
|
228
196
|
version
|
|
229
197
|
};
|
|
230
|
-
if (
|
|
198
|
+
if (existsSync(versionPath)) {
|
|
231
199
|
try {
|
|
232
|
-
const oldVersionJson = JSON.parse(
|
|
200
|
+
const oldVersionJson = JSON.parse(readFileSync(versionPath, "utf-8"));
|
|
233
201
|
if (isUpdateJSON(oldVersionJson)) {
|
|
234
202
|
_json = oldVersionJson;
|
|
235
203
|
} else {
|
|
@@ -238,28 +206,13 @@ async function buildVersion({
|
|
|
238
206
|
} catch {
|
|
239
207
|
}
|
|
240
208
|
}
|
|
241
|
-
const buffer =
|
|
242
|
-
const sig = await
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
throw new Error("invalid version info");
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
_json.beta = {
|
|
250
|
-
version,
|
|
251
|
-
minimumVersion,
|
|
252
|
-
signature: sig,
|
|
253
|
-
size: buffer.length
|
|
254
|
-
};
|
|
255
|
-
if (!parseVersion(version).stage) {
|
|
256
|
-
_json.version = version;
|
|
257
|
-
_json.minimumVersion = minimumVersion;
|
|
258
|
-
_json.signature = sig;
|
|
259
|
-
_json.size = buffer.length;
|
|
260
|
-
}
|
|
209
|
+
const buffer = readFileSync(gzipPath);
|
|
210
|
+
const sig = await generateSignature(buffer, privateKey, cert, version);
|
|
211
|
+
_json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
|
|
212
|
+
if (!isUpdateJSON(_json)) {
|
|
213
|
+
throw new Error("invalid version info");
|
|
261
214
|
}
|
|
262
|
-
|
|
215
|
+
writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
263
216
|
}
|
|
264
217
|
async function buildEntry({
|
|
265
218
|
sourcemap,
|
|
@@ -297,7 +250,7 @@ async function buildEntry({
|
|
|
297
250
|
}
|
|
298
251
|
const filePaths = Object.keys(metafile?.outputs ?? []);
|
|
299
252
|
for (const filePath of filePaths) {
|
|
300
|
-
let code =
|
|
253
|
+
let code = readFileSync(filePath, "utf-8");
|
|
301
254
|
const fileName = basename(filePath);
|
|
302
255
|
const isEntry = fileName.endsWith("entry.js");
|
|
303
256
|
if (isEntry) {
|
|
@@ -311,8 +264,8 @@ async function buildEntry({
|
|
|
311
264
|
[...protectedStrings, ...isEntry ? getCert(code) : []]
|
|
312
265
|
).code;
|
|
313
266
|
const buffer = await compileToBytecode(transformedCode);
|
|
314
|
-
|
|
315
|
-
|
|
267
|
+
writeFileSync(`${filePath}c`, buffer);
|
|
268
|
+
writeFileSync(
|
|
316
269
|
filePath,
|
|
317
270
|
`${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
|
|
318
271
|
);
|
|
@@ -327,18 +280,36 @@ function getCert(code) {
|
|
|
327
280
|
const cert = code.match(/-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n/)?.[0];
|
|
328
281
|
return cert ? [cert] : [];
|
|
329
282
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
283
|
+
async function defaultZipFile(buffer, targetFilePath) {
|
|
284
|
+
return new Promise((resolve2, reject) => {
|
|
285
|
+
brotliCompress(buffer, (err, buffer2) => {
|
|
286
|
+
if (err) {
|
|
287
|
+
reject(err);
|
|
288
|
+
}
|
|
289
|
+
writeFileSync(targetFilePath, buffer2);
|
|
290
|
+
resolve2();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function hashBuffer(data, length) {
|
|
295
|
+
const hash = createHash("SHA256").update(data).digest("binary");
|
|
296
|
+
return Buffer.from(hash).subarray(0, length);
|
|
297
|
+
}
|
|
298
|
+
function aesEncrypt(plainText, key, iv) {
|
|
299
|
+
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
300
|
+
return cipher.update(plainText, "utf8", "base64url") + cipher.final("base64url");
|
|
301
|
+
}
|
|
302
|
+
function defaultSignature(buffer, privateKey, cert, version) {
|
|
303
|
+
const sig = createSign("RSA-SHA256").update(buffer).sign(createPrivateKey(privateKey), "base64");
|
|
304
|
+
return aesEncrypt(`${sig}%${version}`, hashBuffer(cert, 32), hashBuffer(buffer, 16));
|
|
305
|
+
}
|
|
335
306
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
336
307
|
const privateKeyDir = dirname(privateKeyPath);
|
|
337
|
-
if (!
|
|
308
|
+
if (!existsSync(privateKeyDir)) {
|
|
338
309
|
mkdirSync(privateKeyDir, { recursive: true });
|
|
339
310
|
}
|
|
340
311
|
const certDir = dirname(certPath);
|
|
341
|
-
if (!
|
|
312
|
+
if (!existsSync(certDir)) {
|
|
342
313
|
mkdirSync(certDir, { recursive: true });
|
|
343
314
|
}
|
|
344
315
|
const { cert, private: privateKey } = generate(subject, {
|
|
@@ -346,8 +317,8 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
|
346
317
|
algorithm: "sha256",
|
|
347
318
|
days
|
|
348
319
|
});
|
|
349
|
-
|
|
350
|
-
|
|
320
|
+
writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
321
|
+
writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
351
322
|
}
|
|
352
323
|
function parseKeys({
|
|
353
324
|
keyLength,
|
|
@@ -357,15 +328,15 @@ function parseKeys({
|
|
|
357
328
|
days
|
|
358
329
|
}) {
|
|
359
330
|
const keysDir = dirname(privateKeyPath);
|
|
360
|
-
if (!
|
|
331
|
+
if (!existsSync(keysDir)) {
|
|
361
332
|
mkdirSync(keysDir);
|
|
362
333
|
}
|
|
363
|
-
if (!
|
|
334
|
+
if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
|
|
364
335
|
log.warn("no key pair found, generate new key pair");
|
|
365
336
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
366
337
|
}
|
|
367
|
-
const privateKey = process.env.UPDATER_PK ||
|
|
368
|
-
const cert = process.env.UPDATER_CERT ||
|
|
338
|
+
const privateKey = process.env.UPDATER_PK || readFileSync(privateKeyPath, "utf-8");
|
|
339
|
+
const cert = process.env.UPDATER_CERT || readFileSync(certPath, "utf-8");
|
|
369
340
|
return { privateKey, cert };
|
|
370
341
|
}
|
|
371
342
|
function parseSubjects(subject) {
|
|
@@ -396,11 +367,14 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
396
367
|
privateKeyPath = "keys/private.pem",
|
|
397
368
|
certPath = "keys/cert.pem",
|
|
398
369
|
keyLength = 2048,
|
|
399
|
-
certInfo = {}
|
|
400
|
-
|
|
370
|
+
certInfo = {}
|
|
371
|
+
} = {},
|
|
372
|
+
overrideGenerator: {
|
|
373
|
+
generateGzipFile = defaultZipFile,
|
|
374
|
+
generateSignature = defaultSignature,
|
|
375
|
+
generateVersionJson = defaultVersionJsonGenerator
|
|
401
376
|
} = {}
|
|
402
377
|
} = options;
|
|
403
|
-
const { generateSignature, generateVersionJson } = overrideGenerator;
|
|
404
378
|
let {
|
|
405
379
|
subject = {
|
|
406
380
|
commonName: pkg.name,
|
|
@@ -413,7 +387,8 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
413
387
|
asarOutputPath,
|
|
414
388
|
gzipPath,
|
|
415
389
|
electronDistPath,
|
|
416
|
-
rendererDistPath
|
|
390
|
+
rendererDistPath,
|
|
391
|
+
generateGzipFile
|
|
417
392
|
};
|
|
418
393
|
const buildEntryOption = {
|
|
419
394
|
minify: entryMinify ?? minify,
|
|
@@ -442,12 +417,6 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
442
417
|
};
|
|
443
418
|
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
|
|
444
419
|
}
|
|
445
|
-
|
|
446
|
-
// src/build-plugins/bytecode/index.ts
|
|
447
|
-
import path2 from "node:path";
|
|
448
|
-
import fs2 from "node:fs";
|
|
449
|
-
import { createFilter, normalizePath } from "vite";
|
|
450
|
-
import MagicString2 from "magic-string";
|
|
451
420
|
function bytecodePlugin(isBuild, env, options = {}) {
|
|
452
421
|
if (!isBuild) {
|
|
453
422
|
return null;
|
|
@@ -525,7 +494,7 @@ function bytecodePlugin(isBuild, env, options = {}) {
|
|
|
525
494
|
let _code = chunk.code;
|
|
526
495
|
if (bytecodeRE && _code.match(bytecodeRE)) {
|
|
527
496
|
let match;
|
|
528
|
-
const s = new
|
|
497
|
+
const s = new MagicString(_code);
|
|
529
498
|
while (match = bytecodeRE.exec(_code)) {
|
|
530
499
|
const [prefix, chunkName] = match;
|
|
531
500
|
const len = prefix.length + chunkName.length;
|
|
@@ -538,7 +507,7 @@ function bytecodePlugin(isBuild, env, options = {}) {
|
|
|
538
507
|
const chunkFilePath = path2.resolve(outDir, name);
|
|
539
508
|
if (bytecodeChunks.includes(name)) {
|
|
540
509
|
const bytecodeBuffer = await compileToBytecode(_code);
|
|
541
|
-
|
|
510
|
+
fs.writeFileSync(path2.resolve(outDir, name + "c"), bytecodeBuffer);
|
|
542
511
|
if (chunk.isEntry) {
|
|
543
512
|
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
544
513
|
const bytecodeModuleBlock = `require("./${path2.basename(name) + "c"}");`;
|
|
@@ -546,9 +515,9 @@ function bytecodePlugin(isBuild, env, options = {}) {
|
|
|
546
515
|
${bytecodeLoaderBlock}
|
|
547
516
|
module.exports=${bytecodeModuleBlock}
|
|
548
517
|
`;
|
|
549
|
-
|
|
518
|
+
fs.writeFileSync(chunkFilePath, code);
|
|
550
519
|
} else {
|
|
551
|
-
|
|
520
|
+
fs.unlinkSync(chunkFilePath);
|
|
552
521
|
}
|
|
553
522
|
bytecodeFiles.push({ name: name + "c", size: bytecodeBuffer.length });
|
|
554
523
|
} else {
|
|
@@ -575,7 +544,7 @@ module.exports=${bytecodeModuleBlock}
|
|
|
575
544
|
_code = hasBytecodeMoudle ? _code.replace(useStrict, `${useStrict}
|
|
576
545
|
${bytecodeLoaderBlock}`) : _code;
|
|
577
546
|
}
|
|
578
|
-
|
|
547
|
+
fs.writeFileSync(chunkFilePath, _code);
|
|
579
548
|
}
|
|
580
549
|
}
|
|
581
550
|
})
|
|
@@ -607,9 +576,9 @@ function debugStartup(args) {
|
|
|
607
576
|
function getMainFilePath(options) {
|
|
608
577
|
let mainFilePath;
|
|
609
578
|
if (typeof options === "string") {
|
|
610
|
-
mainFilePath =
|
|
579
|
+
mainFilePath = basename(options);
|
|
611
580
|
} else if (Array.isArray(options)) {
|
|
612
|
-
mainFilePath =
|
|
581
|
+
mainFilePath = basename(options[0]);
|
|
613
582
|
} else {
|
|
614
583
|
const name = options?.index ?? options?.main;
|
|
615
584
|
if (!name) {
|
|
@@ -620,7 +589,7 @@ function getMainFilePath(options) {
|
|
|
620
589
|
return mainFilePath.replace(/\.[cm]?ts$/, ".js");
|
|
621
590
|
}
|
|
622
591
|
function parseVersionPath(versionPath) {
|
|
623
|
-
versionPath =
|
|
592
|
+
versionPath = normalizePath(versionPath);
|
|
624
593
|
if (!versionPath.startsWith("./")) {
|
|
625
594
|
versionPath = "./" + versionPath;
|
|
626
595
|
}
|
|
@@ -661,8 +630,8 @@ async function electronWithUpdater(options) {
|
|
|
661
630
|
const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert } = _options;
|
|
662
631
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
663
632
|
sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
|
|
664
|
-
const _appPath =
|
|
665
|
-
if (resolve(
|
|
633
|
+
const _appPath = normalizePath(join(entryOutputDirPath, "entry.js"));
|
|
634
|
+
if (resolve(normalizePath(pkg.main)) !== resolve(_appPath)) {
|
|
666
635
|
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
667
636
|
}
|
|
668
637
|
const define = {
|
|
@@ -684,12 +653,12 @@ async function electronWithUpdater(options) {
|
|
|
684
653
|
};
|
|
685
654
|
const _postBuild = postBuild ? async () => await postBuild({
|
|
686
655
|
getPathFromEntryOutputDir(...paths) {
|
|
687
|
-
return
|
|
656
|
+
return join(entryOutputDirPath, ...paths);
|
|
688
657
|
},
|
|
689
658
|
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
690
|
-
if (
|
|
691
|
-
const target =
|
|
692
|
-
if (!skipIfExist || !
|
|
659
|
+
if (existsSync(from)) {
|
|
660
|
+
const target = join(entryOutputDirPath, to ?? basename(from));
|
|
661
|
+
if (!skipIfExist || !existsSync(target)) {
|
|
693
662
|
try {
|
|
694
663
|
cpSync(from, target);
|
|
695
664
|
} catch (error) {
|
|
@@ -719,7 +688,7 @@ async function electronWithUpdater(options) {
|
|
|
719
688
|
args.startup();
|
|
720
689
|
}
|
|
721
690
|
},
|
|
722
|
-
vite:
|
|
691
|
+
vite: mergeConfig(
|
|
723
692
|
{
|
|
724
693
|
plugins: [
|
|
725
694
|
!isBuild && useNotBundle ? notBundle() : void 0,
|
|
@@ -739,7 +708,7 @@ async function electronWithUpdater(options) {
|
|
|
739
708
|
preload: {
|
|
740
709
|
input: _preload.files,
|
|
741
710
|
onstart: _preload.onstart,
|
|
742
|
-
vite:
|
|
711
|
+
vite: mergeConfig(
|
|
743
712
|
{
|
|
744
713
|
plugins: [
|
|
745
714
|
bytecodeOptions && bytecodePlugin(isBuild, "preload", bytecodeOptions),
|
|
@@ -786,7 +755,7 @@ async function electronWithUpdater(options) {
|
|
|
786
755
|
}
|
|
787
756
|
let extraHmrPlugin;
|
|
788
757
|
if (nativeModuleEntryMap) {
|
|
789
|
-
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(
|
|
758
|
+
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath(file)));
|
|
790
759
|
extraHmrPlugin = {
|
|
791
760
|
name: `${id}-dev`,
|
|
792
761
|
apply() {
|
|
@@ -806,7 +775,5 @@ async function electronWithUpdater(options) {
|
|
|
806
775
|
}
|
|
807
776
|
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
808
777
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
electronWithUpdater
|
|
812
|
-
};
|
|
778
|
+
|
|
779
|
+
export { debugStartup, electronWithUpdater };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.3",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"author": "subframe7536",
|
|
7
7
|
"license": "MIT",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"registry": "https://registry.npmjs.org/"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@babel/core": "^7.24.7",
|
|
56
|
-
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
|
57
55
|
"@electron/asar": "*",
|
|
58
56
|
"esbuild": "*",
|
|
59
|
-
"magic-string": "*"
|
|
60
|
-
"vite-plugin-electron": "^0.15.6 || ^0.28"
|
|
57
|
+
"magic-string": "*"
|
|
61
58
|
},
|
|
62
59
|
"dependencies": {
|
|
60
|
+
"@babel/core": "^7.24.7",
|
|
61
|
+
"@babel/plugin-transform-arrow-functions": "^7.24.7",
|
|
63
62
|
"@subframe7536/type-utils": "^0.1.6",
|
|
64
63
|
"local-pkg": "^0.5.0",
|
|
65
|
-
"selfsigned": "^2.4.1"
|
|
64
|
+
"selfsigned": "^2.4.1",
|
|
65
|
+
"vite-plugin-electron": "^0.28.7"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@subframe7536/eslint-config": "^0.7.2",
|