electron-incremental-update 2.2.0 → 2.2.1

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 CHANGED
@@ -840,30 +840,32 @@ export interface BuildEntryOption {
840
840
  */
841
841
  nativeModuleEntryMap?: Record<string, string>
842
842
  /**
843
- * Custom options for esbuild
843
+ * Skip process dynamic require
844
+ *
845
+ * Useful for `better-sqlite3` and other old packages
846
+ */
847
+ ignoreDynamicRequires?: boolean
848
+ /**
849
+ * `external` option in `build.rollupOptions`, external `.node` by default
850
+ */
851
+ external?: string | string[] | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void)
852
+ /**
853
+ * Custom options for `vite` build
844
854
  * ```ts
845
- * // default options
846
855
  * const options = {
847
- * entryPoints: {
848
- * entry: appEntryPath,
849
- * ...moduleEntryMap,
850
- * },
851
- * bundle: true,
852
- * platform: 'node',
853
- * outdir: entryOutputDirPath,
854
- * minify,
855
- * sourcemap,
856
- * entryNames: '[dir]/[name]',
857
- * assetNames: '[dir]/[name]',
858
- * external: ['electron', 'original-fs'],
859
- * loader: {
860
- * '.node': 'empty',
856
+ * plugins: [esm(), bytecodePlugin()], // load on needed
857
+ * build: {
858
+ * sourcemap,
859
+ * minify,
860
+ * outDir: entryOutputDirPath,
861
+ * commonjsOptions: { ignoreDynamicRequires },
862
+ * rollupOptions: { external },
861
863
  * },
862
864
  * define,
863
865
  * }
864
866
  * ```
865
867
  */
866
- overrideEsbuildOptions?: BuildOptions
868
+ overrideViteOptions?: InlineConfig
867
869
  /**
868
870
  * Resolve extra files on startup, such as `.node`
869
871
  * @remark won't trigger will reload
@@ -889,6 +891,20 @@ export interface BuildEntryOption {
889
891
  */
890
892
  skipIfExist?: boolean
891
893
  }) => void
894
+ /**
895
+ * Copy specified modules to entry output dir, just like `external` option in rollup
896
+ */
897
+ copyModules: (options: {
898
+ /**
899
+ * External Modules
900
+ */
901
+ modules: string[]
902
+ /**
903
+ * Skip copy if `to` exist
904
+ * @default true
905
+ */
906
+ skipIfExist?: boolean
907
+ }) => void
892
908
  }) => Promisable<void>
893
909
  }
894
910
 
@@ -1,6 +1,5 @@
1
- import { readableSize } from './chunk-WYQ5DRO7.js';
2
- import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-I2EHKJU4.js';
3
- import './chunk-CTUEQCKL.js';
1
+ import { readableSize } from './chunk-TPTWE33H.js';
2
+ import { convertLiteral, bytecodeModuleLoaderCode, bytecodeModuleLoader, convertArrowFunctionAndTemplate, compileToBytecode, useStrict, toRelativePath } from './chunk-7JCGLFGU.js';
4
3
  import { bytecodeLog, bytecodeId } from './chunk-5NKEXGI3.js';
5
4
  import path from 'node:path';
6
5
  import fs from 'node:fs';
@@ -1,4 +1,3 @@
1
- import { parseVersion } from './chunk-CTUEQCKL.js';
2
1
  import { bytecodeLog } from './chunk-5NKEXGI3.js';
3
2
  import path from 'node:path';
4
3
  import fs from 'node:fs';
@@ -10,6 +9,50 @@ import { getPackageInfoSync } from 'local-pkg';
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,5 +1,4 @@
1
- import { electronMajorVersion } from './chunk-I2EHKJU4.js';
2
- import './chunk-CTUEQCKL.js';
1
+ import { electronMajorVersion } from './chunk-7JCGLFGU.js';
3
2
  import { esmId } from './chunk-5NKEXGI3.js';
4
3
  import MagicString from 'magic-string';
5
4
 
package/dist/index.d.cts CHANGED
@@ -1,9 +1,46 @@
1
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';
2
+ import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.cjs';
3
+ import { I as IProvider, D as DownloadingInfo, U as UpdateJSONWithURL } from './types-C6lSLZWB.cjs';
5
4
  import { Promisable } from '@subframe7536/type-utils';
6
5
 
6
+ type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
7
+ type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
8
+ declare class UpdaterError extends Error {
9
+ code: UpdaterErrorCode;
10
+ constructor(code: UpdaterErrorCode, info: string);
11
+ }
12
+ interface Logger {
13
+ info: (msg: string) => void;
14
+ debug: (msg: string) => void;
15
+ warn: (msg: string) => void;
16
+ error: (msg: string, e?: unknown) => void;
17
+ }
18
+ interface UpdaterOption {
19
+ /**
20
+ * Update provider
21
+ *
22
+ * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
23
+ */
24
+ provider?: IProvider;
25
+ /**
26
+ * Certifaction key of signature, which will be auto generated by plugin,
27
+ * generate by `selfsigned` if not set
28
+ */
29
+ SIGNATURE_CERT?: string;
30
+ /**
31
+ * Whether to receive beta update
32
+ */
33
+ receiveBeta?: boolean;
34
+ /**
35
+ * Updater logger
36
+ */
37
+ logger?: Logger;
38
+ }
39
+ type UpdateInfoWithExtraVersion = UpdateInfo & {
40
+ appVersion: string;
41
+ entryVersion: string;
42
+ };
43
+
7
44
  declare class Updater extends EventEmitter<{
8
45
  'checking': any;
9
46
  'update-available': [data: UpdateInfoWithExtraVersion];
@@ -143,4 +180,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
143
180
  */
144
181
  declare const initApp: typeof createElectronApp;
145
182
 
146
- export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
183
+ 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,9 +1,46 @@
1
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';
2
+ import { U as UpdateInfo, a as UpdateJSON } from './version-BYVQ367i.js';
3
+ import { I as IProvider, D as DownloadingInfo, U as UpdateJSONWithURL } from './types-nE_pIMPo.js';
5
4
  import { Promisable } from '@subframe7536/type-utils';
6
5
 
6
+ type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
7
+ type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
8
+ declare class UpdaterError extends Error {
9
+ code: UpdaterErrorCode;
10
+ constructor(code: UpdaterErrorCode, info: string);
11
+ }
12
+ interface Logger {
13
+ info: (msg: string) => void;
14
+ debug: (msg: string) => void;
15
+ warn: (msg: string) => void;
16
+ error: (msg: string, e?: unknown) => void;
17
+ }
18
+ interface UpdaterOption {
19
+ /**
20
+ * Update provider
21
+ *
22
+ * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
23
+ */
24
+ provider?: IProvider;
25
+ /**
26
+ * Certifaction key of signature, which will be auto generated by plugin,
27
+ * generate by `selfsigned` if not set
28
+ */
29
+ SIGNATURE_CERT?: string;
30
+ /**
31
+ * Whether to receive beta update
32
+ */
33
+ receiveBeta?: boolean;
34
+ /**
35
+ * Updater logger
36
+ */
37
+ logger?: Logger;
38
+ }
39
+ type UpdateInfoWithExtraVersion = UpdateInfo & {
40
+ appVersion: string;
41
+ entryVersion: string;
42
+ };
43
+
7
44
  declare class Updater extends EventEmitter<{
8
45
  'checking': any;
9
46
  'update-available': [data: UpdateInfoWithExtraVersion];
@@ -143,4 +180,4 @@ declare function createElectronApp(appOptions?: AppOption): Promise<void>;
143
180
  */
144
181
  declare const initApp: typeof createElectronApp;
145
182
 
146
- export { type AppOption, Logger, UpdateInfoWithExtraVersion, Updater, UpdaterError, UpdaterOption, UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
183
+ export { type AppOption, type Logger, type UpdateInfoWithExtraVersion, Updater, UpdaterError, type UpdaterErrorCode, type UpdaterOption, type UpdaterUnavailableCode, autoUpdate, createElectronApp, initApp, startupWithUpdater };
package/dist/provider.cjs CHANGED
@@ -141,7 +141,7 @@ async function defaultDownloadAsar(url, headers, signal, onDownloading) {
141
141
  transferred += delta;
142
142
  const current = Date.now();
143
143
  onDownloading?.({
144
- percent: total ? +(transferred / total).toFixed(2) * 100 : -1,
144
+ percent: total > 0 ? +(transferred / total).toFixed(2) * 100 : -1,
145
145
  total,
146
146
  transferred,
147
147
  delta,
@@ -1,6 +1,6 @@
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
- import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.cjs';
3
- import { d as defaultIsLowerVersion, U as UpdateJSON } from './version-DcFMG3pT.cjs';
1
+ import { I as IProvider, U as UpdateJSONWithURL, a as UpdateInfoWithURL, D as DownloadingInfo, b as URLHandler, O as OnDownloading } from './types-C6lSLZWB.cjs';
2
+ import { f as defaultVerifySignature, a as defaultUnzipFile } from './crypto-Zynscwmj.cjs';
3
+ import { d as defaultIsLowerVersion, a as UpdateJSON } from './version-BYVQ367i.cjs';
4
4
  import { Arrayable } from '@subframe7536/type-utils';
5
5
 
6
6
  declare abstract class BaseProvider implements IProvider {
@@ -163,4 +163,4 @@ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string,
163
163
  */
164
164
  declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
165
165
 
166
- export { BaseProvider, DownloadingInfo, GitHubApiProvider, type GitHubApiProviderOptions, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, UpdateJSONWithURL, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, getHeader };
166
+ export { BaseProvider, DownloadingInfo, GitHubApiProvider, type GitHubApiProviderOptions, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, UpdateInfoWithURL, UpdateJSONWithURL, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, getHeader };
@@ -1,6 +1,6 @@
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
- import { f as defaultVerifySignature, a as defaultUnzipFile } from './zip-rm9ED9nU.js';
3
- import { d as defaultIsLowerVersion, U as UpdateJSON } from './version-DcFMG3pT.js';
1
+ import { I as IProvider, U as UpdateJSONWithURL, a as UpdateInfoWithURL, D as DownloadingInfo, b as URLHandler, O as OnDownloading } from './types-nE_pIMPo.js';
2
+ import { f as defaultVerifySignature, a as defaultUnzipFile } from './crypto-Zynscwmj.js';
3
+ import { d as defaultIsLowerVersion, a as UpdateJSON } from './version-BYVQ367i.js';
4
4
  import { Arrayable } from '@subframe7536/type-utils';
5
5
 
6
6
  declare abstract class BaseProvider implements IProvider {
@@ -163,4 +163,4 @@ declare function defaultDownloadUpdateJSON(url: string, headers: Record<string,
163
163
  */
164
164
  declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
165
165
 
166
- export { BaseProvider, DownloadingInfo, GitHubApiProvider, type GitHubApiProviderOptions, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, UpdateJSONWithURL, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, getHeader };
166
+ export { BaseProvider, DownloadingInfo, GitHubApiProvider, type GitHubApiProviderOptions, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, UpdateInfoWithURL, UpdateJSONWithURL, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, getHeader };
package/dist/provider.js CHANGED
@@ -81,7 +81,7 @@ async function defaultDownloadAsar(url, headers, signal, onDownloading) {
81
81
  transferred += delta;
82
82
  const current = Date.now();
83
83
  onDownloading?.({
84
- percent: total ? +(transferred / total).toFixed(2) * 100 : -1,
84
+ percent: total > 0 ? +(transferred / total).toFixed(2) * 100 : -1,
85
85
  total,
86
86
  transferred,
87
87
  delta,
@@ -1,47 +1,9 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { a as UpdateInfo } from './version-DcFMG3pT.js';
2
+ import { U as UpdateInfo } from './version-BYVQ367i.cjs';
3
3
 
4
- type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
5
- type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
6
- declare class UpdaterError extends Error {
7
- code: UpdaterErrorCode;
8
- constructor(code: UpdaterErrorCode, info: string);
9
- }
10
- interface Logger {
11
- info: (msg: string) => void;
12
- debug: (msg: string) => void;
13
- warn: (msg: string) => void;
14
- error: (msg: string, e?: unknown) => void;
15
- }
16
- interface UpdaterOption {
17
- /**
18
- * Update provider
19
- *
20
- * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
21
- */
22
- provider?: IProvider;
23
- /**
24
- * Certifaction key of signature, which will be auto generated by plugin,
25
- * generate by `selfsigned` if not set
26
- */
27
- SIGNATURE_CERT?: string;
28
- /**
29
- * Whether to receive beta update
30
- */
31
- receiveBeta?: boolean;
32
- /**
33
- * Updater logger
34
- */
35
- logger?: Logger;
36
- }
37
4
  type UpdateInfoWithURL = UpdateInfo & {
38
5
  url: string;
39
6
  };
40
- type UpdateInfoWithExtraVersion = UpdateInfo & {
41
- appVersion: string;
42
- entryVersion: string;
43
- };
44
-
45
7
  type OnDownloading = (progress: DownloadingInfo) => void;
46
8
  interface DownloadingInfo {
47
9
  /**
@@ -114,4 +76,4 @@ interface IProvider {
114
76
  }
115
77
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
116
78
 
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 };
79
+ export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, UpdateJSONWithURL as U, UpdateInfoWithURL as a, URLHandler as b };
@@ -1,47 +1,9 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
- import { a as UpdateInfo } from './version-DcFMG3pT.cjs';
2
+ import { U as UpdateInfo } from './version-BYVQ367i.js';
3
3
 
4
- type UpdaterErrorCode = 'ERR_DOWNLOAD' | 'ERR_VALIDATE' | 'ERR_PARAM' | 'ERR_NETWORK';
5
- type UpdaterUnavailableCode = 'UNAVAILABLE_ERROR' | 'UNAVAILABLE_DEV' | 'UNAVAILABLE_VERSION';
6
- declare class UpdaterError extends Error {
7
- code: UpdaterErrorCode;
8
- constructor(code: UpdaterErrorCode, info: string);
9
- }
10
- interface Logger {
11
- info: (msg: string) => void;
12
- debug: (msg: string) => void;
13
- warn: (msg: string) => void;
14
- error: (msg: string, e?: unknown) => void;
15
- }
16
- interface UpdaterOption {
17
- /**
18
- * Update provider
19
- *
20
- * If you will not setup `UpdateJSON` or `Buffer` in params when checking update or download, this option is **required**
21
- */
22
- provider?: IProvider;
23
- /**
24
- * Certifaction key of signature, which will be auto generated by plugin,
25
- * generate by `selfsigned` if not set
26
- */
27
- SIGNATURE_CERT?: string;
28
- /**
29
- * Whether to receive beta update
30
- */
31
- receiveBeta?: boolean;
32
- /**
33
- * Updater logger
34
- */
35
- logger?: Logger;
36
- }
37
4
  type UpdateInfoWithURL = UpdateInfo & {
38
5
  url: string;
39
6
  };
40
- type UpdateInfoWithExtraVersion = UpdateInfo & {
41
- appVersion: string;
42
- entryVersion: string;
43
- };
44
-
45
7
  type OnDownloading = (progress: DownloadingInfo) => void;
46
8
  interface DownloadingInfo {
47
9
  /**
@@ -114,4 +76,4 @@ interface IProvider {
114
76
  }
115
77
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
116
78
 
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 };
79
+ export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, UpdateJSONWithURL as U, UpdateInfoWithURL as a, URLHandler as b };
package/dist/utils.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-rm9ED9nU.cjs';
3
- export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-DcFMG3pT.cjs';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './crypto-Zynscwmj.cjs';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-BYVQ367i.cjs';
4
4
 
5
5
  /**
6
6
  * Compile time dev check
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BrowserWindow } from 'electron';
2
- export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './zip-rm9ED9nU.js';
3
- export { a as UpdateInfo, U as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-DcFMG3pT.js';
2
+ export { e as aesDecrypt, b as aesEncrypt, c as defaultSignature, a as defaultUnzipFile, f as defaultVerifySignature, d as defaultZipFile, h as hashBuffer } from './crypto-Zynscwmj.js';
3
+ export { U as UpdateInfo, a as UpdateJSON, V as Version, d as defaultIsLowerVersion, b as defaultVersionJsonGenerator, i as isUpdateJSON, p as parseVersion } from './version-BYVQ367i.js';
4
4
 
5
5
  /**
6
6
  * Compile time dev check
@@ -59,4 +59,4 @@ declare function isUpdateJSON(json: any): json is UpdateJSON;
59
59
  */
60
60
  declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
61
61
 
62
- export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
62
+ export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
@@ -59,4 +59,4 @@ declare function isUpdateJSON(json: any): json is UpdateJSON;
59
59
  */
60
60
  declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
61
61
 
62
- export { type UpdateJSON as U, type Version as V, type UpdateInfo as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
62
+ export { type UpdateInfo as U, type Version as V, type UpdateJSON as a, defaultVersionJsonGenerator as b, defaultIsLowerVersion as d, isUpdateJSON as i, parseVersion as p };
package/dist/vite.d.ts CHANGED
@@ -2,6 +2,7 @@ import { InlineConfig, PluginOption } from 'vite';
2
2
  import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
3
3
  import { Promisable } from '@subframe7536/type-utils';
4
4
  export { isCI } from 'ci-info';
5
+ export { getPackageInfo, getPackageInfoSync, loadPackageJSON, resolveModule } from 'local-pkg';
5
6
 
6
7
  /**
7
8
  * Update info json
@@ -18,12 +19,6 @@ type UpdateJSON = UpdateInfo & {
18
19
  beta: UpdateInfo;
19
20
  };
20
21
 
21
- interface PKG {
22
- name: string;
23
- version: string;
24
- main: string;
25
- type: 'commonjs' | 'module';
26
- }
27
22
  interface DistinguishedName {
28
23
  countryName?: string;
29
24
  stateOrProvinceName?: string;
@@ -37,6 +32,13 @@ interface DistinguishedName {
37
32
  businessCategory?: string;
38
33
  emailAddress?: string;
39
34
  }
35
+
36
+ interface PKG {
37
+ name: string;
38
+ version: string;
39
+ main: string;
40
+ type: 'commonjs' | 'module';
41
+ }
40
42
  interface BuildEntryOption {
41
43
  /**
42
44
  * Override to minify on entry
@@ -72,12 +74,24 @@ interface BuildEntryOption {
72
74
  */
73
75
  ignoreDynamicRequires?: boolean;
74
76
  /**
75
- * `external` option in `build.rollupOptions`
76
- * @default source => source.endsWith('.node')
77
+ * `external` option in `build.rollupOptions`, external `.node` by default
77
78
  */
78
- external?: (source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void;
79
+ external?: string | string[] | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void);
79
80
  /**
80
81
  * Custom options for `vite` build
82
+ * ```ts
83
+ * const options = {
84
+ * plugins: [esm(), bytecodePlugin()], // load on needed
85
+ * build: {
86
+ * sourcemap,
87
+ * minify,
88
+ * outDir: entryOutputDirPath,
89
+ * commonjsOptions: { ignoreDynamicRequires },
90
+ * rollupOptions: { external },
91
+ * },
92
+ * define,
93
+ * }
94
+ * ```
81
95
  */
82
96
  overrideViteOptions?: InlineConfig;
83
97
  /**
@@ -105,6 +119,20 @@ interface BuildEntryOption {
105
119
  */
106
120
  skipIfExist?: boolean;
107
121
  }) => void;
122
+ /**
123
+ * Copy specified modules to entry output dir, just like `external` option in rollup
124
+ */
125
+ copyModules: (options: {
126
+ /**
127
+ * External Modules
128
+ */
129
+ modules: string[];
130
+ /**
131
+ * Skip copy if `to` exist
132
+ * @default true
133
+ */
134
+ skipIfExist?: boolean;
135
+ }) => void;
108
136
  }) => Promisable<void>;
109
137
  }
110
138
  interface GeneratorOverrideFunctions {
@@ -238,6 +266,17 @@ interface BytecodeOptions {
238
266
  beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
239
267
  }
240
268
 
269
+ /**
270
+ * Obfuscate string
271
+ * @param code source code
272
+ * @param sourcemap whether to generate sourcemap
273
+ * @param offset custom offset
274
+ */
275
+ declare function convertLiteral(code: string, sourcemap?: boolean, offset?: number): {
276
+ code: string;
277
+ map?: any;
278
+ };
279
+
241
280
  type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
242
281
  [P in K]-?: T[P];
243
282
  };
@@ -393,4 +432,4 @@ interface ElectronWithUpdaterOptions {
393
432
  */
394
433
  declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
395
434
 
396
- export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater as default, electronWithUpdater };
435
+ export { type ElectronWithUpdaterOptions, convertLiteral, debugStartup, electronWithUpdater as default, electronWithUpdater };
package/dist/vite.js CHANGED
@@ -1,13 +1,15 @@
1
- import { readableSize } from './chunk-WYQ5DRO7.js';
2
- import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-CTUEQCKL.js';
1
+ import { readableSize, copyAndSkipIfExist } from './chunk-TPTWE33H.js';
2
+ import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-7JCGLFGU.js';
3
+ export { convertLiteral } from './chunk-7JCGLFGU.js';
3
4
  import { log, id } from './chunk-5NKEXGI3.js';
4
5
  import path3 from 'node:path';
5
6
  import fs2 from 'node:fs';
7
+ import { loadPackageJSON, getPackageInfoSync } from 'local-pkg';
8
+ export { getPackageInfo, getPackageInfoSync, loadPackageJSON, resolveModule } from 'local-pkg';
6
9
  import { normalizePath, mergeConfig } from 'vite';
7
10
  import ElectronSimple from 'vite-plugin-electron/simple';
8
11
  import { startup, build } from 'vite-plugin-electron';
9
12
  import { notBundle } from 'vite-plugin-electron/plugin';
10
- import { loadPackageJSON } from 'local-pkg';
11
13
  import { isCI } from 'ci-info';
12
14
  export { isCI } from 'ci-info';
13
15
  import Asar from '@electron/asar';
@@ -86,19 +88,15 @@ async function buildEntry({
86
88
  },
87
89
  vite: mergeConfig({
88
90
  plugins: [
89
- isESM && await import('./esm-5YR6V7VN.js').then((m) => m.esm()),
90
- bytecodeOptions && await import('./bytecode-Z5ZF4YGN.js').then((m) => m.bytecodePlugin("main", bytecodeOptions))
91
+ isESM && await import('./esm-UJAQJA65.js').then((m) => m.esm()),
92
+ bytecodeOptions && await import('./bytecode-7V24FFYI.js').then((m) => m.bytecodePlugin("main", bytecodeOptions))
91
93
  ],
92
94
  build: {
93
95
  sourcemap,
94
96
  minify,
95
97
  outDir: entryOutputDirPath,
96
- commonjsOptions: {
97
- ignoreDynamicRequires
98
- },
99
- rollupOptions: {
100
- external
101
- }
98
+ commonjsOptions: { ignoreDynamicRequires },
99
+ rollupOptions: { external }
102
100
  },
103
101
  define
104
102
  }, overrideViteOptions ?? {})
@@ -179,7 +177,7 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
179
177
  nativeModuleEntryMap = {},
180
178
  postBuild,
181
179
  ignoreDynamicRequires = false,
182
- external = (source) => source.endsWith(".node"),
180
+ external,
183
181
  overrideViteOptions = {}
184
182
  } = {},
185
183
  paths: {
@@ -223,7 +221,21 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
223
221
  nativeModuleEntryMap,
224
222
  overrideViteOptions,
225
223
  ignoreDynamicRequires,
226
- external
224
+ external: (source, importer, isResolved) => {
225
+ if (source.endsWith(".node")) {
226
+ return false;
227
+ }
228
+ if (!external) {
229
+ return void 0;
230
+ }
231
+ if (typeof external === "string") {
232
+ return source === external;
233
+ }
234
+ if (Array.isArray(external)) {
235
+ return external.includes(source);
236
+ }
237
+ return external(source, importer, isResolved);
238
+ }
227
239
  };
228
240
  const { privateKey, cert } = parseKeys({
229
241
  keyLength,
@@ -342,15 +354,22 @@ async function electronWithUpdater(options) {
342
354
  return path3.join(entryOutputDirPath, ...paths);
343
355
  },
344
356
  copyToEntryOutputDir({ from, to, skipIfExist = true }) {
345
- if (fs2.existsSync(from)) {
346
- const target = path3.join(entryOutputDirPath, to ?? path3.basename(from));
347
- if (!skipIfExist || !fs2.existsSync(target)) {
348
- try {
349
- fs2.cpSync(from, target);
350
- } catch (error) {
351
- log.warn(`Copy failed: ${error}`, { timestamp: true });
352
- }
357
+ if (!fs2.existsSync(from)) {
358
+ log.warn(`${from} not found`, { timestamp: true });
359
+ return;
360
+ }
361
+ const target = path3.join(entryOutputDirPath, to ?? path3.basename(from));
362
+ copyAndSkipIfExist(from, target, skipIfExist);
363
+ },
364
+ copyModules({ modules, skipIfExist = true }) {
365
+ const nodeModulesPath = path3.join(entryOutputDirPath, "node_modules");
366
+ for (const m of modules) {
367
+ const { rootPath } = getPackageInfoSync(m) || {};
368
+ if (!rootPath) {
369
+ log.warn(`Package '${m}' not found`, { timestamp: true });
370
+ continue;
353
371
  }
372
+ copyAndSkipIfExist(rootPath, path3.join(nodeModulesPath, m), skipIfExist);
354
373
  }
355
374
  }
356
375
  }) : async () => {
@@ -360,7 +379,7 @@ async function electronWithUpdater(options) {
360
379
  external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src) || src === "original-fs",
361
380
  treeshake: true
362
381
  };
363
- const esmShimPlugin = isESM ? (await import('./esm-5YR6V7VN.js')).esm() : void 0;
382
+ const esmShimPlugin = isESM ? (await import('./esm-UJAQJA65.js')).esm() : void 0;
364
383
  const electronPluginOptions = {
365
384
  main: {
366
385
  entry: _main.files,
@@ -380,7 +399,7 @@ async function electronWithUpdater(options) {
380
399
  {
381
400
  plugins: [
382
401
  !isBuild && useNotBundle ? notBundle() : void 0,
383
- bytecodeOptions && await import('./bytecode-Z5ZF4YGN.js').then((m) => m.bytecodePlugin("main", bytecodeOptions)),
402
+ bytecodeOptions && await import('./bytecode-7V24FFYI.js').then((m) => m.bytecodePlugin("main", bytecodeOptions)),
384
403
  esmShimPlugin
385
404
  ],
386
405
  build: {
@@ -400,7 +419,7 @@ async function electronWithUpdater(options) {
400
419
  vite: mergeConfig(
401
420
  {
402
421
  plugins: [
403
- bytecodeOptions && (await import('./bytecode-Z5ZF4YGN.js')).bytecodePlugin("preload", bytecodeOptions),
422
+ bytecodeOptions && (await import('./bytecode-7V24FFYI.js')).bytecodePlugin("preload", bytecodeOptions),
404
423
  esmShimPlugin,
405
424
  {
406
425
  name: `${id}-build`,
package/package.json CHANGED
@@ -1,87 +1,87 @@
1
- {
2
- "name": "electron-incremental-update",
3
- "type": "module",
4
- "version": "2.2.0",
5
- "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
- "author": "subframe7536",
7
- "license": "MIT",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/subframe7536/electron-incremental-update.git"
11
- },
12
- "keywords": [
13
- "electron",
14
- "incremental update",
15
- "updater",
16
- "bytecode"
17
- ],
18
- "exports": {
19
- ".": {
20
- "import": "./dist/index.js",
21
- "require": "./dist/index.cjs"
22
- },
23
- "./vite": {
24
- "import": "./dist/vite.js"
25
- },
26
- "./utils": {
27
- "import": "./dist/utils.js",
28
- "require": "./dist/utils.cjs"
29
- },
30
- "./provider": {
31
- "import": "./dist/provider.js",
32
- "require": "./dist/provider.cjs"
33
- }
34
- },
35
- "main": "dist/index.cjs",
36
- "module": "dist/index.js",
37
- "files": [
38
- "dist",
39
- "provider.d.ts",
40
- "provider.js",
41
- "utils.d.ts",
42
- "utils.js",
43
- "vite.d.ts",
44
- "vite.js"
45
- ],
46
- "scripts": {
47
- "dev": "tsup --watch",
48
- "build": "tsup && esno fix-module.cjs",
49
- "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
50
- "test": "vitest --run",
51
- "test:dev": "vitest",
52
- "format": "eslint . --fix"
53
- },
54
- "publishConfig": {
55
- "access": "public",
56
- "registry": "https://registry.npmjs.org/"
57
- },
58
- "peerDependencies": {
59
- "@electron/asar": "*",
60
- "esbuild": "*"
61
- },
62
- "dependencies": {
63
- "@babel/core": "^7.25.2",
64
- "@babel/plugin-transform-arrow-functions": "^7.24.7",
65
- "@babel/plugin-transform-template-literals": "^7.24.7",
66
- "@subframe7536/type-utils": "^0.1.6",
67
- "ci-info": "^4.0.0",
68
- "local-pkg": "^0.5.0",
69
- "magic-string": "^0.30.11",
70
- "selfsigned": "^2.4.1",
71
- "vite-plugin-electron": "^0.28.7"
72
- },
73
- "devDependencies": {
74
- "@subframe7536/eslint-config": "^0.8.0",
75
- "@types/babel__core": "^7.20.5",
76
- "@types/node": "^20.16.3",
77
- "bumpp": "^9.5.2",
78
- "electron": "28.2.10",
79
- "eslint": "^9.9.1",
80
- "esno": "^4.7.0",
81
- "tsup": "^8.2.4",
82
- "typescript": "^5.5.4",
83
- "vite": "^5.4.2",
84
- "vite-plugin-electron": "^0.28.7",
85
- "vitest": "^2.0.5"
86
- }
87
- }
1
+ {
2
+ "name": "electron-incremental-update",
3
+ "type": "module",
4
+ "version": "2.2.1",
5
+ "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
+ "author": "subframe7536",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/subframe7536/electron-incremental-update.git"
11
+ },
12
+ "keywords": [
13
+ "electron",
14
+ "incremental update",
15
+ "updater",
16
+ "bytecode"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ },
23
+ "./vite": {
24
+ "import": "./dist/vite.js"
25
+ },
26
+ "./utils": {
27
+ "import": "./dist/utils.js",
28
+ "require": "./dist/utils.cjs"
29
+ },
30
+ "./provider": {
31
+ "import": "./dist/provider.js",
32
+ "require": "./dist/provider.cjs"
33
+ }
34
+ },
35
+ "main": "dist/index.cjs",
36
+ "module": "dist/index.js",
37
+ "files": [
38
+ "dist",
39
+ "provider.d.ts",
40
+ "provider.js",
41
+ "utils.d.ts",
42
+ "utils.js",
43
+ "vite.d.ts",
44
+ "vite.js"
45
+ ],
46
+ "scripts": {
47
+ "dev": "tsup --watch",
48
+ "build": "tsup && esno fix-module.cjs",
49
+ "release": "pnpm test && pnpm run build && bumpp --all && npm publish",
50
+ "test": "vitest --run",
51
+ "test:dev": "vitest",
52
+ "format": "eslint . --fix"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public",
56
+ "registry": "https://registry.npmjs.org/"
57
+ },
58
+ "peerDependencies": {
59
+ "@electron/asar": "*",
60
+ "esbuild": "*"
61
+ },
62
+ "dependencies": {
63
+ "@babel/core": "^7.25.2",
64
+ "@babel/plugin-transform-arrow-functions": "^7.24.7",
65
+ "@babel/plugin-transform-template-literals": "^7.24.7",
66
+ "@subframe7536/type-utils": "^0.1.6",
67
+ "ci-info": "^4.0.0",
68
+ "local-pkg": "^0.5.0",
69
+ "magic-string": "^0.30.11",
70
+ "selfsigned": "^2.4.1",
71
+ "vite-plugin-electron": "^0.28.7"
72
+ },
73
+ "devDependencies": {
74
+ "@subframe7536/eslint-config": "^0.9.0",
75
+ "@types/babel__core": "^7.20.5",
76
+ "@types/node": "^20.16.5",
77
+ "bumpp": "^9.5.2",
78
+ "electron": "28.2.10",
79
+ "eslint": "^9.9.1",
80
+ "esno": "^4.7.0",
81
+ "tsup": "^8.2.4",
82
+ "typescript": "^5.5.4",
83
+ "vite": "^5.4.3",
84
+ "vite-plugin-electron": "^0.28.7",
85
+ "vitest": "^2.0.5"
86
+ }
87
+ }
@@ -1,43 +0,0 @@
1
- // src/utils/version.ts
2
- function parseVersion(version) {
3
- const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
4
- if (!match) {
5
- throw new TypeError(`invalid version: ${version}`);
6
- }
7
- const [major, minor, patch] = match.slice(1, 4).map(Number);
8
- const ret = {
9
- major,
10
- minor,
11
- patch,
12
- stage: "",
13
- stageVersion: -1
14
- };
15
- if (match[4]) {
16
- let [stage, _v] = match[4].split(".");
17
- ret.stage = stage;
18
- ret.stageVersion = Number(_v) || -1;
19
- }
20
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
21
- throw new TypeError(`Invalid version: ${version}`);
22
- }
23
- return ret;
24
- }
25
- var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
26
- function isUpdateJSON(json) {
27
- return is(json) && is(json?.beta);
28
- }
29
- function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
30
- existingJson.beta = {
31
- version,
32
- minimumVersion,
33
- signature
34
- };
35
- if (!parseVersion(version).stage) {
36
- existingJson.version = version;
37
- existingJson.minimumVersion = minimumVersion;
38
- existingJson.signature = signature;
39
- }
40
- return existingJson;
41
- }
42
-
43
- export { defaultVersionJsonGenerator, isUpdateJSON, parseVersion };
@@ -1,12 +0,0 @@
1
- // src/vite/utils.ts
2
- function readableSize(size) {
3
- const units = ["B", "KB", "MB", "GB"];
4
- let i = 0;
5
- while (size >= 1024 && i < units.length - 1) {
6
- size /= 1024;
7
- i++;
8
- }
9
- return `${size.toFixed(2)} ${units[i]}`;
10
- }
11
-
12
- export { readableSize };
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Default function to compress file using brotli
3
+ * @param buffer uncompressed file buffer
4
+ */
5
+ declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
6
+ /**
7
+ * Default function to decompress file using brotli
8
+ * @param buffer compressed file buffer
9
+ */
10
+ declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
11
+
1
12
  declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
13
  declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
14
  /**
@@ -19,15 +30,4 @@ declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): str
19
30
  */
20
31
  declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
21
32
 
22
- /**
23
- * Default function to compress file using brotli
24
- * @param buffer uncompressed file buffer
25
- */
26
- declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
27
- /**
28
- * Default function to decompress file using brotli
29
- * @param buffer compressed file buffer
30
- */
31
- declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
32
-
33
33
  export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Default function to compress file using brotli
3
+ * @param buffer uncompressed file buffer
4
+ */
5
+ declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
6
+ /**
7
+ * Default function to decompress file using brotli
8
+ * @param buffer compressed file buffer
9
+ */
10
+ declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
11
+
1
12
  declare function hashBuffer(data: string | Buffer, length: number): Buffer;
2
13
  declare function aesEncrypt(plainText: string, key: Buffer, iv: Buffer): string;
3
14
  /**
@@ -19,15 +30,4 @@ declare function aesDecrypt(encryptedText: string, key: Buffer, iv: Buffer): str
19
30
  */
20
31
  declare function defaultVerifySignature(buffer: Buffer, version: string, signature: string, cert: string): boolean;
21
32
 
22
- /**
23
- * Default function to compress file using brotli
24
- * @param buffer uncompressed file buffer
25
- */
26
- declare function defaultZipFile(buffer: Buffer): Promise<Buffer>;
27
- /**
28
- * Default function to decompress file using brotli
29
- * @param buffer compressed file buffer
30
- */
31
- declare function defaultUnzipFile(buffer: Buffer): Promise<Buffer>;
32
-
33
33
  export { defaultUnzipFile as a, aesEncrypt as b, defaultSignature as c, defaultZipFile as d, aesDecrypt as e, defaultVerifySignature as f, hashBuffer as h };