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