electron-incremental-update 0.9.1 → 1.0.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 +172 -112
- package/dist/{chunk-CMBFI77K.mjs → chunk-GB6VLKJZ.mjs} +48 -28
- package/dist/{chunk-5BZLJPHJ.mjs → chunk-GXZSAUBR.mjs} +1 -8
- package/dist/chunk-OUZLSVQC.mjs +148 -0
- package/dist/index.d.mts +102 -80
- package/dist/index.d.ts +102 -80
- package/dist/index.js +134 -71
- package/dist/index.mjs +97 -43
- package/dist/noDep-TvZoKVF8.d.mts +31 -0
- package/dist/noDep-TvZoKVF8.d.ts +31 -0
- package/dist/utils.d.mts +85 -48
- package/dist/utils.d.ts +85 -48
- package/dist/utils.js +127 -86
- package/dist/utils.mjs +14 -20
- package/dist/vite.d.mts +218 -41
- package/dist/vite.d.ts +218 -41
- package/dist/vite.js +245 -122
- package/dist/vite.mjs +222 -98
- package/package.json +18 -11
- package/dist/chunk-SPZL37O5.mjs +0 -124
- package/dist/updateJson-synsK-Pt.d.mts +0 -11
- package/dist/updateJson-synsK-Pt.d.ts +0 -11
package/dist/vite.mjs
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isUpdateJSON,
|
|
3
2
|
signature
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GXZSAUBR.mjs";
|
|
5
4
|
import {
|
|
5
|
+
isUpdateJSON,
|
|
6
6
|
parseVersion,
|
|
7
7
|
zipFile
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GB6VLKJZ.mjs";
|
|
9
9
|
|
|
10
10
|
// src/vite.ts
|
|
11
|
-
import {
|
|
11
|
+
import { join as join2, resolve } from "node:path";
|
|
12
|
+
import { rmSync } from "node:fs";
|
|
13
|
+
import { createLogger, mergeConfig, normalizePath } from "vite";
|
|
14
|
+
import ElectronSimple from "vite-plugin-electron/simple";
|
|
15
|
+
import { startup } from "vite-plugin-electron";
|
|
16
|
+
import { notBundle } from "vite-plugin-electron/plugin";
|
|
12
17
|
|
|
13
18
|
// src/build-plugins/build.ts
|
|
14
19
|
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
15
|
-
import { existsSync } from "node:fs";
|
|
20
|
+
import { cpSync, existsSync } from "node:fs";
|
|
21
|
+
import { basename, join } from "node:path";
|
|
16
22
|
import Asar from "@electron/asar";
|
|
17
23
|
import { build } from "esbuild";
|
|
18
24
|
async function buildAsar({
|
|
@@ -22,8 +28,8 @@ async function buildAsar({
|
|
|
22
28
|
electronDistPath,
|
|
23
29
|
rendererDistPath
|
|
24
30
|
}) {
|
|
25
|
-
await rename(rendererDistPath,
|
|
26
|
-
await writeFile(
|
|
31
|
+
await rename(rendererDistPath, join(electronDistPath, "renderer"));
|
|
32
|
+
await writeFile(join(electronDistPath, "version"), version);
|
|
27
33
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
28
34
|
await zipFile(asarOutputPath, gzipPath);
|
|
29
35
|
}
|
|
@@ -51,13 +57,15 @@ async function buildVersion({
|
|
|
51
57
|
};
|
|
52
58
|
if (existsSync(versionPath)) {
|
|
53
59
|
try {
|
|
54
|
-
|
|
60
|
+
const oldVersionJson = JSON.parse(await readFile(versionPath, "utf-8"));
|
|
61
|
+
if (isUpdateJSON(oldVersionJson)) {
|
|
62
|
+
_json = oldVersionJson;
|
|
63
|
+
} else {
|
|
64
|
+
console.warn("old version json is invalid, ignore it");
|
|
65
|
+
}
|
|
55
66
|
} catch (error) {
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
|
-
if (!isUpdateJSON(_json)) {
|
|
59
|
-
throw new Error("invalid version file");
|
|
60
|
-
}
|
|
61
69
|
const buffer = await readFile(gzipPath);
|
|
62
70
|
const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
|
|
63
71
|
if (generateVersionJson) {
|
|
@@ -66,10 +74,12 @@ async function buildVersion({
|
|
|
66
74
|
throw new Error("invalid version info");
|
|
67
75
|
}
|
|
68
76
|
} else {
|
|
69
|
-
_json.beta
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
_json.beta = {
|
|
78
|
+
version,
|
|
79
|
+
minimumVersion,
|
|
80
|
+
signature: sig,
|
|
81
|
+
size: buffer.length
|
|
82
|
+
};
|
|
73
83
|
if (!parseVersion(version).stage) {
|
|
74
84
|
_json.version = version;
|
|
75
85
|
_json.minimumVersion = minimumVersion;
|
|
@@ -80,17 +90,44 @@ async function buildVersion({
|
|
|
80
90
|
await writeFile(versionPath, JSON.stringify(_json, null, 2));
|
|
81
91
|
}
|
|
82
92
|
async function buildEntry({
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
sourcemap,
|
|
94
|
+
minify,
|
|
95
|
+
appEntryPath,
|
|
96
|
+
entryOutputDirPath,
|
|
97
|
+
nativeModuleEntryMap,
|
|
98
|
+
overrideEsbuildOptions,
|
|
99
|
+
postBuild
|
|
86
100
|
}) {
|
|
87
101
|
await build({
|
|
88
|
-
entryPoints:
|
|
102
|
+
entryPoints: {
|
|
103
|
+
entry: appEntryPath,
|
|
104
|
+
...nativeModuleEntryMap
|
|
105
|
+
},
|
|
89
106
|
bundle: true,
|
|
90
107
|
platform: "node",
|
|
91
|
-
|
|
108
|
+
outdir: entryOutputDirPath,
|
|
92
109
|
minify,
|
|
93
|
-
|
|
110
|
+
sourcemap,
|
|
111
|
+
entryNames: "[dir]/[name]",
|
|
112
|
+
assetNames: "[dir]/[name]",
|
|
113
|
+
external: ["electron", "original-fs"],
|
|
114
|
+
loader: {
|
|
115
|
+
".node": "empty"
|
|
116
|
+
},
|
|
117
|
+
...overrideEsbuildOptions
|
|
118
|
+
});
|
|
119
|
+
await postBuild?.({
|
|
120
|
+
getPathFromEntryOutputDir(...paths) {
|
|
121
|
+
return join(entryOutputDirPath, ...paths);
|
|
122
|
+
},
|
|
123
|
+
existsAndCopyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
124
|
+
if (existsSync(from)) {
|
|
125
|
+
const target = join(entryOutputDirPath, to ?? basename(from));
|
|
126
|
+
if (!skipIfExist || !existsSync(target)) {
|
|
127
|
+
cpSync(from, target);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
94
131
|
});
|
|
95
132
|
}
|
|
96
133
|
|
|
@@ -115,31 +152,21 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
|
115
152
|
writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
116
153
|
writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
117
154
|
}
|
|
118
|
-
|
|
155
|
+
var noCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
156
|
+
var existCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
157
|
+
function writeCertToEntry(entryPath, cert) {
|
|
158
|
+
if (!existsSync2(entryPath)) {
|
|
159
|
+
throw new Error(`entry not exist: ${entryPath}`);
|
|
160
|
+
}
|
|
119
161
|
const file = readFileSync(entryPath, "utf-8");
|
|
120
|
-
const
|
|
121
|
-
const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
122
|
-
const eol = file.includes("\r") ? "\r\n" : "\n";
|
|
123
|
-
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol} + `);
|
|
162
|
+
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join("\n + ");
|
|
124
163
|
let replaced = file;
|
|
125
|
-
if (
|
|
126
|
-
replaced = file.replace(
|
|
127
|
-
} else if (
|
|
128
|
-
replaced = file.replace(
|
|
164
|
+
if (noCertRegex.test(file)) {
|
|
165
|
+
replaced = file.replace(noCertRegex, replacement);
|
|
166
|
+
} else if (existCertRegex.test(file)) {
|
|
167
|
+
replaced = file.replace(existCertRegex, replacement);
|
|
129
168
|
} else {
|
|
130
|
-
|
|
131
|
-
const r = `${eol}const SIGNATURE_CERT = ${replacement}${eol}`;
|
|
132
|
-
let isMatched = false;
|
|
133
|
-
for (let i = 0; i < lines.length; i++) {
|
|
134
|
-
const line = lines[i];
|
|
135
|
-
if (!line.startsWith("import") && !line.startsWith("/")) {
|
|
136
|
-
lines.splice(i, 0, r);
|
|
137
|
-
isMatched = true;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
!isMatched && lines.push(r);
|
|
142
|
-
replaced = lines.join(eol);
|
|
169
|
+
throw new Error("no `SIGNATURE_CERT` found in entry");
|
|
143
170
|
}
|
|
144
171
|
writeFileSync(entryPath, replaced);
|
|
145
172
|
}
|
|
@@ -147,45 +174,41 @@ function parseKeys({
|
|
|
147
174
|
keyLength,
|
|
148
175
|
privateKeyPath,
|
|
149
176
|
certPath,
|
|
150
|
-
|
|
177
|
+
appEntryPath,
|
|
151
178
|
subject,
|
|
152
179
|
days
|
|
153
180
|
}) {
|
|
154
181
|
const keysDir = dirname(privateKeyPath);
|
|
155
182
|
!existsSync2(keysDir) && mkdirSync(keysDir);
|
|
156
183
|
if (!existsSync2(privateKeyPath) || !existsSync2(certPath)) {
|
|
184
|
+
console.warn("no key pair found, generate new key pair");
|
|
157
185
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
158
186
|
}
|
|
159
187
|
const privateKey = process.env.UPDATER_PK || readFileSync(privateKeyPath, "utf-8");
|
|
160
188
|
const cert = process.env.UPDATER_CERT || readFileSync(certPath, "utf-8");
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
privateKey,
|
|
164
|
-
cert
|
|
165
|
-
};
|
|
189
|
+
writeCertToEntry(appEntryPath, cert);
|
|
190
|
+
return { privateKey, cert };
|
|
166
191
|
}
|
|
167
192
|
function parseSubjects(subject) {
|
|
168
|
-
|
|
169
|
-
Object.keys(subject).forEach((name) => {
|
|
170
|
-
const value = subject[name];
|
|
171
|
-
value && ret.push({ name, value });
|
|
172
|
-
});
|
|
173
|
-
return ret;
|
|
193
|
+
return Object.entries(subject).filter(([_, value]) => !!value).map(([name, value]) => ({ name, value }));
|
|
174
194
|
}
|
|
175
195
|
|
|
176
196
|
// src/build-plugins/option.ts
|
|
177
|
-
function parseOptions(options) {
|
|
197
|
+
function parseOptions(isBuild, pkg, options = {}) {
|
|
178
198
|
const {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
minimumVersion = "0.0.0",
|
|
200
|
+
entry: {
|
|
201
|
+
minify = isBuild,
|
|
202
|
+
sourcemap = isBuild,
|
|
203
|
+
entryOutputDirPath = "dist-entry",
|
|
204
|
+
appEntryPath = "electron/entry.ts",
|
|
205
|
+
nativeModuleEntryMap = {},
|
|
206
|
+
postBuild,
|
|
207
|
+
overrideEsbuildOptions
|
|
208
|
+
} = {},
|
|
184
209
|
paths: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
asarOutputPath = `release/${productName}.asar`,
|
|
188
|
-
gzipPath = `release/${productName}-${version}.asar.gz`,
|
|
210
|
+
asarOutputPath = `release/${pkg.name}.asar`,
|
|
211
|
+
gzipPath = `release/${pkg.name}-${pkg.version}.asar.gz`,
|
|
189
212
|
electronDistPath = "dist-electron",
|
|
190
213
|
rendererDistPath = "dist",
|
|
191
214
|
versionPath = "version.json"
|
|
@@ -195,39 +218,43 @@ function parseOptions(options) {
|
|
|
195
218
|
certPath = "keys/cert.pem",
|
|
196
219
|
keyLength = 2048,
|
|
197
220
|
certInfo = {},
|
|
198
|
-
|
|
221
|
+
overrideGenerator = {}
|
|
199
222
|
} = {}
|
|
200
223
|
} = options;
|
|
201
|
-
const { generateSignature, generateVersionJson } =
|
|
224
|
+
const { generateSignature, generateVersionJson } = overrideGenerator;
|
|
202
225
|
let {
|
|
203
226
|
subject = {
|
|
204
|
-
commonName:
|
|
205
|
-
organizationName: `org.${
|
|
227
|
+
commonName: pkg.name,
|
|
228
|
+
organizationName: `org.${pkg.name}`
|
|
206
229
|
},
|
|
207
|
-
days =
|
|
230
|
+
days = 3650
|
|
208
231
|
} = certInfo;
|
|
209
232
|
const buildAsarOption = {
|
|
210
|
-
version,
|
|
233
|
+
version: pkg.version,
|
|
211
234
|
asarOutputPath,
|
|
212
235
|
gzipPath,
|
|
213
236
|
electronDistPath,
|
|
214
237
|
rendererDistPath
|
|
215
238
|
};
|
|
216
239
|
const buildEntryOption = {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
240
|
+
minify,
|
|
241
|
+
sourcemap,
|
|
242
|
+
entryOutputDirPath,
|
|
243
|
+
appEntryPath,
|
|
244
|
+
nativeModuleEntryMap,
|
|
245
|
+
postBuild,
|
|
246
|
+
overrideEsbuildOptions
|
|
220
247
|
};
|
|
221
248
|
const { privateKey, cert } = parseKeys({
|
|
222
249
|
keyLength,
|
|
223
250
|
privateKeyPath,
|
|
224
251
|
certPath,
|
|
225
|
-
|
|
252
|
+
appEntryPath,
|
|
226
253
|
subject,
|
|
227
254
|
days
|
|
228
255
|
});
|
|
229
256
|
const buildVersionOption = {
|
|
230
|
-
version,
|
|
257
|
+
version: pkg.version,
|
|
231
258
|
minimumVersion,
|
|
232
259
|
gzipPath,
|
|
233
260
|
privateKey,
|
|
@@ -236,33 +263,130 @@ function parseOptions(options) {
|
|
|
236
263
|
generateSignature,
|
|
237
264
|
generateVersionJson
|
|
238
265
|
};
|
|
239
|
-
return {
|
|
266
|
+
return { buildAsarOption, buildEntryOption, buildVersionOption };
|
|
240
267
|
}
|
|
241
268
|
|
|
242
269
|
// src/vite.ts
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
function debugStartup(args) {
|
|
271
|
+
process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
|
|
272
|
+
}
|
|
273
|
+
var id = "electron-incremental-updater";
|
|
274
|
+
var log = createLogger("info", { prefix: `[${id}]` });
|
|
275
|
+
function electronWithUpdater(options) {
|
|
276
|
+
const {
|
|
277
|
+
isBuild,
|
|
278
|
+
pkg,
|
|
279
|
+
main: _main,
|
|
280
|
+
preload: _preload,
|
|
281
|
+
updater,
|
|
282
|
+
useNotBundle = true,
|
|
283
|
+
logParsedOptions
|
|
284
|
+
} = options;
|
|
285
|
+
const _options = parseOptions(isBuild, pkg, updater);
|
|
286
|
+
try {
|
|
287
|
+
rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
288
|
+
rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
289
|
+
} catch (ignore) {
|
|
290
|
+
}
|
|
291
|
+
log.info(`remove old files`, { timestamp: true });
|
|
292
|
+
const { buildAsarOption, buildEntryOption, buildVersionOption } = _options;
|
|
293
|
+
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
294
|
+
const sourcemap = isBuild || !!process.env.VSCODE_DEBUG;
|
|
295
|
+
const _appPath = join2(entryOutputDirPath, "entry.js");
|
|
296
|
+
if (resolve(normalizePath(pkg.main)) !== resolve(normalizePath(_appPath))) {
|
|
297
|
+
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${normalizePath(_appPath)}"`);
|
|
298
|
+
}
|
|
299
|
+
let isInit = false;
|
|
300
|
+
const _buildEntry = async () => {
|
|
301
|
+
await buildEntry(buildEntryOption);
|
|
302
|
+
log.info(`build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
303
|
+
};
|
|
304
|
+
const electronPluginOptions = {
|
|
305
|
+
main: {
|
|
306
|
+
entry: _main.files,
|
|
307
|
+
onstart: async (args) => {
|
|
308
|
+
if (!isInit) {
|
|
309
|
+
isInit = true;
|
|
310
|
+
await _buildEntry();
|
|
311
|
+
}
|
|
312
|
+
_main.onstart?.(args) ?? args.startup();
|
|
313
|
+
},
|
|
314
|
+
vite: mergeConfig(
|
|
315
|
+
{
|
|
316
|
+
plugins: !isBuild && useNotBundle ? [notBundle()] : void 0,
|
|
317
|
+
build: {
|
|
318
|
+
sourcemap,
|
|
319
|
+
minify: isBuild,
|
|
320
|
+
outDir: `${buildAsarOption.electronDistPath}/main`,
|
|
321
|
+
rollupOptions: {
|
|
322
|
+
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
_main.vite ?? {}
|
|
327
|
+
)
|
|
328
|
+
},
|
|
329
|
+
preload: {
|
|
330
|
+
input: _preload.files,
|
|
331
|
+
onstart: _preload.onstart,
|
|
332
|
+
vite: mergeConfig(
|
|
333
|
+
{
|
|
334
|
+
plugins: [
|
|
335
|
+
{
|
|
336
|
+
name: `${id}-build`,
|
|
337
|
+
enforce: "post",
|
|
338
|
+
apply() {
|
|
339
|
+
return isBuild;
|
|
340
|
+
},
|
|
341
|
+
async closeBundle() {
|
|
342
|
+
await _buildEntry();
|
|
343
|
+
await buildAsar(buildAsarOption);
|
|
344
|
+
log.info(`build asar to '${buildAsarOption.asarOutputPath}'`, { timestamp: true });
|
|
345
|
+
await buildVersion(buildVersionOption);
|
|
346
|
+
log.info(`build version info to '${buildVersionOption.versionPath}'`, { timestamp: true });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
build: {
|
|
351
|
+
sourcemap: sourcemap ? "inline" : void 0,
|
|
352
|
+
minify: isBuild,
|
|
353
|
+
outDir: `${buildAsarOption.electronDistPath}/preload`,
|
|
354
|
+
rollupOptions: {
|
|
355
|
+
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
_preload.vite ?? {}
|
|
360
|
+
)
|
|
263
361
|
}
|
|
264
362
|
};
|
|
363
|
+
logParsedOptions && log.info(
|
|
364
|
+
JSON.stringify(
|
|
365
|
+
{
|
|
366
|
+
...electronPluginOptions,
|
|
367
|
+
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
368
|
+
},
|
|
369
|
+
(key, value) => key === "privateKey" || key === "cert" ? "***" : value,
|
|
370
|
+
2
|
|
371
|
+
),
|
|
372
|
+
{ timestamp: true }
|
|
373
|
+
);
|
|
374
|
+
let extraHmrPlugin;
|
|
375
|
+
if (nativeModuleEntryMap) {
|
|
376
|
+
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath(file)));
|
|
377
|
+
extraHmrPlugin = {
|
|
378
|
+
name: `${id}-dev`,
|
|
379
|
+
apply() {
|
|
380
|
+
return !isBuild;
|
|
381
|
+
},
|
|
382
|
+
configureServer: (server) => {
|
|
383
|
+
server.watcher.add(files).on("change", (p) => files.includes(p) && _buildEntry().then(() => startup()));
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
265
388
|
}
|
|
266
389
|
export {
|
|
267
|
-
|
|
390
|
+
debugStartup,
|
|
391
|
+
electronWithUpdater
|
|
268
392
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "electron incremental update tools, powered by vite",
|
|
5
5
|
"author": "subframe7536",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,22 +45,29 @@
|
|
|
45
45
|
"registry": "https://registry.npmjs.org/"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"esbuild": "*"
|
|
48
|
+
"esbuild": "*",
|
|
49
|
+
"vite-plugin-electron": "^0.15.6 || ^0.28"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
52
|
"@electron/asar": "^3.2.8",
|
|
52
|
-
"
|
|
53
|
+
"@subframe7536/type-utils": "^0.1.4",
|
|
53
54
|
"selfsigned": "^2.4.1"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@subframe7536/eslint-config": "^0.5.
|
|
57
|
-
"@types/node": "^20.
|
|
58
|
-
"bumpp": "^9.
|
|
59
|
-
"electron": "
|
|
60
|
-
"eslint": "^8.
|
|
57
|
+
"@subframe7536/eslint-config": "^0.5.9",
|
|
58
|
+
"@types/node": "^20.11.5",
|
|
59
|
+
"bumpp": "^9.3.0",
|
|
60
|
+
"electron": "28.1.1",
|
|
61
|
+
"eslint": "^8.56.0",
|
|
61
62
|
"tsup": "^8.0.1",
|
|
62
|
-
"typescript": "^5.3.
|
|
63
|
-
"vite": "^5.0.
|
|
64
|
-
"
|
|
63
|
+
"typescript": "^5.3.3",
|
|
64
|
+
"vite": "^5.0.12",
|
|
65
|
+
"vite-plugin-electron": "^0.15.6",
|
|
66
|
+
"vitest": "^1.2.1"
|
|
67
|
+
},
|
|
68
|
+
"pnpm": {
|
|
69
|
+
"overrides": {
|
|
70
|
+
"has": "npm:@nolyfill/has@latest"
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
}
|
package/dist/chunk-SPZL37O5.mjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./chunk-CMBFI77K.mjs";
|
|
4
|
-
|
|
5
|
-
// src/utils/core.ts
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
7
|
-
import { dirname, join } from "node:path";
|
|
8
|
-
import { release } from "node:os";
|
|
9
|
-
import { app } from "electron";
|
|
10
|
-
var DEFAULT_APP_NAME = "product";
|
|
11
|
-
var is = {
|
|
12
|
-
dev: !app.isPackaged,
|
|
13
|
-
win: process.platform === "win32",
|
|
14
|
-
mac: process.platform === "darwin",
|
|
15
|
-
linux: process.platform === "linux"
|
|
16
|
-
};
|
|
17
|
-
function getLocale() {
|
|
18
|
-
return app.isReady() ? app.getLocale() : void 0;
|
|
19
|
-
}
|
|
20
|
-
function getProductAsarPath(name = DEFAULT_APP_NAME) {
|
|
21
|
-
return !app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "DEV.asar";
|
|
22
|
-
}
|
|
23
|
-
function getElectronVersion() {
|
|
24
|
-
return app.getVersion();
|
|
25
|
-
}
|
|
26
|
-
function getAppVersion(name = DEFAULT_APP_NAME) {
|
|
27
|
-
return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
|
|
28
|
-
}
|
|
29
|
-
var NoSuchNativeModuleError = class extends Error {
|
|
30
|
-
moduleName;
|
|
31
|
-
constructor(moduleName) {
|
|
32
|
-
super(`no such native module: ${moduleName}`);
|
|
33
|
-
this.moduleName = moduleName;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
function isNoSuchNativeModuleError(e) {
|
|
37
|
-
return e instanceof NoSuchNativeModuleError;
|
|
38
|
-
}
|
|
39
|
-
function requireNative(packageName) {
|
|
40
|
-
const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
|
|
41
|
-
try {
|
|
42
|
-
return __require(path);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return new NoSuchNativeModuleError(packageName);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function restartApp() {
|
|
48
|
-
app.relaunch();
|
|
49
|
-
app.quit();
|
|
50
|
-
}
|
|
51
|
-
function setAppUserModelId(id) {
|
|
52
|
-
is.win && app.setAppUserModelId(is.dev ? process.execPath : id);
|
|
53
|
-
}
|
|
54
|
-
function disableHWAccForWin7() {
|
|
55
|
-
if (release().startsWith("6.1")) {
|
|
56
|
-
app.disableHardwareAcceleration();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function singleInstance() {
|
|
60
|
-
if (!app.requestSingleInstanceLock()) {
|
|
61
|
-
app.quit();
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function setPortableAppDataPath(dirName = "data", create) {
|
|
66
|
-
if (!is.win) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
70
|
-
let exists = existsSync(portablePath);
|
|
71
|
-
if (create && !exists) {
|
|
72
|
-
mkdirSync(portablePath);
|
|
73
|
-
exists = true;
|
|
74
|
-
}
|
|
75
|
-
if (exists) {
|
|
76
|
-
app.setPath("appData", portablePath);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function waitAppReady(timeout = 1e3) {
|
|
80
|
-
return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
81
|
-
const _ = setTimeout(() => {
|
|
82
|
-
reject(new Error("app is not ready"));
|
|
83
|
-
}, timeout);
|
|
84
|
-
app.whenReady().then(() => {
|
|
85
|
-
clearTimeout(_);
|
|
86
|
-
resolve();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/utils/utils.ts
|
|
92
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
93
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
94
|
-
throw new Error("origin url must start with https://github.com/");
|
|
95
|
-
}
|
|
96
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
97
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
98
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
99
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
100
|
-
}
|
|
101
|
-
function handleUnexpectedErrors(callback) {
|
|
102
|
-
process.on("uncaughtException", callback);
|
|
103
|
-
process.on("unhandledRejection", callback);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export {
|
|
107
|
-
DEFAULT_APP_NAME,
|
|
108
|
-
is,
|
|
109
|
-
getLocale,
|
|
110
|
-
getProductAsarPath,
|
|
111
|
-
getElectronVersion,
|
|
112
|
-
getAppVersion,
|
|
113
|
-
NoSuchNativeModuleError,
|
|
114
|
-
isNoSuchNativeModuleError,
|
|
115
|
-
requireNative,
|
|
116
|
-
restartApp,
|
|
117
|
-
setAppUserModelId,
|
|
118
|
-
disableHWAccForWin7,
|
|
119
|
-
singleInstance,
|
|
120
|
-
setPortableAppDataPath,
|
|
121
|
-
waitAppReady,
|
|
122
|
-
parseGithubCdnURL,
|
|
123
|
-
handleUnexpectedErrors
|
|
124
|
-
};
|