electron-incremental-update 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vite.d.mts +16 -17
- package/dist/vite.d.ts +16 -17
- package/dist/vite.js +53 -36
- package/dist/vite.mjs +54 -37
- package/package.json +4 -2
package/dist/vite.d.mts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
-
import { DistinguishedName } from '@cyyynthia/jscert';
|
|
4
3
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type DistinguishedName = {
|
|
5
|
+
countryName?: string;
|
|
6
|
+
stateOrProvinceName?: string;
|
|
7
|
+
localityName?: string;
|
|
8
|
+
organizationName?: string;
|
|
9
|
+
organizationalUnitName?: string;
|
|
10
|
+
commonName?: string;
|
|
11
|
+
serialNumber?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
businessCategory?: string;
|
|
15
|
+
emailAddress?: string;
|
|
8
16
|
};
|
|
9
17
|
type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string;
|
|
10
18
|
type Options = {
|
|
@@ -98,26 +106,17 @@ type Options = {
|
|
|
98
106
|
/**
|
|
99
107
|
* the subject of the certificate
|
|
100
108
|
*
|
|
101
|
-
* @default { commonName: productName,
|
|
109
|
+
* @default { commonName: productName, organizationName: `org.${productName}` }
|
|
102
110
|
*/
|
|
103
111
|
subject?: DistinguishedName;
|
|
104
112
|
/**
|
|
105
|
-
*
|
|
106
|
-
* - `Date`: expire date
|
|
107
|
-
* - `number`: expire duration in seconds
|
|
113
|
+
* expire days of the certificate
|
|
108
114
|
*
|
|
109
|
-
* @default
|
|
115
|
+
* @default 365
|
|
110
116
|
*/
|
|
111
|
-
|
|
117
|
+
days?: number;
|
|
112
118
|
};
|
|
113
119
|
overrideFunctions?: {
|
|
114
|
-
/**
|
|
115
|
-
* custom key pair generate function {@link FunctionGenerateKeyPair}
|
|
116
|
-
* @param keyLength key length
|
|
117
|
-
* @param subject subject info
|
|
118
|
-
* @param expires expire date
|
|
119
|
-
*/
|
|
120
|
-
generateKeyPair?: FunctionGenerateKeyPair;
|
|
121
120
|
/**
|
|
122
121
|
* custom signature generate function {@link FunctionGenerateSignature}
|
|
123
122
|
* @param buffer file buffer
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
-
import { DistinguishedName } from '@cyyynthia/jscert';
|
|
4
3
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type DistinguishedName = {
|
|
5
|
+
countryName?: string;
|
|
6
|
+
stateOrProvinceName?: string;
|
|
7
|
+
localityName?: string;
|
|
8
|
+
organizationName?: string;
|
|
9
|
+
organizationalUnitName?: string;
|
|
10
|
+
commonName?: string;
|
|
11
|
+
serialNumber?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
businessCategory?: string;
|
|
15
|
+
emailAddress?: string;
|
|
8
16
|
};
|
|
9
17
|
type FunctionGenerateSignature = (buffer: Buffer, privateKey: string, cert: string, version: string) => string;
|
|
10
18
|
type Options = {
|
|
@@ -98,26 +106,17 @@ type Options = {
|
|
|
98
106
|
/**
|
|
99
107
|
* the subject of the certificate
|
|
100
108
|
*
|
|
101
|
-
* @default { commonName: productName,
|
|
109
|
+
* @default { commonName: productName, organizationName: `org.${productName}` }
|
|
102
110
|
*/
|
|
103
111
|
subject?: DistinguishedName;
|
|
104
112
|
/**
|
|
105
|
-
*
|
|
106
|
-
* - `Date`: expire date
|
|
107
|
-
* - `number`: expire duration in seconds
|
|
113
|
+
* expire days of the certificate
|
|
108
114
|
*
|
|
109
|
-
* @default
|
|
115
|
+
* @default 365
|
|
110
116
|
*/
|
|
111
|
-
|
|
117
|
+
days?: number;
|
|
112
118
|
};
|
|
113
119
|
overrideFunctions?: {
|
|
114
|
-
/**
|
|
115
|
-
* custom key pair generate function {@link FunctionGenerateKeyPair}
|
|
116
|
-
* @param keyLength key length
|
|
117
|
-
* @param subject subject info
|
|
118
|
-
* @param expires expire date
|
|
119
|
-
*/
|
|
120
|
-
generateKeyPair?: FunctionGenerateKeyPair;
|
|
121
120
|
/**
|
|
122
121
|
* custom signature generate function {@link FunctionGenerateSignature}
|
|
123
122
|
* @param buffer file buffer
|
package/dist/vite.js
CHANGED
|
@@ -142,20 +142,44 @@ var import_ci_info = require("ci-info");
|
|
|
142
142
|
var import_node_fs2 = require("fs");
|
|
143
143
|
var import_node_path2 = require("path");
|
|
144
144
|
var import_node_os = require("os");
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
var import_node_child_process = require("child_process");
|
|
146
|
+
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
147
|
+
const starter = `try {
|
|
148
|
+
require('selfsigned')
|
|
149
|
+
} catch (e) {
|
|
150
|
+
console.error('to generate private key, please run "npm install --dev selfsigned"')
|
|
150
151
|
}
|
|
151
|
-
|
|
152
|
-
const {
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
152
|
+
try {
|
|
153
|
+
const { existsSync, mkdirSync, writeFileSync } = require('node:fs')
|
|
154
|
+
const { dirname } = require('node:path')
|
|
155
|
+
const { generate } = require('selfsigned')
|
|
156
|
+
const privateKeyPath = '${privateKeyPath.replace(/\\/g, "/")}'
|
|
157
|
+
const certPath = '${certPath.replace(/\\/g, "/")}'
|
|
158
|
+
const privateKeyDir = dirname(privateKeyPath)
|
|
159
|
+
existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true })
|
|
160
|
+
const certDir = dirname(certPath)
|
|
161
|
+
existsSync(certDir) || mkdirSync(certDir, { recursive: true })
|
|
162
|
+
|
|
163
|
+
const { cert, private: privateKey } = generate(${JSON.stringify(subject)}, {
|
|
164
|
+
keySize: ${keyLength}, algorithm: 'sha256', days: ${days},
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
writeFileSync(privateKeyPath, privateKey.replace(/\\r/g, ''))
|
|
168
|
+
writeFileSync(certPath, cert.replace(/\\r/g, ''))
|
|
169
|
+
} catch (e) {
|
|
170
|
+
console.error(e)
|
|
171
|
+
process.exit(-1)
|
|
172
|
+
} finally {
|
|
173
|
+
process.exit(0)
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
const fileName = "key-gen.js";
|
|
177
|
+
(0, import_node_fs2.writeFileSync)(`./${fileName}`, starter);
|
|
178
|
+
try {
|
|
179
|
+
(0, import_node_child_process.execSync)(`npx electron ${fileName}`, { stdio: "inherit" });
|
|
180
|
+
} finally {
|
|
181
|
+
(0, import_node_fs2.rmSync)(`./${fileName}`);
|
|
182
|
+
}
|
|
159
183
|
}
|
|
160
184
|
function writeCertToMain(entryPath, cert) {
|
|
161
185
|
const file = (0, import_node_fs2.readFileSync)(entryPath, "utf-8");
|
|
@@ -188,29 +212,29 @@ function parseKeys({
|
|
|
188
212
|
certPath,
|
|
189
213
|
entryPath,
|
|
190
214
|
subject,
|
|
191
|
-
|
|
192
|
-
generateKeyPair
|
|
215
|
+
days
|
|
193
216
|
}) {
|
|
194
217
|
const keysDir = (0, import_node_path2.dirname)(privateKeyPath);
|
|
195
218
|
!(0, import_node_fs2.existsSync)(keysDir) && (0, import_node_fs2.mkdirSync)(keysDir);
|
|
196
|
-
let privateKey, cert;
|
|
197
219
|
if (!(0, import_node_fs2.existsSync)(privateKeyPath) || !(0, import_node_fs2.existsSync)(certPath)) {
|
|
198
|
-
|
|
199
|
-
const keys = _func(keyLength, subject, expires);
|
|
200
|
-
privateKey = keys.privateKey;
|
|
201
|
-
cert = keys.cert;
|
|
202
|
-
(0, import_node_fs2.writeFileSync)(privateKeyPath, privateKey);
|
|
203
|
-
(0, import_node_fs2.writeFileSync)(certPath, cert);
|
|
204
|
-
} else {
|
|
205
|
-
privateKey = (0, import_node_fs2.readFileSync)(privateKeyPath, "utf-8");
|
|
206
|
-
cert = (0, import_node_fs2.readFileSync)(certPath, "utf-8");
|
|
220
|
+
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
207
221
|
}
|
|
222
|
+
const privateKey = (0, import_node_fs2.readFileSync)(privateKeyPath, "utf-8");
|
|
223
|
+
const cert = (0, import_node_fs2.readFileSync)(certPath, "utf-8");
|
|
208
224
|
writeCertToMain(entryPath, cert);
|
|
209
225
|
return {
|
|
210
226
|
privateKey,
|
|
211
227
|
cert
|
|
212
228
|
};
|
|
213
229
|
}
|
|
230
|
+
function parseSubjects(subject) {
|
|
231
|
+
const ret = [];
|
|
232
|
+
Object.keys(subject).forEach((name) => {
|
|
233
|
+
const value = subject[name];
|
|
234
|
+
value && ret.push({ name, value });
|
|
235
|
+
});
|
|
236
|
+
return ret;
|
|
237
|
+
}
|
|
214
238
|
|
|
215
239
|
// src/build-plugins/option.ts
|
|
216
240
|
function parseOptions(options) {
|
|
@@ -236,16 +260,13 @@ function parseOptions(options) {
|
|
|
236
260
|
overrideFunctions = {}
|
|
237
261
|
} = {}
|
|
238
262
|
} = options;
|
|
239
|
-
const {
|
|
240
|
-
generateKeyPair,
|
|
241
|
-
generateSignature
|
|
242
|
-
} = overrideFunctions;
|
|
263
|
+
const { generateSignature } = overrideFunctions;
|
|
243
264
|
let {
|
|
244
265
|
subject = {
|
|
245
266
|
commonName: productName,
|
|
246
|
-
|
|
267
|
+
organizationName: `org.${productName}`
|
|
247
268
|
},
|
|
248
|
-
|
|
269
|
+
days = 365
|
|
249
270
|
} = certInfo;
|
|
250
271
|
const buildAsarOption = {
|
|
251
272
|
version,
|
|
@@ -261,17 +282,13 @@ function parseOptions(options) {
|
|
|
261
282
|
};
|
|
262
283
|
let buildVersionOption;
|
|
263
284
|
if (!import_ci_info.isCI) {
|
|
264
|
-
if (typeof expires === "number") {
|
|
265
|
-
expires = new Date(Date.now() + expires);
|
|
266
|
-
}
|
|
267
285
|
const { privateKey, cert } = parseKeys({
|
|
268
286
|
keyLength,
|
|
269
287
|
privateKeyPath,
|
|
270
288
|
certPath,
|
|
271
289
|
entryPath,
|
|
272
290
|
subject,
|
|
273
|
-
|
|
274
|
-
generateKeyPair
|
|
291
|
+
days
|
|
275
292
|
});
|
|
276
293
|
buildVersionOption = {
|
|
277
294
|
version,
|
package/dist/vite.mjs
CHANGED
|
@@ -75,23 +75,47 @@ async function buildEntry({
|
|
|
75
75
|
import { isCI } from "ci-info";
|
|
76
76
|
|
|
77
77
|
// src/build-plugins/key.ts
|
|
78
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
78
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
79
79
|
import { dirname } from "node:path";
|
|
80
80
|
import { EOL } from "node:os";
|
|
81
|
-
import {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
import { execSync } from "node:child_process";
|
|
82
|
+
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
83
|
+
const starter = `try {
|
|
84
|
+
require('selfsigned')
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error('to generate private key, please run "npm install --dev selfsigned"')
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
const {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
88
|
+
try {
|
|
89
|
+
const { existsSync, mkdirSync, writeFileSync } = require('node:fs')
|
|
90
|
+
const { dirname } = require('node:path')
|
|
91
|
+
const { generate } = require('selfsigned')
|
|
92
|
+
const privateKeyPath = '${privateKeyPath.replace(/\\/g, "/")}'
|
|
93
|
+
const certPath = '${certPath.replace(/\\/g, "/")}'
|
|
94
|
+
const privateKeyDir = dirname(privateKeyPath)
|
|
95
|
+
existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true })
|
|
96
|
+
const certDir = dirname(certPath)
|
|
97
|
+
existsSync(certDir) || mkdirSync(certDir, { recursive: true })
|
|
98
|
+
|
|
99
|
+
const { cert, private: privateKey } = generate(${JSON.stringify(subject)}, {
|
|
100
|
+
keySize: ${keyLength}, algorithm: 'sha256', days: ${days},
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
writeFileSync(privateKeyPath, privateKey.replace(/\\r/g, ''))
|
|
104
|
+
writeFileSync(certPath, cert.replace(/\\r/g, ''))
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.error(e)
|
|
107
|
+
process.exit(-1)
|
|
108
|
+
} finally {
|
|
109
|
+
process.exit(0)
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
const fileName = "key-gen.js";
|
|
113
|
+
writeFileSync(`./${fileName}`, starter);
|
|
114
|
+
try {
|
|
115
|
+
execSync(`npx electron ${fileName}`, { stdio: "inherit" });
|
|
116
|
+
} finally {
|
|
117
|
+
rmSync(`./${fileName}`);
|
|
118
|
+
}
|
|
95
119
|
}
|
|
96
120
|
function writeCertToMain(entryPath, cert) {
|
|
97
121
|
const file = readFileSync(entryPath, "utf-8");
|
|
@@ -124,29 +148,29 @@ function parseKeys({
|
|
|
124
148
|
certPath,
|
|
125
149
|
entryPath,
|
|
126
150
|
subject,
|
|
127
|
-
|
|
128
|
-
generateKeyPair
|
|
151
|
+
days
|
|
129
152
|
}) {
|
|
130
153
|
const keysDir = dirname(privateKeyPath);
|
|
131
154
|
!existsSync(keysDir) && mkdirSync(keysDir);
|
|
132
|
-
let privateKey, cert;
|
|
133
155
|
if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
|
|
134
|
-
|
|
135
|
-
const keys = _func(keyLength, subject, expires);
|
|
136
|
-
privateKey = keys.privateKey;
|
|
137
|
-
cert = keys.cert;
|
|
138
|
-
writeFileSync(privateKeyPath, privateKey);
|
|
139
|
-
writeFileSync(certPath, cert);
|
|
140
|
-
} else {
|
|
141
|
-
privateKey = readFileSync(privateKeyPath, "utf-8");
|
|
142
|
-
cert = readFileSync(certPath, "utf-8");
|
|
156
|
+
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
143
157
|
}
|
|
158
|
+
const privateKey = readFileSync(privateKeyPath, "utf-8");
|
|
159
|
+
const cert = readFileSync(certPath, "utf-8");
|
|
144
160
|
writeCertToMain(entryPath, cert);
|
|
145
161
|
return {
|
|
146
162
|
privateKey,
|
|
147
163
|
cert
|
|
148
164
|
};
|
|
149
165
|
}
|
|
166
|
+
function parseSubjects(subject) {
|
|
167
|
+
const ret = [];
|
|
168
|
+
Object.keys(subject).forEach((name) => {
|
|
169
|
+
const value = subject[name];
|
|
170
|
+
value && ret.push({ name, value });
|
|
171
|
+
});
|
|
172
|
+
return ret;
|
|
173
|
+
}
|
|
150
174
|
|
|
151
175
|
// src/build-plugins/option.ts
|
|
152
176
|
function parseOptions(options) {
|
|
@@ -172,16 +196,13 @@ function parseOptions(options) {
|
|
|
172
196
|
overrideFunctions = {}
|
|
173
197
|
} = {}
|
|
174
198
|
} = options;
|
|
175
|
-
const {
|
|
176
|
-
generateKeyPair,
|
|
177
|
-
generateSignature
|
|
178
|
-
} = overrideFunctions;
|
|
199
|
+
const { generateSignature } = overrideFunctions;
|
|
179
200
|
let {
|
|
180
201
|
subject = {
|
|
181
202
|
commonName: productName,
|
|
182
|
-
|
|
203
|
+
organizationName: `org.${productName}`
|
|
183
204
|
},
|
|
184
|
-
|
|
205
|
+
days = 365
|
|
185
206
|
} = certInfo;
|
|
186
207
|
const buildAsarOption = {
|
|
187
208
|
version,
|
|
@@ -197,17 +218,13 @@ function parseOptions(options) {
|
|
|
197
218
|
};
|
|
198
219
|
let buildVersionOption;
|
|
199
220
|
if (!isCI) {
|
|
200
|
-
if (typeof expires === "number") {
|
|
201
|
-
expires = new Date(Date.now() + expires);
|
|
202
|
-
}
|
|
203
221
|
const { privateKey, cert } = parseKeys({
|
|
204
222
|
keyLength,
|
|
205
223
|
privateKeyPath,
|
|
206
224
|
certPath,
|
|
207
225
|
entryPath,
|
|
208
226
|
subject,
|
|
209
|
-
|
|
210
|
-
generateKeyPair
|
|
227
|
+
days
|
|
211
228
|
});
|
|
212
229
|
buildVersionOption = {
|
|
213
230
|
version,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
3
|
"author": "subframe7536",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.3",
|
|
5
5
|
"description": "electron incremental update tools, powered by vite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsup && node fix-module.js",
|
|
@@ -56,7 +56,9 @@
|
|
|
56
56
|
"vitest": "^0.32.2"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@cyyynthia/jscert": "^0.1.2",
|
|
60
59
|
"ci-info": "^3.8.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"selfsigned": "^2.1.1"
|
|
61
63
|
}
|
|
62
64
|
}
|