electron-incremental-update 1.0.2 → 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/dist/utils.js CHANGED
@@ -1,255 +1,4 @@
1
- "use strict";
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
@@ -1,8 +1,18 @@
1
+ import * as vite from 'vite';
1
2
  import { Plugin } from 'vite';
2
3
  import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
3
- import { Promisable, Prettify } from '@subframe7536/type-utils';
4
+ import { Promisable } from '@subframe7536/type-utils';
4
5
  import { BuildOptions } from 'esbuild';
5
- import { a as UpdateJSON } from './noDep-TvZoKVF8.js';
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
+ };
6
16
 
7
17
  type PKG = {
8
18
  name: string;
@@ -27,22 +37,22 @@ type BuildEntryOption = {
27
37
  * whether to minify
28
38
  * @default isBuild
29
39
  */
30
- minify: boolean;
40
+ minify?: boolean;
31
41
  /**
32
- * Whether to generate sourcemap
42
+ * whether to generate sourcemap
33
43
  * @default isBuild
34
44
  */
35
- sourcemap: boolean;
45
+ sourcemap?: boolean;
36
46
  /**
37
47
  * path to app entry output file
38
48
  * @default 'dist-entry'
39
49
  */
40
- entryOutputDirPath: string;
50
+ entryOutputDirPath?: string;
41
51
  /**
42
52
  * path to app entry file
43
53
  * @default 'electron/entry.ts'
44
54
  */
45
- appEntryPath: string;
55
+ appEntryPath?: string;
46
56
  /**
47
57
  * esbuild path map of native modules in entry directory
48
58
  *
@@ -76,7 +86,8 @@ type BuildEntryOption = {
76
86
  */
77
87
  overrideEsbuildOptions?: BuildOptions;
78
88
  /**
79
- * resolve extra files, such as `.node`
89
+ * resolve extra files on startup, such as `.node`
90
+ * @remark won't trigger will reload
80
91
  */
81
92
  postBuild?: (args: {
82
93
  /**
@@ -84,13 +95,13 @@ type BuildEntryOption = {
84
95
  */
85
96
  getPathFromEntryOutputDir: (...paths: string[]) => string;
86
97
  /**
87
- * copy file to `entryOutputDirPath`
98
+ * check exist and copy file to `entryOutputDirPath`
88
99
  *
89
100
  * if `to` absent, set to `basename(from)`
90
101
  *
91
102
  * if `skipIfExist` absent, skip copy if `to` exist
92
103
  */
93
- existsAndCopyToEntryOutputDir: (options: {
104
+ copyToEntryOutputDir: (options: {
94
105
  from: string;
95
106
  to?: string;
96
107
  /**
@@ -130,7 +141,7 @@ type ElectronUpdaterOptions = {
130
141
  /**
131
142
  * config for entry (app.asar)
132
143
  */
133
- entry?: Partial<BuildEntryOption>;
144
+ entry?: BuildEntryOption;
134
145
  /**
135
146
  * paths config
136
147
  */
@@ -243,24 +254,20 @@ type ElectronWithUpdaterOptions = {
243
254
  */
244
255
  isBuild: boolean;
245
256
  /**
246
- * name, version and main in `package.json`
257
+ * manullay setup package.json, read name, version and main
247
258
  * ```ts
248
259
  * import pkg from './package.json'
249
260
  * ```
250
261
  */
251
- pkg: PKG;
252
- /**
253
- * main options
254
- */
255
- main: Prettify<MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'>>;
262
+ pkg?: PKG;
256
263
  /**
257
- * preload options
264
+ * whether to generate sourcemap
258
265
  */
259
- preload: Prettify<MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'>>;
266
+ sourcemap?: boolean;
260
267
  /**
261
- * updater options
268
+ * whether to minify the code
262
269
  */
263
- updater?: ElectronUpdaterOptions;
270
+ minify?: boolean;
264
271
  /**
265
272
  * use NotBundle() plugin in main
266
273
  * @default true
@@ -270,7 +277,20 @@ type ElectronWithUpdaterOptions = {
270
277
  * Whether to log parsed options
271
278
  */
272
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;
273
292
  };
293
+ declare const log: vite.Logger;
274
294
  /**
275
295
  * build options for `vite-plugin-electron/simple`
276
296
  * - integrate with updater
@@ -321,6 +341,6 @@ type ElectronWithUpdaterOptions = {
321
341
  * }
322
342
  * })
323
343
  */
324
- declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[];
344
+ declare function electronWithUpdater(options: ElectronWithUpdaterOptions): (Plugin<any> | Promise<Plugin<any>[]> | undefined)[] | null;
325
345
 
326
- export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };
346
+ export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater, log };