electron-incremental-update 2.0.0-beta.9 → 2.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 +307 -198
- package/dist/chunk-IABBXJFB.js +87 -0
- package/dist/{chunk-72ZAJ7AF.js → chunk-RCRKUKFX.js} +1 -1
- package/dist/index.cjs +91 -71
- package/dist/index.d.cts +64 -80
- package/dist/index.d.ts +64 -80
- package/dist/index.js +88 -70
- package/dist/provider.cjs +72 -52
- package/dist/provider.d.cts +47 -30
- package/dist/provider.d.ts +47 -30
- package/dist/provider.js +72 -53
- package/dist/{types-D7OK98ln.d.ts → types-BLdN9rkY.d.ts} +20 -27
- package/dist/{types-mEfMjnlV.d.cts → types-DkCn03M3.d.cts} +20 -27
- package/dist/utils.cjs +25 -17
- package/dist/utils.d.cts +37 -16
- package/dist/utils.d.ts +37 -16
- package/dist/utils.js +2 -2
- package/dist/version-BYVQ367i.d.cts +62 -0
- package/dist/version-BYVQ367i.d.ts +62 -0
- package/dist/vite.d.ts +58 -94
- package/dist/vite.js +57 -39
- package/dist/{zip-DPF5IFkK.d.ts → zip-rm9ED9nU.d.cts} +23 -0
- package/dist/{zip-DPF5IFkK.d.cts → zip-rm9ED9nU.d.ts} +23 -0
- package/package.json +10 -7
- package/dist/chunk-4MH6ZXCY.js +0 -81
- package/dist/version-DgfjJQUx.d.cts +0 -27
- package/dist/version-DgfjJQUx.d.ts +0 -27
package/dist/vite.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { BuildOptions } from 'esbuild';
|
|
|
5
5
|
export { isCI } from 'ci-info';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Update info json
|
|
9
9
|
*/
|
|
10
10
|
type UpdateInfo = {
|
|
11
11
|
signature: string;
|
|
@@ -23,6 +23,7 @@ interface PKG {
|
|
|
23
23
|
name: string;
|
|
24
24
|
version: string;
|
|
25
25
|
main: string;
|
|
26
|
+
type: 'commonjs' | 'module';
|
|
26
27
|
}
|
|
27
28
|
interface DistinguishedName {
|
|
28
29
|
countryName?: string;
|
|
@@ -39,27 +40,26 @@ interface DistinguishedName {
|
|
|
39
40
|
}
|
|
40
41
|
interface BuildEntryOption {
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* Override to minify on entry
|
|
43
44
|
* @default isBuild
|
|
44
45
|
*/
|
|
45
46
|
minify?: boolean;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @default isBuild
|
|
48
|
+
* Override to generate sourcemap on entry
|
|
49
49
|
*/
|
|
50
50
|
sourcemap?: boolean;
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Path to app entry output file
|
|
53
53
|
* @default 'dist-entry'
|
|
54
54
|
*/
|
|
55
55
|
entryOutputDirPath?: string;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Path to app entry file
|
|
58
58
|
* @default 'electron/entry.ts'
|
|
59
59
|
*/
|
|
60
60
|
appEntryPath?: string;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Esbuild path map of native modules in entry directory
|
|
63
63
|
*
|
|
64
64
|
* @default {}
|
|
65
65
|
* @example
|
|
@@ -67,7 +67,7 @@ interface BuildEntryOption {
|
|
|
67
67
|
*/
|
|
68
68
|
nativeModuleEntryMap?: Record<string, string>;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Custom options for esbuild
|
|
71
71
|
* ```ts
|
|
72
72
|
* // default options
|
|
73
73
|
* const options = {
|
|
@@ -86,34 +86,32 @@ interface BuildEntryOption {
|
|
|
86
86
|
* loader: {
|
|
87
87
|
* '.node': 'empty',
|
|
88
88
|
* },
|
|
89
|
-
* define
|
|
90
|
-
* __SIGNATURE_CERT__: JSON.stringify(cert),
|
|
91
|
-
* },
|
|
89
|
+
* define,
|
|
92
90
|
* }
|
|
93
91
|
* ```
|
|
94
92
|
*/
|
|
95
93
|
overrideEsbuildOptions?: BuildOptions;
|
|
96
94
|
/**
|
|
97
|
-
*
|
|
95
|
+
* Resolve extra files on startup, such as `.node`
|
|
98
96
|
* @remark won't trigger will reload
|
|
99
97
|
*/
|
|
100
98
|
postBuild?: (args: {
|
|
101
99
|
/**
|
|
102
|
-
*
|
|
100
|
+
* Get path from `entryOutputDirPath`
|
|
103
101
|
*/
|
|
104
102
|
getPathFromEntryOutputDir: (...paths: string[]) => string;
|
|
105
103
|
/**
|
|
106
|
-
*
|
|
104
|
+
* Check exist and copy file to `entryOutputDirPath`
|
|
107
105
|
*
|
|
108
|
-
*
|
|
106
|
+
* If `to` absent, set to `basename(from)`
|
|
109
107
|
*
|
|
110
|
-
*
|
|
108
|
+
* If `skipIfExist` absent, skip copy if `to` exist
|
|
111
109
|
*/
|
|
112
110
|
copyToEntryOutputDir: (options: {
|
|
113
111
|
from: string;
|
|
114
112
|
to?: string;
|
|
115
113
|
/**
|
|
116
|
-
*
|
|
114
|
+
* Skip copy if `to` exist
|
|
117
115
|
* @default true
|
|
118
116
|
*/
|
|
119
117
|
skipIfExist?: boolean;
|
|
@@ -122,15 +120,15 @@ interface BuildEntryOption {
|
|
|
122
120
|
}
|
|
123
121
|
interface GeneratorOverrideFunctions {
|
|
124
122
|
/**
|
|
125
|
-
*
|
|
123
|
+
* Custom signature generate function
|
|
126
124
|
* @param buffer file buffer
|
|
127
125
|
* @param privateKey private key
|
|
128
126
|
* @param cert certificate string, **EOL must be '\n'**
|
|
129
127
|
* @param version current version
|
|
130
128
|
*/
|
|
131
|
-
generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) =>
|
|
129
|
+
generateSignature?: (buffer: Buffer, privateKey: string, cert: string, version: string) => Promisable<string>;
|
|
132
130
|
/**
|
|
133
|
-
*
|
|
131
|
+
* Custom generate version json function
|
|
134
132
|
* @param existingJson The existing JSON object.
|
|
135
133
|
* @param buffer file buffer
|
|
136
134
|
* @param signature generated signature
|
|
@@ -138,25 +136,25 @@ interface GeneratorOverrideFunctions {
|
|
|
138
136
|
* @param minVersion The minimum version
|
|
139
137
|
* @returns The updated version json
|
|
140
138
|
*/
|
|
141
|
-
generateVersionJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) =>
|
|
139
|
+
generateVersionJson?: (existingJson: UpdateJSON, signature: string, version: string, minVersion: string) => Promisable<UpdateJSON>;
|
|
142
140
|
/**
|
|
143
|
-
*
|
|
141
|
+
* Custom generate zip file buffer
|
|
144
142
|
* @param buffer source buffer
|
|
145
143
|
*/
|
|
146
|
-
generateGzipFile?: (buffer: Buffer) =>
|
|
144
|
+
generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
|
|
147
145
|
}
|
|
148
146
|
interface ElectronUpdaterOptions {
|
|
149
147
|
/**
|
|
150
|
-
*
|
|
148
|
+
* Minimum version of entry
|
|
151
149
|
* @default '0.0.0'
|
|
152
150
|
*/
|
|
153
151
|
minimumVersion?: string;
|
|
154
152
|
/**
|
|
155
|
-
*
|
|
153
|
+
* Options for entry (app.asar)
|
|
156
154
|
*/
|
|
157
155
|
entry?: BuildEntryOption;
|
|
158
156
|
/**
|
|
159
|
-
* paths
|
|
157
|
+
* Options for paths
|
|
160
158
|
*/
|
|
161
159
|
paths?: {
|
|
162
160
|
/**
|
|
@@ -190,40 +188,40 @@ interface ElectronUpdaterOptions {
|
|
|
190
188
|
*/
|
|
191
189
|
keys?: {
|
|
192
190
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
191
|
+
* Path to the pem file that contains private key
|
|
192
|
+
* If not ended with .pem, it will be appended
|
|
195
193
|
*
|
|
196
|
-
* **
|
|
194
|
+
* **If `UPDATER_PK` is set, will read it instead of read from `privateKeyPath`**
|
|
197
195
|
* @default 'keys/private.pem'
|
|
198
196
|
*/
|
|
199
197
|
privateKeyPath?: string;
|
|
200
198
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
199
|
+
* Path to the pem file that contains public key
|
|
200
|
+
* If not ended with .pem, it will be appended
|
|
203
201
|
*
|
|
204
|
-
* **
|
|
202
|
+
* **If `UPDATER_CERT` is set, will read it instead of read from `certPath`**
|
|
205
203
|
* @default 'keys/cert.pem'
|
|
206
204
|
*/
|
|
207
205
|
certPath?: string;
|
|
208
206
|
/**
|
|
209
|
-
*
|
|
207
|
+
* Length of the key
|
|
210
208
|
* @default 2048
|
|
211
209
|
*/
|
|
212
210
|
keyLength?: number;
|
|
213
211
|
/**
|
|
214
212
|
* X509 certificate info
|
|
215
213
|
*
|
|
216
|
-
*
|
|
214
|
+
* Only generate simple **self-signed** certificate **without extensions**
|
|
217
215
|
*/
|
|
218
216
|
certInfo?: {
|
|
219
217
|
/**
|
|
220
|
-
*
|
|
218
|
+
* The subject of the certificate
|
|
221
219
|
*
|
|
222
220
|
* @default { commonName: `${app.name}`, organizationName: `org.${app.name}` }
|
|
223
221
|
*/
|
|
224
222
|
subject?: DistinguishedName;
|
|
225
223
|
/**
|
|
226
|
-
*
|
|
224
|
+
* Expire days of the certificate
|
|
227
225
|
*
|
|
228
226
|
* @default 3650
|
|
229
227
|
*/
|
|
@@ -236,15 +234,15 @@ interface ElectronUpdaterOptions {
|
|
|
236
234
|
interface BytecodeOptions {
|
|
237
235
|
enable: boolean;
|
|
238
236
|
/**
|
|
239
|
-
* Remember to set `sandbox: false` when creating window
|
|
237
|
+
* Enable in preload script. Remember to set `sandbox: false` when creating window
|
|
240
238
|
*/
|
|
241
239
|
preload?: boolean;
|
|
242
240
|
/**
|
|
243
|
-
*
|
|
241
|
+
* Before transformed code compile function. If return `Falsy` value, it will be ignored
|
|
244
242
|
* @param code transformed code
|
|
245
243
|
* @param id file path
|
|
246
244
|
*/
|
|
247
|
-
beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined>;
|
|
245
|
+
beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
|
|
248
246
|
}
|
|
249
247
|
|
|
250
248
|
type MakeRequired<T, K extends keyof T> = Exclude<T, undefined> & {
|
|
@@ -284,7 +282,7 @@ type ExcludeOutputDirOptions = {
|
|
|
284
282
|
};
|
|
285
283
|
interface ElectronWithUpdaterOptions {
|
|
286
284
|
/**
|
|
287
|
-
*
|
|
285
|
+
* Whether is in build mode
|
|
288
286
|
* ```ts
|
|
289
287
|
* export default defineConfig(({ command }) => {
|
|
290
288
|
* const isBuild = command === 'build'
|
|
@@ -293,113 +291,79 @@ interface ElectronWithUpdaterOptions {
|
|
|
293
291
|
*/
|
|
294
292
|
isBuild: boolean;
|
|
295
293
|
/**
|
|
296
|
-
*
|
|
294
|
+
* Manually setup package.json, read name, version and main,
|
|
295
|
+
* use `local-pkg` of `loadPackageJSON()` to load package.json by default
|
|
297
296
|
* ```ts
|
|
298
297
|
* import pkg from './package.json'
|
|
299
298
|
* ```
|
|
300
299
|
*/
|
|
301
300
|
pkg?: PKG;
|
|
302
301
|
/**
|
|
303
|
-
*
|
|
302
|
+
* Whether to generate sourcemap
|
|
304
303
|
* @default !isBuild
|
|
305
304
|
*/
|
|
306
305
|
sourcemap?: boolean;
|
|
307
306
|
/**
|
|
308
|
-
*
|
|
307
|
+
* Whether to minify the code
|
|
309
308
|
* @default isBuild
|
|
310
309
|
*/
|
|
311
310
|
minify?: boolean;
|
|
312
311
|
/**
|
|
313
|
-
*
|
|
312
|
+
* Whether to generate bytecode
|
|
314
313
|
*
|
|
315
|
-
* **
|
|
314
|
+
* **Only support CommonJS**
|
|
316
315
|
*
|
|
317
|
-
*
|
|
316
|
+
* Only main process by default, if you want to use in preload script, please use `electronWithUpdater({ bytecode: { enablePreload: true } })` and set `sandbox: false` when creating window
|
|
318
317
|
*/
|
|
319
318
|
bytecode?: boolean | BytecodeOptions;
|
|
320
319
|
/**
|
|
321
|
-
*
|
|
320
|
+
* Use `NotBundle()` plugin in main
|
|
322
321
|
* @default true
|
|
323
322
|
*/
|
|
324
323
|
useNotBundle?: boolean;
|
|
325
324
|
/**
|
|
326
|
-
*
|
|
325
|
+
* Whether to generate version json
|
|
327
326
|
* @default isCI
|
|
328
327
|
*/
|
|
329
328
|
buildVersionJson?: boolean;
|
|
330
329
|
/**
|
|
331
330
|
* Whether to log parsed options
|
|
332
331
|
*
|
|
333
|
-
*
|
|
332
|
+
* To show certificate and private keys, set `logParsedOptions: { showKeys: true }`
|
|
334
333
|
*/
|
|
335
334
|
logParsedOptions?: boolean | {
|
|
336
335
|
showKeys: boolean;
|
|
337
336
|
};
|
|
338
337
|
/**
|
|
339
|
-
*
|
|
338
|
+
* Main process options
|
|
340
339
|
*
|
|
341
|
-
*
|
|
340
|
+
* To change output directories, use `options.updater.paths.electronDistPath` instead
|
|
342
341
|
*/
|
|
343
342
|
main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
|
|
344
343
|
/**
|
|
345
|
-
*
|
|
344
|
+
* Preload process options
|
|
346
345
|
*
|
|
347
|
-
*
|
|
346
|
+
* To change output directories, use `options.updater.paths.electronDistPath` instead
|
|
348
347
|
*/
|
|
349
348
|
preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
|
|
350
349
|
/**
|
|
351
|
-
*
|
|
350
|
+
* Updater options
|
|
352
351
|
*/
|
|
353
352
|
updater?: ElectronUpdaterOptions;
|
|
354
353
|
}
|
|
355
354
|
/**
|
|
356
|
-
*
|
|
355
|
+
* Base on `vite-plugin-electron/simple`
|
|
357
356
|
* - integrate with updater
|
|
358
|
-
* -
|
|
359
|
-
* - remove old
|
|
357
|
+
* - no `renderer` config
|
|
358
|
+
* - remove old output file
|
|
360
359
|
* - externalize dependencies
|
|
361
360
|
* - auto restart when entry file changes
|
|
362
361
|
* - other configs in {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
|
|
363
|
-
* - no `vite-plugin-electron-renderer` config
|
|
364
362
|
*
|
|
365
|
-
*
|
|
363
|
+
* You can override all the vite configs, except output directories (use `options.updater.paths.electronDistPath` instead)
|
|
366
364
|
*
|
|
367
365
|
* @example
|
|
368
|
-
* import { defineConfig } from 'vite'
|
|
369
|
-
* import { debugStartup, electronWithUpdater } from 'electron-incremental-update/vite'
|
|
370
|
-
* import pkg from './package.json'
|
|
371
|
-
*
|
|
372
|
-
* export default defineConfig(async ({ command }) => {
|
|
373
|
-
* const isBuild = command === 'build'
|
|
374
|
-
* return {
|
|
375
|
-
* plugins: [
|
|
376
|
-
* electronWithUpdater({
|
|
377
|
-
* pkg,
|
|
378
|
-
* isBuild,
|
|
379
|
-
* logParsedOptions: true,
|
|
380
|
-
* main: {
|
|
381
|
-
* files: ['./electron/main/index.ts', './electron/main/worker.ts'],
|
|
382
|
-
* // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
|
|
383
|
-
* onstart: debugStartup,
|
|
384
|
-
* },
|
|
385
|
-
* preload: {
|
|
386
|
-
* files: './electron/preload/index.ts',
|
|
387
|
-
* },
|
|
388
|
-
* updater: {
|
|
389
|
-
* // options
|
|
390
|
-
* }
|
|
391
|
-
* }),
|
|
392
|
-
* ],
|
|
393
|
-
* server: process.env.VSCODE_DEBUG && (() => {
|
|
394
|
-
* const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
|
395
|
-
* return {
|
|
396
|
-
* host: url.hostname,
|
|
397
|
-
* port: +url.port,
|
|
398
|
-
* }
|
|
399
|
-
* })(),
|
|
400
|
-
* }
|
|
401
|
-
* })
|
|
402
366
|
*/
|
|
403
367
|
declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
|
|
404
368
|
|
|
405
|
-
export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater };
|
|
369
|
+
export { type ElectronWithUpdaterOptions, debugStartup, electronWithUpdater as default, electronWithUpdater };
|
package/dist/vite.js
CHANGED
|
@@ -38,7 +38,7 @@ function parseVersion(version) {
|
|
|
38
38
|
ret.stageVersion = Number(_v) || -1;
|
|
39
39
|
}
|
|
40
40
|
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
41
|
-
throw new TypeError(`
|
|
41
|
+
throw new TypeError(`Invalid version: ${version}`);
|
|
42
42
|
}
|
|
43
43
|
return ret;
|
|
44
44
|
}
|
|
@@ -91,7 +91,7 @@ function getElectronPath() {
|
|
|
91
91
|
return electronExecPath;
|
|
92
92
|
}
|
|
93
93
|
function getBytecodeCompilerPath() {
|
|
94
|
-
const scriptPath = path5.join(electronModulePath, "
|
|
94
|
+
const scriptPath = path5.join(electronModulePath, "EIU_bytenode.cjs");
|
|
95
95
|
if (!fs3.existsSync(scriptPath)) {
|
|
96
96
|
fs3.writeFileSync(scriptPath, bytecodeGeneratorScript);
|
|
97
97
|
}
|
|
@@ -140,7 +140,7 @@ function convertArrowFunctionAndTemplate(code) {
|
|
|
140
140
|
}
|
|
141
141
|
var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
|
|
142
142
|
function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
|
|
143
|
-
const hexArray = input.split("").map((c) =>
|
|
143
|
+
const hexArray = input.split("").map((c) => `0x${(c.charCodeAt(0) + offset).toString(16)}`);
|
|
144
144
|
return `_0xstr_([${hexArray.join(",")}],${offset})`;
|
|
145
145
|
}
|
|
146
146
|
function convertLiteral(code, sourcemap, offset) {
|
|
@@ -148,7 +148,7 @@ function convertLiteral(code, sourcemap, offset) {
|
|
|
148
148
|
let hasTransformed = false;
|
|
149
149
|
const ast = babel.parse(code, { ast: true });
|
|
150
150
|
if (!ast) {
|
|
151
|
-
throw new Error("
|
|
151
|
+
throw new Error("Cannot parse code");
|
|
152
152
|
}
|
|
153
153
|
babel.traverse(ast, {
|
|
154
154
|
StringLiteral(path6) {
|
|
@@ -168,6 +168,9 @@ function convertLiteral(code, sourcemap, offset) {
|
|
|
168
168
|
if (parent.type.startsWith("Import")) {
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
+
if (parent.type === "ObjectMethod" && parent.key === node) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
171
174
|
if (parent.type === "ObjectProperty" && parent.key === node) {
|
|
172
175
|
const result2 = `[${obfuscateString(node.value, offset)}]`;
|
|
173
176
|
const start2 = node.start;
|
|
@@ -224,7 +227,7 @@ async function buildAsar({
|
|
|
224
227
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
225
228
|
const buf = await generateGzipFile(fs3.readFileSync(asarOutputPath));
|
|
226
229
|
fs3.writeFileSync(gzipPath, buf);
|
|
227
|
-
log.info(`
|
|
230
|
+
log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
|
|
228
231
|
return buf;
|
|
229
232
|
}
|
|
230
233
|
async function buildVersion({
|
|
@@ -252,7 +255,7 @@ async function buildVersion({
|
|
|
252
255
|
if (isUpdateJSON(oldVersionJson)) {
|
|
253
256
|
_json = oldVersionJson;
|
|
254
257
|
} else {
|
|
255
|
-
log.warn("
|
|
258
|
+
log.warn("Old version json is invalid, ignore it", { timestamp: true });
|
|
256
259
|
}
|
|
257
260
|
} catch {
|
|
258
261
|
}
|
|
@@ -260,7 +263,7 @@ async function buildVersion({
|
|
|
260
263
|
const sig = await generateSignature(asarBuffer, privateKey, cert, version);
|
|
261
264
|
_json = await generateVersionJson(_json, sig, version, minimumVersion);
|
|
262
265
|
if (!isUpdateJSON(_json)) {
|
|
263
|
-
throw new Error("
|
|
266
|
+
throw new Error("Invalid version info");
|
|
264
267
|
}
|
|
265
268
|
fs3.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
266
269
|
log.info(`build version info to '${versionPath}'`, { timestamp: true });
|
|
@@ -272,7 +275,7 @@ async function buildEntry({
|
|
|
272
275
|
entryOutputDirPath,
|
|
273
276
|
nativeModuleEntryMap,
|
|
274
277
|
overrideEsbuildOptions
|
|
275
|
-
}, define, bytecodeOptions) {
|
|
278
|
+
}, isESM, define, bytecodeOptions) {
|
|
276
279
|
const option = mergeConfig(
|
|
277
280
|
{
|
|
278
281
|
entryPoints: {
|
|
@@ -292,7 +295,8 @@ async function buildEntry({
|
|
|
292
295
|
loader: {
|
|
293
296
|
".node": "empty"
|
|
294
297
|
},
|
|
295
|
-
define
|
|
298
|
+
define,
|
|
299
|
+
format: isESM ? "esm" : "cjs"
|
|
296
300
|
},
|
|
297
301
|
overrideEsbuildOptions ?? {}
|
|
298
302
|
);
|
|
@@ -376,14 +380,14 @@ function parseKeys({
|
|
|
376
380
|
let privateKey = process.env.UPDATER_PK;
|
|
377
381
|
let cert = process.env.UPDATER_CERT;
|
|
378
382
|
if (privateKey && cert) {
|
|
379
|
-
log.info("
|
|
383
|
+
log.info("Use `UPDATER_PK` and `UPDATER_CERT` from environment variables", { timestamp: true });
|
|
380
384
|
return { privateKey, cert };
|
|
381
385
|
}
|
|
382
386
|
if (!fs3.existsSync(keysDir)) {
|
|
383
387
|
fs3.mkdirSync(keysDir);
|
|
384
388
|
}
|
|
385
389
|
if (!fs3.existsSync(privateKeyPath) || !fs3.existsSync(certPath)) {
|
|
386
|
-
log.info("
|
|
390
|
+
log.info("No key pair found, generate new key pair", { timestamp: true });
|
|
387
391
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
388
392
|
}
|
|
389
393
|
privateKey = fs3.readFileSync(privateKeyPath, "utf-8");
|
|
@@ -476,7 +480,7 @@ function bytecodePlugin(env, options) {
|
|
|
476
480
|
return null;
|
|
477
481
|
}
|
|
478
482
|
if (!preload && env === "preload") {
|
|
479
|
-
bytecodeLog.warn('bytecodePlugin is skiped in preload. To enable in preload, please manually set the "enablePreload" option to true and set `sandbox: false` when creating the window', { timestamp: true });
|
|
483
|
+
bytecodeLog.warn('`bytecodePlugin` is skiped in preload. To enable in preload, please manually set the "enablePreload" option to true and set `sandbox: false` when creating the window', { timestamp: true });
|
|
480
484
|
return null;
|
|
481
485
|
}
|
|
482
486
|
const filter = createFilter(/\.(m?[jt]s|[jt]sx)$/);
|
|
@@ -499,7 +503,8 @@ function bytecodePlugin(env, options) {
|
|
|
499
503
|
if (options2.format !== "es" && bytecodeRequired) {
|
|
500
504
|
this.emitFile({
|
|
501
505
|
type: "asset",
|
|
502
|
-
source: bytecodeModuleLoaderCode
|
|
506
|
+
source: `${bytecodeModuleLoaderCode}
|
|
507
|
+
`,
|
|
503
508
|
name: "Bytecode Loader File",
|
|
504
509
|
fileName: bytecodeModuleLoader
|
|
505
510
|
});
|
|
@@ -508,7 +513,7 @@ function bytecodePlugin(env, options) {
|
|
|
508
513
|
renderChunk(code, chunk, options2) {
|
|
509
514
|
if (options2.format === "es") {
|
|
510
515
|
bytecodeLog.warn(
|
|
511
|
-
'bytecodePlugin does not support ES module, please
|
|
516
|
+
'`bytecodePlugin` does not support ES module, please set "build.rollupOptions.output.format" option to "cjs"',
|
|
512
517
|
{ timestamp: true }
|
|
513
518
|
);
|
|
514
519
|
return null;
|
|
@@ -541,8 +546,9 @@ function bytecodePlugin(env, options) {
|
|
|
541
546
|
const chunk = output[name];
|
|
542
547
|
if (chunk.type === "chunk") {
|
|
543
548
|
let _code = chunk.code;
|
|
549
|
+
const chunkFilePath = path5.resolve(outDir, name);
|
|
544
550
|
if (beforeCompile) {
|
|
545
|
-
const cbResult = await beforeCompile(_code,
|
|
551
|
+
const cbResult = await beforeCompile(_code, chunkFilePath);
|
|
546
552
|
if (cbResult) {
|
|
547
553
|
_code = cbResult;
|
|
548
554
|
}
|
|
@@ -553,19 +559,18 @@ function bytecodePlugin(env, options) {
|
|
|
553
559
|
while (match = bytecodeRE.exec(_code)) {
|
|
554
560
|
const [prefix, chunkName] = match;
|
|
555
561
|
const len = prefix.length + chunkName.length;
|
|
556
|
-
s.overwrite(match.index, match.index + len, prefix + chunkName
|
|
562
|
+
s.overwrite(match.index, match.index + len, `${prefix + chunkName}c`, {
|
|
557
563
|
contentOnly: true
|
|
558
564
|
});
|
|
559
565
|
}
|
|
560
566
|
_code = s.toString();
|
|
561
567
|
}
|
|
562
|
-
const chunkFilePath = path5.resolve(outDir, name);
|
|
563
568
|
if (bytecodeChunks.includes(name)) {
|
|
564
569
|
const bytecodeBuffer = await compileToBytecode(_code);
|
|
565
|
-
fs3.writeFileSync(chunkFilePath
|
|
570
|
+
fs3.writeFileSync(`${chunkFilePath}c`, bytecodeBuffer);
|
|
566
571
|
if (chunk.isEntry) {
|
|
567
572
|
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
568
|
-
const bytecodeModuleBlock = `require("./${path5.basename(name)
|
|
573
|
+
const bytecodeModuleBlock = `require("./${`${path5.basename(name)}c`}");`;
|
|
569
574
|
const code = `${useStrict}
|
|
570
575
|
${bytecodeLoaderBlock}
|
|
571
576
|
module.exports=${bytecodeModuleBlock}
|
|
@@ -574,7 +579,7 @@ module.exports=${bytecodeModuleBlock}
|
|
|
574
579
|
} else {
|
|
575
580
|
fs3.unlinkSync(chunkFilePath);
|
|
576
581
|
}
|
|
577
|
-
bytecodeFiles.push({ name: name
|
|
582
|
+
bytecodeFiles.push({ name: `${name}c`, size: bytecodeBuffer.length });
|
|
578
583
|
} else {
|
|
579
584
|
if (chunk.isEntry) {
|
|
580
585
|
let hasBytecodeMoudle = false;
|
|
@@ -638,12 +643,13 @@ function getMainFilePath(options) {
|
|
|
638
643
|
}
|
|
639
644
|
mainFilePath = options?.index ? "index.js" : "main.js";
|
|
640
645
|
}
|
|
646
|
+
log.info(`Using "${mainFilePath}" as main file`, { timestamp: true });
|
|
641
647
|
return mainFilePath.replace(/\.[cm]?ts$/, ".js");
|
|
642
648
|
}
|
|
643
649
|
function parseVersionPath(versionPath) {
|
|
644
650
|
versionPath = normalizePath(versionPath);
|
|
645
651
|
if (!versionPath.startsWith("./")) {
|
|
646
|
-
versionPath =
|
|
652
|
+
versionPath = `./${versionPath}`;
|
|
647
653
|
}
|
|
648
654
|
return new URL(versionPath, "file://").pathname.slice(1);
|
|
649
655
|
}
|
|
@@ -661,33 +667,43 @@ async function electronWithUpdater(options) {
|
|
|
661
667
|
useNotBundle = true,
|
|
662
668
|
logParsedOptions
|
|
663
669
|
} = options;
|
|
664
|
-
if (!pkg) {
|
|
665
|
-
log.error(
|
|
670
|
+
if (!pkg || !pkg.version || !pkg.name || !pkg.main) {
|
|
671
|
+
log.error("package.json not found or invalid", { timestamp: true });
|
|
666
672
|
return void 0;
|
|
667
673
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
674
|
+
const isESM = pkg.type === "module";
|
|
675
|
+
let bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { enable: true } : void 0;
|
|
676
|
+
if (isESM && bytecodeOptions?.enable) {
|
|
677
|
+
bytecodeLog.warn(
|
|
678
|
+
'`bytecodePlugin` does not support ES module, please remove "type": "module" in package.json',
|
|
679
|
+
{ timestamp: true }
|
|
680
|
+
);
|
|
681
|
+
bytecodeOptions = void 0;
|
|
671
682
|
}
|
|
672
|
-
const
|
|
673
|
-
|
|
683
|
+
const {
|
|
684
|
+
buildAsarOption,
|
|
685
|
+
buildEntryOption,
|
|
686
|
+
buildVersionOption,
|
|
687
|
+
postBuild,
|
|
688
|
+
cert
|
|
689
|
+
} = parseOptions(pkg, sourcemap, minify, updater);
|
|
690
|
+
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
674
691
|
try {
|
|
675
|
-
fs3.rmSync(
|
|
676
|
-
fs3.rmSync(
|
|
692
|
+
fs3.rmSync(buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
693
|
+
fs3.rmSync(entryOutputDirPath, { recursive: true, force: true });
|
|
677
694
|
} catch {
|
|
678
695
|
}
|
|
679
|
-
log.info(`
|
|
680
|
-
const { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert } = _options;
|
|
681
|
-
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
696
|
+
log.info(`Clear cache files`, { timestamp: true });
|
|
682
697
|
sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
|
|
683
698
|
const _appPath = normalizePath(path5.join(entryOutputDirPath, "entry.js"));
|
|
684
699
|
if (path5.resolve(normalizePath(pkg.main)) !== path5.resolve(_appPath)) {
|
|
685
|
-
throw new Error(`
|
|
700
|
+
throw new Error(`Wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
686
701
|
}
|
|
687
702
|
const define = {
|
|
688
703
|
__EIU_ELECTRON_DIST_PATH__: JSON.stringify(buildAsarOption.electronDistPath),
|
|
689
704
|
__EIU_ENTRY_DIST_PATH__: JSON.stringify(buildEntryOption.entryOutputDirPath),
|
|
690
705
|
__EIU_IS_DEV__: JSON.stringify(!isBuild),
|
|
706
|
+
__EIU_IS_ESM__: JSON.stringify(isESM),
|
|
691
707
|
__EIU_MAIN_DEV_DIR__: JSON.stringify(buildAsarOption.electronDistPath),
|
|
692
708
|
__EIU_MAIN_FILE__: JSON.stringify(getMainFilePath(_main.files)),
|
|
693
709
|
__EIU_SIGNATURE_CERT__: JSON.stringify(cert),
|
|
@@ -696,10 +712,11 @@ async function electronWithUpdater(options) {
|
|
|
696
712
|
const _buildEntry = async () => {
|
|
697
713
|
await buildEntry(
|
|
698
714
|
buildEntryOption,
|
|
715
|
+
isESM,
|
|
699
716
|
define,
|
|
700
717
|
bytecodeOptions
|
|
701
718
|
);
|
|
702
|
-
log.info(`
|
|
719
|
+
log.info(`Build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
703
720
|
};
|
|
704
721
|
const _postBuild = postBuild ? async () => await postBuild({
|
|
705
722
|
getPathFromEntryOutputDir(...paths) {
|
|
@@ -712,7 +729,7 @@ async function electronWithUpdater(options) {
|
|
|
712
729
|
try {
|
|
713
730
|
fs3.cpSync(from, target);
|
|
714
731
|
} catch (error) {
|
|
715
|
-
log.warn(`
|
|
732
|
+
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
716
733
|
}
|
|
717
734
|
}
|
|
718
735
|
}
|
|
@@ -774,7 +791,7 @@ async function electronWithUpdater(options) {
|
|
|
774
791
|
await _postBuild();
|
|
775
792
|
const buffer = await buildAsar(buildAsarOption);
|
|
776
793
|
if (!buildVersionJson && !isCI) {
|
|
777
|
-
log.warn("
|
|
794
|
+
log.warn("No `buildVersionJson` setup, skip build version json. Will build in CI by default", { timestamp: true });
|
|
778
795
|
} else {
|
|
779
796
|
await buildVersion(buildVersionOption, buffer);
|
|
780
797
|
}
|
|
@@ -800,7 +817,7 @@ async function electronWithUpdater(options) {
|
|
|
800
817
|
...electronPluginOptions,
|
|
801
818
|
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
802
819
|
},
|
|
803
|
-
(key, value) =>
|
|
820
|
+
(key, value) => ["privateKey", "cert", "define"].includes(key) && !(typeof logParsedOptions === "object" && logParsedOptions.showKeys === true) ? "***" : value,
|
|
804
821
|
2
|
|
805
822
|
),
|
|
806
823
|
{ timestamp: true }
|
|
@@ -831,5 +848,6 @@ async function electronWithUpdater(options) {
|
|
|
831
848
|
}
|
|
832
849
|
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
833
850
|
}
|
|
851
|
+
var vite_default = electronWithUpdater;
|
|
834
852
|
|
|
835
|
-
export { debugStartup, electronWithUpdater };
|
|
853
|
+
export { debugStartup, vite_default as default, electronWithUpdater };
|