electron-incremental-update 1.0.3 → 1.1.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 +549 -535
- package/dist/{chunk-OUZLSVQC.mjs → chunk-CXHA5TF7.js} +92 -4
- package/dist/{index.mjs → index.cjs} +172 -38
- package/dist/{index.d.mts → index.d.cts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +53 -157
- package/dist/utils.cjs +270 -0
- package/dist/{utils.d.mts → utils.d.cts} +9 -11
- package/dist/utils.d.ts +9 -11
- package/dist/utils.js +21 -253
- package/dist/vite.d.ts +31 -14
- package/dist/vite.js +121 -135
- package/package.json +24 -27
- package/utils.js +1 -1
- package/dist/chunk-GB6VLKJZ.mjs +0 -95
- package/dist/chunk-GXZSAUBR.mjs +0 -36
- package/dist/utils.mjs +0 -40
- package/dist/vite.d.mts +0 -329
- package/dist/vite.mjs +0 -404
- /package/dist/{noDep-TvZoKVF8.d.mts → pure-GoN_3MEj.d.cts} +0 -0
- /package/dist/{noDep-TvZoKVF8.d.ts → pure-GoN_3MEj.d.ts} +0 -0
package/dist/utils.js
CHANGED
|
@@ -1,255 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/index.ts
|
|
21
|
-
var utils_exports = {};
|
|
22
|
-
__export(utils_exports, {
|
|
23
|
-
disableHWAccForWin7: () => disableHWAccForWin7,
|
|
24
|
-
getPathFromAppNameAsar: () => getPathFromAppNameAsar,
|
|
25
|
-
getPaths: () => getPaths,
|
|
26
|
-
getVersions: () => getVersions,
|
|
27
|
-
handleUnexpectedErrors: () => handleUnexpectedErrors,
|
|
28
|
-
is: () => is,
|
|
29
|
-
isUpdateJSON: () => isUpdateJSON,
|
|
30
|
-
loadNativeModuleFromEntry: () => loadNativeModuleFromEntry,
|
|
31
|
-
parseGithubCdnURL: () => parseGithubCdnURL,
|
|
32
|
-
parseVersion: () => parseVersion,
|
|
33
|
-
restartApp: () => restartApp,
|
|
34
|
-
setAppUserModelId: () => setAppUserModelId,
|
|
35
|
-
setPortableAppDataPath: () => setPortableAppDataPath,
|
|
36
|
-
singleInstance: () => singleInstance,
|
|
37
|
-
unzipFile: () => unzipFile,
|
|
38
|
-
waitAppReady: () => waitAppReady,
|
|
39
|
-
zipFile: () => zipFile
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(utils_exports);
|
|
42
|
-
|
|
43
|
-
// src/utils/electron.ts
|
|
44
|
-
var import_node_fs = require("fs");
|
|
45
|
-
var import_node_path = require("path");
|
|
46
|
-
var import_node_os = require("os");
|
|
47
|
-
var import_electron = require("electron");
|
|
48
|
-
var is = {
|
|
49
|
-
dev: !import_electron.app.isPackaged,
|
|
50
|
-
win: process.platform === "win32",
|
|
51
|
-
mac: process.platform === "darwin",
|
|
52
|
-
linux: process.platform === "linux"
|
|
53
|
-
};
|
|
54
|
-
function getPathFromAppNameAsar(...path) {
|
|
55
|
-
return is.dev ? "DEV.asar" : (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getAppPath()), `${import_electron.app.name}.asar`, ...path);
|
|
56
|
-
}
|
|
57
|
-
function getVersions() {
|
|
58
|
-
const platform = is.win ? "Windows" : is.mac ? "MacOS" : process.platform.toUpperCase();
|
|
59
|
-
return {
|
|
60
|
-
appVersion: is.dev ? import_electron.app.getVersion() : (0, import_node_fs.readFileSync)(getPathFromAppNameAsar("version"), "utf-8"),
|
|
61
|
-
entryVersion: import_electron.app.getVersion(),
|
|
62
|
-
electronVersion: process.versions.electron,
|
|
63
|
-
nodeVersion: process.versions.node,
|
|
64
|
-
systemVersion: `${platform} ${(0, import_node_os.release)()}`
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function loadNativeModuleFromEntry(devEntryDirPath = "../../dist-entry", entryDirPath = (0, import_node_path.join)(import_electron.app.getAppPath(), (0, import_node_path.basename)(devEntryDirPath))) {
|
|
68
|
-
const path = is.dev ? devEntryDirPath : entryDirPath;
|
|
69
|
-
return (moduleName) => {
|
|
70
|
-
try {
|
|
71
|
-
return require((0, import_node_path.join)(path, moduleName));
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error("fail to load module", error);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function restartApp() {
|
|
78
|
-
import_electron.app.relaunch();
|
|
79
|
-
import_electron.app.quit();
|
|
80
|
-
}
|
|
81
|
-
function setAppUserModelId(id) {
|
|
82
|
-
import_electron.app.setAppUserModelId(is.dev ? process.execPath : id ?? `org.${import_electron.app.name}`);
|
|
83
|
-
}
|
|
84
|
-
function disableHWAccForWin7() {
|
|
85
|
-
if ((0, import_node_os.release)().startsWith("6.1")) {
|
|
86
|
-
import_electron.app.disableHardwareAcceleration();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function singleInstance(window) {
|
|
90
|
-
const result = import_electron.app.requestSingleInstanceLock();
|
|
91
|
-
result ? import_electron.app.on("second-instance", () => {
|
|
92
|
-
if (window) {
|
|
93
|
-
window.show();
|
|
94
|
-
if (window.isMinimized()) {
|
|
95
|
-
window.restore();
|
|
96
|
-
}
|
|
97
|
-
window.focus();
|
|
98
|
-
}
|
|
99
|
-
}) : import_electron.app.quit();
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
function setPortableAppDataPath(dirName = "data") {
|
|
103
|
-
const portablePath = (0, import_node_path.join)((0, import_node_path.dirname)(import_electron.app.getPath("exe")), dirName);
|
|
104
|
-
if (!(0, import_node_fs.existsSync)(portablePath)) {
|
|
105
|
-
(0, import_node_fs.mkdirSync)(portablePath);
|
|
106
|
-
}
|
|
107
|
-
import_electron.app.setPath("appData", portablePath);
|
|
108
|
-
}
|
|
109
|
-
function waitAppReady(timeout = 1e3) {
|
|
110
|
-
return import_electron.app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
111
|
-
const _ = setTimeout(() => {
|
|
112
|
-
reject(new Error("app is not ready"));
|
|
113
|
-
}, timeout);
|
|
114
|
-
import_electron.app.whenReady().then(() => {
|
|
115
|
-
clearTimeout(_);
|
|
116
|
-
resolve();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
function getPaths(entryDirName = "dist-entry") {
|
|
121
|
-
const root = (0, import_node_path.join)(__dirname, "..");
|
|
122
|
-
const mainDirPath = (0, import_node_path.join)(root, "main");
|
|
123
|
-
const preloadDirPath = (0, import_node_path.join)(root, "preload");
|
|
124
|
-
const rendererDirPath = (0, import_node_path.join)(root, "renderer");
|
|
125
|
-
const devServerURL = process.env.VITE_DEV_SERVER_URL;
|
|
126
|
-
const indexHTMLPath = (0, import_node_path.join)(rendererDirPath, "index.html");
|
|
127
|
-
const publicDirPath = devServerURL ? (0, import_node_path.join)(root, "../public") : rendererDirPath;
|
|
128
|
-
return {
|
|
129
|
-
/**
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* devServerURL && win.loadURL(devServerURL)
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
devServerURL,
|
|
136
|
-
/**
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* win.loadFile(indexHTMLPath)
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
indexHTMLPath,
|
|
143
|
-
/**
|
|
144
|
-
* get path inside entry asar
|
|
145
|
-
* @param paths joined path
|
|
146
|
-
*/
|
|
147
|
-
getPathFromEntryAsar(...paths) {
|
|
148
|
-
return (0, import_node_path.join)(import_electron.app.getAppPath(), entryDirName, ...paths);
|
|
149
|
-
},
|
|
150
|
-
/**
|
|
151
|
-
* get path inside `${app.name}.asar/main`
|
|
152
|
-
* @param paths joined path
|
|
153
|
-
*/
|
|
154
|
-
getPathFromMain(...paths) {
|
|
155
|
-
return (0, import_node_path.join)(mainDirPath, ...paths);
|
|
156
|
-
},
|
|
157
|
-
/**
|
|
158
|
-
* get path inside `${app.name}.asar/preload`
|
|
159
|
-
* @param paths joined path
|
|
160
|
-
*/
|
|
161
|
-
getPathFromPreload(...paths) {
|
|
162
|
-
return (0, import_node_path.join)(preloadDirPath, ...paths);
|
|
163
|
-
},
|
|
164
|
-
/**
|
|
165
|
-
* get path inside public dir
|
|
166
|
-
* @param paths joined path
|
|
167
|
-
*/
|
|
168
|
-
getPathFromPublic(...paths) {
|
|
169
|
-
return (0, import_node_path.join)(publicDirPath, ...paths);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/utils/zip.ts
|
|
175
|
-
var import_node_fs2 = require("fs");
|
|
176
|
-
var import_node_zlib = require("zlib");
|
|
177
|
-
async function unzipFile(gzipPath, targetFilePath = gzipPath.slice(0, -3)) {
|
|
178
|
-
if (!(0, import_node_fs2.existsSync)(gzipPath)) {
|
|
179
|
-
throw new Error(`path to zipped file not exist: ${gzipPath}`);
|
|
180
|
-
}
|
|
181
|
-
const compressedBuffer = (0, import_node_fs2.readFileSync)(gzipPath);
|
|
182
|
-
return new Promise((resolve, reject) => {
|
|
183
|
-
(0, import_node_zlib.gunzip)(compressedBuffer, (err, buffer) => {
|
|
184
|
-
(0, import_node_fs2.rmSync)(gzipPath);
|
|
185
|
-
if (err) {
|
|
186
|
-
reject(err);
|
|
187
|
-
}
|
|
188
|
-
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer);
|
|
189
|
-
resolve(null);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
async function zipFile(filePath, targetFilePath = `${filePath}.gz`) {
|
|
194
|
-
if (!(0, import_node_fs2.existsSync)(filePath)) {
|
|
195
|
-
throw new Error(`path to be zipped not exist: ${filePath}`);
|
|
196
|
-
}
|
|
197
|
-
const buffer = (0, import_node_fs2.readFileSync)(filePath);
|
|
198
|
-
return new Promise((resolve, reject) => {
|
|
199
|
-
(0, import_node_zlib.gzip)(buffer, (err, buffer2) => {
|
|
200
|
-
if (err) {
|
|
201
|
-
reject(err);
|
|
202
|
-
}
|
|
203
|
-
(0, import_node_fs2.writeFileSync)(targetFilePath, buffer2);
|
|
204
|
-
resolve(null);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// src/utils/noDep.ts
|
|
210
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
211
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
212
|
-
throw new Error("origin url must start with https://github.com/");
|
|
213
|
-
}
|
|
214
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
215
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
216
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
217
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
218
|
-
}
|
|
219
|
-
function handleUnexpectedErrors(callback) {
|
|
220
|
-
process.on("uncaughtException", callback);
|
|
221
|
-
process.on("unhandledRejection", callback);
|
|
222
|
-
}
|
|
223
|
-
function parseVersion(version) {
|
|
224
|
-
const semver = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9\.-]+))?/i;
|
|
225
|
-
const match = semver.exec(version);
|
|
226
|
-
if (!match) {
|
|
227
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
228
|
-
}
|
|
229
|
-
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
230
|
-
const ret = {
|
|
231
|
-
major,
|
|
232
|
-
minor,
|
|
233
|
-
patch,
|
|
234
|
-
stage: "",
|
|
235
|
-
stageVersion: -1
|
|
236
|
-
};
|
|
237
|
-
if (match[4]) {
|
|
238
|
-
let [stage, _v] = match[4].split(".");
|
|
239
|
-
ret.stage = stage;
|
|
240
|
-
ret.stageVersion = Number(_v) || -1;
|
|
241
|
-
}
|
|
242
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
243
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
244
|
-
}
|
|
245
|
-
return ret;
|
|
246
|
-
}
|
|
247
|
-
function isUpdateJSON(json) {
|
|
248
|
-
const is2 = (j) => !!(j && j.minimumVersion && j.signature && j.size && j.version);
|
|
249
|
-
return is2(json) && is2(json?.beta);
|
|
250
|
-
}
|
|
251
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
-
0 && (module.exports = {
|
|
1
|
+
import {
|
|
253
2
|
disableHWAccForWin7,
|
|
254
3
|
getPathFromAppNameAsar,
|
|
255
4
|
getPaths,
|
|
@@ -267,4 +16,23 @@ function isUpdateJSON(json) {
|
|
|
267
16
|
unzipFile,
|
|
268
17
|
waitAppReady,
|
|
269
18
|
zipFile
|
|
270
|
-
}
|
|
19
|
+
} from "./chunk-CXHA5TF7.js";
|
|
20
|
+
export {
|
|
21
|
+
disableHWAccForWin7,
|
|
22
|
+
getPathFromAppNameAsar,
|
|
23
|
+
getPaths,
|
|
24
|
+
getVersions,
|
|
25
|
+
handleUnexpectedErrors,
|
|
26
|
+
is,
|
|
27
|
+
isUpdateJSON,
|
|
28
|
+
loadNativeModuleFromEntry,
|
|
29
|
+
parseGithubCdnURL,
|
|
30
|
+
parseVersion,
|
|
31
|
+
restartApp,
|
|
32
|
+
setAppUserModelId,
|
|
33
|
+
setPortableAppDataPath,
|
|
34
|
+
singleInstance,
|
|
35
|
+
unzipFile,
|
|
36
|
+
waitAppReady,
|
|
37
|
+
zipFile
|
|
38
|
+
};
|
package/dist/vite.d.ts
CHANGED
|
@@ -3,7 +3,16 @@ import { Plugin } from 'vite';
|
|
|
3
3
|
import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
|
|
4
4
|
import { Promisable } from '@subframe7536/type-utils';
|
|
5
5
|
import { BuildOptions } from 'esbuild';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
type UpdateInfo = {
|
|
8
|
+
signature: string;
|
|
9
|
+
minimumVersion: string;
|
|
10
|
+
version: string;
|
|
11
|
+
size: number;
|
|
12
|
+
};
|
|
13
|
+
type UpdateJSON = UpdateInfo & {
|
|
14
|
+
beta: UpdateInfo;
|
|
15
|
+
};
|
|
7
16
|
|
|
8
17
|
type PKG = {
|
|
9
18
|
name: string;
|
|
@@ -86,13 +95,13 @@ type BuildEntryOption = {
|
|
|
86
95
|
*/
|
|
87
96
|
getPathFromEntryOutputDir: (...paths: string[]) => string;
|
|
88
97
|
/**
|
|
89
|
-
* copy file to `entryOutputDirPath`
|
|
98
|
+
* check exist and copy file to `entryOutputDirPath`
|
|
90
99
|
*
|
|
91
100
|
* if `to` absent, set to `basename(from)`
|
|
92
101
|
*
|
|
93
102
|
* if `skipIfExist` absent, skip copy if `to` exist
|
|
94
103
|
*/
|
|
95
|
-
|
|
104
|
+
copyToEntryOutputDir: (options: {
|
|
96
105
|
from: string;
|
|
97
106
|
to?: string;
|
|
98
107
|
/**
|
|
@@ -245,24 +254,20 @@ type ElectronWithUpdaterOptions = {
|
|
|
245
254
|
*/
|
|
246
255
|
isBuild: boolean;
|
|
247
256
|
/**
|
|
248
|
-
* name, version and main
|
|
257
|
+
* manullay setup package.json, read name, version and main
|
|
249
258
|
* ```ts
|
|
250
259
|
* import pkg from './package.json'
|
|
251
260
|
* ```
|
|
252
261
|
*/
|
|
253
|
-
pkg
|
|
254
|
-
/**
|
|
255
|
-
* main options
|
|
256
|
-
*/
|
|
257
|
-
main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'>;
|
|
262
|
+
pkg?: PKG;
|
|
258
263
|
/**
|
|
259
|
-
*
|
|
264
|
+
* whether to generate sourcemap
|
|
260
265
|
*/
|
|
261
|
-
|
|
266
|
+
sourcemap?: boolean;
|
|
262
267
|
/**
|
|
263
|
-
*
|
|
268
|
+
* whether to minify the code
|
|
264
269
|
*/
|
|
265
|
-
|
|
270
|
+
minify?: boolean;
|
|
266
271
|
/**
|
|
267
272
|
* use NotBundle() plugin in main
|
|
268
273
|
* @default true
|
|
@@ -272,6 +277,18 @@ type ElectronWithUpdaterOptions = {
|
|
|
272
277
|
* Whether to log parsed options
|
|
273
278
|
*/
|
|
274
279
|
logParsedOptions?: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* main options
|
|
282
|
+
*/
|
|
283
|
+
main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'>;
|
|
284
|
+
/**
|
|
285
|
+
* preload options
|
|
286
|
+
*/
|
|
287
|
+
preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'>;
|
|
288
|
+
/**
|
|
289
|
+
* updater options
|
|
290
|
+
*/
|
|
291
|
+
updater?: ElectronUpdaterOptions;
|
|
275
292
|
};
|
|
276
293
|
declare const log: vite.Logger;
|
|
277
294
|
/**
|
|
@@ -324,6 +341,6 @@ declare const log: vite.Logger;
|
|
|
324
341
|
* }
|
|
325
342
|
* })
|
|
326
343
|
*/
|
|
327
|
-
declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[];
|
|
344
|
+
declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[] | null;
|
|
328
345
|
|
|
329
346
|
export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater, log };
|