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/dist/utils.cjs
CHANGED
|
@@ -62,21 +62,15 @@ function disableHWAccForWin7() {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
function singleInstance(window) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (window) {
|
|
69
|
-
window.
|
|
70
|
-
if (window.isMinimized()) {
|
|
71
|
-
window.restore();
|
|
72
|
-
}
|
|
73
|
-
window.focus();
|
|
65
|
+
electron__default.default.app.on("second-instance", () => {
|
|
66
|
+
if (window) {
|
|
67
|
+
window.show();
|
|
68
|
+
if (window.isMinimized()) {
|
|
69
|
+
window.restore();
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
71
|
+
window.focus();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
80
74
|
}
|
|
81
75
|
function setPortableAppDataPath(dirName = "data") {
|
|
82
76
|
const portablePath = path__default.default.join(path__default.default.dirname(electron__default.default.app.getPath("exe")), dirName);
|
|
@@ -121,24 +115,12 @@ function handleUnexpectedErrors(callback) {
|
|
|
121
115
|
}
|
|
122
116
|
async function defaultZipFile(buffer) {
|
|
123
117
|
return new Promise((resolve, reject) => {
|
|
124
|
-
zlib__default.default.brotliCompress(buffer, (err, buffer2) =>
|
|
125
|
-
if (err) {
|
|
126
|
-
reject(err);
|
|
127
|
-
} else {
|
|
128
|
-
resolve(buffer2);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
118
|
+
zlib__default.default.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
131
119
|
});
|
|
132
120
|
}
|
|
133
121
|
async function defaultUnzipFile(buffer) {
|
|
134
122
|
return new Promise((resolve, reject) => {
|
|
135
|
-
zlib__default.default.brotliDecompress(buffer, (err, buffer2) =>
|
|
136
|
-
if (err) {
|
|
137
|
-
reject(err);
|
|
138
|
-
} else {
|
|
139
|
-
resolve(buffer2);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
123
|
+
zlib__default.default.brotliDecompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
142
124
|
});
|
|
143
125
|
}
|
|
144
126
|
|
|
@@ -166,17 +148,17 @@ function parseVersion(version) {
|
|
|
166
148
|
}
|
|
167
149
|
return ret;
|
|
168
150
|
}
|
|
151
|
+
function compareStrings(str1, str2) {
|
|
152
|
+
if (str1 === "") {
|
|
153
|
+
return str2 !== "";
|
|
154
|
+
} else if (str2 === "") {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return str1 < str2;
|
|
158
|
+
}
|
|
169
159
|
function defaultIsLowerVersion(oldVer, newVer) {
|
|
170
160
|
const oldV = parseVersion(oldVer);
|
|
171
161
|
const newV = parseVersion(newVer);
|
|
172
|
-
function compareStrings(str1, str2) {
|
|
173
|
-
if (str1 === "") {
|
|
174
|
-
return str2 !== "";
|
|
175
|
-
} else if (str2 === "") {
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
return str1 < str2;
|
|
179
|
-
}
|
|
180
162
|
for (let key of Object.keys(oldV)) {
|
|
181
163
|
if (key === "stage" && compareStrings(oldV[key], newV[key])) {
|
|
182
164
|
return true;
|
|
@@ -186,8 +168,8 @@ function defaultIsLowerVersion(oldVer, newVer) {
|
|
|
186
168
|
}
|
|
187
169
|
return false;
|
|
188
170
|
}
|
|
171
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
189
172
|
function isUpdateJSON(json) {
|
|
190
|
-
const is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
191
173
|
return is(json) && is(json?.beta);
|
|
192
174
|
}
|
|
193
175
|
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
package/dist/utils.d.cts
CHANGED
|
@@ -55,9 +55,8 @@ declare function disableHWAccForWin7(): void;
|
|
|
55
55
|
/**
|
|
56
56
|
* Keep single electron instance and auto restore window on `second-instance` event
|
|
57
57
|
* @param window brwoser window to show
|
|
58
|
-
* @returns `false` if the app is running
|
|
59
58
|
*/
|
|
60
|
-
declare function singleInstance(window?: BrowserWindow):
|
|
59
|
+
declare function singleInstance(window?: BrowserWindow): void;
|
|
61
60
|
/**
|
|
62
61
|
* Set `AppData` dir to the dir of .exe file
|
|
63
62
|
*
|
|
@@ -71,13 +70,28 @@ declare function setPortableAppDataPath(dirName?: string): void;
|
|
|
71
70
|
* @param htmlFilePath html file path, default is `index.html`
|
|
72
71
|
*/
|
|
73
72
|
declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
|
|
74
|
-
|
|
73
|
+
interface BeautifyDevToolsOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Sans-serif font family
|
|
76
|
+
*/
|
|
75
77
|
sans: string;
|
|
78
|
+
/**
|
|
79
|
+
* Monospace font family
|
|
80
|
+
*/
|
|
76
81
|
mono: string;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to round scrollbar
|
|
84
|
+
*/
|
|
77
85
|
scrollbar?: boolean;
|
|
78
|
-
}
|
|
86
|
+
}
|
|
79
87
|
/**
|
|
80
|
-
*
|
|
88
|
+
* Beautify devtools' font and scrollbar
|
|
89
|
+
* @param win target window
|
|
90
|
+
* @param options sans font family, mono font family and scrollbar
|
|
91
|
+
*/
|
|
92
|
+
declare function beautifyDevTools(win: BrowserWindow, options: BeautifyDevToolsOptions): void;
|
|
93
|
+
/**
|
|
94
|
+
* Get joined path from main dir
|
|
81
95
|
* @param paths rest paths
|
|
82
96
|
*/
|
|
83
97
|
declare function getPathFromMain(...paths: string[]): string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -55,9 +55,8 @@ declare function disableHWAccForWin7(): void;
|
|
|
55
55
|
/**
|
|
56
56
|
* Keep single electron instance and auto restore window on `second-instance` event
|
|
57
57
|
* @param window brwoser window to show
|
|
58
|
-
* @returns `false` if the app is running
|
|
59
58
|
*/
|
|
60
|
-
declare function singleInstance(window?: BrowserWindow):
|
|
59
|
+
declare function singleInstance(window?: BrowserWindow): void;
|
|
61
60
|
/**
|
|
62
61
|
* Set `AppData` dir to the dir of .exe file
|
|
63
62
|
*
|
|
@@ -71,13 +70,28 @@ declare function setPortableAppDataPath(dirName?: string): void;
|
|
|
71
70
|
* @param htmlFilePath html file path, default is `index.html`
|
|
72
71
|
*/
|
|
73
72
|
declare function loadPage(win: BrowserWindow, htmlFilePath?: string): void;
|
|
74
|
-
|
|
73
|
+
interface BeautifyDevToolsOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Sans-serif font family
|
|
76
|
+
*/
|
|
75
77
|
sans: string;
|
|
78
|
+
/**
|
|
79
|
+
* Monospace font family
|
|
80
|
+
*/
|
|
76
81
|
mono: string;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to round scrollbar
|
|
84
|
+
*/
|
|
77
85
|
scrollbar?: boolean;
|
|
78
|
-
}
|
|
86
|
+
}
|
|
79
87
|
/**
|
|
80
|
-
*
|
|
88
|
+
* Beautify devtools' font and scrollbar
|
|
89
|
+
* @param win target window
|
|
90
|
+
* @param options sans font family, mono font family and scrollbar
|
|
91
|
+
*/
|
|
92
|
+
declare function beautifyDevTools(win: BrowserWindow, options: BeautifyDevToolsOptions): void;
|
|
93
|
+
/**
|
|
94
|
+
* Get joined path from main dir
|
|
81
95
|
* @param paths rest paths
|
|
82
96
|
*/
|
|
83
97
|
declare function getPathFromMain(...paths: string[]): string;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-
|
|
2
|
-
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-
|
|
3
|
-
export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-
|
|
1
|
+
export { beautifyDevTools, disableHWAccForWin7, getAppVersion, getEntryVersion, getPathFromAppNameAsar, getPathFromEntryAsar, getPathFromMain, getPathFromPreload, getPathFromPublic, handleUnexpectedErrors, importNative, isDev, isLinux, isMac, isWin, loadPage, requireNative, restartApp, setAppUserModelId, setPortableAppDataPath, singleInstance } from './chunk-JI27JWJN.js';
|
|
2
|
+
export { aesDecrypt, aesEncrypt, defaultSignature, defaultUnzipFile, defaultVerifySignature, defaultZipFile, hashBuffer } from './chunk-PUVBFHOK.js';
|
|
3
|
+
export { defaultIsLowerVersion, defaultVersionJsonGenerator, isUpdateJSON, parseVersion } from './chunk-AAAM44NW.js';
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { PluginOption } from 'vite';
|
|
1
|
+
import { InlineConfig, PluginOption } from 'vite';
|
|
2
2
|
import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
|
|
3
3
|
import { Promisable } from '@subframe7536/type-utils';
|
|
4
|
-
import { BuildOptions } from 'esbuild';
|
|
5
4
|
export { isCI } from 'ci-info';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -67,30 +66,20 @@ interface BuildEntryOption {
|
|
|
67
66
|
*/
|
|
68
67
|
nativeModuleEntryMap?: Record<string, string>;
|
|
69
68
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* bundle: true,
|
|
79
|
-
* platform: 'node',
|
|
80
|
-
* outdir: entryOutputDirPath,
|
|
81
|
-
* minify,
|
|
82
|
-
* sourcemap,
|
|
83
|
-
* entryNames: '[dir]/[name]',
|
|
84
|
-
* assetNames: '[dir]/[name]',
|
|
85
|
-
* external: ['electron', 'original-fs'],
|
|
86
|
-
* loader: {
|
|
87
|
-
* '.node': 'empty',
|
|
88
|
-
* },
|
|
89
|
-
* define,
|
|
90
|
-
* }
|
|
91
|
-
* ```
|
|
69
|
+
* Skip process dynamic require
|
|
70
|
+
*
|
|
71
|
+
* Useful for `better-sqlite3` and other old packages
|
|
72
|
+
*/
|
|
73
|
+
ignoreDynamicRequires?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* `external` option in `build.rollupOptions`
|
|
76
|
+
* @default source => source.endsWith('.node')
|
|
92
77
|
*/
|
|
93
|
-
|
|
78
|
+
external?: (source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void;
|
|
79
|
+
/**
|
|
80
|
+
* Custom options for `vite` build
|
|
81
|
+
*/
|
|
82
|
+
overrideViteOptions?: InlineConfig;
|
|
94
83
|
/**
|
|
95
84
|
* Resolve extra files on startup, such as `.node`
|
|
96
85
|
* @remark won't trigger will reload
|
|
@@ -367,6 +356,40 @@ interface ElectronWithUpdaterOptions {
|
|
|
367
356
|
* You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
|
|
368
357
|
*
|
|
369
358
|
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* import { defineConfig } from 'vite'
|
|
361
|
+
* import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
|
|
362
|
+
*
|
|
363
|
+
* export default defineConfig(async ({ command }) => {
|
|
364
|
+
* const isBuild = command === 'build'
|
|
365
|
+
* return {
|
|
366
|
+
* plugins: [
|
|
367
|
+
* electronWithUpdater({
|
|
368
|
+
* isBuild,
|
|
369
|
+
* logParsedOptions: true,
|
|
370
|
+
* main: {
|
|
371
|
+
* files: ['./electron/main/index.ts', './electron/main/worker.ts'],
|
|
372
|
+
* // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
|
|
373
|
+
* onstart: debugStartup,
|
|
374
|
+
* },
|
|
375
|
+
* preload: {
|
|
376
|
+
* files: './electron/preload/index.ts',
|
|
377
|
+
* },
|
|
378
|
+
* updater: {
|
|
379
|
+
* // options
|
|
380
|
+
* }
|
|
381
|
+
* }),
|
|
382
|
+
* ],
|
|
383
|
+
* server: process.env.VSCODE_DEBUG && (() => {
|
|
384
|
+
* const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
|
385
|
+
* return {
|
|
386
|
+
* host: url.hostname,
|
|
387
|
+
* port: +url.port,
|
|
388
|
+
* }
|
|
389
|
+
* })(),
|
|
390
|
+
* }
|
|
391
|
+
* })
|
|
392
|
+
* ```
|
|
370
393
|
*/
|
|
371
394
|
declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
|
|
372
395
|
|
package/dist/vite.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { readableSize } from './chunk-WYQ5DRO7.js';
|
|
2
|
-
import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-
|
|
3
|
-
import { log, id
|
|
2
|
+
import { isUpdateJSON, defaultVersionJsonGenerator } from './chunk-CTUEQCKL.js';
|
|
3
|
+
import { log, id } from './chunk-5NKEXGI3.js';
|
|
4
4
|
import path3 from 'node:path';
|
|
5
|
-
import
|
|
5
|
+
import fs2 from 'node:fs';
|
|
6
6
|
import { normalizePath, mergeConfig } from 'vite';
|
|
7
7
|
import ElectronSimple from 'vite-plugin-electron/simple';
|
|
8
|
-
import { startup } from 'vite-plugin-electron';
|
|
8
|
+
import { startup, build } from 'vite-plugin-electron';
|
|
9
9
|
import { notBundle } from 'vite-plugin-electron/plugin';
|
|
10
10
|
import { loadPackageJSON } from 'local-pkg';
|
|
11
11
|
import { isCI } from 'ci-info';
|
|
12
12
|
export { isCI } from 'ci-info';
|
|
13
13
|
import Asar from '@electron/asar';
|
|
14
|
-
import { build } from 'esbuild';
|
|
15
14
|
import zlib from 'node:zlib';
|
|
16
15
|
import crypto from 'node:crypto';
|
|
17
16
|
import { generate } from 'selfsigned';
|
|
@@ -24,11 +23,11 @@ async function buildAsar({
|
|
|
24
23
|
rendererDistPath,
|
|
25
24
|
generateGzipFile
|
|
26
25
|
}) {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
fs2.renameSync(rendererDistPath, path3.join(electronDistPath, "renderer"));
|
|
27
|
+
fs2.writeFileSync(path3.join(electronDistPath, "version"), version);
|
|
29
28
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
30
|
-
const buf = await generateGzipFile(
|
|
31
|
-
|
|
29
|
+
const buf = await generateGzipFile(fs2.readFileSync(asarOutputPath));
|
|
30
|
+
fs2.writeFileSync(gzipPath, buf);
|
|
32
31
|
log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
|
|
33
32
|
return buf;
|
|
34
33
|
}
|
|
@@ -51,9 +50,9 @@ async function buildVersion({
|
|
|
51
50
|
signature: "",
|
|
52
51
|
version
|
|
53
52
|
};
|
|
54
|
-
if (
|
|
53
|
+
if (fs2.existsSync(versionPath)) {
|
|
55
54
|
try {
|
|
56
|
-
const oldVersionJson = JSON.parse(
|
|
55
|
+
const oldVersionJson = JSON.parse(fs2.readFileSync(versionPath, "utf-8"));
|
|
57
56
|
if (isUpdateJSON(oldVersionJson)) {
|
|
58
57
|
_json = oldVersionJson;
|
|
59
58
|
} else {
|
|
@@ -67,7 +66,7 @@ async function buildVersion({
|
|
|
67
66
|
if (!isUpdateJSON(_json)) {
|
|
68
67
|
throw new Error("Invalid version info");
|
|
69
68
|
}
|
|
70
|
-
|
|
69
|
+
fs2.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
71
70
|
log.info(`build version info to '${versionPath}'`, { timestamp: true });
|
|
72
71
|
}
|
|
73
72
|
async function buildEntry({
|
|
@@ -76,96 +75,38 @@ async function buildEntry({
|
|
|
76
75
|
appEntryPath,
|
|
77
76
|
entryOutputDirPath,
|
|
78
77
|
nativeModuleEntryMap,
|
|
79
|
-
|
|
78
|
+
ignoreDynamicRequires,
|
|
79
|
+
external,
|
|
80
|
+
overrideViteOptions
|
|
80
81
|
}, isESM, define, bytecodeOptions) {
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...nativeModuleEntryMap
|
|
86
|
-
},
|
|
87
|
-
bundle: true,
|
|
88
|
-
metafile: true,
|
|
89
|
-
platform: "node",
|
|
90
|
-
outdir: entryOutputDirPath,
|
|
91
|
-
minify,
|
|
92
|
-
sourcemap,
|
|
93
|
-
entryNames: "[dir]/[name]",
|
|
94
|
-
assetNames: "[dir]/[name]",
|
|
95
|
-
external: ["electron", "original-fs"],
|
|
96
|
-
treeShaking: true,
|
|
97
|
-
loader: {
|
|
98
|
-
".node": "empty"
|
|
99
|
-
},
|
|
100
|
-
define,
|
|
101
|
-
format: isESM ? "esm" : "cjs",
|
|
102
|
-
write: !isESM,
|
|
103
|
-
plugins: isESM ? [
|
|
104
|
-
{
|
|
105
|
-
name: "entry-esm-shim",
|
|
106
|
-
setup(build2) {
|
|
107
|
-
build2.onEnd(async ({ outputFiles }) => {
|
|
108
|
-
const parse = (await import('./utils-KPSYP7HQ.js')).insertCJSShim;
|
|
109
|
-
fs.mkdirSync(entryOutputDirPath, { recursive: true });
|
|
110
|
-
outputFiles?.filter((file) => file.path.endsWith(".js")).forEach((file) => {
|
|
111
|
-
const output = parse(file.text, sourcemap);
|
|
112
|
-
fs.writeFileSync(file.path, output?.code || file.text, "utf-8");
|
|
113
|
-
if (sourcemap && output?.map) {
|
|
114
|
-
fs.writeFileSync(`${file.path}.map`, output.map.toString(), "utf-8");
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
] : void 0
|
|
82
|
+
await build({
|
|
83
|
+
entry: {
|
|
84
|
+
entry: appEntryPath,
|
|
85
|
+
...nativeModuleEntryMap
|
|
121
86
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (bytecodeOptions.beforeCompile) {
|
|
142
|
-
const result = await bytecodeOptions.beforeCompile(transformedCode, filePath);
|
|
143
|
-
if (result) {
|
|
144
|
-
transformedCode = result;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const buffer = await compileToBytecode(transformedCode, bytecodeOptions.electronPath);
|
|
148
|
-
fs.writeFileSync(
|
|
149
|
-
filePath,
|
|
150
|
-
`${isEntry ? bytecodeModuleLoaderCode : useStrict}${isEntry ? "" : "module.exports = "}require("./${fileName}c")`
|
|
151
|
-
);
|
|
152
|
-
fs.writeFileSync(`${filePath}c`, buffer);
|
|
153
|
-
bytecodeLog.info(
|
|
154
|
-
`${filePath} [${(buffer.byteLength / 1e3).toFixed(2)} kB]`,
|
|
155
|
-
{ timestamp: true }
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
bytecodeLog.info(`${filePaths.length} file${filePaths.length > 1 ? "s" : ""} compiled into bytecode`, { timestamp: true });
|
|
87
|
+
vite: mergeConfig({
|
|
88
|
+
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
|
+
],
|
|
92
|
+
build: {
|
|
93
|
+
sourcemap,
|
|
94
|
+
minify,
|
|
95
|
+
outDir: entryOutputDirPath,
|
|
96
|
+
commonjsOptions: {
|
|
97
|
+
ignoreDynamicRequires
|
|
98
|
+
},
|
|
99
|
+
rollupOptions: {
|
|
100
|
+
external
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
define
|
|
104
|
+
}, overrideViteOptions ?? {})
|
|
105
|
+
});
|
|
159
106
|
}
|
|
160
107
|
async function defaultZipFile(buffer) {
|
|
161
108
|
return new Promise((resolve, reject) => {
|
|
162
|
-
zlib.brotliCompress(buffer, (err, buffer2) =>
|
|
163
|
-
if (err) {
|
|
164
|
-
reject(err);
|
|
165
|
-
} else {
|
|
166
|
-
resolve(buffer2);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
109
|
+
zlib.brotliCompress(buffer, (err, buffer2) => err ? reject(err) : resolve(buffer2));
|
|
169
110
|
});
|
|
170
111
|
}
|
|
171
112
|
function hashBuffer(data, length) {
|
|
@@ -182,20 +123,20 @@ function defaultSignature(buffer, privateKey, cert, version) {
|
|
|
182
123
|
}
|
|
183
124
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
184
125
|
const privateKeyDir = path3.dirname(privateKeyPath);
|
|
185
|
-
if (!
|
|
186
|
-
|
|
126
|
+
if (!fs2.existsSync(privateKeyDir)) {
|
|
127
|
+
fs2.mkdirSync(privateKeyDir, { recursive: true });
|
|
187
128
|
}
|
|
188
129
|
const certDir = path3.dirname(certPath);
|
|
189
|
-
if (!
|
|
190
|
-
|
|
130
|
+
if (!fs2.existsSync(certDir)) {
|
|
131
|
+
fs2.mkdirSync(certDir, { recursive: true });
|
|
191
132
|
}
|
|
192
133
|
const { cert, private: privateKey } = generate(subject, {
|
|
193
134
|
keySize: keyLength,
|
|
194
135
|
algorithm: "sha256",
|
|
195
136
|
days
|
|
196
137
|
});
|
|
197
|
-
|
|
198
|
-
|
|
138
|
+
fs2.writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
139
|
+
fs2.writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
199
140
|
}
|
|
200
141
|
function parseKeys({
|
|
201
142
|
keyLength,
|
|
@@ -211,15 +152,15 @@ function parseKeys({
|
|
|
211
152
|
log.info("Use `UPDATER_PK` and `UPDATER_CERT` from environment variables", { timestamp: true });
|
|
212
153
|
return { privateKey, cert };
|
|
213
154
|
}
|
|
214
|
-
if (!
|
|
215
|
-
|
|
155
|
+
if (!fs2.existsSync(keysDir)) {
|
|
156
|
+
fs2.mkdirSync(keysDir);
|
|
216
157
|
}
|
|
217
|
-
if (!
|
|
158
|
+
if (!fs2.existsSync(privateKeyPath) || !fs2.existsSync(certPath)) {
|
|
218
159
|
log.info("No key pair found, generate new key pair", { timestamp: true });
|
|
219
160
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
220
161
|
}
|
|
221
|
-
privateKey =
|
|
222
|
-
cert =
|
|
162
|
+
privateKey = fs2.readFileSync(privateKeyPath, "utf-8");
|
|
163
|
+
cert = fs2.readFileSync(certPath, "utf-8");
|
|
223
164
|
return { privateKey, cert };
|
|
224
165
|
}
|
|
225
166
|
function parseSubjects(subject) {
|
|
@@ -237,7 +178,9 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
237
178
|
appEntryPath = "electron/entry.ts",
|
|
238
179
|
nativeModuleEntryMap = {},
|
|
239
180
|
postBuild,
|
|
240
|
-
|
|
181
|
+
ignoreDynamicRequires = false,
|
|
182
|
+
external = (source) => source.endsWith(".node"),
|
|
183
|
+
overrideViteOptions = {}
|
|
241
184
|
} = {},
|
|
242
185
|
paths: {
|
|
243
186
|
asarOutputPath = `release/${pkg.name}.asar`,
|
|
@@ -278,7 +221,9 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
278
221
|
entryOutputDirPath,
|
|
279
222
|
appEntryPath,
|
|
280
223
|
nativeModuleEntryMap,
|
|
281
|
-
|
|
224
|
+
overrideViteOptions,
|
|
225
|
+
ignoreDynamicRequires,
|
|
226
|
+
external
|
|
282
227
|
};
|
|
283
228
|
const { privateKey, cert } = parseKeys({
|
|
284
229
|
keyLength,
|
|
@@ -305,7 +250,7 @@ function debugStartup(args) {
|
|
|
305
250
|
args.startup();
|
|
306
251
|
}
|
|
307
252
|
}
|
|
308
|
-
function
|
|
253
|
+
function getMainFileBaseName(options) {
|
|
309
254
|
let mainFilePath;
|
|
310
255
|
if (typeof options === "string") {
|
|
311
256
|
mainFilePath = path3.basename(options);
|
|
@@ -314,7 +259,7 @@ function getMainFilePath(options) {
|
|
|
314
259
|
} else {
|
|
315
260
|
const name = options?.index ?? options?.main;
|
|
316
261
|
if (!name) {
|
|
317
|
-
throw new Error(`\`options.main.files\` (${options}) must have "index" or "main" key, like \`{ index: "
|
|
262
|
+
throw new Error(`\`options.main.files\` (${options}) must have "index" or "main" key, like \`{ index: "./electron/main/index.ts" }\``);
|
|
318
263
|
}
|
|
319
264
|
mainFilePath = options?.index ? "index.js" : "main.js";
|
|
320
265
|
}
|
|
@@ -364,8 +309,8 @@ async function electronWithUpdater(options) {
|
|
|
364
309
|
} = parseOptions(pkg, sourcemap, minify, updater);
|
|
365
310
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
366
311
|
try {
|
|
367
|
-
|
|
368
|
-
|
|
312
|
+
fs2.rmSync(buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
313
|
+
fs2.rmSync(entryOutputDirPath, { recursive: true, force: true });
|
|
369
314
|
} catch {
|
|
370
315
|
}
|
|
371
316
|
log.info(`Clear cache files`, { timestamp: true });
|
|
@@ -379,8 +324,7 @@ async function electronWithUpdater(options) {
|
|
|
379
324
|
__EIU_ENTRY_DIST_PATH__: JSON.stringify(normalizePath(buildEntryOption.entryOutputDirPath)),
|
|
380
325
|
__EIU_IS_DEV__: JSON.stringify(!isBuild),
|
|
381
326
|
__EIU_IS_ESM__: JSON.stringify(isESM),
|
|
382
|
-
|
|
383
|
-
__EIU_MAIN_FILE__: JSON.stringify(getMainFilePath(_main.files)),
|
|
327
|
+
__EIU_MAIN_FILE__: JSON.stringify(getMainFileBaseName(_main.files)),
|
|
384
328
|
__EIU_SIGNATURE_CERT__: JSON.stringify(cert),
|
|
385
329
|
__EIU_VERSION_PATH__: JSON.stringify(parseVersionPath(normalizePath(buildVersionOption.versionPath)))
|
|
386
330
|
};
|
|
@@ -398,11 +342,11 @@ async function electronWithUpdater(options) {
|
|
|
398
342
|
return path3.join(entryOutputDirPath, ...paths);
|
|
399
343
|
},
|
|
400
344
|
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
401
|
-
if (
|
|
345
|
+
if (fs2.existsSync(from)) {
|
|
402
346
|
const target = path3.join(entryOutputDirPath, to ?? path3.basename(from));
|
|
403
|
-
if (!skipIfExist || !
|
|
347
|
+
if (!skipIfExist || !fs2.existsSync(target)) {
|
|
404
348
|
try {
|
|
405
|
-
|
|
349
|
+
fs2.cpSync(from, target);
|
|
406
350
|
} catch (error) {
|
|
407
351
|
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
408
352
|
}
|
|
@@ -416,7 +360,7 @@ async function electronWithUpdater(options) {
|
|
|
416
360
|
external: (src) => src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src) || src === "original-fs",
|
|
417
361
|
treeshake: true
|
|
418
362
|
};
|
|
419
|
-
const esmShimPlugin = isESM ? (await import('./esm-
|
|
363
|
+
const esmShimPlugin = isESM ? (await import('./esm-5YR6V7VN.js')).esm() : void 0;
|
|
420
364
|
const electronPluginOptions = {
|
|
421
365
|
main: {
|
|
422
366
|
entry: _main.files,
|
|
@@ -436,7 +380,7 @@ async function electronWithUpdater(options) {
|
|
|
436
380
|
{
|
|
437
381
|
plugins: [
|
|
438
382
|
!isBuild && useNotBundle ? notBundle() : void 0,
|
|
439
|
-
bytecodeOptions &&
|
|
383
|
+
bytecodeOptions && await import('./bytecode-Z5ZF4YGN.js').then((m) => m.bytecodePlugin("main", bytecodeOptions)),
|
|
440
384
|
esmShimPlugin
|
|
441
385
|
],
|
|
442
386
|
build: {
|
|
@@ -456,7 +400,7 @@ async function electronWithUpdater(options) {
|
|
|
456
400
|
vite: mergeConfig(
|
|
457
401
|
{
|
|
458
402
|
plugins: [
|
|
459
|
-
bytecodeOptions && (await import('./bytecode-
|
|
403
|
+
bytecodeOptions && (await import('./bytecode-Z5ZF4YGN.js')).bytecodePlugin("preload", bytecodeOptions),
|
|
460
404
|
esmShimPlugin,
|
|
461
405
|
{
|
|
462
406
|
name: `${id}-build`,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "Electron incremental update tools with Vite plugin, support bytecode protection",
|
|
6
6
|
"author": "subframe7536",
|
|
7
7
|
"license": "MIT",
|
|
@@ -71,16 +71,16 @@
|
|
|
71
71
|
"vite-plugin-electron": "^0.28.7"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@subframe7536/eslint-config": "^0.
|
|
74
|
+
"@subframe7536/eslint-config": "^0.8.0",
|
|
75
75
|
"@types/babel__core": "^7.20.5",
|
|
76
|
-
"@types/node": "^20.
|
|
77
|
-
"bumpp": "^9.5.
|
|
76
|
+
"@types/node": "^20.16.3",
|
|
77
|
+
"bumpp": "^9.5.2",
|
|
78
78
|
"electron": "28.2.10",
|
|
79
|
-
"eslint": "^9.9.
|
|
79
|
+
"eslint": "^9.9.1",
|
|
80
80
|
"esno": "^4.7.0",
|
|
81
81
|
"tsup": "^8.2.4",
|
|
82
82
|
"typescript": "^5.5.4",
|
|
83
|
-
"vite": "^5.4.
|
|
83
|
+
"vite": "^5.4.2",
|
|
84
84
|
"vite-plugin-electron": "^0.28.7",
|
|
85
85
|
"vitest": "^2.0.5"
|
|
86
86
|
}
|
package/dist/chunk-7IRGAAL2.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// src/vite/bytecode/code.ts
|
|
2
|
-
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";
|
|
3
|
-
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';
|
|
4
|
-
|
|
5
|
-
export { bytecodeGeneratorScript, bytecodeModuleLoaderCode };
|
package/dist/code-P5OANH3Q.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { bytecodeGeneratorScript, bytecodeModuleLoaderCode } from './chunk-7IRGAAL2.js';
|