electron-incremental-update 2.2.0 → 2.2.2
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 +39 -21
- package/dist/{bytecode-Z5ZF4YGN.js → bytecode-R2B4KTMV.js} +4 -5
- package/dist/{chunk-I2EHKJU4.js → chunk-LR7LR5WG.js} +48 -5
- package/dist/chunk-TPTWE33H.js +23 -0
- package/dist/{chunk-PUVBFHOK.js → chunk-XGWQQVIZ.js} +12 -12
- package/dist/{esm-5YR6V7VN.js → esm-4S4XCVEW.js} +1 -2
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +55 -9
- package/dist/index.d.ts +55 -9
- package/dist/index.js +12 -8
- package/dist/provider.cjs +45 -49
- package/dist/provider.d.cts +37 -36
- package/dist/provider.d.ts +37 -36
- package/dist/provider.js +20 -23
- package/dist/{types-DQKdsHc_.d.ts → types-CStrrQPl.d.ts} +5 -42
- package/dist/{types-BPH66pNz.d.cts → types-CWtySwqA.d.cts} +5 -42
- package/dist/utils.cjs +37 -37
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -1
- package/dist/{version-DcFMG3pT.d.ts → version-Bl_0oO5f.d.cts} +13 -1
- package/dist/{version-DcFMG3pT.d.cts → version-Bl_0oO5f.d.ts} +13 -1
- package/dist/vite.d.ts +94 -32
- package/dist/vite.js +64 -36
- package/dist/{zip-rm9ED9nU.d.cts → zip-DQdr8pFv.d.cts} +1 -1
- package/dist/{zip-rm9ED9nU.d.ts → zip-DQdr8pFv.d.ts} +1 -1
- package/package.json +15 -16
- package/dist/chunk-CTUEQCKL.js +0 -43
- package/dist/chunk-WYQ5DRO7.js +0 -12
package/README.md
CHANGED
|
@@ -94,8 +94,8 @@ See all config in [types](#plugin)
|
|
|
94
94
|
in `vite.config.mts`
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
|
-
import { defineConfig } from 'vite'
|
|
98
97
|
import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
|
|
98
|
+
import { defineConfig } from 'vite'
|
|
99
99
|
|
|
100
100
|
export default defineConfig(async ({ command }) => {
|
|
101
101
|
const isBuild = command === 'build'
|
|
@@ -180,9 +180,9 @@ The update steps are similar to [electron-updater](https://github.com/electron-u
|
|
|
180
180
|
in `electron/main/index.ts`
|
|
181
181
|
|
|
182
182
|
```ts
|
|
183
|
-
import { UpdaterError, startupWithUpdater } from 'electron-incremental-update'
|
|
184
|
-
import { getPathFromAppNameAsar, getVersions } from 'electron-incremental-update/utils'
|
|
185
183
|
import { app } from 'electron'
|
|
184
|
+
import { startupWithUpdater, UpdaterError } from 'electron-incremental-update'
|
|
185
|
+
import { getPathFromAppNameAsar, getVersions } from 'electron-incremental-update/utils'
|
|
186
186
|
|
|
187
187
|
export default startupWithUpdater((updater) => {
|
|
188
188
|
await app.whenReady()
|
|
@@ -260,7 +260,7 @@ const plugin = electronWithUpdater({
|
|
|
260
260
|
db: './electron/native/db.ts',
|
|
261
261
|
img: './electron/native/img.ts',
|
|
262
262
|
},
|
|
263
|
-
postBuild: async ({ copyToEntryOutputDir }) => {
|
|
263
|
+
postBuild: async ({ copyToEntryOutputDir, copyModules }) => {
|
|
264
264
|
// for better-sqlite3
|
|
265
265
|
copyToEntryOutputDir({
|
|
266
266
|
from: './node_modules/better-sqlite3/build/Release/better_sqlite3.node',
|
|
@@ -273,6 +273,8 @@ const plugin = electronWithUpdater({
|
|
|
273
273
|
copyToEntryOutputDir({
|
|
274
274
|
from: `./node_modules/.pnpm/${fileName}/node_modules/@napi-rs/image-${archName}/image.${archName}.node`,
|
|
275
275
|
})
|
|
276
|
+
// or just copy specific dependency
|
|
277
|
+
copyModules({ modules: ['better-sqlite3'] })
|
|
276
278
|
},
|
|
277
279
|
},
|
|
278
280
|
},
|
|
@@ -840,30 +842,32 @@ export interface BuildEntryOption {
|
|
|
840
842
|
*/
|
|
841
843
|
nativeModuleEntryMap?: Record<string, string>
|
|
842
844
|
/**
|
|
843
|
-
*
|
|
845
|
+
* Skip process dynamic require
|
|
846
|
+
*
|
|
847
|
+
* Useful for `better-sqlite3` and other old packages
|
|
848
|
+
*/
|
|
849
|
+
ignoreDynamicRequires?: boolean
|
|
850
|
+
/**
|
|
851
|
+
* `external` option in `build.rollupOptions`, external `.node` by default
|
|
852
|
+
*/
|
|
853
|
+
external?: string | string[] | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void)
|
|
854
|
+
/**
|
|
855
|
+
* Custom options for `vite` build
|
|
844
856
|
* ```ts
|
|
845
|
-
* // default options
|
|
846
857
|
* const options = {
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
*
|
|
853
|
-
*
|
|
854
|
-
* minify,
|
|
855
|
-
* sourcemap,
|
|
856
|
-
* entryNames: '[dir]/[name]',
|
|
857
|
-
* assetNames: '[dir]/[name]',
|
|
858
|
-
* external: ['electron', 'original-fs'],
|
|
859
|
-
* loader: {
|
|
860
|
-
* '.node': 'empty',
|
|
858
|
+
* plugins: [esm(), bytecodePlugin()], // load on needed
|
|
859
|
+
* build: {
|
|
860
|
+
* sourcemap,
|
|
861
|
+
* minify,
|
|
862
|
+
* outDir: entryOutputDirPath,
|
|
863
|
+
* commonjsOptions: { ignoreDynamicRequires },
|
|
864
|
+
* rollupOptions: { external },
|
|
861
865
|
* },
|
|
862
866
|
* define,
|
|
863
867
|
* }
|
|
864
868
|
* ```
|
|
865
869
|
*/
|
|
866
|
-
|
|
870
|
+
overrideViteOptions?: InlineConfig
|
|
867
871
|
/**
|
|
868
872
|
* Resolve extra files on startup, such as `.node`
|
|
869
873
|
* @remark won't trigger will reload
|
|
@@ -889,6 +893,20 @@ export interface BuildEntryOption {
|
|
|
889
893
|
*/
|
|
890
894
|
skipIfExist?: boolean
|
|
891
895
|
}) => void
|
|
896
|
+
/**
|
|
897
|
+
* Copy specified modules to entry output dir, just like `external` option in rollup
|
|
898
|
+
*/
|
|
899
|
+
copyModules: (options: {
|
|
900
|
+
/**
|
|
901
|
+
* External Modules
|
|
902
|
+
*/
|
|
903
|
+
modules: string[]
|
|
904
|
+
/**
|
|
905
|
+
* Skip copy if `to` exist
|
|
906
|
+
* @default true
|
|
907
|
+
*/
|
|
908
|
+
skipIfExist?: boolean
|
|
909
|
+
}) => void
|
|
892
910
|
}) => Promisable<void>
|
|
893
911
|
}
|
|
894
912
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { readableSize } from './chunk-
|
|
2
|
-
import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-
|
|
3
|
-
import './chunk-CTUEQCKL.js';
|
|
1
|
+
import { readableSize } from './chunk-TPTWE33H.js';
|
|
2
|
+
import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-LR7LR5WG.js';
|
|
4
3
|
import { bytecodeLog, bytecodeId } from './chunk-5NKEXGI3.js';
|
|
5
|
-
import path from 'node:path';
|
|
6
4
|
import fs from 'node:fs';
|
|
7
|
-
import
|
|
5
|
+
import path from 'node:path';
|
|
8
6
|
import MagicString from 'magic-string';
|
|
7
|
+
import { createFilter, normalizePath } from 'vite';
|
|
9
8
|
|
|
10
9
|
function getBytecodeLoaderBlock(chunkFileName) {
|
|
11
10
|
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
@@ -1,15 +1,58 @@
|
|
|
1
|
-
import { parseVersion } from './chunk-CTUEQCKL.js';
|
|
2
1
|
import { bytecodeLog } from './chunk-5NKEXGI3.js';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
2
|
import cp from 'node:child_process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
6
5
|
import * as babel from '@babel/core';
|
|
7
|
-
import MagicString from 'magic-string';
|
|
8
6
|
import { getPackageInfoSync } from 'local-pkg';
|
|
7
|
+
import MagicString from 'magic-string';
|
|
9
8
|
|
|
10
9
|
// src/vite/bytecode/code.ts
|
|
11
10
|
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
11
|
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';
|
|
12
|
+
|
|
13
|
+
// src/utils/version.ts
|
|
14
|
+
function parseVersion(version) {
|
|
15
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
16
|
+
if (!match) {
|
|
17
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
18
|
+
}
|
|
19
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
20
|
+
const ret = {
|
|
21
|
+
major,
|
|
22
|
+
minor,
|
|
23
|
+
patch,
|
|
24
|
+
stage: "",
|
|
25
|
+
stageVersion: -1
|
|
26
|
+
};
|
|
27
|
+
if (match[4]) {
|
|
28
|
+
let [stage, _v] = match[4].split(".");
|
|
29
|
+
ret.stage = stage;
|
|
30
|
+
ret.stageVersion = Number(_v) || -1;
|
|
31
|
+
}
|
|
32
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
33
|
+
throw new TypeError(`Invalid version: ${version}`);
|
|
34
|
+
}
|
|
35
|
+
return ret;
|
|
36
|
+
}
|
|
37
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
38
|
+
function isUpdateJSON(json) {
|
|
39
|
+
return is(json) && is(json?.beta);
|
|
40
|
+
}
|
|
41
|
+
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
|
42
|
+
existingJson.beta = {
|
|
43
|
+
version,
|
|
44
|
+
minimumVersion,
|
|
45
|
+
signature
|
|
46
|
+
};
|
|
47
|
+
if (!parseVersion(version).stage) {
|
|
48
|
+
existingJson.version = version;
|
|
49
|
+
existingJson.minimumVersion = minimumVersion;
|
|
50
|
+
existingJson.signature = signature;
|
|
51
|
+
}
|
|
52
|
+
return existingJson;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/vite/bytecode/utils.ts
|
|
13
56
|
var electronModule = getPackageInfoSync("electron");
|
|
14
57
|
var electronMajorVersion = parseVersion(electronModule.version).major;
|
|
15
58
|
var useStrict = "'use strict';";
|
|
@@ -146,4 +189,4 @@ function convertLiteral(code, sourcemap, offset) {
|
|
|
146
189
|
};
|
|
147
190
|
}
|
|
148
191
|
|
|
149
|
-
export { bytecodeModuleLoader, bytecodeModuleLoaderCode, compileToBytecode, convertArrowFunctionAndTemplate, convertLiteral, electronMajorVersion, toRelativePath, useStrict };
|
|
192
|
+
export { bytecodeModuleLoader, bytecodeModuleLoaderCode, compileToBytecode, convertArrowFunctionAndTemplate, convertLiteral, defaultVersionJsonGenerator, electronMajorVersion, isUpdateJSON, toRelativePath, useStrict };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { log } from './chunk-5NKEXGI3.js';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
|
|
4
|
+
function readableSize(size) {
|
|
5
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
6
|
+
let i = 0;
|
|
7
|
+
while (size >= 1024 && i < units.length - 1) {
|
|
8
|
+
size /= 1024;
|
|
9
|
+
i++;
|
|
10
|
+
}
|
|
11
|
+
return `${size.toFixed(2)} ${units[i]}`;
|
|
12
|
+
}
|
|
13
|
+
function copyAndSkipIfExist(from, to, skipIfExist) {
|
|
14
|
+
if (!skipIfExist || !fs.existsSync(to)) {
|
|
15
|
+
try {
|
|
16
|
+
fs.cpSync(from, to, { recursive: true });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { copyAndSkipIfExist, readableSize };
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import zlib from 'node:zlib';
|
|
2
1
|
import crypto from 'node:crypto';
|
|
2
|
+
import zlib from 'node:zlib';
|
|
3
3
|
|
|
4
|
-
// src/utils/
|
|
5
|
-
async function defaultZipFile(buffer) {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
async function defaultUnzipFile(buffer) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
zlib.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
13
|
-
});
|
|
14
|
-
}
|
|
4
|
+
// src/utils/crypto.ts
|
|
15
5
|
function hashBuffer(data, length) {
|
|
16
6
|
const hash = crypto.createHash("SHA256").update(data).digest("binary");
|
|
17
7
|
return Buffer.from(hash).subarray(0, length);
|
|
@@ -39,5 +29,15 @@ function defaultVerifySignature(buffer, version, signature, cert) {
|
|
|
39
29
|
return false;
|
|
40
30
|
}
|
|
41
31
|
}
|
|
32
|
+
async function defaultZipFile(buffer) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async function defaultUnzipFile(buffer) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
zlib.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
42
|
|
|
43
43
|
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer };
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var fs3 = require('fs');
|
|
4
|
-
var
|
|
4
|
+
var path2 = require('path');
|
|
5
5
|
var electron = require('electron');
|
|
6
|
-
var
|
|
6
|
+
var events = require('events');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
10
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
11
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
11
12
|
var electron__default = /*#__PURE__*/_interopDefault(electron);
|
|
12
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
13
|
|
|
14
14
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
15
15
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -17,18 +17,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
17
17
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
18
18
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
// src/utils/version.ts
|
|
22
|
-
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
23
|
-
function isUpdateJSON(json) {
|
|
24
|
-
return is(json) && is(json?.beta);
|
|
25
|
-
}
|
|
26
20
|
var isDev = __EIU_IS_DEV__;
|
|
27
21
|
process.platform === "win32";
|
|
28
22
|
process.platform === "darwin";
|
|
29
23
|
process.platform === "linux";
|
|
30
24
|
function getPathFromAppNameAsar(...paths) {
|
|
31
|
-
return isDev ? "DEV.asar" :
|
|
25
|
+
return isDev ? "DEV.asar" : path2__default.default.join(path2__default.default.dirname(electron__default.default.app.getAppPath()), `${electron__default.default.app.name}.asar`, ...paths);
|
|
32
26
|
}
|
|
33
27
|
function getAppVersion() {
|
|
34
28
|
return isDev ? getEntryVersion() : fs3__default.default.readFileSync(getPathFromAppNameAsar("version"), "utf-8");
|
|
@@ -40,8 +34,11 @@ function restartApp() {
|
|
|
40
34
|
electron__default.default.app.relaunch();
|
|
41
35
|
electron__default.default.app.quit();
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
|
|
38
|
+
// src/utils/version.ts
|
|
39
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
40
|
+
function isUpdateJSON(json) {
|
|
41
|
+
return is(json) && is(json?.beta);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
// src/entry/types.ts
|
|
@@ -136,18 +133,19 @@ var Updater = class extends events.EventEmitter {
|
|
|
136
133
|
if (!_data) {
|
|
137
134
|
return emitUnavailable("Failed to get update info", "UNAVAILABLE_ERROR");
|
|
138
135
|
}
|
|
139
|
-
const { signature, version, minimumVersion, url = "" } = this.receiveBeta ? _data.beta : _data;
|
|
136
|
+
const { signature, version, minimumVersion, url = "", ...rest } = this.receiveBeta ? _data.beta : _data;
|
|
140
137
|
const info = { signature, minimumVersion, version, url };
|
|
141
138
|
const extraVersionInfo = {
|
|
142
139
|
signature,
|
|
143
140
|
minimumVersion,
|
|
144
141
|
version,
|
|
145
142
|
appVersion: getAppVersion(),
|
|
146
|
-
entryVersion: getEntryVersion()
|
|
143
|
+
entryVersion: getEntryVersion(),
|
|
144
|
+
...rest
|
|
147
145
|
};
|
|
148
146
|
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
149
147
|
if (isDev && !this.forceUpdate && !data) {
|
|
150
|
-
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV"
|
|
148
|
+
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV");
|
|
151
149
|
}
|
|
152
150
|
const isLowerVersion = this.provider.isLowerVersion;
|
|
153
151
|
try {
|
|
@@ -225,6 +223,8 @@ async function autoUpdate(updater) {
|
|
|
225
223
|
updater.quitAndInstall();
|
|
226
224
|
}
|
|
227
225
|
}
|
|
226
|
+
|
|
227
|
+
// src/entry/core.ts
|
|
228
228
|
function startupWithUpdater(fn) {
|
|
229
229
|
return fn;
|
|
230
230
|
}
|
|
@@ -235,7 +235,7 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
235
235
|
async function createElectronApp(appOptions = {}) {
|
|
236
236
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
237
237
|
const {
|
|
238
|
-
mainPath =
|
|
238
|
+
mainPath = isDev ? path2__default.default.join(electron__default.default.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", __EIU_MAIN_FILE__) : path2__default.default.join(path2__default.default.dirname(electron__default.default.app.getAppPath()), __EIU_ASAR_BASE_NAME__, "main", __EIU_MAIN_FILE__),
|
|
239
239
|
updater,
|
|
240
240
|
onInstall = defaultOnInstall,
|
|
241
241
|
beforeStart,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,59 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { U as UpdateJSON, a as UpdateInfo } from './version-DcFMG3pT.cjs';
|
|
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
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { I as IProvider, D as DownloadingInfo, U as UpdateJSONWithURL } from './types-CWtySwqA.cjs';
|
|
3
|
+
import { U as UpdateInfo, a as UpdateJSON } from './version-Bl_0oO5f.cjs';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
import 'node:url';
|
|
6
|
+
|
|
7
|
+
type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
|
|
8
|
+
type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
|
|
9
|
+
declare class UpdaterError extends Error {
|
|
10
|
+
code: UpdaterErrorCode;
|
|
11
|
+
constructor(code: UpdaterErrorCode, info: string);
|
|
12
|
+
}
|
|
13
|
+
interface Logger {
|
|
14
|
+
info: (msg: string) => void;
|
|
15
|
+
debug: (msg: string) => void;
|
|
16
|
+
warn: (msg: string) => void;
|
|
17
|
+
error: (msg: string, e?: unknown) => void;
|
|
18
|
+
}
|
|
19
|
+
interface UpdaterOption {
|
|
20
|
+
/**
|
|
21
|
+
* Update provider
|
|
22
|
+
*
|
|
23
|
+
* If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
|
|
24
|
+
*/
|
|
25
|
+
provider?: IProvider;
|
|
26
|
+
/**
|
|
27
|
+
* Certifaction key of signature, which will be auto generated by plugin,
|
|
28
|
+
* generate by `selfsigned` if not set
|
|
29
|
+
*/
|
|
30
|
+
SIGNATURE_CERT?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to receive beta update
|
|
33
|
+
*/
|
|
34
|
+
receiveBeta?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Updater logger
|
|
37
|
+
*/
|
|
38
|
+
logger?: Logger;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Update info with current app version and entry version
|
|
42
|
+
*/
|
|
43
|
+
type UpdateInfoWithExtraVersion = UpdateInfo & {
|
|
44
|
+
/**
|
|
45
|
+
* Current app version
|
|
46
|
+
*/
|
|
47
|
+
appVersion: string;
|
|
48
|
+
/**
|
|
49
|
+
* Current entry version
|
|
50
|
+
*/
|
|
51
|
+
entryVersion: string;
|
|
52
|
+
};
|
|
6
53
|
|
|
7
|
-
declare class Updater extends EventEmitter<{
|
|
8
|
-
'
|
|
9
|
-
'update-available': [
|
|
10
|
-
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
|
|
54
|
+
declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtraVersion> extends EventEmitter<{
|
|
55
|
+
'update-available': [data: T];
|
|
56
|
+
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: T];
|
|
11
57
|
'error': [error: UpdaterError];
|
|
12
58
|
'download-progress': [info: DownloadingInfo];
|
|
13
59
|
'update-downloaded': any;
|
|
@@ -143,4 +189,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
|
|
|
143
189
|
*/
|
|
144
190
|
declare const initApp: typeof createElectronApp;
|
|
145
191
|
|
|
146
|
-
export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
|
192
|
+
export { type AppOption, type Logger, type UpdateInfoWithExtraVersion, Updater, UpdaterError, type UpdaterErrorCode, type UpdaterOption, type UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,59 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { U as UpdateJSON, a as UpdateInfo } from './version-DcFMG3pT.js';
|
|
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
1
|
import { Promisable } from '@subframe7536/type-utils';
|
|
2
|
+
import { I as IProvider, D as DownloadingInfo, U as UpdateJSONWithURL } from './types-CStrrQPl.js';
|
|
3
|
+
import { U as UpdateInfo, a as UpdateJSON } from './version-Bl_0oO5f.js';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
import 'node:url';
|
|
6
|
+
|
|
7
|
+
type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
|
|
8
|
+
type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
|
|
9
|
+
declare class UpdaterError extends Error {
|
|
10
|
+
code: UpdaterErrorCode;
|
|
11
|
+
constructor(code: UpdaterErrorCode, info: string);
|
|
12
|
+
}
|
|
13
|
+
interface Logger {
|
|
14
|
+
info: (msg: string) => void;
|
|
15
|
+
debug: (msg: string) => void;
|
|
16
|
+
warn: (msg: string) => void;
|
|
17
|
+
error: (msg: string, e?: unknown) => void;
|
|
18
|
+
}
|
|
19
|
+
interface UpdaterOption {
|
|
20
|
+
/**
|
|
21
|
+
* Update provider
|
|
22
|
+
*
|
|
23
|
+
* If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
|
|
24
|
+
*/
|
|
25
|
+
provider?: IProvider;
|
|
26
|
+
/**
|
|
27
|
+
* Certifaction key of signature, which will be auto generated by plugin,
|
|
28
|
+
* generate by `selfsigned` if not set
|
|
29
|
+
*/
|
|
30
|
+
SIGNATURE_CERT?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to receive beta update
|
|
33
|
+
*/
|
|
34
|
+
receiveBeta?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Updater logger
|
|
37
|
+
*/
|
|
38
|
+
logger?: Logger;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Update info with current app version and entry version
|
|
42
|
+
*/
|
|
43
|
+
type UpdateInfoWithExtraVersion = UpdateInfo & {
|
|
44
|
+
/**
|
|
45
|
+
* Current app version
|
|
46
|
+
*/
|
|
47
|
+
appVersion: string;
|
|
48
|
+
/**
|
|
49
|
+
* Current entry version
|
|
50
|
+
*/
|
|
51
|
+
entryVersion: string;
|
|
52
|
+
};
|
|
6
53
|
|
|
7
|
-
declare class Updater extends EventEmitter<{
|
|
8
|
-
'
|
|
9
|
-
'update-available': [
|
|
10
|
-
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: UpdateInfoWithExtraVersion];
|
|
54
|
+
declare class Updater<T extends UpdateInfoWithExtraVersion = UpdateInfoWithExtraVersion> extends EventEmitter<{
|
|
55
|
+
'update-available': [data: T];
|
|
56
|
+
'update-not-available': [code: UpdaterUnavailableCode, msg: string, info?: T];
|
|
11
57
|
'error': [error: UpdaterError];
|
|
12
58
|
'download-progress': [info: DownloadingInfo];
|
|
13
59
|
'update-downloaded': any;
|
|
@@ -143,4 +189,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
|
|
|
143
189
|
*/
|
|
144
190
|
declare const initApp: typeof createElectronApp;
|
|
145
191
|
|
|
146
|
-
export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
|
192
|
+
export { type AppOption, type Logger, type UpdateInfoWithExtraVersion, Updater, UpdaterError, type UpdaterErrorCode, type UpdaterOption, type UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp
|
|
1
|
+
import { isDev, getAppVersion, getEntryVersion, getPathFromAppNameAsar, restartApp } from './chunk-JI27JWJN.js';
|
|
2
2
|
import { isUpdateJSON, __require } from './chunk-AAAM44NW.js';
|
|
3
3
|
import fs2 from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import electron2 from 'electron';
|
|
4
6
|
import { EventEmitter } from 'node:events';
|
|
5
|
-
import electron from 'electron';
|
|
6
7
|
|
|
7
8
|
// src/entry/types.ts
|
|
8
9
|
var UpdaterError = class extends Error {
|
|
@@ -66,7 +67,7 @@ var Updater = class extends EventEmitter {
|
|
|
66
67
|
}
|
|
67
68
|
this.logger?.debug(`Download from \`${this.provider.name}\``);
|
|
68
69
|
try {
|
|
69
|
-
const result = format === "json" ? await this.provider.downloadJSON(
|
|
70
|
+
const result = format === "json" ? await this.provider.downloadJSON(electron2.app.name, __EIU_VERSION_PATH__, this.controller.signal) : await this.provider.downloadAsar(this.info, this.controller.signal, (info) => this.emit("download-progress", info));
|
|
70
71
|
this.logger?.debug(`Download ${format} success${format === "buffer" ? `, file size: ${result.length}` : ""}`);
|
|
71
72
|
return result;
|
|
72
73
|
} catch (e) {
|
|
@@ -96,18 +97,19 @@ var Updater = class extends EventEmitter {
|
|
|
96
97
|
if (!_data) {
|
|
97
98
|
return emitUnavailable("Failed to get update info", "UNAVAILABLE_ERROR");
|
|
98
99
|
}
|
|
99
|
-
const { signature, version, minimumVersion, url = "" } = this.receiveBeta ? _data.beta : _data;
|
|
100
|
+
const { signature, version, minimumVersion, url = "", ...rest } = this.receiveBeta ? _data.beta : _data;
|
|
100
101
|
const info = { signature, minimumVersion, version, url };
|
|
101
102
|
const extraVersionInfo = {
|
|
102
103
|
signature,
|
|
103
104
|
minimumVersion,
|
|
104
105
|
version,
|
|
105
106
|
appVersion: getAppVersion(),
|
|
106
|
-
entryVersion: getEntryVersion()
|
|
107
|
+
entryVersion: getEntryVersion(),
|
|
108
|
+
...rest
|
|
107
109
|
};
|
|
108
110
|
this.logger?.debug(`Checked update, version: ${version}, signature: ${signature}`);
|
|
109
111
|
if (isDev && !this.forceUpdate && !data) {
|
|
110
|
-
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV"
|
|
112
|
+
return emitUnavailable("Skip check update in dev mode. To force update, set `updater.forceUpdate` to true or call checkUpdate with UpdateJSON", "UNAVAILABLE_DEV");
|
|
111
113
|
}
|
|
112
114
|
const isLowerVersion = this.provider.isLowerVersion;
|
|
113
115
|
try {
|
|
@@ -185,6 +187,8 @@ async function autoUpdate(updater) {
|
|
|
185
187
|
updater.quitAndInstall();
|
|
186
188
|
}
|
|
187
189
|
}
|
|
190
|
+
|
|
191
|
+
// src/entry/core.ts
|
|
188
192
|
function startupWithUpdater(fn) {
|
|
189
193
|
return fn;
|
|
190
194
|
}
|
|
@@ -195,7 +199,7 @@ var defaultOnInstall = (install, _, __, logger) => {
|
|
|
195
199
|
async function createElectronApp(appOptions = {}) {
|
|
196
200
|
const appNameAsarPath = getPathFromAppNameAsar();
|
|
197
201
|
const {
|
|
198
|
-
mainPath =
|
|
202
|
+
mainPath = isDev ? path.join(electron2.app.getAppPath(), __EIU_ELECTRON_DIST_PATH__, "main", __EIU_MAIN_FILE__) : path.join(path.dirname(electron2.app.getAppPath()), __EIU_ASAR_BASE_NAME__, "main", __EIU_MAIN_FILE__),
|
|
199
203
|
updater,
|
|
200
204
|
onInstall = defaultOnInstall,
|
|
201
205
|
beforeStart,
|
|
@@ -218,7 +222,7 @@ async function createElectronApp(appOptions = {}) {
|
|
|
218
222
|
} catch (error) {
|
|
219
223
|
logger?.error("startup error", error);
|
|
220
224
|
onStartError?.(error, logger);
|
|
221
|
-
|
|
225
|
+
electron2.app.quit();
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
228
|
var initApp = createElectronApp;
|