electron-incremental-update 2.3.8 → 2.4.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 +31 -9
- package/dist/index.cjs +32 -17
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -17
- package/dist/provider.cjs +2 -0
- package/dist/provider.js +2 -0
- package/dist/vite.d.ts +114 -122
- package/dist/vite.js +30 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,7 +103,6 @@ export default defineConfig(async ({ command }) => {
|
|
|
103
103
|
plugins: [
|
|
104
104
|
electronWithUpdater({
|
|
105
105
|
isBuild,
|
|
106
|
-
logParsedOptions: true,
|
|
107
106
|
main: {
|
|
108
107
|
files: ['./electron/main/index.ts', './electron/main/worker.ts'],
|
|
109
108
|
// see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
|
|
@@ -128,6 +127,35 @@ export default defineConfig(async ({ command }) => {
|
|
|
128
127
|
})
|
|
129
128
|
```
|
|
130
129
|
|
|
130
|
+
Or use the helper function
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { defineElectronConfig } from 'electron-incremental-update/vite'
|
|
134
|
+
|
|
135
|
+
export default defineElectronConfig({
|
|
136
|
+
main: {
|
|
137
|
+
files: ['./electron/main/index.ts', './electron/main/worker.ts'],
|
|
138
|
+
// see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
|
|
139
|
+
onstart: debugStartup,
|
|
140
|
+
},
|
|
141
|
+
preload: {
|
|
142
|
+
files: './electron/preload/index.ts',
|
|
143
|
+
},
|
|
144
|
+
updater: {
|
|
145
|
+
// options
|
|
146
|
+
},
|
|
147
|
+
renderer: {
|
|
148
|
+
server: process.env.VSCODE_DEBUG && (() => {
|
|
149
|
+
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
|
150
|
+
return {
|
|
151
|
+
host: url.hostname,
|
|
152
|
+
port: +url.port,
|
|
153
|
+
}
|
|
154
|
+
})(),
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
```
|
|
158
|
+
|
|
131
159
|
### Modify package.json
|
|
132
160
|
|
|
133
161
|
```json
|
|
@@ -824,12 +852,6 @@ export interface ElectronWithUpdaterOptions {
|
|
|
824
852
|
* @default isCI
|
|
825
853
|
*/
|
|
826
854
|
buildVersionJson?: boolean
|
|
827
|
-
/**
|
|
828
|
-
* Whether to log parsed options
|
|
829
|
-
*
|
|
830
|
-
* To show certificate and private keys, set `logParsedOptions: { showKeys: true }`
|
|
831
|
-
*/
|
|
832
|
-
logParsedOptions?: boolean | { showKeys: boolean }
|
|
833
855
|
/**
|
|
834
856
|
* Main process options
|
|
835
857
|
*
|
|
@@ -845,10 +867,10 @@ export interface ElectronWithUpdaterOptions {
|
|
|
845
867
|
/**
|
|
846
868
|
* Updater options
|
|
847
869
|
*/
|
|
848
|
-
updater?:
|
|
870
|
+
updater?: UpdaterOptions
|
|
849
871
|
}
|
|
850
872
|
|
|
851
|
-
export interface
|
|
873
|
+
export interface UpdaterOptions {
|
|
852
874
|
/**
|
|
853
875
|
* Minimum version of entry
|
|
854
876
|
* @default '0.0.0'
|
package/dist/index.cjs
CHANGED
|
@@ -56,6 +56,7 @@ var Updater = class extends events.EventEmitter {
|
|
|
56
56
|
controller;
|
|
57
57
|
info;
|
|
58
58
|
tmpFilePath;
|
|
59
|
+
processing = false;
|
|
59
60
|
provider;
|
|
60
61
|
/**
|
|
61
62
|
* Updater logger
|
|
@@ -142,9 +143,17 @@ var Updater = class extends events.EventEmitter {
|
|
|
142
143
|
async checkForUpdates(data) {
|
|
143
144
|
const emitUnavailable = (msg, code, info2) => {
|
|
144
145
|
this.logger?.info(`[${code}] ${msg}`);
|
|
146
|
+
this.logger?.debug("Check update end");
|
|
147
|
+
this.processing = false;
|
|
145
148
|
this.emit("update-not-available", code, msg, info2);
|
|
146
149
|
return false;
|
|
147
150
|
};
|
|
151
|
+
if (this.processing) {
|
|
152
|
+
this.logger?.info("Updater is already processing, skip check update");
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
this.processing = true;
|
|
156
|
+
this.logger?.debug("Check update start");
|
|
148
157
|
if (!data && !this.provider) {
|
|
149
158
|
const msg = "No update json or provider";
|
|
150
159
|
this.err("Check update failed", "ERR_PARAM", msg);
|
|
@@ -195,8 +204,10 @@ var Updater = class extends events.EventEmitter {
|
|
|
195
204
|
);
|
|
196
205
|
}
|
|
197
206
|
this.logger?.info(`Update available: ${version}`);
|
|
198
|
-
this.emit("update-available", extraVersionInfo);
|
|
199
207
|
this.info = info;
|
|
208
|
+
this.processing = false;
|
|
209
|
+
this.logger?.debug("Check update end");
|
|
210
|
+
this.emit("update-available", extraVersionInfo);
|
|
200
211
|
return true;
|
|
201
212
|
} catch {
|
|
202
213
|
const msg = "Fail to parse version string";
|
|
@@ -209,41 +220,45 @@ var Updater = class extends events.EventEmitter {
|
|
|
209
220
|
}
|
|
210
221
|
}
|
|
211
222
|
async downloadUpdate(data, info) {
|
|
223
|
+
const emitError = (code, errorInfo) => {
|
|
224
|
+
this.err(`Download update failed`, code, errorInfo);
|
|
225
|
+
this.logger?.debug("Download update end");
|
|
226
|
+
this.processing = false;
|
|
227
|
+
return false;
|
|
228
|
+
};
|
|
229
|
+
if (this.processing) {
|
|
230
|
+
this.logger?.info("Updater is already processing, skip download update");
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
this.processing = true;
|
|
234
|
+
this.logger?.debug("Download update start");
|
|
212
235
|
const _sig = info?.signature ?? this.info?.signature;
|
|
213
236
|
const _version = info?.version ?? this.info?.version;
|
|
214
237
|
if (!_sig || !_version) {
|
|
215
|
-
|
|
216
|
-
"Download failed",
|
|
238
|
+
return emitError(
|
|
217
239
|
"ERR_PARAM",
|
|
218
240
|
"No update signature, please call `checkUpdate` first or manually setup params"
|
|
219
241
|
);
|
|
220
|
-
return false;
|
|
221
242
|
}
|
|
222
243
|
if (!data && !this.provider) {
|
|
223
|
-
|
|
224
|
-
"Download failed",
|
|
244
|
+
return emitError(
|
|
225
245
|
"ERR_PARAM",
|
|
226
246
|
"No update asar buffer and provider"
|
|
227
247
|
);
|
|
228
|
-
return false;
|
|
229
248
|
}
|
|
230
249
|
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
231
250
|
if (!buffer) {
|
|
232
|
-
|
|
233
|
-
"Download failed",
|
|
251
|
+
return emitError(
|
|
234
252
|
"ERR_PARAM",
|
|
235
253
|
"No update asar file buffer"
|
|
236
254
|
);
|
|
237
|
-
return false;
|
|
238
255
|
}
|
|
239
256
|
this.logger?.debug("Validation start");
|
|
240
257
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
241
|
-
|
|
242
|
-
"Download failed",
|
|
258
|
+
return emitError(
|
|
243
259
|
"ERR_VALIDATE",
|
|
244
260
|
"Invalid update asar file"
|
|
245
261
|
);
|
|
246
|
-
return false;
|
|
247
262
|
}
|
|
248
263
|
this.logger?.debug("Validation end");
|
|
249
264
|
try {
|
|
@@ -253,15 +268,15 @@ var Updater = class extends events.EventEmitter {
|
|
|
253
268
|
this.logger?.info(`Download success, version: ${_version}`);
|
|
254
269
|
this.info = void 0;
|
|
255
270
|
this.emit("update-downloaded");
|
|
271
|
+
this.processing = false;
|
|
272
|
+
this.logger?.debug("Download update end");
|
|
256
273
|
return true;
|
|
257
274
|
} catch (error) {
|
|
258
275
|
this.cleanup();
|
|
259
|
-
|
|
260
|
-
"Download failed",
|
|
276
|
+
return emitError(
|
|
261
277
|
"ERR_DOWNLOAD",
|
|
262
|
-
`
|
|
278
|
+
`Failed to write update file: ${error instanceof Error ? error.message : error}`
|
|
263
279
|
);
|
|
264
|
-
return false;
|
|
265
280
|
}
|
|
266
281
|
}
|
|
267
282
|
/**
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var Updater = class extends EventEmitter {
|
|
|
20
20
|
controller;
|
|
21
21
|
info;
|
|
22
22
|
tmpFilePath;
|
|
23
|
+
processing = false;
|
|
23
24
|
provider;
|
|
24
25
|
/**
|
|
25
26
|
* Updater logger
|
|
@@ -106,9 +107,17 @@ var Updater = class extends EventEmitter {
|
|
|
106
107
|
async checkForUpdates(data) {
|
|
107
108
|
const emitUnavailable = (msg, code, info2) => {
|
|
108
109
|
this.logger?.info(`[${code}] ${msg}`);
|
|
110
|
+
this.logger?.debug("Check update end");
|
|
111
|
+
this.processing = false;
|
|
109
112
|
this.emit("update-not-available", code, msg, info2);
|
|
110
113
|
return false;
|
|
111
114
|
};
|
|
115
|
+
if (this.processing) {
|
|
116
|
+
this.logger?.info("Updater is already processing, skip check update");
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
this.processing = true;
|
|
120
|
+
this.logger?.debug("Check update start");
|
|
112
121
|
if (!data && !this.provider) {
|
|
113
122
|
const msg = "No update json or provider";
|
|
114
123
|
this.err("Check update failed", "ERR_PARAM", msg);
|
|
@@ -159,8 +168,10 @@ var Updater = class extends EventEmitter {
|
|
|
159
168
|
);
|
|
160
169
|
}
|
|
161
170
|
this.logger?.info(`Update available: ${version}`);
|
|
162
|
-
this.emit("update-available", extraVersionInfo);
|
|
163
171
|
this.info = info;
|
|
172
|
+
this.processing = false;
|
|
173
|
+
this.logger?.debug("Check update end");
|
|
174
|
+
this.emit("update-available", extraVersionInfo);
|
|
164
175
|
return true;
|
|
165
176
|
} catch {
|
|
166
177
|
const msg = "Fail to parse version string";
|
|
@@ -173,41 +184,45 @@ var Updater = class extends EventEmitter {
|
|
|
173
184
|
}
|
|
174
185
|
}
|
|
175
186
|
async downloadUpdate(data, info) {
|
|
187
|
+
const emitError = (code, errorInfo) => {
|
|
188
|
+
this.err(`Download update failed`, code, errorInfo);
|
|
189
|
+
this.logger?.debug("Download update end");
|
|
190
|
+
this.processing = false;
|
|
191
|
+
return false;
|
|
192
|
+
};
|
|
193
|
+
if (this.processing) {
|
|
194
|
+
this.logger?.info("Updater is already processing, skip download update");
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
this.processing = true;
|
|
198
|
+
this.logger?.debug("Download update start");
|
|
176
199
|
const _sig = info?.signature ?? this.info?.signature;
|
|
177
200
|
const _version = info?.version ?? this.info?.version;
|
|
178
201
|
if (!_sig || !_version) {
|
|
179
|
-
|
|
180
|
-
"Download failed",
|
|
202
|
+
return emitError(
|
|
181
203
|
"ERR_PARAM",
|
|
182
204
|
"No update signature, please call `checkUpdate` first or manually setup params"
|
|
183
205
|
);
|
|
184
|
-
return false;
|
|
185
206
|
}
|
|
186
207
|
if (!data && !this.provider) {
|
|
187
|
-
|
|
188
|
-
"Download failed",
|
|
208
|
+
return emitError(
|
|
189
209
|
"ERR_PARAM",
|
|
190
210
|
"No update asar buffer and provider"
|
|
191
211
|
);
|
|
192
|
-
return false;
|
|
193
212
|
}
|
|
194
213
|
const buffer = await this.fetch("buffer", data ? Buffer.from(data) : void 0);
|
|
195
214
|
if (!buffer) {
|
|
196
|
-
|
|
197
|
-
"Download failed",
|
|
215
|
+
return emitError(
|
|
198
216
|
"ERR_PARAM",
|
|
199
217
|
"No update asar file buffer"
|
|
200
218
|
);
|
|
201
|
-
return false;
|
|
202
219
|
}
|
|
203
220
|
this.logger?.debug("Validation start");
|
|
204
221
|
if (!await this.provider.verifySignaure(buffer, _version, _sig, this.CERT)) {
|
|
205
|
-
|
|
206
|
-
"Download failed",
|
|
222
|
+
return emitError(
|
|
207
223
|
"ERR_VALIDATE",
|
|
208
224
|
"Invalid update asar file"
|
|
209
225
|
);
|
|
210
|
-
return false;
|
|
211
226
|
}
|
|
212
227
|
this.logger?.debug("Validation end");
|
|
213
228
|
try {
|
|
@@ -217,15 +232,15 @@ var Updater = class extends EventEmitter {
|
|
|
217
232
|
this.logger?.info(`Download success, version: ${_version}`);
|
|
218
233
|
this.info = void 0;
|
|
219
234
|
this.emit("update-downloaded");
|
|
235
|
+
this.processing = false;
|
|
236
|
+
this.logger?.debug("Download update end");
|
|
220
237
|
return true;
|
|
221
238
|
} catch (error) {
|
|
222
239
|
this.cleanup();
|
|
223
|
-
|
|
224
|
-
"Download failed",
|
|
240
|
+
return emitError(
|
|
225
241
|
"ERR_DOWNLOAD",
|
|
226
|
-
`
|
|
242
|
+
`Failed to write update file: ${error instanceof Error ? error.message : error}`
|
|
227
243
|
);
|
|
228
|
-
return false;
|
|
229
244
|
}
|
|
230
245
|
}
|
|
231
246
|
/**
|
package/dist/provider.cjs
CHANGED
|
@@ -337,6 +337,8 @@ var GitHubAtomProvider = class extends BaseGitHubProvider {
|
|
|
337
337
|
return `releases/download/v${tag}/${versionPath}`;
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
|
+
|
|
341
|
+
// src/provider/github/file.ts
|
|
340
342
|
var GitHubProvider = class extends BaseGitHubProvider {
|
|
341
343
|
name = "GithubProvider";
|
|
342
344
|
/**
|
package/dist/provider.js
CHANGED
|
@@ -149,6 +149,8 @@ var GitHubAtomProvider = class extends BaseGitHubProvider {
|
|
|
149
149
|
return `releases/download/v${tag}/${versionPath}`;
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
+
|
|
153
|
+
// src/provider/github/file.ts
|
|
152
154
|
var GitHubProvider = class extends BaseGitHubProvider {
|
|
153
155
|
name = "GithubProvider";
|
|
154
156
|
/**
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { Promisable, AnyFunction } from '@subframe7536/type-utils';
|
|
2
2
|
import { InlineConfig, PluginOption } from 'vite';
|
|
3
|
-
import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
|
|
3
|
+
import { ElectronSimpleOptions } from 'vite-plugin-electron/simple.js';
|
|
4
|
+
import { ElectronSimpleOptions as ElectronSimpleOptions$1 } from 'vite-plugin-electron/simple';
|
|
4
5
|
export { isCI } from 'ci-info';
|
|
5
6
|
export { getPackageInfo, getPackageInfoSync, loadPackageJSON, resolveModule } from 'local-pkg';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Before transformed code compile function. If return `Falsy` value, it will be ignored
|
|
19
|
-
* @param code transformed code
|
|
20
|
-
* @param id file path
|
|
21
|
-
*/
|
|
22
|
-
beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
|
|
23
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* Obfuscate string
|
|
10
|
+
* @param code source code
|
|
11
|
+
* @param sourcemap whether to generate sourcemap
|
|
12
|
+
* @param offset custom offset
|
|
13
|
+
*/
|
|
14
|
+
declare function convertLiteral(code: string, sourcemap?: boolean, offset?: number): {
|
|
15
|
+
code: string;
|
|
16
|
+
map?: any;
|
|
17
|
+
};
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
20
|
* Update info json
|
|
@@ -49,6 +43,24 @@ type UpdateJSON = UpdateInfo & {
|
|
|
49
43
|
beta: UpdateInfo;
|
|
50
44
|
};
|
|
51
45
|
|
|
46
|
+
interface BytecodeOptions {
|
|
47
|
+
enable: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Enable in preload script. Remember to set `sandbox: false` when creating window
|
|
50
|
+
*/
|
|
51
|
+
preload?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Custom electron binary path
|
|
54
|
+
*/
|
|
55
|
+
electronPath?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Before transformed code compile function. If return `Falsy` value, it will be ignored
|
|
58
|
+
* @param code transformed code
|
|
59
|
+
* @param id file path
|
|
60
|
+
*/
|
|
61
|
+
beforeCompile?: (code: string, id: string) => Promisable<string | null | undefined | void>;
|
|
62
|
+
}
|
|
63
|
+
|
|
52
64
|
interface DistinguishedName {
|
|
53
65
|
countryName?: string;
|
|
54
66
|
stateOrProvinceName?: string;
|
|
@@ -69,6 +81,88 @@ interface PKG {
|
|
|
69
81
|
main: string;
|
|
70
82
|
type: 'commonjs' | 'module';
|
|
71
83
|
}
|
|
84
|
+
type MakeRequired<T, K extends keyof T> = NonNullable<T> & {
|
|
85
|
+
[P in K]-?: T[P];
|
|
86
|
+
};
|
|
87
|
+
type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
|
|
88
|
+
[P in NewKey]: T[Key];
|
|
89
|
+
};
|
|
90
|
+
type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
|
|
91
|
+
type ExcludeOutputDirOptions = {
|
|
92
|
+
vite?: {
|
|
93
|
+
build?: {
|
|
94
|
+
outDir: never;
|
|
95
|
+
rollupOptions?: {
|
|
96
|
+
output?: {
|
|
97
|
+
dir: never;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
interface ElectronWithUpdaterOptions {
|
|
104
|
+
/**
|
|
105
|
+
* Whether is in build mode
|
|
106
|
+
* ```ts
|
|
107
|
+
* export default defineConfig(({ command }) => {
|
|
108
|
+
* const isBuild = command === 'build'
|
|
109
|
+
* })
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
isBuild: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Manually setup package.json, read name, version and main,
|
|
115
|
+
* use `local-pkg` of `loadPackageJSON()` to load package.json by default
|
|
116
|
+
* ```ts
|
|
117
|
+
* import pkg from './package.json'
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
pkg?: PKG;
|
|
121
|
+
/**
|
|
122
|
+
* Whether to generate sourcemap
|
|
123
|
+
* @default !isBuild
|
|
124
|
+
*/
|
|
125
|
+
sourcemap?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Whether to minify the code
|
|
128
|
+
* @default isBuild
|
|
129
|
+
*/
|
|
130
|
+
minify?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Whether to generate bytecode
|
|
133
|
+
*
|
|
134
|
+
* **Only support CommonJS**
|
|
135
|
+
*
|
|
136
|
+
* 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
|
|
137
|
+
*/
|
|
138
|
+
bytecode?: boolean | BytecodeOptions;
|
|
139
|
+
/**
|
|
140
|
+
* Use `NotBundle()` plugin in main
|
|
141
|
+
* @default true
|
|
142
|
+
*/
|
|
143
|
+
useNotBundle?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Whether to generate version json
|
|
146
|
+
* @default isCI
|
|
147
|
+
*/
|
|
148
|
+
buildVersionJson?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Main process options
|
|
151
|
+
*
|
|
152
|
+
* To change output directories, use `options.updater.paths.electronDistPath` instead
|
|
153
|
+
*/
|
|
154
|
+
main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
|
|
155
|
+
/**
|
|
156
|
+
* Preload process options
|
|
157
|
+
*
|
|
158
|
+
* To change output directories, use `options.updater.paths.electronDistPath` instead
|
|
159
|
+
*/
|
|
160
|
+
preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
|
|
161
|
+
/**
|
|
162
|
+
* Updater options
|
|
163
|
+
*/
|
|
164
|
+
updater?: UpdaterOptions;
|
|
165
|
+
}
|
|
72
166
|
interface BuildEntryOption {
|
|
73
167
|
/**
|
|
74
168
|
* Override to minify on entry
|
|
@@ -197,7 +291,7 @@ interface GeneratorOverrideFunctions {
|
|
|
197
291
|
*/
|
|
198
292
|
generateGzipFile?: (buffer: Buffer) => Promisable<Buffer>;
|
|
199
293
|
}
|
|
200
|
-
interface
|
|
294
|
+
interface UpdaterOptions {
|
|
201
295
|
/**
|
|
202
296
|
* Minimum version of entry
|
|
203
297
|
* @default '0.0.0'
|
|
@@ -285,25 +379,7 @@ interface ElectronUpdaterOptions {
|
|
|
285
379
|
overrideGenerator?: GeneratorOverrideFunctions;
|
|
286
380
|
}
|
|
287
381
|
|
|
288
|
-
|
|
289
|
-
* Obfuscate string
|
|
290
|
-
* @param code source code
|
|
291
|
-
* @param sourcemap whether to generate sourcemap
|
|
292
|
-
* @param offset custom offset
|
|
293
|
-
*/
|
|
294
|
-
declare function convertLiteral(code: string, sourcemap?: boolean, offset?: number): {
|
|
295
|
-
code: string;
|
|
296
|
-
map?: any;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
type MakeRequired<T, K extends keyof T> = NonNullable<T> & {
|
|
300
|
-
[P in K]-?: T[P];
|
|
301
|
-
};
|
|
302
|
-
type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> & {
|
|
303
|
-
[P in NewKey]: T[Key];
|
|
304
|
-
};
|
|
305
|
-
type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
|
|
306
|
-
type StartupFn = NonNullable<NonNullable<ElectronSimpleOptions['main']>['onstart']>;
|
|
382
|
+
type StartupFn = NonNullable<NonNullable<ElectronSimpleOptions$1['main']>['onstart']>;
|
|
307
383
|
/**
|
|
308
384
|
* Startup function for debug
|
|
309
385
|
* @see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
|
|
@@ -349,89 +425,6 @@ declare function filterErrorMessageStartup(args: Parameters<StartupFn>[0], filte
|
|
|
349
425
|
* })
|
|
350
426
|
*/
|
|
351
427
|
declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
|
|
352
|
-
type ExcludeOutputDirOptions = {
|
|
353
|
-
vite?: {
|
|
354
|
-
build?: {
|
|
355
|
-
outDir: never;
|
|
356
|
-
rollupOptions?: {
|
|
357
|
-
output?: {
|
|
358
|
-
dir: never;
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
|
-
interface ElectronWithUpdaterOptions {
|
|
365
|
-
/**
|
|
366
|
-
* Whether is in build mode
|
|
367
|
-
* ```ts
|
|
368
|
-
* export default defineConfig(({ command }) => {
|
|
369
|
-
* const isBuild = command === 'build'
|
|
370
|
-
* })
|
|
371
|
-
* ```
|
|
372
|
-
*/
|
|
373
|
-
isBuild: boolean;
|
|
374
|
-
/**
|
|
375
|
-
* Manually setup package.json, read name, version and main,
|
|
376
|
-
* use `local-pkg` of `loadPackageJSON()` to load package.json by default
|
|
377
|
-
* ```ts
|
|
378
|
-
* import pkg from './package.json'
|
|
379
|
-
* ```
|
|
380
|
-
*/
|
|
381
|
-
pkg?: PKG;
|
|
382
|
-
/**
|
|
383
|
-
* Whether to generate sourcemap
|
|
384
|
-
* @default !isBuild
|
|
385
|
-
*/
|
|
386
|
-
sourcemap?: boolean;
|
|
387
|
-
/**
|
|
388
|
-
* Whether to minify the code
|
|
389
|
-
* @default isBuild
|
|
390
|
-
*/
|
|
391
|
-
minify?: boolean;
|
|
392
|
-
/**
|
|
393
|
-
* Whether to generate bytecode
|
|
394
|
-
*
|
|
395
|
-
* **Only support CommonJS**
|
|
396
|
-
*
|
|
397
|
-
* 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
|
|
398
|
-
*/
|
|
399
|
-
bytecode?: boolean | BytecodeOptions;
|
|
400
|
-
/**
|
|
401
|
-
* Use `NotBundle()` plugin in main
|
|
402
|
-
* @default true
|
|
403
|
-
*/
|
|
404
|
-
useNotBundle?: boolean;
|
|
405
|
-
/**
|
|
406
|
-
* Whether to generate version json
|
|
407
|
-
* @default isCI
|
|
408
|
-
*/
|
|
409
|
-
buildVersionJson?: boolean;
|
|
410
|
-
/**
|
|
411
|
-
* Whether to log parsed options
|
|
412
|
-
*
|
|
413
|
-
* To show certificate and private keys, set `logParsedOptions: { showKeys: true }`
|
|
414
|
-
*/
|
|
415
|
-
logParsedOptions?: boolean | {
|
|
416
|
-
showKeys: boolean;
|
|
417
|
-
};
|
|
418
|
-
/**
|
|
419
|
-
* Main process options
|
|
420
|
-
*
|
|
421
|
-
* To change output directories, use `options.updater.paths.electronDistPath` instead
|
|
422
|
-
*/
|
|
423
|
-
main: MakeRequiredAndReplaceKey<ElectronSimpleOptions['main'], 'entry', 'files'> & ExcludeOutputDirOptions;
|
|
424
|
-
/**
|
|
425
|
-
* Preload process options
|
|
426
|
-
*
|
|
427
|
-
* To change output directories, use `options.updater.paths.electronDistPath` instead
|
|
428
|
-
*/
|
|
429
|
-
preload: MakeRequiredAndReplaceKey<Exclude<ElectronSimpleOptions['preload'], undefined>, 'input', 'files'> & ExcludeOutputDirOptions;
|
|
430
|
-
/**
|
|
431
|
-
* Updater options
|
|
432
|
-
*/
|
|
433
|
-
updater?: ElectronUpdaterOptions;
|
|
434
|
-
}
|
|
435
428
|
/**
|
|
436
429
|
* Base on `vite-plugin-electron/simple`
|
|
437
430
|
* - integrate with updater
|
|
@@ -454,7 +447,6 @@ interface ElectronWithUpdaterOptions {
|
|
|
454
447
|
* plugins: [
|
|
455
448
|
* electronWithUpdater({
|
|
456
449
|
* isBuild,
|
|
457
|
-
* logParsedOptions: true,
|
|
458
450
|
* main: {
|
|
459
451
|
* files: ['./electron/main/index.ts', './electron/main/worker.ts'],
|
|
460
452
|
* // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
|
package/dist/vite.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
import cp from 'child_process';
|
|
1
2
|
import fs5 from 'fs';
|
|
2
3
|
import path5 from 'path';
|
|
3
|
-
import
|
|
4
|
-
export { isCI } from 'ci-info';
|
|
4
|
+
import * as babel from '@babel/core';
|
|
5
5
|
import { getPackageInfoSync, loadPackageJSON } from 'local-pkg';
|
|
6
6
|
export { getPackageInfo, getPackageInfoSync, loadPackageJSON, resolveModule } from 'local-pkg';
|
|
7
|
+
import MagicString from 'magic-string';
|
|
7
8
|
import { createLogger, normalizePath, mergeConfig, createFilter } from 'vite';
|
|
9
|
+
import { isCI } from 'ci-info';
|
|
10
|
+
export { isCI } from 'ci-info';
|
|
8
11
|
import { startup, build } from 'vite-plugin-electron';
|
|
9
12
|
import { notBundle } from 'vite-plugin-electron/plugin';
|
|
10
13
|
import ElectronSimple from 'vite-plugin-electron/simple';
|
|
11
14
|
import Asar from '@electron/asar';
|
|
12
|
-
import MagicString from 'magic-string';
|
|
13
|
-
import cp from 'child_process';
|
|
14
|
-
import * as babel from '@babel/core';
|
|
15
15
|
import { builtinModules } from 'module';
|
|
16
16
|
import crypto from 'crypto';
|
|
17
17
|
import zlib from 'zlib';
|
|
18
18
|
import { generate } from 'selfsigned';
|
|
19
19
|
|
|
20
|
-
// src/vite/
|
|
20
|
+
// src/vite/bytecode/utils.ts
|
|
21
21
|
|
|
22
22
|
// src/utils/version.ts
|
|
23
23
|
function parseVersion(version) {
|
|
@@ -65,28 +65,12 @@ var bytecodeId = `${id}-bytecode`;
|
|
|
65
65
|
var esmId = `${id}-esm`;
|
|
66
66
|
var log = createLogger("info", { prefix: `[${id}]` });
|
|
67
67
|
var bytecodeLog = createLogger("info", { prefix: `[${bytecodeId}]` });
|
|
68
|
-
function readableSize(size) {
|
|
69
|
-
const units = ["B", "KB", "MB", "GB"];
|
|
70
|
-
let i = 0;
|
|
71
|
-
while (size >= 1024 && i < units.length - 1) {
|
|
72
|
-
size /= 1024;
|
|
73
|
-
i++;
|
|
74
|
-
}
|
|
75
|
-
return `${size.toFixed(2)} ${units[i]}`;
|
|
76
|
-
}
|
|
77
|
-
function copyAndSkipIfExist(from, to, skipIfExist) {
|
|
78
|
-
if (!skipIfExist || !fs5.existsSync(to)) {
|
|
79
|
-
try {
|
|
80
|
-
fs5.cpSync(from, to, { recursive: true });
|
|
81
|
-
} catch (error) {
|
|
82
|
-
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
68
|
|
|
87
69
|
// src/vite/bytecode/code.ts
|
|
88
70
|
var bytecodeGeneratorScript = "const vm = require('vm')\nconst v8 = require('v8')\nconst wrap = require('module').wrap\nv8.setFlagsFromString('--no-lazy')\nv8.setFlagsFromString('--no-flush-bytecode')\nlet code = ''\nprocess.stdin.setEncoding('utf-8')\nprocess.stdin.on('readable', () => {\n const data = process.stdin.read()\n if (data !== null) {\n code += data\n }\n})\nprocess.stdin.on('end', () => {\n try {\n if (typeof code !== 'string') {\n throw new Error('javascript code must be string.')\n }\n const script = new vm.Script(wrap(code), { produceCachedData: true })\n const bytecodeBuffer = script.createCachedData()\n process.stdout.write(bytecodeBuffer)\n } catch (error) {\n console.error(error)\n }\n})\n";
|
|
89
71
|
var bytecodeModuleLoaderCode = '"use strict";\nconst fs = require("fs");\nconst path = require("path");\nconst vm = require("vm");\nconst v8 = require("v8");\nconst Module = require("module");\nv8.setFlagsFromString("--no-lazy");\nv8.setFlagsFromString("--no-flush-bytecode");\nconst FLAG_HASH_OFFSET = 12;\nconst SOURCE_HASH_OFFSET = 8;\nlet dummyBytecode;\nfunction setFlagHashHeader(bytecodeBuffer) {\n if (!dummyBytecode) {\n const script = new vm.Script("", {\n produceCachedData: true\n });\n dummyBytecode = script.createCachedData();\n }\n dummyBytecode.slice(FLAG_HASH_OFFSET, FLAG_HASH_OFFSET + 4).copy(bytecodeBuffer, FLAG_HASH_OFFSET);\n};\nfunction getSourceHashHeader(bytecodeBuffer) {\n return bytecodeBuffer.slice(SOURCE_HASH_OFFSET, SOURCE_HASH_OFFSET + 4);\n};\nfunction buffer2Number(buffer) {\n let ret = 0;\n ret |= buffer[3] << 24;\n ret |= buffer[2] << 16;\n ret |= buffer[1] << 8;\n ret |= buffer[0];\n return ret;\n};\nModule._extensions[".jsc"] = Module._extensions[".cjsc"] = function (module, filename) {\n const bytecodeBuffer = fs.readFileSync(filename);\n if (!Buffer.isBuffer(bytecodeBuffer)) {\n throw new Error("BytecodeBuffer must be a buffer object.");\n }\n setFlagHashHeader(bytecodeBuffer);\n const length = buffer2Number(getSourceHashHeader(bytecodeBuffer));\n let dummyCode = "";\n if (length > 1) {\n dummyCode = "\\"" + "\\u200b".repeat(length - 2) + "\\"";\n }\n const script = new vm.Script(dummyCode, {\n filename: filename,\n lineOffset: 0,\n displayErrors: true,\n cachedData: bytecodeBuffer\n });\n if (script.cachedDataRejected) {\n throw new Error("Invalid or incompatible cached data (cachedDataRejected)");\n }\n const require = function (id) {\n return module.require(id);\n };\n require.resolve = function (request, options) {\n return Module._resolveFilename(request, module, false, options);\n };\n if (process.mainModule) {\n require.main = process.mainModule;\n }\n require.extensions = Module._extensions;\n require.cache = Module._cache;\n const compiledWrapper = script.runInThisContext({\n filename: filename,\n lineOffset: 0,\n columnOffset: 0,\n displayErrors: true\n });\n const dirname = path.dirname(filename);\n const args = [module.exports, require, module, filename, dirname, process, global];\n return compiledWrapper.apply(module.exports, args);\n};\n';
|
|
72
|
+
|
|
73
|
+
// src/vite/bytecode/utils.ts
|
|
90
74
|
var electronModule = getPackageInfoSync("electron");
|
|
91
75
|
var electronMajorVersion = parseVersion(electronModule.version).major;
|
|
92
76
|
var useStrict = "'use strict';";
|
|
@@ -222,6 +206,24 @@ function convertLiteral(code, sourcemap, offset) {
|
|
|
222
206
|
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
223
207
|
};
|
|
224
208
|
}
|
|
209
|
+
function readableSize(size) {
|
|
210
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
211
|
+
let i = 0;
|
|
212
|
+
while (size >= 1024 && i < units.length - 1) {
|
|
213
|
+
size /= 1024;
|
|
214
|
+
i++;
|
|
215
|
+
}
|
|
216
|
+
return `${size.toFixed(2)} ${units[i]}`;
|
|
217
|
+
}
|
|
218
|
+
function copyAndSkipIfExist(from, to, skipIfExist) {
|
|
219
|
+
if (!skipIfExist || !fs5.existsSync(to)) {
|
|
220
|
+
try {
|
|
221
|
+
fs5.cpSync(from, to, { recursive: true });
|
|
222
|
+
} catch (error) {
|
|
223
|
+
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
225
227
|
|
|
226
228
|
// src/vite/bytecode/index.ts
|
|
227
229
|
function getBytecodeLoaderBlock(chunkFileName) {
|
|
@@ -672,7 +674,8 @@ function parseOptions(isBuild, pkg, sourcemap = false, minify = false, options =
|
|
|
672
674
|
};
|
|
673
675
|
return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
|
|
674
676
|
}
|
|
675
|
-
|
|
677
|
+
|
|
678
|
+
// src/vite/core.ts
|
|
676
679
|
var debugStartup = async (args) => {
|
|
677
680
|
if (process.env.VSCODE_DEBUG) {
|
|
678
681
|
console.log("[startup] Electron App");
|
|
@@ -735,8 +738,7 @@ async function electronWithUpdater(options) {
|
|
|
735
738
|
buildVersionJson,
|
|
736
739
|
updater,
|
|
737
740
|
bytecode,
|
|
738
|
-
useNotBundle = true
|
|
739
|
-
logParsedOptions
|
|
741
|
+
useNotBundle = true
|
|
740
742
|
} = options;
|
|
741
743
|
if (!pkg || !pkg.version || !pkg.name || !pkg.main) {
|
|
742
744
|
log.error("package.json not found or invalid", { timestamp: true });
|
|
@@ -887,20 +889,6 @@ async function electronWithUpdater(options) {
|
|
|
887
889
|
)
|
|
888
890
|
}
|
|
889
891
|
};
|
|
890
|
-
if (logParsedOptions) {
|
|
891
|
-
const shouldShowKey = typeof logParsedOptions === "object" && logParsedOptions.showKeys === true;
|
|
892
|
-
log.info(
|
|
893
|
-
JSON.stringify(
|
|
894
|
-
{
|
|
895
|
-
...electronPluginOptions,
|
|
896
|
-
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
897
|
-
},
|
|
898
|
-
(key, value) => key === "privateKey" || key === "cert" ? shouldShowKey ? value : `<${key.toUpperCase()}>` : value,
|
|
899
|
-
2
|
|
900
|
-
),
|
|
901
|
-
{ timestamp: true }
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
892
|
const result = [ElectronSimple(electronPluginOptions)];
|
|
905
893
|
if (nativeModuleEntryMap) {
|
|
906
894
|
const files = [
|
|
@@ -943,4 +931,4 @@ async function electronWithUpdater(options) {
|
|
|
943
931
|
return result;
|
|
944
932
|
}
|
|
945
933
|
|
|
946
|
-
export { convertLiteral, debugStartup,
|
|
934
|
+
export { convertLiteral, debugStartup, electronWithUpdater as default, electronWithUpdater, filterErrorMessageStartup, fixWinCharEncoding };
|
package/package.json
CHANGED