electron-incremental-update 2.1.1 → 2.2.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 +126 -3
- package/dist/{bytecode-I4PMYUGT.js → bytecode-Z5ZF4YGN.js} +5 -6
- package/dist/{chunk-RCRKUKFX.js → chunk-AAAM44NW.js} +9 -9
- package/dist/{chunk-7M7DIMDN.js → chunk-CTUEQCKL.js} +1 -1
- package/dist/{chunk-AUY7A2FL.js → chunk-I2EHKJU4.js} +6 -4
- package/dist/{chunk-ZM5CIZ4L.js → chunk-JI27JWJN.js} +9 -15
- package/dist/{chunk-KZSYEXLO.js → chunk-PUVBFHOK.js} +2 -14
- package/dist/{chunk-5CE27A6G.js → esm-5YR6V7VN.js} +23 -2
- package/dist/index.cjs +8 -14
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -17
- package/dist/provider.cjs +10 -16
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +2 -2
- package/dist/{types-DADYYy6C.d.cts → types-BPH66pNz.d.cts} +5 -5
- package/dist/{types-BVcfNRXE.d.ts → types-DQKdsHc_.d.ts} +5 -5
- package/dist/utils.cjs +19 -37
- package/dist/utils.d.cts +19 -5
- package/dist/utils.d.ts +19 -5
- package/dist/utils.js +3 -3
- package/dist/vite.d.ts +48 -25
- package/dist/vite.js +66 -122
- package/package.json +6 -6
- package/dist/chunk-7IRGAAL2.js +0 -5
- package/dist/code-P5OANH3Q.js +0 -1
- package/dist/esm-ZFXJ56BN.js +0 -26
- package/dist/utils-JZ4CMTJG.js +0 -4
- package/dist/utils-KPSYP7HQ.js +0 -5
package/README.md
CHANGED
|
@@ -245,7 +245,7 @@ Luckily, `Esbuild` can bundle all the dependencies. Just follow the steps:
|
|
|
245
245
|
1. setup `nativeModuleEntryMap` option
|
|
246
246
|
2. Manually copy the native binaries in `postBuild` callback
|
|
247
247
|
3. Exclude all the dependencies in `electron-builder`'s config
|
|
248
|
-
4. call the native functions with `requireNative` in your code
|
|
248
|
+
4. call the native functions with `requireNative` / `importNative` in your code
|
|
249
249
|
|
|
250
250
|
#### Example
|
|
251
251
|
|
|
@@ -283,8 +283,9 @@ in `electron/native/db.ts`
|
|
|
283
283
|
|
|
284
284
|
```ts
|
|
285
285
|
import Database from 'better-sqlite3'
|
|
286
|
+
import { getPathFromEntryAsar } from 'electron-incremental-update/utils'
|
|
286
287
|
|
|
287
|
-
const db = new Database(':memory:', { nativeBinding: './better_sqlite3.node' })
|
|
288
|
+
const db = new Database(':memory:', { nativeBinding: getPathFromEntryAsar('./better_sqlite3.node') })
|
|
288
289
|
|
|
289
290
|
export function test(): void {
|
|
290
291
|
db.exec(
|
|
@@ -308,9 +309,13 @@ export function test(): void {
|
|
|
308
309
|
in `electron/main/service.ts`
|
|
309
310
|
|
|
310
311
|
```ts
|
|
311
|
-
import { requireNative } from 'electron-incremental-update/utils'
|
|
312
|
+
import { importNative, requireNative } from 'electron-incremental-update/utils'
|
|
312
313
|
|
|
314
|
+
// commonjs
|
|
313
315
|
requireNative<typeof import('../native/db')>('db').test()
|
|
316
|
+
|
|
317
|
+
// esm
|
|
318
|
+
importNative<typeof import('../native/db')>('db').test()
|
|
314
319
|
```
|
|
315
320
|
|
|
316
321
|
in `electron-builder.config.js`
|
|
@@ -349,6 +354,124 @@ https://electron-vite.org/guide/source-code-protection
|
|
|
349
354
|
- Only support commonjs
|
|
350
355
|
- Only for main process by default, if you want to use in preload script, please use `electronWithUpdater({ bytecode: { enablePreload: true } })` and set `sandbox: false` when creating window
|
|
351
356
|
|
|
357
|
+
### Utils
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
/**
|
|
361
|
+
* Compile time dev check
|
|
362
|
+
*/
|
|
363
|
+
const isDev: boolean
|
|
364
|
+
const isWin: boolean
|
|
365
|
+
const isMac: boolean
|
|
366
|
+
const isLinux: boolean
|
|
367
|
+
/**
|
|
368
|
+
* Get joined path of `${electron.app.name}.asar` (not `app.asar`)
|
|
369
|
+
*
|
|
370
|
+
* If is in dev, **always** return `'DEV.asar'`
|
|
371
|
+
*/
|
|
372
|
+
function getPathFromAppNameAsar(...paths: string[]): string
|
|
373
|
+
/**
|
|
374
|
+
* Get app version, if is in dev, return `getEntryVersion()`
|
|
375
|
+
*/
|
|
376
|
+
function getAppVersion(): string
|
|
377
|
+
/**
|
|
378
|
+
* Get entry version
|
|
379
|
+
*/
|
|
380
|
+
function getEntryVersion(): string
|
|
381
|
+
/**
|
|
382
|
+
* Use `require` to load native module from entry asar
|
|
383
|
+
* @param moduleName file name in entry
|
|
384
|
+
* @example
|
|
385
|
+
* requireNative<typeof import('../native/db')>('db')
|
|
386
|
+
*/
|
|
387
|
+
function requireNative<T = any>(moduleName: string): T
|
|
388
|
+
/**
|
|
389
|
+
* Use `import` to load native module from entry asar
|
|
390
|
+
* @param moduleName file name in entry
|
|
391
|
+
* @example
|
|
392
|
+
* await importNative<typeof import('../native/db')>('db')
|
|
393
|
+
*/
|
|
394
|
+
function importNative<T = any>(moduleName: string): Promise<T>
|
|
395
|
+
/**
|
|
396
|
+
* Restarts the Electron app.
|
|
397
|
+
*/
|
|
398
|
+
function restartApp(): void
|
|
399
|
+
/**
|
|
400
|
+
* Fix app use model id, only for Windows
|
|
401
|
+
* @param id app id, default is `org.${electron.app.name}`
|
|
402
|
+
*/
|
|
403
|
+
function setAppUserModelId(id?: string): void
|
|
404
|
+
/**
|
|
405
|
+
* Disable hardware acceleration for Windows 7
|
|
406
|
+
*
|
|
407
|
+
* Only support CommonJS
|
|
408
|
+
*/
|
|
409
|
+
function disableHWAccForWin7(): void
|
|
410
|
+
/**
|
|
411
|
+
* Keep single electron instance and auto restore window on `second-instance` event
|
|
412
|
+
* @param window brwoser window to show
|
|
413
|
+
*/
|
|
414
|
+
function singleInstance(window?: BrowserWindow): void
|
|
415
|
+
/**
|
|
416
|
+
* Set `AppData` dir to the dir of .exe file
|
|
417
|
+
*
|
|
418
|
+
* Useful for portable Windows app
|
|
419
|
+
* @param dirName dir name, default to `data`
|
|
420
|
+
*/
|
|
421
|
+
function setPortableAppDataPath(dirName?: string): void
|
|
422
|
+
/**
|
|
423
|
+
* Load `process.env.VITE_DEV_SERVER_URL` when dev, else load html file
|
|
424
|
+
* @param win window
|
|
425
|
+
* @param htmlFilePath html file path, default is `index.html`
|
|
426
|
+
*/
|
|
427
|
+
function loadPage(win: BrowserWindow, htmlFilePath?: string): void
|
|
428
|
+
interface BeautifyDevToolsOptions {
|
|
429
|
+
/**
|
|
430
|
+
* Sans-serif font family
|
|
431
|
+
*/
|
|
432
|
+
sans: string
|
|
433
|
+
/**
|
|
434
|
+
* Monospace font family
|
|
435
|
+
*/
|
|
436
|
+
mono: string
|
|
437
|
+
/**
|
|
438
|
+
* Whether to round scrollbar
|
|
439
|
+
*/
|
|
440
|
+
scrollbar?: boolean
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Beautify devtools' font and scrollbar
|
|
444
|
+
* @param win target window
|
|
445
|
+
* @param options sans font family, mono font family and scrollbar
|
|
446
|
+
*/
|
|
447
|
+
function beautifyDevTools(win: BrowserWindow, options: BeautifyDevToolsOptions): void
|
|
448
|
+
/**
|
|
449
|
+
* Get joined path from main dir
|
|
450
|
+
* @param paths rest paths
|
|
451
|
+
*/
|
|
452
|
+
function getPathFromMain(...paths: string[]): string
|
|
453
|
+
/**
|
|
454
|
+
* Get joined path from preload dir
|
|
455
|
+
* @param paths rest paths
|
|
456
|
+
*/
|
|
457
|
+
function getPathFromPreload(...paths: string[]): string
|
|
458
|
+
/**
|
|
459
|
+
* Get joined path from publich dir
|
|
460
|
+
* @param paths rest paths
|
|
461
|
+
*/
|
|
462
|
+
function getPathFromPublic(...paths: string[]): string
|
|
463
|
+
/**
|
|
464
|
+
* Get joined path from entry asar
|
|
465
|
+
* @param paths rest paths
|
|
466
|
+
*/
|
|
467
|
+
function getPathFromEntryAsar(...paths: string[]): string
|
|
468
|
+
/**
|
|
469
|
+
* Handle all unhandled error
|
|
470
|
+
* @param callback callback function
|
|
471
|
+
*/
|
|
472
|
+
function handleUnexpectedErrors(callback: (err: unknown) => void): void
|
|
473
|
+
```
|
|
474
|
+
|
|
352
475
|
### Types
|
|
353
476
|
|
|
354
477
|
#### Entry
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { readableSize } from './chunk-WYQ5DRO7.js';
|
|
2
|
-
import { convertLiteral, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-
|
|
3
|
-
import './chunk-
|
|
2
|
+
import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-I2EHKJU4.js';
|
|
3
|
+
import './chunk-CTUEQCKL.js';
|
|
4
4
|
import { bytecodeLog, bytecodeId } from './chunk-5NKEXGI3.js';
|
|
5
|
-
import { bytecodeModuleLoaderCode } from './chunk-7IRGAAL2.js';
|
|
6
5
|
import path from 'node:path';
|
|
7
6
|
import fs from 'node:fs';
|
|
8
7
|
import { createFilter, normalizePath } from 'vite';
|
|
9
8
|
import MagicString from 'magic-string';
|
|
10
9
|
|
|
10
|
+
function getBytecodeLoaderBlock(chunkFileName) {
|
|
11
|
+
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
12
|
+
}
|
|
11
13
|
function bytecodePlugin(env, options) {
|
|
12
14
|
const {
|
|
13
15
|
enable,
|
|
@@ -77,9 +79,6 @@ function bytecodePlugin(env, options) {
|
|
|
77
79
|
const nonEntryChunks = chunks.filter((chunk) => !chunk.isEntry).map((chunk) => path.basename(chunk.fileName));
|
|
78
80
|
const pattern = nonEntryChunks.map((chunk) => `(${chunk})`).join("|");
|
|
79
81
|
const bytecodeRE = pattern ? new RegExp(`require\\(\\S*(?=(${pattern})\\S*\\))`, "g") : null;
|
|
80
|
-
const getBytecodeLoaderBlock = (chunkFileName) => {
|
|
81
|
-
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
82
|
-
};
|
|
83
82
|
await Promise.all(
|
|
84
83
|
bundles.map(async (name) => {
|
|
85
84
|
const chunk = output[name];
|
|
@@ -29,17 +29,17 @@ function parseVersion(version) {
|
|
|
29
29
|
}
|
|
30
30
|
return ret;
|
|
31
31
|
}
|
|
32
|
+
function compareStrings(str1, str2) {
|
|
33
|
+
if (str1 === "") {
|
|
34
|
+
return str2 !== "";
|
|
35
|
+
} else if (str2 === "") {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return str1 < str2;
|
|
39
|
+
}
|
|
32
40
|
function defaultIsLowerVersion(oldVer, newVer) {
|
|
33
41
|
const oldV = parseVersion(oldVer);
|
|
34
42
|
const newV = parseVersion(newVer);
|
|
35
|
-
function compareStrings(str1, str2) {
|
|
36
|
-
if (str1 === "") {
|
|
37
|
-
return str2 !== "";
|
|
38
|
-
} else if (str2 === "") {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return str1 < str2;
|
|
42
|
-
}
|
|
43
43
|
for (let key of Object.keys(oldV)) {
|
|
44
44
|
if (key === "stage" && compareStrings(oldV[key], newV[key])) {
|
|
45
45
|
return true;
|
|
@@ -49,8 +49,8 @@ function defaultIsLowerVersion(oldVer, newVer) {
|
|
|
49
49
|
}
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
52
53
|
function isUpdateJSON(json) {
|
|
53
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
54
54
|
return is(json) && is(json?.beta);
|
|
55
55
|
}
|
|
56
56
|
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
|
@@ -22,8 +22,8 @@ function parseVersion(version) {
|
|
|
22
22
|
}
|
|
23
23
|
return ret;
|
|
24
24
|
}
|
|
25
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
25
26
|
function isUpdateJSON(json) {
|
|
26
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
27
27
|
return is(json) && is(json?.beta);
|
|
28
28
|
}
|
|
29
29
|
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { parseVersion } from './chunk-
|
|
1
|
+
import { parseVersion } from './chunk-CTUEQCKL.js';
|
|
2
2
|
import { bytecodeLog } from './chunk-5NKEXGI3.js';
|
|
3
|
-
import { bytecodeGeneratorScript } from './chunk-7IRGAAL2.js';
|
|
4
3
|
import path from 'node:path';
|
|
5
4
|
import fs from 'node:fs';
|
|
6
5
|
import cp from 'node:child_process';
|
|
@@ -8,6 +7,9 @@ import * as babel from '@babel/core';
|
|
|
8
7
|
import MagicString from 'magic-string';
|
|
9
8
|
import { getPackageInfoSync } from 'local-pkg';
|
|
10
9
|
|
|
10
|
+
// src/vite/bytecode/code.ts
|
|
11
|
+
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";
|
|
12
|
+
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';
|
|
11
13
|
var electronModule = getPackageInfoSync("electron");
|
|
12
14
|
var electronMajorVersion = parseVersion(electronModule.version).major;
|
|
13
15
|
var useStrict = "'use strict';";
|
|
@@ -44,9 +46,9 @@ function toRelativePath(filename, importer) {
|
|
|
44
46
|
const relPath = path.posix.relative(path.dirname(importer), filename);
|
|
45
47
|
return relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
46
48
|
}
|
|
49
|
+
var logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
47
50
|
function compileToBytecode(code, electronPath = getElectronPath()) {
|
|
48
51
|
let data = Buffer.from([]);
|
|
49
|
-
const logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
50
52
|
const bytecodePath = getBytecodeCompilerPath();
|
|
51
53
|
return new Promise((resolve, reject) => {
|
|
52
54
|
const proc = cp.spawn(electronPath, [bytecodePath], {
|
|
@@ -144,4 +146,4 @@ function convertLiteral(code, sourcemap, offset) {
|
|
|
144
146
|
};
|
|
145
147
|
}
|
|
146
148
|
|
|
147
|
-
export { bytecodeModuleLoader, compileToBytecode, convertArrowFunctionAndTemplate, convertLiteral,
|
|
149
|
+
export { bytecodeModuleLoader, bytecodeModuleLoaderCode, compileToBytecode, convertArrowFunctionAndTemplate, convertLiteral, electronMajorVersion, toRelativePath, useStrict };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __require } from './chunk-
|
|
1
|
+
import { __require } from './chunk-AAAM44NW.js';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import electron from 'electron';
|
|
@@ -45,21 +45,15 @@ function disableHWAccForWin7() {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
function singleInstance(window) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (window) {
|
|
52
|
-
window.
|
|
53
|
-
if (window.isMinimized()) {
|
|
54
|
-
window.restore();
|
|
55
|
-
}
|
|
56
|
-
window.focus();
|
|
48
|
+
electron.app.on("second-instance", () => {
|
|
49
|
+
if (window) {
|
|
50
|
+
window.show();
|
|
51
|
+
if (window.isMinimized()) {
|
|
52
|
+
window.restore();
|
|
57
53
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
54
|
+
window.focus();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
63
57
|
}
|
|
64
58
|
function setPortableAppDataPath(dirName = "data") {
|
|
65
59
|
const portablePath = path.join(path.dirname(electron.app.getPath("exe")), dirName);
|
|
@@ -4,24 +4,12 @@ import crypto from 'node:crypto';
|
|
|
4
4
|
// src/utils/zip.ts
|
|
5
5
|
async function defaultZipFile(buffer) {
|
|
6
6
|
return new Promise((resolve, reject) => {
|
|
7
|
-
zlib.brotliCompress(buffer, (err, buffer2) =>
|
|
8
|
-
if (err) {
|
|
9
|
-
reject(err);
|
|
10
|
-
} else {
|
|
11
|
-
resolve(buffer2);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
7
|
+
zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
14
8
|
});
|
|
15
9
|
}
|
|
16
10
|
async function defaultUnzipFile(buffer) {
|
|
17
11
|
return new Promise((resolve, reject) => {
|
|
18
|
-
zlib.brotliDecompress(buffer, (err, buffer2) =>
|
|
19
|
-
if (err) {
|
|
20
|
-
reject(err);
|
|
21
|
-
} else {
|
|
22
|
-
resolve(buffer2);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
12
|
+
zlib.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
25
13
|
});
|
|
26
14
|
}
|
|
27
15
|
function hashBuffer(data, length) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { electronMajorVersion } from './chunk-
|
|
1
|
+
import { electronMajorVersion } from './chunk-I2EHKJU4.js';
|
|
2
|
+
import './chunk-CTUEQCKL.js';
|
|
3
|
+
import { esmId } from './chunk-5NKEXGI3.js';
|
|
2
4
|
import MagicString from 'magic-string';
|
|
3
5
|
|
|
4
6
|
// src/vite/esm/constant.ts
|
|
@@ -41,4 +43,23 @@ function insertCJSShim(code, sourcemap, insertPosition = 0) {
|
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
// src/vite/esm/index.ts
|
|
47
|
+
function esm() {
|
|
48
|
+
let sourcemap;
|
|
49
|
+
return {
|
|
50
|
+
name: esmId,
|
|
51
|
+
enforce: "post",
|
|
52
|
+
configResolved(config) {
|
|
53
|
+
sourcemap = config.build.sourcemap;
|
|
54
|
+
},
|
|
55
|
+
renderChunk(code, _chunk, options) {
|
|
56
|
+
if (options.format === "es") {
|
|
57
|
+
const lastESMImport = findStaticImports(code).pop();
|
|
58
|
+
const pos = lastESMImport ? lastESMImport.end : 0;
|
|
59
|
+
return insertCJSShim(code, sourcemap, pos);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { esm };
|
package/dist/index.cjs
CHANGED
|
@@ -19,8 +19,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// src/utils/version.ts
|
|
22
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
22
23
|
function isUpdateJSON(json) {
|
|
23
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
24
24
|
return is(json) && is(json?.beta);
|
|
25
25
|
}
|
|
26
26
|
var isDev = __EIU_IS_DEV__;
|
|
@@ -40,6 +40,9 @@ function restartApp() {
|
|
|
40
40
|
electron__default.default.app.relaunch();
|
|
41
41
|
electron__default.default.app.quit();
|
|
42
42
|
}
|
|
43
|
+
function getPathFromMain(...paths) {
|
|
44
|
+
return isDev ? path__default.default.join(electron__default.default.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", ...paths) : getPathFromAppNameAsar("main", ...paths);
|
|
45
|
+
}
|
|
43
46
|
|
|
44
47
|
// src/entry/types.ts
|
|
45
48
|
var UpdaterError = class extends Error {
|
|
@@ -103,7 +106,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
103
106
|
}
|
|
104
107
|
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
105
108
|
try {
|
|
106
|
-
const result = format === "json" ? await this.provider.downloadJSON(
|
|
109
|
+
const result = format === "json" ? await this.provider.downloadJSON(electron__default.default.app.name, __EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
107
110
|
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
108
111
|
return result;
|
|
109
112
|
} catch (e) {
|
|
@@ -232,22 +235,13 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
232
235
|
async function createElectronApp(appOptions = {}) {
|
|
233
236
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
234
237
|
const {
|
|
235
|
-
mainPath =
|
|
236
|
-
isDev ? path__default.default.join(electron.app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
237
|
-
"main",
|
|
238
|
-
__EIU_MAIN_FILE__
|
|
239
|
-
),
|
|
238
|
+
mainPath = getPathFromMain(__EIU_MAIN_FILE__),
|
|
240
239
|
updater,
|
|
241
240
|
onInstall = defaultOnInstall,
|
|
242
241
|
beforeStart,
|
|
243
242
|
onStartError
|
|
244
243
|
} = appOptions;
|
|
245
|
-
|
|
246
|
-
if (typeof updater === "object" || !updater) {
|
|
247
|
-
updaterInstance = new Updater(updater);
|
|
248
|
-
} else {
|
|
249
|
-
updaterInstance = await updater();
|
|
250
|
-
}
|
|
244
|
+
const updaterInstance = typeof updater === "object" || !updater ? new Updater(updater) : await updater();
|
|
251
245
|
const logger = updaterInstance.logger;
|
|
252
246
|
try {
|
|
253
247
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
@@ -264,7 +258,7 @@ async function createElectronApp(appOptions = {}) {
|
|
|
264
258
|
} catch (error) {
|
|
265
259
|
logger?.error("startup error", error);
|
|
266
260
|
onStartError?.(error, logger);
|
|
267
|
-
|
|
261
|
+
electron__default.default.app.quit();
|
|
268
262
|
}
|
|
269
263
|
}
|
|
270
264
|
var initApp = createElectronApp;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { U as UpdateJSON, a as UpdateInfo } from './version-DcFMG3pT.cjs';
|
|
3
|
-
import { U as UpdateInfoWithExtraVersion, a as
|
|
4
|
-
export {
|
|
3
|
+
import { U as UpdateInfoWithExtraVersion, a as UpdaterUnavailableCode, b as UpdaterError, D as DownloadingInfo, I as IProvider, L as Logger, c as UpdaterOption, d as UpdateJSONWithURL } from './types-BPH66pNz.cjs';
|
|
4
|
+
export { f as UpdateInfoWithURL, e as UpdaterErrorCode } from './types-BPH66pNz.cjs';
|
|
5
5
|
import { Promisable } from '@subframe7536/type-utils';
|
|
6
6
|
|
|
7
7
|
declare class Updater extends EventEmitter<{
|
|
8
8
|
'checking': any;
|
|
9
9
|
'update-available': [data: UpdateInfoWithExtraVersion];
|
|
10
|
-
'update-not-available': [code:
|
|
10
|
+
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
|
|
11
11
|
'error': [error: UpdaterError];
|
|
12
12
|
'download-progress': [info: DownloadingInfo];
|
|
13
13
|
'update-downloaded': any;
|
|
@@ -143,4 +143,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
|
|
|
143
143
|
*/
|
|
144
144
|
declare const initApp: typeof createElectronApp;
|
|
145
145
|
|
|
146
|
-
export { type AppOption, Logger,
|
|
146
|
+
export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { U as UpdateJSON, a as UpdateInfo } from './version-DcFMG3pT.js';
|
|
3
|
-
import { U as UpdateInfoWithExtraVersion, a as
|
|
4
|
-
export {
|
|
3
|
+
import { U as UpdateInfoWithExtraVersion, a as UpdaterUnavailableCode, b as UpdaterError, D as DownloadingInfo, I as IProvider, L as Logger, c as UpdaterOption, d as UpdateJSONWithURL } from './types-DQKdsHc_.js';
|
|
4
|
+
export { f as UpdateInfoWithURL, e as UpdaterErrorCode } from './types-DQKdsHc_.js';
|
|
5
5
|
import { Promisable } from '@subframe7536/type-utils';
|
|
6
6
|
|
|
7
7
|
declare class Updater extends EventEmitter<{
|
|
8
8
|
'checking': any;
|
|
9
9
|
'update-available': [data: UpdateInfoWithExtraVersion];
|
|
10
|
-
'update-not-available': [code:
|
|
10
|
+
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
|
|
11
11
|
'error': [error: UpdaterError];
|
|
12
12
|
'download-progress': [info: DownloadingInfo];
|
|
13
13
|
'update-downloaded': any;
|
|
@@ -143,4 +143,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
|
|
|
143
143
|
*/
|
|
144
144
|
declare const initApp: typeof createElectronApp;
|
|
145
145
|
|
|
146
|
-
export { type AppOption, Logger,
|
|
146
|
+
export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp } from './chunk-
|
|
2
|
-
import { isUpdateJSON, __require } from './chunk-
|
|
1
|
+
import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp, getPathFromMain } from './chunk-JI27JWJN.js';
|
|
2
|
+
import { isUpdateJSON, __require } from './chunk-AAAM44NW.js';
|
|
3
3
|
import fs2 from 'node:fs';
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
|
-
import
|
|
6
|
-
import path from 'node:path';
|
|
5
|
+
import electron from 'electron';
|
|
7
6
|
|
|
8
7
|
// src/entry/types.ts
|
|
9
8
|
var UpdaterError = class extends Error {
|
|
@@ -67,7 +66,7 @@ var Updater = class extends EventEmitter {
|
|
|
67
66
|
}
|
|
68
67
|
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
69
68
|
try {
|
|
70
|
-
const result = format === "json" ? await this.provider.downloadJSON(app.name, __EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
69
|
+
const result = format === "json" ? await this.provider.downloadJSON(electron.app.name, __EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
71
70
|
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
72
71
|
return result;
|
|
73
72
|
} catch (e) {
|
|
@@ -196,22 +195,13 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
196
195
|
async function createElectronApp(appOptions = {}) {
|
|
197
196
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
198
197
|
const {
|
|
199
|
-
mainPath =
|
|
200
|
-
isDev ? path.join(app.getAppPath(), __EIU_MAIN_DEV_DIR__) : appNameAsarPath,
|
|
201
|
-
"main",
|
|
202
|
-
__EIU_MAIN_FILE__
|
|
203
|
-
),
|
|
198
|
+
mainPath = getPathFromMain(__EIU_MAIN_FILE__),
|
|
204
199
|
updater,
|
|
205
200
|
onInstall = defaultOnInstall,
|
|
206
201
|
beforeStart,
|
|
207
202
|
onStartError
|
|
208
203
|
} = appOptions;
|
|
209
|
-
|
|
210
|
-
if (typeof updater === "object" || !updater) {
|
|
211
|
-
updaterInstance = new Updater(updater);
|
|
212
|
-
} else {
|
|
213
|
-
updaterInstance = await updater();
|
|
214
|
-
}
|
|
204
|
+
const updaterInstance = typeof updater === "object" || !updater ? new Updater(updater) : await updater();
|
|
215
205
|
const logger = updaterInstance.logger;
|
|
216
206
|
try {
|
|
217
207
|
const tempAsarPath = `${appNameAsarPath}.tmp`;
|
|
@@ -228,7 +218,7 @@ async function createElectronApp(appOptions = {}) {
|
|
|
228
218
|
} catch (error) {
|
|
229
219
|
logger?.error("startup error", error);
|
|
230
220
|
onStartError?.(error, logger);
|
|
231
|
-
app.quit();
|
|
221
|
+
electron.app.quit();
|
|
232
222
|
}
|
|
233
223
|
}
|
|
234
224
|
var initApp = createElectronApp;
|
package/dist/provider.cjs
CHANGED
|
@@ -37,17 +37,17 @@ function parseVersion(version) {
|
|
|
37
37
|
}
|
|
38
38
|
return ret;
|
|
39
39
|
}
|
|
40
|
+
function compareStrings(str1, str2) {
|
|
41
|
+
if (str1 === "") {
|
|
42
|
+
return str2 !== "";
|
|
43
|
+
} else if (str2 === "") {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return str1 < str2;
|
|
47
|
+
}
|
|
40
48
|
function defaultIsLowerVersion(oldVer, newVer) {
|
|
41
49
|
const oldV = parseVersion(oldVer);
|
|
42
50
|
const newV = parseVersion(newVer);
|
|
43
|
-
function compareStrings(str1, str2) {
|
|
44
|
-
if (str1 === "") {
|
|
45
|
-
return str2 !== "";
|
|
46
|
-
} else if (str2 === "") {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return str1 < str2;
|
|
50
|
-
}
|
|
51
51
|
for (let key of Object.keys(oldV)) {
|
|
52
52
|
if (key === "stage" && compareStrings(oldV[key], newV[key])) {
|
|
53
53
|
return true;
|
|
@@ -57,8 +57,8 @@ function defaultIsLowerVersion(oldVer, newVer) {
|
|
|
57
57
|
}
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
60
61
|
function isUpdateJSON(json) {
|
|
61
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
62
62
|
return is(json) && is(json?.beta);
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -175,13 +175,7 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
175
175
|
}
|
|
176
176
|
async function defaultUnzipFile(buffer) {
|
|
177
177
|
return new Promise((resolve, reject) => {
|
|
178
|
-
zlib__default.default.brotliDecompress(buffer, (err, buffer2) =>
|
|
179
|
-
if (err) {
|
|
180
|
-
reject(err);
|
|
181
|
-
} else {
|
|
182
|
-
resolve(buffer2);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
178
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
185
179
|
});
|
|
186
180
|
}
|
|
187
181
|
|
package/dist/provider.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IProvider, d as UpdateJSONWithURL,
|
|
1
|
+
import { I as IProvider, d as UpdateJSONWithURL, f as UpdateInfoWithURL, D as DownloadingInfo, g as URLHandler, O as OnDownloading } from './types-BPH66pNz.cjs';
|
|
2
2
|
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.cjs';
|
|
3
3
|
import { d as defaultIsLowerVersion, U as UpdateJSON } from './version-DcFMG3pT.cjs';
|
|
4
4
|
import { Arrayable } from '@subframe7536/type-utils';
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IProvider, d as UpdateJSONWithURL,
|
|
1
|
+
import { I as IProvider, d as UpdateJSONWithURL, f as UpdateInfoWithURL, D as DownloadingInfo, g as URLHandler, O as OnDownloading } from './types-DQKdsHc_.js';
|
|
2
2
|
import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.js';
|
|
3
3
|
import { d as defaultIsLowerVersion, U as UpdateJSON } from './version-DcFMG3pT.js';
|
|
4
4
|
import { Arrayable } from '@subframe7536/type-utils';
|
package/dist/provider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defaultVerifySignature, defaultUnzipFile } from './chunk-
|
|
2
|
-
import { isUpdateJSON, defaultIsLowerVersion } from './chunk-
|
|
1
|
+
import { defaultVerifySignature, defaultUnzipFile } from './chunk-PUVBFHOK.js';
|
|
2
|
+
import { isUpdateJSON, defaultIsLowerVersion } from './chunk-AAAM44NW.js';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
4
|
import electron from 'electron';
|
|
5
5
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
2
|
import { a as UpdateInfo } from './version-DcFMG3pT.cjs';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
type
|
|
4
|
+
type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
|
|
5
|
+
type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
|
|
6
6
|
declare class UpdaterError extends Error {
|
|
7
|
-
code:
|
|
8
|
-
constructor(code:
|
|
7
|
+
code: UpdaterErrorCode;
|
|
8
|
+
constructor(code: UpdaterErrorCode, info: string);
|
|
9
9
|
}
|
|
10
10
|
interface Logger {
|
|
11
11
|
info: (msg: string) => void;
|
|
@@ -114,4 +114,4 @@ interface IProvider {
|
|
|
114
114
|
}
|
|
115
115
|
type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
|
|
116
116
|
|
|
117
|
-
export { type DownloadingInfo as D, type
|
|
117
|
+
export { type DownloadingInfo as D, type IProvider as I, type Logger as L, type OnDownloading as O, type UpdateInfoWithExtraVersion as U, type UpdaterUnavailableCode as a, UpdaterError as b, type UpdaterOption as c, type UpdateJSONWithURL as d, type UpdaterErrorCode as e, type UpdateInfoWithURL as f, type URLHandler as g };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
2
|
import { a as UpdateInfo } from './version-DcFMG3pT.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
type
|
|
4
|
+
type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
|
|
5
|
+
type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
|
|
6
6
|
declare class UpdaterError extends Error {
|
|
7
|
-
code:
|
|
8
|
-
constructor(code:
|
|
7
|
+
code: UpdaterErrorCode;
|
|
8
|
+
constructor(code: UpdaterErrorCode, info: string);
|
|
9
9
|
}
|
|
10
10
|
interface Logger {
|
|
11
11
|
info: (msg: string) => void;
|
|
@@ -114,4 +114,4 @@ interface IProvider {
|
|
|
114
114
|
}
|
|
115
115
|
type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
|
|
116
116
|
|
|
117
|
-
export { type DownloadingInfo as D, type
|
|
117
|
+
export { type DownloadingInfo as D, type IProvider as I, type Logger as L, type OnDownloading as O, type UpdateInfoWithExtraVersion as U, type UpdaterUnavailableCode as a, UpdaterError as b, type UpdaterOption as c, type UpdateJSONWithURL as d, type UpdaterErrorCode as e, type UpdateInfoWithURL as f, type URLHandler as g };
|