electron-incremental-update 2.0.0-beta.1 → 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/vite.js CHANGED
@@ -1,18 +1,20 @@
1
- // src/vite.ts
2
- import { basename as basename2, join as join2, resolve } from "node:path";
3
- import { cpSync, existsSync as existsSync4, rmSync } from "node:fs";
4
- import { mergeConfig as mergeConfig2, normalizePath as normalizePath2 } from "vite";
5
- import ElectronSimple from "vite-plugin-electron/simple";
6
- import { startup } from "vite-plugin-electron";
7
- import { notBundle } from "vite-plugin-electron/plugin";
8
- import { loadPackageJSON } from "local-pkg";
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/build-plugins/build.ts
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
- // src/utils/zip.ts
47
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
48
- import { brotliCompress } from "node:zlib";
49
- async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
50
- if (!existsSync(filePath)) {
51
- throw new Error(`path to be zipped not exist: ${filePath}`);
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
- const buffer = readFileSync(filePath);
54
- return new Promise((resolve2, reject) => {
55
- brotliCompress(buffer, (err, buffer2) => {
56
- if (err) {
57
- reject(err);
58
- }
59
- writeFileSync(targetFilePath, buffer2);
60
- resolve2(null);
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 = path.join(electronModulePath, "path.txt");
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 = path.join(electronModulePath, "dist", executablePath);
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 = path.join(electronModulePath, "bytenode.cjs");
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 = path.posix.relative(path.dirname(importer), filename);
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
- writeFileSync2(join(electronDistPath, "version"), version);
172
+ writeFileSync(join(electronDistPath, "version"), version);
205
173
  await Asar.createPackage(electronDistPath, asarOutputPath);
206
- await zipFile(asarOutputPath, gzipPath);
174
+ await generateGzipFile(readFileSync(asarOutputPath), gzipPath);
207
175
  }
208
176
  async function buildVersion({
209
177
  gzipPath,
@@ -227,39 +195,24 @@ async function buildVersion({
227
195
  size: 0,
228
196
  version
229
197
  };
230
- if (existsSync2(versionPath)) {
198
+ if (existsSync(versionPath)) {
231
199
  try {
232
- const oldVersionJson = JSON.parse(readFileSync2(versionPath, "utf-8"));
200
+ const oldVersionJson = JSON.parse(readFileSync(versionPath, "utf-8"));
233
201
  if (isUpdateJSON(oldVersionJson)) {
234
202
  _json = oldVersionJson;
235
203
  } else {
236
204
  log.warn("old version json is invalid, ignore it");
237
205
  }
238
- } catch (error) {
206
+ } catch {
239
207
  }
240
208
  }
241
- const buffer = readFileSync2(gzipPath);
242
- const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
243
- if (generateVersionJson) {
244
- _json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
245
- if (!isUpdateJSON(_json)) {
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
- writeFileSync2(versionPath, JSON.stringify(_json, null, 2));
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 = readFileSync2(filePath, "utf-8");
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
- writeFileSync2(`${filePath}c`, buffer);
315
- writeFileSync2(
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
- // src/build-plugins/key.ts
332
- import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
333
- import { dirname } from "node:path";
334
- import { generate } from "selfsigned";
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 (!existsSync3(privateKeyDir)) {
308
+ if (!existsSync(privateKeyDir)) {
338
309
  mkdirSync(privateKeyDir, { recursive: true });
339
310
  }
340
311
  const certDir = dirname(certPath);
341
- if (!existsSync3(certDir)) {
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
- writeFileSync3(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
350
- writeFileSync3(certPath, cert.replace(/\r\n?/g, "\n"));
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,13 +328,15 @@ function parseKeys({
357
328
  days
358
329
  }) {
359
330
  const keysDir = dirname(privateKeyPath);
360
- !existsSync3(keysDir) && mkdirSync(keysDir);
361
- if (!existsSync3(privateKeyPath) || !existsSync3(certPath)) {
331
+ if (!existsSync(keysDir)) {
332
+ mkdirSync(keysDir);
333
+ }
334
+ if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
362
335
  log.warn("no key pair found, generate new key pair");
363
336
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
364
337
  }
365
- const privateKey = process.env.UPDATER_PK || readFileSync3(privateKeyPath, "utf-8");
366
- const cert = process.env.UPDATER_CERT || readFileSync3(certPath, "utf-8");
338
+ const privateKey = process.env.UPDATER_PK || readFileSync(privateKeyPath, "utf-8");
339
+ const cert = process.env.UPDATER_CERT || readFileSync(certPath, "utf-8");
367
340
  return { privateKey, cert };
368
341
  }
369
342
  function parseSubjects(subject) {
@@ -394,11 +367,14 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
394
367
  privateKeyPath = "keys/private.pem",
395
368
  certPath = "keys/cert.pem",
396
369
  keyLength = 2048,
397
- certInfo = {},
398
- overrideGenerator = {}
370
+ certInfo = {}
371
+ } = {},
372
+ overrideGenerator: {
373
+ generateGzipFile = defaultZipFile,
374
+ generateSignature = defaultSignature,
375
+ generateVersionJson = defaultVersionJsonGenerator
399
376
  } = {}
400
377
  } = options;
401
- const { generateSignature, generateVersionJson } = overrideGenerator;
402
378
  let {
403
379
  subject = {
404
380
  commonName: pkg.name,
@@ -411,7 +387,8 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
411
387
  asarOutputPath,
412
388
  gzipPath,
413
389
  electronDistPath,
414
- rendererDistPath
390
+ rendererDistPath,
391
+ generateGzipFile
415
392
  };
416
393
  const buildEntryOption = {
417
394
  minify: entryMinify ?? minify,
@@ -440,12 +417,6 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
440
417
  };
441
418
  return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
442
419
  }
443
-
444
- // src/build-plugins/bytecode/index.ts
445
- import path2 from "node:path";
446
- import fs2 from "node:fs";
447
- import { createFilter, normalizePath } from "vite";
448
- import MagicString2 from "magic-string";
449
420
  function bytecodePlugin(isBuild, env, options = {}) {
450
421
  if (!isBuild) {
451
422
  return null;
@@ -523,7 +494,7 @@ function bytecodePlugin(isBuild, env, options = {}) {
523
494
  let _code = chunk.code;
524
495
  if (bytecodeRE && _code.match(bytecodeRE)) {
525
496
  let match;
526
- const s = new MagicString2(_code);
497
+ const s = new MagicString(_code);
527
498
  while (match = bytecodeRE.exec(_code)) {
528
499
  const [prefix, chunkName] = match;
529
500
  const len = prefix.length + chunkName.length;
@@ -536,7 +507,7 @@ function bytecodePlugin(isBuild, env, options = {}) {
536
507
  const chunkFilePath = path2.resolve(outDir, name);
537
508
  if (bytecodeChunks.includes(name)) {
538
509
  const bytecodeBuffer = await compileToBytecode(_code);
539
- fs2.writeFileSync(path2.resolve(outDir, name + "c"), bytecodeBuffer);
510
+ fs.writeFileSync(path2.resolve(outDir, name + "c"), bytecodeBuffer);
540
511
  if (chunk.isEntry) {
541
512
  const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
542
513
  const bytecodeModuleBlock = `require("./${path2.basename(name) + "c"}");`;
@@ -544,9 +515,9 @@ function bytecodePlugin(isBuild, env, options = {}) {
544
515
  ${bytecodeLoaderBlock}
545
516
  module.exports=${bytecodeModuleBlock}
546
517
  `;
547
- fs2.writeFileSync(chunkFilePath, code);
518
+ fs.writeFileSync(chunkFilePath, code);
548
519
  } else {
549
- fs2.unlinkSync(chunkFilePath);
520
+ fs.unlinkSync(chunkFilePath);
550
521
  }
551
522
  bytecodeFiles.push({ name: name + "c", size: bytecodeBuffer.length });
552
523
  } else {
@@ -573,7 +544,7 @@ module.exports=${bytecodeModuleBlock}
573
544
  _code = hasBytecodeMoudle ? _code.replace(useStrict, `${useStrict}
574
545
  ${bytecodeLoaderBlock}`) : _code;
575
546
  }
576
- fs2.writeFileSync(chunkFilePath, _code);
547
+ fs.writeFileSync(chunkFilePath, _code);
577
548
  }
578
549
  }
579
550
  })
@@ -596,14 +567,18 @@ ${bytecodeLoaderBlock}`) : _code;
596
567
 
597
568
  // src/vite.ts
598
569
  function debugStartup(args) {
599
- process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
570
+ if (process.env.VSCODE_DEBUG) {
571
+ console.log("[startup] Electron App");
572
+ } else {
573
+ args.startup();
574
+ }
600
575
  }
601
576
  function getMainFilePath(options) {
602
577
  let mainFilePath;
603
578
  if (typeof options === "string") {
604
- mainFilePath = basename2(options);
579
+ mainFilePath = basename(options);
605
580
  } else if (Array.isArray(options)) {
606
- mainFilePath = basename2(options[0]);
581
+ mainFilePath = basename(options[0]);
607
582
  } else {
608
583
  const name = options?.index ?? options?.main;
609
584
  if (!name) {
@@ -614,7 +589,7 @@ function getMainFilePath(options) {
614
589
  return mainFilePath.replace(/\.[cm]?ts$/, ".js");
615
590
  }
616
591
  function parseVersionPath(versionPath) {
617
- versionPath = normalizePath2(versionPath);
592
+ versionPath = normalizePath(versionPath);
618
593
  if (!versionPath.startsWith("./")) {
619
594
  versionPath = "./" + versionPath;
620
595
  }
@@ -635,11 +610,11 @@ async function electronWithUpdater(options) {
635
610
  } = options;
636
611
  if (!pkg) {
637
612
  log.error(`package.json not found`, { timestamp: true });
638
- return null;
613
+ return void 0;
639
614
  }
640
615
  if (!pkg.version || !pkg.name || !pkg.main) {
641
616
  log.error(`package.json not valid`, { timestamp: true });
642
- return null;
617
+ return void 0;
643
618
  }
644
619
  const _options = parseOptions(pkg, sourcemap, minify, updater);
645
620
  const bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { protectedStrings: [] } : void 0;
@@ -649,14 +624,14 @@ async function electronWithUpdater(options) {
649
624
  try {
650
625
  rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
651
626
  rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
652
- } catch (ignore) {
627
+ } catch {
653
628
  }
654
629
  log.info(`remove old files`, { timestamp: true });
655
630
  const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert } = _options;
656
631
  const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
657
632
  sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
658
- const _appPath = normalizePath2(join2(entryOutputDirPath, "entry.js"));
659
- if (resolve(normalizePath2(pkg.main)) !== resolve(_appPath)) {
633
+ const _appPath = normalizePath(join(entryOutputDirPath, "entry.js"));
634
+ if (resolve(normalizePath(pkg.main)) !== resolve(_appPath)) {
660
635
  throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
661
636
  }
662
637
  const define = {
@@ -678,12 +653,12 @@ async function electronWithUpdater(options) {
678
653
  };
679
654
  const _postBuild = postBuild ? async () => await postBuild({
680
655
  getPathFromEntryOutputDir(...paths) {
681
- return join2(entryOutputDirPath, ...paths);
656
+ return join(entryOutputDirPath, ...paths);
682
657
  },
683
658
  copyToEntryOutputDir({ from, to, skipIfExist = true }) {
684
- if (existsSync4(from)) {
685
- const target = join2(entryOutputDirPath, to ?? basename2(from));
686
- if (!skipIfExist || !existsSync4(target)) {
659
+ if (existsSync(from)) {
660
+ const target = join(entryOutputDirPath, to ?? basename(from));
661
+ if (!skipIfExist || !existsSync(target)) {
687
662
  try {
688
663
  cpSync(from, target);
689
664
  } catch (error) {
@@ -707,9 +682,13 @@ async function electronWithUpdater(options) {
707
682
  await _buildEntry();
708
683
  await _postBuild();
709
684
  }
710
- _main.onstart ? _main.onstart(args) : args.startup();
685
+ if (_main.onstart) {
686
+ _main.onstart(args);
687
+ } else {
688
+ args.startup();
689
+ }
711
690
  },
712
- vite: mergeConfig2(
691
+ vite: mergeConfig(
713
692
  {
714
693
  plugins: [
715
694
  !isBuild && useNotBundle ? notBundle() : void 0,
@@ -729,7 +708,7 @@ async function electronWithUpdater(options) {
729
708
  preload: {
730
709
  input: _preload.files,
731
710
  onstart: _preload.onstart,
732
- vite: mergeConfig2(
711
+ vite: mergeConfig(
733
712
  {
734
713
  plugins: [
735
714
  bytecodeOptions && bytecodePlugin(isBuild, "preload", bytecodeOptions),
@@ -761,20 +740,22 @@ async function electronWithUpdater(options) {
761
740
  )
762
741
  }
763
742
  };
764
- logParsedOptions && log.info(
765
- JSON.stringify(
766
- {
767
- ...electronPluginOptions,
768
- updater: { buildAsarOption, buildEntryOption, buildVersionOption }
769
- },
770
- (key, value) => (key === "privateKey" || key === "cert") && !(typeof logParsedOptions === "object" && logParsedOptions.showKeys === true) ? "***" : value,
771
- 2
772
- ),
773
- { timestamp: true }
774
- );
743
+ if (logParsedOptions) {
744
+ log.info(
745
+ JSON.stringify(
746
+ {
747
+ ...electronPluginOptions,
748
+ updater: { buildAsarOption, buildEntryOption, buildVersionOption }
749
+ },
750
+ (key, value) => (key === "privateKey" || key === "cert") && !(typeof logParsedOptions === "object" && logParsedOptions.showKeys === true) ? "***" : value,
751
+ 2
752
+ ),
753
+ { timestamp: true }
754
+ );
755
+ }
775
756
  let extraHmrPlugin;
776
757
  if (nativeModuleEntryMap) {
777
- const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath2(file)));
758
+ const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath(file)));
778
759
  extraHmrPlugin = {
779
760
  name: `${id}-dev`,
780
761
  apply() {
@@ -794,7 +775,5 @@ async function electronWithUpdater(options) {
794
775
  }
795
776
  return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
796
777
  }
797
- export {
798
- debugStartup,
799
- electronWithUpdater
800
- };
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.1",
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,30 +52,30 @@
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
- "@subframe7536/eslint-config": "^0.6.6",
68
+ "@subframe7536/eslint-config": "^0.7.2",
69
69
  "@types/babel__core": "^7.20.5",
70
- "@types/node": "^20.14.10",
70
+ "@types/node": "^20.14.11",
71
71
  "bumpp": "^9.4.1",
72
72
  "electron": "28.2.10",
73
73
  "eslint": "^9.7.0",
74
74
  "esno": "^4.7.0",
75
75
  "tsup": "^8.1.0",
76
76
  "typescript": "^5.5.3",
77
- "vite": "^5.3.3",
77
+ "vite": "^5.3.4",
78
78
  "vite-plugin-electron": "^0.28.7",
79
- "vitest": "^2.0.2"
79
+ "vitest": "^2.0.3"
80
80
  }
81
81
  }