electron-incremental-update 2.3.3 → 2.3.4
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 +3 -1
- package/dist/vite.d.ts +4 -2
- package/dist/vite.js +485 -60
- package/package.json +1 -1
- package/dist/bytecode-7J2ZQDDO.js +0 -167
- package/dist/chunk-5NKEXGI3.js +0 -10
- package/dist/chunk-LR7LR5WG.js +0 -192
- package/dist/chunk-TPTWE33H.js +0 -23
- package/dist/constant-ME27JB5D.js +0 -1
- package/dist/esm-4S4XCVEW.js +0 -64
package/README.md
CHANGED
|
@@ -920,7 +920,9 @@ export interface BuildEntryOption {
|
|
|
920
920
|
*/
|
|
921
921
|
ignoreDynamicRequires?: boolean
|
|
922
922
|
/**
|
|
923
|
-
* `external` option in `build.rollupOptions`,
|
|
923
|
+
* `external` option in `build.rollupOptions`,
|
|
924
|
+
* default is node built-in modules or native modules.
|
|
925
|
+
* If is in dev, also external `dependencies` in package.json
|
|
924
926
|
*/
|
|
925
927
|
external?: NonNullable<NonNullable<InlineConfig['build']>['rollupOptions']>['external']
|
|
926
928
|
/**
|
package/dist/vite.d.ts
CHANGED
|
@@ -104,7 +104,9 @@ interface BuildEntryOption {
|
|
|
104
104
|
*/
|
|
105
105
|
ignoreDynamicRequires?: boolean;
|
|
106
106
|
/**
|
|
107
|
-
* `external` option in `build.rollupOptions`,
|
|
107
|
+
* `external` option in `build.rollupOptions`,
|
|
108
|
+
* default is node built-in modules or native modules.
|
|
109
|
+
* If is in dev, also external `dependencies` in package.json
|
|
108
110
|
*/
|
|
109
111
|
external?: NonNullable<NonNullable<InlineConfig['build']>['rollupOptions']>['external'];
|
|
110
112
|
/**
|
|
@@ -322,7 +324,7 @@ declare const debugStartup: StartupFn;
|
|
|
322
324
|
* startup: args => filterErrorMessageStartup(
|
|
323
325
|
* args,
|
|
324
326
|
* // ignore error message when function returns false
|
|
325
|
-
* msg => !/"code":-32601/.test(
|
|
327
|
+
* msg => !/"code":-32601/.test(msg)
|
|
326
328
|
* )
|
|
327
329
|
* },
|
|
328
330
|
* })
|
package/dist/vite.js
CHANGED
|
@@ -1,23 +1,447 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export { convertLiteral } from './chunk-LR7LR5WG.js';
|
|
4
|
-
import { log, id } from './chunk-5NKEXGI3.js';
|
|
5
|
-
import fs2 from 'node:fs';
|
|
6
|
-
import path3 from 'node:path';
|
|
1
|
+
import fs5 from 'node:fs';
|
|
2
|
+
import path5 from 'node:path';
|
|
7
3
|
import { isCI } from 'ci-info';
|
|
8
4
|
export { isCI } from 'ci-info';
|
|
9
|
-
import {
|
|
5
|
+
import { getPackageInfoSync, loadPackageJSON } from 'local-pkg';
|
|
10
6
|
export { getPackageInfo, getPackageInfoSync, loadPackageJSON, resolveModule } from 'local-pkg';
|
|
11
|
-
import { normalizePath, mergeConfig } from 'vite';
|
|
7
|
+
import { createLogger, normalizePath, mergeConfig, createFilter } from 'vite';
|
|
12
8
|
import { startup, build } from 'vite-plugin-electron';
|
|
13
9
|
import { notBundle } from 'vite-plugin-electron/plugin';
|
|
14
10
|
import ElectronSimple from 'vite-plugin-electron/simple';
|
|
15
11
|
import Asar from '@electron/asar';
|
|
12
|
+
import MagicString from 'magic-string';
|
|
13
|
+
import cp from 'node:child_process';
|
|
14
|
+
import * as babel from '@babel/core';
|
|
16
15
|
import { builtinModules } from 'node:module';
|
|
17
16
|
import crypto from 'node:crypto';
|
|
18
17
|
import zlib from 'node:zlib';
|
|
19
18
|
import { generate } from 'selfsigned';
|
|
20
19
|
|
|
20
|
+
// src/vite/index.ts
|
|
21
|
+
|
|
22
|
+
// src/utils/version.ts
|
|
23
|
+
function parseVersion(version) {
|
|
24
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
25
|
+
if (!match) {
|
|
26
|
+
throw new TypeError(`invalid version: ${version}`);
|
|
27
|
+
}
|
|
28
|
+
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
29
|
+
const ret = {
|
|
30
|
+
major,
|
|
31
|
+
minor,
|
|
32
|
+
patch,
|
|
33
|
+
stage: "",
|
|
34
|
+
stageVersion: -1
|
|
35
|
+
};
|
|
36
|
+
if (match[4]) {
|
|
37
|
+
let [stage, _v] = match[4].split(".");
|
|
38
|
+
ret.stage = stage;
|
|
39
|
+
ret.stageVersion = Number(_v) || -1;
|
|
40
|
+
}
|
|
41
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
42
|
+
throw new TypeError(`Invalid version: ${version}`);
|
|
43
|
+
}
|
|
44
|
+
return ret;
|
|
45
|
+
}
|
|
46
|
+
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
47
|
+
function isUpdateJSON(json) {
|
|
48
|
+
return is(json) && is(json?.beta);
|
|
49
|
+
}
|
|
50
|
+
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
|
51
|
+
existingJson.beta = {
|
|
52
|
+
version,
|
|
53
|
+
minimumVersion,
|
|
54
|
+
signature
|
|
55
|
+
};
|
|
56
|
+
if (!parseVersion(version).stage) {
|
|
57
|
+
existingJson.version = version;
|
|
58
|
+
existingJson.minimumVersion = minimumVersion;
|
|
59
|
+
existingJson.signature = signature;
|
|
60
|
+
}
|
|
61
|
+
return existingJson;
|
|
62
|
+
}
|
|
63
|
+
var id = "electron-incremental-updater";
|
|
64
|
+
var bytecodeId = `${id}-bytecode`;
|
|
65
|
+
var esmId = `${id}-esm`;
|
|
66
|
+
var log = createLogger("info", { prefix: `[${id}]` });
|
|
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
|
+
|
|
87
|
+
// src/vite/bytecode/code.ts
|
|
88
|
+
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
|
+
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';
|
|
90
|
+
var electronModule = getPackageInfoSync("electron");
|
|
91
|
+
var electronMajorVersion = parseVersion(electronModule.version).major;
|
|
92
|
+
var useStrict = "'use strict';";
|
|
93
|
+
var bytecodeModuleLoader = "__loader__.js";
|
|
94
|
+
function getElectronPath() {
|
|
95
|
+
const electronModulePath = electronModule.rootPath;
|
|
96
|
+
let electronExecPath = process.env.ELECTRON_EXEC_PATH || "";
|
|
97
|
+
if (!electronExecPath) {
|
|
98
|
+
if (!electronModulePath) {
|
|
99
|
+
throw new Error("Electron is not installed");
|
|
100
|
+
}
|
|
101
|
+
const pathFile = path5.join(electronModulePath, "path.txt");
|
|
102
|
+
let executablePath;
|
|
103
|
+
if (fs5.existsSync(pathFile)) {
|
|
104
|
+
executablePath = fs5.readFileSync(pathFile, "utf-8");
|
|
105
|
+
}
|
|
106
|
+
if (executablePath) {
|
|
107
|
+
electronExecPath = path5.join(electronModulePath, "dist", executablePath);
|
|
108
|
+
process.env.ELECTRON_EXEC_PATH = electronExecPath;
|
|
109
|
+
} else {
|
|
110
|
+
throw new Error("Electron executable file is not existed");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return electronExecPath;
|
|
114
|
+
}
|
|
115
|
+
function getBytecodeCompilerPath() {
|
|
116
|
+
const scriptPath = path5.join(electronModule.rootPath, "EIU_bytenode.cjs");
|
|
117
|
+
if (!fs5.existsSync(scriptPath)) {
|
|
118
|
+
fs5.writeFileSync(scriptPath, bytecodeGeneratorScript);
|
|
119
|
+
}
|
|
120
|
+
return scriptPath;
|
|
121
|
+
}
|
|
122
|
+
function toRelativePath(filename, importer) {
|
|
123
|
+
const relPath = path5.posix.relative(path5.dirname(importer), filename);
|
|
124
|
+
return relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
125
|
+
}
|
|
126
|
+
var logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
127
|
+
function compileToBytecode(code, electronPath = getElectronPath()) {
|
|
128
|
+
let data = Buffer.from([]);
|
|
129
|
+
const bytecodePath = getBytecodeCompilerPath();
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const proc = cp.spawn(electronPath, [bytecodePath], {
|
|
132
|
+
env: { ELECTRON_RUN_AS_NODE: "1" },
|
|
133
|
+
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
134
|
+
});
|
|
135
|
+
if (proc.stdin) {
|
|
136
|
+
proc.stdin.write(code);
|
|
137
|
+
proc.stdin.end();
|
|
138
|
+
}
|
|
139
|
+
if (proc.stdout) {
|
|
140
|
+
proc.stdout.on("data", (chunk) => data = Buffer.concat([data, chunk]));
|
|
141
|
+
proc.stdout.on("error", (err) => logErr(err));
|
|
142
|
+
proc.stdout.on("end", () => resolve(data));
|
|
143
|
+
}
|
|
144
|
+
if (proc.stderr) {
|
|
145
|
+
proc.stderr.on("data", (chunk) => logErr("Error: ", chunk.toString()));
|
|
146
|
+
proc.stderr.on("error", (err) => logErr("Error: ", err));
|
|
147
|
+
}
|
|
148
|
+
proc.addListener("error", (err) => logErr(err));
|
|
149
|
+
proc.on("error", (err) => reject(err));
|
|
150
|
+
proc.on("exit", () => resolve(data));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function convertArrowFunctionAndTemplate(code) {
|
|
154
|
+
const result = babel.transform(code, {
|
|
155
|
+
plugins: ["@babel/plugin-transform-arrow-functions", "@babel/plugin-transform-template-literals"]
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
code: result?.code || code,
|
|
159
|
+
map: result?.map
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
|
|
163
|
+
function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
|
|
164
|
+
const hexArray = input.split("").map((c) => `0x${(c.charCodeAt(0) + offset).toString(16)}`);
|
|
165
|
+
return `_0xstr_([${hexArray.join(",")}],${offset})`;
|
|
166
|
+
}
|
|
167
|
+
function convertLiteral(code, sourcemap, offset) {
|
|
168
|
+
const s = new MagicString(code);
|
|
169
|
+
let hasTransformed = false;
|
|
170
|
+
const ast = babel.parse(code, { ast: true });
|
|
171
|
+
if (!ast) {
|
|
172
|
+
throw new Error("Cannot parse code");
|
|
173
|
+
}
|
|
174
|
+
babel.traverse(ast, {
|
|
175
|
+
StringLiteral(path6) {
|
|
176
|
+
const parent = path6.parent;
|
|
177
|
+
const node = path6.node;
|
|
178
|
+
if (parent.type === "CallExpression") {
|
|
179
|
+
if (parent.callee.type === "Identifier" && parent.callee.name === "require") {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (parent.callee.type === "Import") {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (parent.type.startsWith("Export")) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (parent.type.startsWith("Import")) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (parent.type === "ObjectMethod" && parent.key === node) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (parent.type === "ObjectProperty" && parent.key === node) {
|
|
196
|
+
const result2 = `[${obfuscateString(node.value, offset)}]`;
|
|
197
|
+
const start2 = node.start;
|
|
198
|
+
const end2 = node.end;
|
|
199
|
+
if (start2 && end2) {
|
|
200
|
+
s.overwrite(start2, end2, result2);
|
|
201
|
+
hasTransformed = true;
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (!node.value.trim()) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const result = obfuscateString(node.value, offset);
|
|
209
|
+
const start = node.start;
|
|
210
|
+
const end = node.end;
|
|
211
|
+
if (start && end) {
|
|
212
|
+
s.overwrite(start, end, result);
|
|
213
|
+
hasTransformed = true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
if (hasTransformed) {
|
|
218
|
+
s.append("\n").append(decodeFn);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
code: s.toString(),
|
|
222
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/vite/bytecode/index.ts
|
|
227
|
+
function getBytecodeLoaderBlock(chunkFileName) {
|
|
228
|
+
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
229
|
+
}
|
|
230
|
+
function bytecodePlugin(env, options) {
|
|
231
|
+
const {
|
|
232
|
+
enable,
|
|
233
|
+
preload = false,
|
|
234
|
+
electronPath,
|
|
235
|
+
beforeCompile
|
|
236
|
+
} = options;
|
|
237
|
+
if (!enable) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
if (!preload && env === "preload") {
|
|
241
|
+
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 });
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const filter = createFilter(/\.(m?[jt]s|[jt]sx)$/);
|
|
245
|
+
let config;
|
|
246
|
+
let bytecodeRequired = false;
|
|
247
|
+
let bytecodeFiles = [];
|
|
248
|
+
return {
|
|
249
|
+
name: `${bytecodeId}-${env}`,
|
|
250
|
+
apply: "build",
|
|
251
|
+
enforce: "post",
|
|
252
|
+
configResolved(resolvedConfig) {
|
|
253
|
+
config = resolvedConfig;
|
|
254
|
+
},
|
|
255
|
+
transform(code, id2) {
|
|
256
|
+
if (!filter(id2)) {
|
|
257
|
+
return convertLiteral(code, !!config.build.sourcemap);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
generateBundle(options2) {
|
|
261
|
+
if (options2.format !== "es" && bytecodeRequired) {
|
|
262
|
+
this.emitFile({
|
|
263
|
+
type: "asset",
|
|
264
|
+
source: `${bytecodeModuleLoaderCode}
|
|
265
|
+
`,
|
|
266
|
+
name: "Bytecode Loader File",
|
|
267
|
+
fileName: bytecodeModuleLoader
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
renderChunk(code, chunk, options2) {
|
|
272
|
+
if (options2.format === "es") {
|
|
273
|
+
bytecodeLog.warn(
|
|
274
|
+
'`bytecodePlugin` does not support ES module, please set "build.rollupOptions.output.format" option to "cjs"',
|
|
275
|
+
{ timestamp: true }
|
|
276
|
+
);
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
if (chunk.type === "chunk") {
|
|
280
|
+
bytecodeRequired = true;
|
|
281
|
+
return convertArrowFunctionAndTemplate(code);
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
},
|
|
285
|
+
async writeBundle(options2, output) {
|
|
286
|
+
if (options2.format === "es" || !bytecodeRequired) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const outDir = options2.dir;
|
|
290
|
+
bytecodeFiles = [];
|
|
291
|
+
const bundles = Object.keys(output);
|
|
292
|
+
const chunks = Object.values(output).filter(
|
|
293
|
+
(chunk) => chunk.type === "chunk" && chunk.fileName !== bytecodeModuleLoader
|
|
294
|
+
);
|
|
295
|
+
const bytecodeChunks = chunks.map((chunk) => chunk.fileName);
|
|
296
|
+
const nonEntryChunks = chunks.filter((chunk) => !chunk.isEntry).map((chunk) => path5.basename(chunk.fileName));
|
|
297
|
+
const pattern = nonEntryChunks.map((chunk) => `(${chunk})`).join("|");
|
|
298
|
+
const bytecodeRE = pattern ? new RegExp(`require\\(\\S*(?=(${pattern})\\S*\\))`, "g") : null;
|
|
299
|
+
await Promise.all(
|
|
300
|
+
bundles.map(async (name) => {
|
|
301
|
+
const chunk = output[name];
|
|
302
|
+
if (chunk.type === "chunk") {
|
|
303
|
+
let _code = chunk.code;
|
|
304
|
+
const chunkFilePath = path5.resolve(outDir, name);
|
|
305
|
+
if (beforeCompile) {
|
|
306
|
+
const cbResult = await beforeCompile(_code, chunkFilePath);
|
|
307
|
+
if (cbResult) {
|
|
308
|
+
_code = cbResult;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (bytecodeRE && _code.match(bytecodeRE)) {
|
|
312
|
+
let match;
|
|
313
|
+
const s = new MagicString(_code);
|
|
314
|
+
while (match = bytecodeRE.exec(_code)) {
|
|
315
|
+
const [prefix, chunkName] = match;
|
|
316
|
+
const len = prefix.length + chunkName.length;
|
|
317
|
+
s.overwrite(match.index, match.index + len, `${prefix + chunkName}c`, {
|
|
318
|
+
contentOnly: true
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
_code = s.toString();
|
|
322
|
+
}
|
|
323
|
+
if (bytecodeChunks.includes(name)) {
|
|
324
|
+
const bytecodeBuffer = await compileToBytecode(_code, electronPath);
|
|
325
|
+
fs5.writeFileSync(`${chunkFilePath}c`, bytecodeBuffer);
|
|
326
|
+
if (chunk.isEntry) {
|
|
327
|
+
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
328
|
+
const bytecodeModuleBlock = `require("./${`${path5.basename(name)}c`}");`;
|
|
329
|
+
const code = `${useStrict}
|
|
330
|
+
${bytecodeLoaderBlock}
|
|
331
|
+
module.exports=${bytecodeModuleBlock}
|
|
332
|
+
`;
|
|
333
|
+
fs5.writeFileSync(chunkFilePath, code);
|
|
334
|
+
} else {
|
|
335
|
+
fs5.unlinkSync(chunkFilePath);
|
|
336
|
+
}
|
|
337
|
+
bytecodeFiles.push({ name: `${name}c`, size: bytecodeBuffer.length });
|
|
338
|
+
} else {
|
|
339
|
+
if (chunk.isEntry) {
|
|
340
|
+
let hasBytecodeMoudle = false;
|
|
341
|
+
const idsToHandle = /* @__PURE__ */ new Set([...chunk.imports, ...chunk.dynamicImports]);
|
|
342
|
+
for (const moduleId of idsToHandle) {
|
|
343
|
+
if (bytecodeChunks.includes(moduleId)) {
|
|
344
|
+
hasBytecodeMoudle = true;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
const moduleInfo = this.getModuleInfo(moduleId);
|
|
348
|
+
if (moduleInfo && !moduleInfo.isExternal) {
|
|
349
|
+
const { importers, dynamicImporters } = moduleInfo;
|
|
350
|
+
for (const importerId of importers) {
|
|
351
|
+
idsToHandle.add(importerId);
|
|
352
|
+
}
|
|
353
|
+
for (const importerId of dynamicImporters) {
|
|
354
|
+
idsToHandle.add(importerId);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
359
|
+
_code = hasBytecodeMoudle ? _code.replace(
|
|
360
|
+
new RegExp(`(${useStrict})|("use strict";)`),
|
|
361
|
+
`${useStrict}
|
|
362
|
+
${bytecodeLoaderBlock}`
|
|
363
|
+
) : _code;
|
|
364
|
+
}
|
|
365
|
+
fs5.writeFileSync(chunkFilePath, _code);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
},
|
|
371
|
+
closeBundle() {
|
|
372
|
+
const outDir = `${normalizePath(path5.relative(config.root, path5.resolve(config.root, config.build.outDir)))}/`;
|
|
373
|
+
bytecodeFiles.forEach((file) => {
|
|
374
|
+
bytecodeLog.info(
|
|
375
|
+
`${outDir}${file.name} [${readableSize(file.size)}]`,
|
|
376
|
+
{ timestamp: true }
|
|
377
|
+
);
|
|
378
|
+
});
|
|
379
|
+
bytecodeLog.info(`${bytecodeFiles.length} bundles compiled into bytecode.`, { timestamp: true });
|
|
380
|
+
bytecodeFiles = [];
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/vite/esm/constant.ts
|
|
386
|
+
var CJSShim = `
|
|
387
|
+
// -- CommonJS Shims --
|
|
388
|
+
import __cjs_url__ from 'node:url';
|
|
389
|
+
import __cjs_path__ from 'node:path';
|
|
390
|
+
import __cjs_mod__ from 'node:module';
|
|
391
|
+
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
392
|
+
const __dirname = __cjs_path__.dirname(__filename);
|
|
393
|
+
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
394
|
+
`;
|
|
395
|
+
var CJSShim_electron_30 = `
|
|
396
|
+
// -- CommonJS Shims --
|
|
397
|
+
import __cjs_mod__ from 'node:module';
|
|
398
|
+
const __filename = import.meta.filename;
|
|
399
|
+
const __dirname = import.meta.dirname;
|
|
400
|
+
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
401
|
+
`;
|
|
402
|
+
var shim = electronMajorVersion >= 30 ? CJSShim_electron_30 : CJSShim;
|
|
403
|
+
|
|
404
|
+
// src/vite/esm/utils.ts
|
|
405
|
+
var ESMStaticImportRe = /(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<=")[^"]*[^\s"](?=\s*")|(?<=')[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
|
|
406
|
+
function findStaticImports(code) {
|
|
407
|
+
const matches = [];
|
|
408
|
+
for (const match of code.matchAll(ESMStaticImportRe)) {
|
|
409
|
+
matches.push({ end: (match.index || 0) + match[0].length });
|
|
410
|
+
}
|
|
411
|
+
return matches;
|
|
412
|
+
}
|
|
413
|
+
function insertCJSShim(code, sourcemap, insertPosition = 0) {
|
|
414
|
+
if (code.includes(shim) || !/__filename|__dirname|require\(|require\.resolve\(|require\.apply\(/.test(code)) {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
const s = new MagicString(code);
|
|
418
|
+
s.appendRight(insertPosition, shim);
|
|
419
|
+
return {
|
|
420
|
+
code: s.toString(),
|
|
421
|
+
map: sourcemap ? s.generateMap({ hires: "boundary" }) : null
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/vite/esm/index.ts
|
|
426
|
+
function esm() {
|
|
427
|
+
let sourcemap;
|
|
428
|
+
return {
|
|
429
|
+
name: esmId,
|
|
430
|
+
enforce: "post",
|
|
431
|
+
configResolved(config) {
|
|
432
|
+
sourcemap = config.build.sourcemap;
|
|
433
|
+
},
|
|
434
|
+
renderChunk(code, _chunk, options) {
|
|
435
|
+
if (options.format === "es") {
|
|
436
|
+
const lastESMImport = findStaticImports(code).pop();
|
|
437
|
+
const pos = lastESMImport ? lastESMImport.end : 0;
|
|
438
|
+
return insertCJSShim(code, sourcemap, pos);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// src/vite/build.ts
|
|
21
445
|
async function buildAsar({
|
|
22
446
|
version,
|
|
23
447
|
asarOutputPath,
|
|
@@ -26,11 +450,11 @@ async function buildAsar({
|
|
|
26
450
|
rendererDistPath,
|
|
27
451
|
generateGzipFile
|
|
28
452
|
}) {
|
|
29
|
-
|
|
30
|
-
|
|
453
|
+
fs5.renameSync(rendererDistPath, path5.join(electronDistPath, "renderer"));
|
|
454
|
+
fs5.writeFileSync(path5.join(electronDistPath, "version"), version);
|
|
31
455
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
32
|
-
const buf = await generateGzipFile(
|
|
33
|
-
|
|
456
|
+
const buf = await generateGzipFile(fs5.readFileSync(asarOutputPath));
|
|
457
|
+
fs5.writeFileSync(gzipPath, buf);
|
|
34
458
|
log.info(`Build update asar to '${gzipPath}' [${readableSize(buf.length)}]`, { timestamp: true });
|
|
35
459
|
return buf;
|
|
36
460
|
}
|
|
@@ -53,9 +477,9 @@ async function buildUpdateJson({
|
|
|
53
477
|
signature: "",
|
|
54
478
|
version
|
|
55
479
|
};
|
|
56
|
-
if (
|
|
480
|
+
if (fs5.existsSync(versionPath)) {
|
|
57
481
|
try {
|
|
58
|
-
const oldVersionJson = JSON.parse(
|
|
482
|
+
const oldVersionJson = JSON.parse(fs5.readFileSync(versionPath, "utf-8"));
|
|
59
483
|
if (isUpdateJSON(oldVersionJson)) {
|
|
60
484
|
_json = oldVersionJson;
|
|
61
485
|
} else {
|
|
@@ -69,7 +493,7 @@ async function buildUpdateJson({
|
|
|
69
493
|
if (!isUpdateJSON(_json)) {
|
|
70
494
|
throw new Error("Invalid update json");
|
|
71
495
|
}
|
|
72
|
-
|
|
496
|
+
fs5.writeFileSync(versionPath, JSON.stringify(_json, null, 2));
|
|
73
497
|
log.info(`build update json to '${versionPath}'`, { timestamp: true });
|
|
74
498
|
}
|
|
75
499
|
async function buildEntry({
|
|
@@ -89,8 +513,8 @@ async function buildEntry({
|
|
|
89
513
|
},
|
|
90
514
|
vite: mergeConfig({
|
|
91
515
|
plugins: [
|
|
92
|
-
isESM &&
|
|
93
|
-
bytecodeOptions &&
|
|
516
|
+
isESM && esm(),
|
|
517
|
+
bytecodeOptions && bytecodePlugin("main", bytecodeOptions)
|
|
94
518
|
],
|
|
95
519
|
build: {
|
|
96
520
|
sourcemap,
|
|
@@ -121,21 +545,21 @@ async function defaultZipFile(buffer) {
|
|
|
121
545
|
});
|
|
122
546
|
}
|
|
123
547
|
function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
124
|
-
const privateKeyDir =
|
|
125
|
-
if (!
|
|
126
|
-
|
|
548
|
+
const privateKeyDir = path5.dirname(privateKeyPath);
|
|
549
|
+
if (!fs5.existsSync(privateKeyDir)) {
|
|
550
|
+
fs5.mkdirSync(privateKeyDir, { recursive: true });
|
|
127
551
|
}
|
|
128
|
-
const certDir =
|
|
129
|
-
if (!
|
|
130
|
-
|
|
552
|
+
const certDir = path5.dirname(certPath);
|
|
553
|
+
if (!fs5.existsSync(certDir)) {
|
|
554
|
+
fs5.mkdirSync(certDir, { recursive: true });
|
|
131
555
|
}
|
|
132
556
|
const { cert, private: privateKey } = generate(subject, {
|
|
133
557
|
keySize: keyLength,
|
|
134
558
|
algorithm: "sha256",
|
|
135
559
|
days
|
|
136
560
|
});
|
|
137
|
-
|
|
138
|
-
|
|
561
|
+
fs5.writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
562
|
+
fs5.writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
139
563
|
}
|
|
140
564
|
function parseKeys({
|
|
141
565
|
keyLength,
|
|
@@ -144,22 +568,22 @@ function parseKeys({
|
|
|
144
568
|
subject,
|
|
145
569
|
days
|
|
146
570
|
}) {
|
|
147
|
-
const keysDir =
|
|
571
|
+
const keysDir = path5.dirname(privateKeyPath);
|
|
148
572
|
let privateKey = process.env.UPDATER_PK;
|
|
149
573
|
let cert = process.env.UPDATER_CERT;
|
|
150
574
|
if (privateKey && cert) {
|
|
151
575
|
log.info("Use `UPDATER_PK` and `UPDATER_CERT` from environment variables", { timestamp: true });
|
|
152
576
|
return { privateKey, cert };
|
|
153
577
|
}
|
|
154
|
-
if (!
|
|
155
|
-
|
|
578
|
+
if (!fs5.existsSync(keysDir)) {
|
|
579
|
+
fs5.mkdirSync(keysDir);
|
|
156
580
|
}
|
|
157
|
-
if (!
|
|
581
|
+
if (!fs5.existsSync(privateKeyPath) || !fs5.existsSync(certPath)) {
|
|
158
582
|
log.info("No key pair found, generate new key pair", { timestamp: true });
|
|
159
583
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
160
584
|
}
|
|
161
|
-
privateKey =
|
|
162
|
-
cert =
|
|
585
|
+
privateKey = fs5.readFileSync(privateKeyPath, "utf-8");
|
|
586
|
+
cert = fs5.readFileSync(certPath, "utf-8");
|
|
163
587
|
return { privateKey, cert };
|
|
164
588
|
}
|
|
165
589
|
function parseSubjects(subject) {
|
|
@@ -167,7 +591,7 @@ function parseSubjects(subject) {
|
|
|
167
591
|
}
|
|
168
592
|
|
|
169
593
|
// src/vite/option.ts
|
|
170
|
-
function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
594
|
+
function parseOptions(isBuild, pkg, sourcemap = false, minify = false, options = {}) {
|
|
171
595
|
const {
|
|
172
596
|
minimumVersion = "0.0.0",
|
|
173
597
|
entry: {
|
|
@@ -182,7 +606,8 @@ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
|
|
|
182
606
|
/^node:.*/,
|
|
183
607
|
/.*\.(node|dll|dylib|so)$/,
|
|
184
608
|
"original-fs",
|
|
185
|
-
...builtinModules
|
|
609
|
+
...builtinModules,
|
|
610
|
+
...isBuild ? [] : Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
186
611
|
],
|
|
187
612
|
overrideViteOptions = {}
|
|
188
613
|
} = {},
|
|
@@ -276,9 +701,9 @@ function fixWinCharEncoding(fn) {
|
|
|
276
701
|
function getMainFileBaseName(options) {
|
|
277
702
|
let mainFilePath;
|
|
278
703
|
if (typeof options === "string") {
|
|
279
|
-
mainFilePath =
|
|
704
|
+
mainFilePath = path5.basename(options);
|
|
280
705
|
} else if (Array.isArray(options)) {
|
|
281
|
-
mainFilePath =
|
|
706
|
+
mainFilePath = path5.basename(options[0]);
|
|
282
707
|
} else {
|
|
283
708
|
const name = options?.index ?? options?.main;
|
|
284
709
|
if (!name) {
|
|
@@ -317,7 +742,7 @@ async function electronWithUpdater(options) {
|
|
|
317
742
|
const isESM = pkg.type === "module";
|
|
318
743
|
let bytecodeOptions = typeof bytecode === "object" ? bytecode : bytecode === true ? { enable: true } : void 0;
|
|
319
744
|
if (isESM && bytecodeOptions?.enable) {
|
|
320
|
-
|
|
745
|
+
bytecodeLog.warn(
|
|
321
746
|
'`bytecodePlugin` does not support ES module, please remove "type": "module" in package.json',
|
|
322
747
|
{ timestamp: true }
|
|
323
748
|
);
|
|
@@ -329,21 +754,21 @@ async function electronWithUpdater(options) {
|
|
|
329
754
|
buildVersionOption,
|
|
330
755
|
postBuild,
|
|
331
756
|
cert
|
|
332
|
-
} = parseOptions(pkg, sourcemap, minify, updater);
|
|
757
|
+
} = parseOptions(isBuild, pkg, sourcemap, minify, updater);
|
|
333
758
|
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath, external } = buildEntryOption;
|
|
334
759
|
try {
|
|
335
|
-
|
|
336
|
-
|
|
760
|
+
fs5.rmSync(buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
761
|
+
fs5.rmSync(entryOutputDirPath, { recursive: true, force: true });
|
|
337
762
|
} catch {
|
|
338
763
|
}
|
|
339
764
|
log.info(`Clear cache files`, { timestamp: true });
|
|
340
765
|
sourcemap ??= isBuild || !!process.env.VSCODE_DEBUG;
|
|
341
|
-
const _appPath = normalizePath(
|
|
342
|
-
if (
|
|
766
|
+
const _appPath = normalizePath(path5.join(entryOutputDirPath, "entry.js"));
|
|
767
|
+
if (path5.resolve(normalizePath(pkg.main)) !== path5.resolve(_appPath)) {
|
|
343
768
|
throw new Error(`Wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath}"`);
|
|
344
769
|
}
|
|
345
770
|
const define = {
|
|
346
|
-
__EIU_ASAR_BASE_NAME__: JSON.stringify(
|
|
771
|
+
__EIU_ASAR_BASE_NAME__: JSON.stringify(path5.basename(buildAsarOption.asarOutputPath)),
|
|
347
772
|
__EIU_ELECTRON_DIST_PATH__: JSON.stringify(normalizePath(buildAsarOption.electronDistPath)),
|
|
348
773
|
__EIU_ENTRY_DIST_PATH__: JSON.stringify(normalizePath(buildEntryOption.entryOutputDirPath)),
|
|
349
774
|
__EIU_IS_DEV__: JSON.stringify(!isBuild),
|
|
@@ -362,25 +787,25 @@ async function electronWithUpdater(options) {
|
|
|
362
787
|
log.info(`Build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
363
788
|
await postBuild?.({
|
|
364
789
|
getPathFromEntryOutputDir(...paths) {
|
|
365
|
-
return
|
|
790
|
+
return path5.join(entryOutputDirPath, ...paths);
|
|
366
791
|
},
|
|
367
792
|
copyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
368
|
-
if (!
|
|
793
|
+
if (!fs5.existsSync(from)) {
|
|
369
794
|
log.warn(`${from} not found`, { timestamp: true });
|
|
370
795
|
return;
|
|
371
796
|
}
|
|
372
|
-
const target =
|
|
797
|
+
const target = path5.join(entryOutputDirPath, to ?? path5.basename(from));
|
|
373
798
|
copyAndSkipIfExist(from, target, skipIfExist);
|
|
374
799
|
},
|
|
375
800
|
copyModules({ modules, skipIfExist = true }) {
|
|
376
|
-
const nodeModulesPath =
|
|
801
|
+
const nodeModulesPath = path5.join(entryOutputDirPath, "node_modules");
|
|
377
802
|
for (const m of modules) {
|
|
378
803
|
const { rootPath } = getPackageInfoSync(m) || {};
|
|
379
804
|
if (!rootPath) {
|
|
380
805
|
log.warn(`Package '${m}' not found`, { timestamp: true });
|
|
381
806
|
continue;
|
|
382
807
|
}
|
|
383
|
-
copyAndSkipIfExist(rootPath,
|
|
808
|
+
copyAndSkipIfExist(rootPath, path5.join(nodeModulesPath, m), skipIfExist);
|
|
384
809
|
}
|
|
385
810
|
}
|
|
386
811
|
});
|
|
@@ -390,7 +815,6 @@ async function electronWithUpdater(options) {
|
|
|
390
815
|
external,
|
|
391
816
|
treeshake: true
|
|
392
817
|
};
|
|
393
|
-
const esmShimPlugin = isESM ? import('./esm-4S4XCVEW.js').then((m) => m.esm()) : void 0;
|
|
394
818
|
const electronPluginOptions = {
|
|
395
819
|
main: {
|
|
396
820
|
entry: _main.files,
|
|
@@ -408,9 +832,9 @@ async function electronWithUpdater(options) {
|
|
|
408
832
|
vite: mergeConfig(
|
|
409
833
|
{
|
|
410
834
|
plugins: [
|
|
411
|
-
!isBuild && useNotBundle
|
|
412
|
-
bytecodeOptions &&
|
|
413
|
-
|
|
835
|
+
!isBuild && useNotBundle && notBundle(),
|
|
836
|
+
bytecodeOptions && bytecodePlugin("main", bytecodeOptions),
|
|
837
|
+
isESM && esm()
|
|
414
838
|
],
|
|
415
839
|
build: {
|
|
416
840
|
sourcemap,
|
|
@@ -429,8 +853,8 @@ async function electronWithUpdater(options) {
|
|
|
429
853
|
vite: mergeConfig(
|
|
430
854
|
{
|
|
431
855
|
plugins: [
|
|
432
|
-
bytecodeOptions &&
|
|
433
|
-
|
|
856
|
+
bytecodeOptions && bytecodePlugin("preload", bytecodeOptions),
|
|
857
|
+
isESM && esm(),
|
|
434
858
|
{
|
|
435
859
|
name: `${id}-build`,
|
|
436
860
|
enforce: "post",
|
|
@@ -461,25 +885,26 @@ async function electronWithUpdater(options) {
|
|
|
461
885
|
}
|
|
462
886
|
};
|
|
463
887
|
if (logParsedOptions) {
|
|
888
|
+
const shouldShowKey = typeof logParsedOptions === "object" && logParsedOptions.showKeys === true;
|
|
464
889
|
log.info(
|
|
465
890
|
JSON.stringify(
|
|
466
891
|
{
|
|
467
892
|
...electronPluginOptions,
|
|
468
893
|
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
469
894
|
},
|
|
470
|
-
(key, value) =>
|
|
895
|
+
(key, value) => (key === "privateKey" || key === "cert") && shouldShowKey ? value : `<${key.toUpperCase()}>`,
|
|
471
896
|
2
|
|
472
897
|
),
|
|
473
898
|
{ timestamp: true }
|
|
474
899
|
);
|
|
475
900
|
}
|
|
476
|
-
|
|
901
|
+
const result = [ElectronSimple(electronPluginOptions)];
|
|
477
902
|
if (nativeModuleEntryMap) {
|
|
478
903
|
const files = [
|
|
479
904
|
...Object.values(nativeModuleEntryMap),
|
|
480
905
|
appEntryPath
|
|
481
|
-
].map((file) =>
|
|
482
|
-
|
|
906
|
+
].map((file) => path5.resolve(normalizePath(file)));
|
|
907
|
+
result.push({
|
|
483
908
|
name: `${id}-dev`,
|
|
484
909
|
apply() {
|
|
485
910
|
return !isBuild;
|
|
@@ -510,9 +935,9 @@ async function electronWithUpdater(options) {
|
|
|
510
935
|
}
|
|
511
936
|
);
|
|
512
937
|
}
|
|
513
|
-
};
|
|
938
|
+
});
|
|
514
939
|
}
|
|
515
|
-
return
|
|
940
|
+
return result;
|
|
516
941
|
}
|
|
517
942
|
|
|
518
|
-
export { debugStartup, vite_default as default, electronWithUpdater, filterErrorMessageStartup, fixWinCharEncoding };
|
|
943
|
+
export { convertLiteral, debugStartup, vite_default as default, electronWithUpdater, filterErrorMessageStartup, fixWinCharEncoding };
|
package/package.json
CHANGED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { readableSize } from './chunk-TPTWE33H.js';
|
|
2
|
-
import { convertArrowFunctionAndTemplate, bytecodeModuleLoader, bytecodeModuleLoaderCode, convertLiteral, compileToBytecode, useStrict, toRelativePath } from './chunk-LR7LR5WG.js';
|
|
3
|
-
import { bytecodeLog, bytecodeId } from './chunk-5NKEXGI3.js';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import MagicString from 'magic-string';
|
|
7
|
-
import { createFilter, normalizePath } from 'vite';
|
|
8
|
-
|
|
9
|
-
function getBytecodeLoaderBlock(chunkFileName) {
|
|
10
|
-
return `require("${toRelativePath(bytecodeModuleLoader, normalizePath(chunkFileName))}");`;
|
|
11
|
-
}
|
|
12
|
-
function bytecodePlugin(env, options) {
|
|
13
|
-
const {
|
|
14
|
-
enable,
|
|
15
|
-
preload = false,
|
|
16
|
-
electronPath,
|
|
17
|
-
beforeCompile
|
|
18
|
-
} = options;
|
|
19
|
-
if (!enable) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
if (!preload && env === "preload") {
|
|
23
|
-
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 });
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
const filter = createFilter(/\.(m?[jt]s|[jt]sx)$/);
|
|
27
|
-
let config;
|
|
28
|
-
let bytecodeRequired = false;
|
|
29
|
-
let bytecodeFiles = [];
|
|
30
|
-
return {
|
|
31
|
-
name: `${bytecodeId}-${env}`,
|
|
32
|
-
apply: "build",
|
|
33
|
-
enforce: "post",
|
|
34
|
-
configResolved(resolvedConfig) {
|
|
35
|
-
config = resolvedConfig;
|
|
36
|
-
},
|
|
37
|
-
transform(code, id) {
|
|
38
|
-
if (!filter(id)) {
|
|
39
|
-
return convertLiteral(code, !!config.build.sourcemap);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
generateBundle(options2) {
|
|
43
|
-
if (options2.format !== "es" && bytecodeRequired) {
|
|
44
|
-
this.emitFile({
|
|
45
|
-
type: "asset",
|
|
46
|
-
source: `${bytecodeModuleLoaderCode}
|
|
47
|
-
`,
|
|
48
|
-
name: "Bytecode Loader File",
|
|
49
|
-
fileName: bytecodeModuleLoader
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
renderChunk(code, chunk, options2) {
|
|
54
|
-
if (options2.format === "es") {
|
|
55
|
-
bytecodeLog.warn(
|
|
56
|
-
'`bytecodePlugin` does not support ES module, please set "build.rollupOptions.output.format" option to "cjs"',
|
|
57
|
-
{ timestamp: true }
|
|
58
|
-
);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
if (chunk.type === "chunk") {
|
|
62
|
-
bytecodeRequired = true;
|
|
63
|
-
return convertArrowFunctionAndTemplate(code);
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
},
|
|
67
|
-
async writeBundle(options2, output) {
|
|
68
|
-
if (options2.format === "es" || !bytecodeRequired) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const outDir = options2.dir;
|
|
72
|
-
bytecodeFiles = [];
|
|
73
|
-
const bundles = Object.keys(output);
|
|
74
|
-
const chunks = Object.values(output).filter(
|
|
75
|
-
(chunk) => chunk.type === "chunk" && chunk.fileName !== bytecodeModuleLoader
|
|
76
|
-
);
|
|
77
|
-
const bytecodeChunks = chunks.map((chunk) => chunk.fileName);
|
|
78
|
-
const nonEntryChunks = chunks.filter((chunk) => !chunk.isEntry).map((chunk) => path.basename(chunk.fileName));
|
|
79
|
-
const pattern = nonEntryChunks.map((chunk) => `(${chunk})`).join("|");
|
|
80
|
-
const bytecodeRE = pattern ? new RegExp(`require\\(\\S*(?=(${pattern})\\S*\\))`, "g") : null;
|
|
81
|
-
await Promise.all(
|
|
82
|
-
bundles.map(async (name) => {
|
|
83
|
-
const chunk = output[name];
|
|
84
|
-
if (chunk.type === "chunk") {
|
|
85
|
-
let _code = chunk.code;
|
|
86
|
-
const chunkFilePath = path.resolve(outDir, name);
|
|
87
|
-
if (beforeCompile) {
|
|
88
|
-
const cbResult = await beforeCompile(_code, chunkFilePath);
|
|
89
|
-
if (cbResult) {
|
|
90
|
-
_code = cbResult;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (bytecodeRE && _code.match(bytecodeRE)) {
|
|
94
|
-
let match;
|
|
95
|
-
const s = new MagicString(_code);
|
|
96
|
-
while (match = bytecodeRE.exec(_code)) {
|
|
97
|
-
const [prefix, chunkName] = match;
|
|
98
|
-
const len = prefix.length + chunkName.length;
|
|
99
|
-
s.overwrite(match.index, match.index + len, `${prefix + chunkName}c`, {
|
|
100
|
-
contentOnly: true
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
_code = s.toString();
|
|
104
|
-
}
|
|
105
|
-
if (bytecodeChunks.includes(name)) {
|
|
106
|
-
const bytecodeBuffer = await compileToBytecode(_code, electronPath);
|
|
107
|
-
fs.writeFileSync(`${chunkFilePath}c`, bytecodeBuffer);
|
|
108
|
-
if (chunk.isEntry) {
|
|
109
|
-
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
110
|
-
const bytecodeModuleBlock = `require("./${`${path.basename(name)}c`}");`;
|
|
111
|
-
const code = `${useStrict}
|
|
112
|
-
${bytecodeLoaderBlock}
|
|
113
|
-
module.exports=${bytecodeModuleBlock}
|
|
114
|
-
`;
|
|
115
|
-
fs.writeFileSync(chunkFilePath, code);
|
|
116
|
-
} else {
|
|
117
|
-
fs.unlinkSync(chunkFilePath);
|
|
118
|
-
}
|
|
119
|
-
bytecodeFiles.push({ name: `${name}c`, size: bytecodeBuffer.length });
|
|
120
|
-
} else {
|
|
121
|
-
if (chunk.isEntry) {
|
|
122
|
-
let hasBytecodeMoudle = false;
|
|
123
|
-
const idsToHandle = /* @__PURE__ */ new Set([...chunk.imports, ...chunk.dynamicImports]);
|
|
124
|
-
for (const moduleId of idsToHandle) {
|
|
125
|
-
if (bytecodeChunks.includes(moduleId)) {
|
|
126
|
-
hasBytecodeMoudle = true;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
const moduleInfo = this.getModuleInfo(moduleId);
|
|
130
|
-
if (moduleInfo && !moduleInfo.isExternal) {
|
|
131
|
-
const { importers, dynamicImporters } = moduleInfo;
|
|
132
|
-
for (const importerId of importers) {
|
|
133
|
-
idsToHandle.add(importerId);
|
|
134
|
-
}
|
|
135
|
-
for (const importerId of dynamicImporters) {
|
|
136
|
-
idsToHandle.add(importerId);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const bytecodeLoaderBlock = getBytecodeLoaderBlock(chunk.fileName);
|
|
141
|
-
_code = hasBytecodeMoudle ? _code.replace(
|
|
142
|
-
new RegExp(`(${useStrict})|("use strict";)`),
|
|
143
|
-
`${useStrict}
|
|
144
|
-
${bytecodeLoaderBlock}`
|
|
145
|
-
) : _code;
|
|
146
|
-
}
|
|
147
|
-
fs.writeFileSync(chunkFilePath, _code);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
},
|
|
153
|
-
closeBundle() {
|
|
154
|
-
const outDir = `${normalizePath(path.relative(config.root, path.resolve(config.root, config.build.outDir)))}/`;
|
|
155
|
-
bytecodeFiles.forEach((file) => {
|
|
156
|
-
bytecodeLog.info(
|
|
157
|
-
`${outDir}${file.name} [${readableSize(file.size)}]`,
|
|
158
|
-
{ timestamp: true }
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
bytecodeLog.info(`${bytecodeFiles.length} bundles compiled into bytecode.`, { timestamp: true });
|
|
162
|
-
bytecodeFiles = [];
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export { bytecodePlugin };
|
package/dist/chunk-5NKEXGI3.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createLogger } from 'vite';
|
|
2
|
-
|
|
3
|
-
// src/vite/constant.ts
|
|
4
|
-
var id = "electron-incremental-updater";
|
|
5
|
-
var bytecodeId = `${id}-bytecode`;
|
|
6
|
-
var esmId = `${id}-esm`;
|
|
7
|
-
var log = createLogger("info", { prefix: `[${id}]` });
|
|
8
|
-
var bytecodeLog = createLogger("info", { prefix: `[${bytecodeId}]` });
|
|
9
|
-
|
|
10
|
-
export { bytecodeId, bytecodeLog, esmId, id, log };
|
package/dist/chunk-LR7LR5WG.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { bytecodeLog } from './chunk-5NKEXGI3.js';
|
|
2
|
-
import cp from 'node:child_process';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import * as babel from '@babel/core';
|
|
6
|
-
import { getPackageInfoSync } from 'local-pkg';
|
|
7
|
-
import MagicString from 'magic-string';
|
|
8
|
-
|
|
9
|
-
// src/vite/bytecode/code.ts
|
|
10
|
-
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";
|
|
11
|
-
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';
|
|
12
|
-
|
|
13
|
-
// src/utils/version.ts
|
|
14
|
-
function parseVersion(version) {
|
|
15
|
-
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?/i.exec(version);
|
|
16
|
-
if (!match) {
|
|
17
|
-
throw new TypeError(`invalid version: ${version}`);
|
|
18
|
-
}
|
|
19
|
-
const [major, minor, patch] = match.slice(1, 4).map(Number);
|
|
20
|
-
const ret = {
|
|
21
|
-
major,
|
|
22
|
-
minor,
|
|
23
|
-
patch,
|
|
24
|
-
stage: "",
|
|
25
|
-
stageVersion: -1
|
|
26
|
-
};
|
|
27
|
-
if (match[4]) {
|
|
28
|
-
let [stage, _v] = match[4].split(".");
|
|
29
|
-
ret.stage = stage;
|
|
30
|
-
ret.stageVersion = Number(_v) || -1;
|
|
31
|
-
}
|
|
32
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch) || Number.isNaN(ret.stageVersion)) {
|
|
33
|
-
throw new TypeError(`Invalid version: ${version}`);
|
|
34
|
-
}
|
|
35
|
-
return ret;
|
|
36
|
-
}
|
|
37
|
-
var is = (j) => !!(j && j.minimumVersion && j.signature && j.version);
|
|
38
|
-
function isUpdateJSON(json) {
|
|
39
|
-
return is(json) && is(json?.beta);
|
|
40
|
-
}
|
|
41
|
-
function defaultVersionJsonGenerator(existingJson, signature, version, minimumVersion) {
|
|
42
|
-
existingJson.beta = {
|
|
43
|
-
version,
|
|
44
|
-
minimumVersion,
|
|
45
|
-
signature
|
|
46
|
-
};
|
|
47
|
-
if (!parseVersion(version).stage) {
|
|
48
|
-
existingJson.version = version;
|
|
49
|
-
existingJson.minimumVersion = minimumVersion;
|
|
50
|
-
existingJson.signature = signature;
|
|
51
|
-
}
|
|
52
|
-
return existingJson;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/vite/bytecode/utils.ts
|
|
56
|
-
var electronModule = getPackageInfoSync("electron");
|
|
57
|
-
var electronMajorVersion = parseVersion(electronModule.version).major;
|
|
58
|
-
var useStrict = "'use strict';";
|
|
59
|
-
var bytecodeModuleLoader = "__loader__.js";
|
|
60
|
-
function getElectronPath() {
|
|
61
|
-
const electronModulePath = electronModule.rootPath;
|
|
62
|
-
let electronExecPath = process.env.ELECTRON_EXEC_PATH || "";
|
|
63
|
-
if (!electronExecPath) {
|
|
64
|
-
if (!electronModulePath) {
|
|
65
|
-
throw new Error("Electron is not installed");
|
|
66
|
-
}
|
|
67
|
-
const pathFile = path.join(electronModulePath, "path.txt");
|
|
68
|
-
let executablePath;
|
|
69
|
-
if (fs.existsSync(pathFile)) {
|
|
70
|
-
executablePath = fs.readFileSync(pathFile, "utf-8");
|
|
71
|
-
}
|
|
72
|
-
if (executablePath) {
|
|
73
|
-
electronExecPath = path.join(electronModulePath, "dist", executablePath);
|
|
74
|
-
process.env.ELECTRON_EXEC_PATH = electronExecPath;
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error("Electron executable file is not existed");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return electronExecPath;
|
|
80
|
-
}
|
|
81
|
-
function getBytecodeCompilerPath() {
|
|
82
|
-
const scriptPath = path.join(electronModule.rootPath, "EIU_bytenode.cjs");
|
|
83
|
-
if (!fs.existsSync(scriptPath)) {
|
|
84
|
-
fs.writeFileSync(scriptPath, bytecodeGeneratorScript);
|
|
85
|
-
}
|
|
86
|
-
return scriptPath;
|
|
87
|
-
}
|
|
88
|
-
function toRelativePath(filename, importer) {
|
|
89
|
-
const relPath = path.posix.relative(path.dirname(importer), filename);
|
|
90
|
-
return relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
91
|
-
}
|
|
92
|
-
var logErr = (...args) => bytecodeLog.error(args.join(" "), { timestamp: true });
|
|
93
|
-
function compileToBytecode(code, electronPath = getElectronPath()) {
|
|
94
|
-
let data = Buffer.from([]);
|
|
95
|
-
const bytecodePath = getBytecodeCompilerPath();
|
|
96
|
-
return new Promise((resolve, reject) => {
|
|
97
|
-
const proc = cp.spawn(electronPath, [bytecodePath], {
|
|
98
|
-
env: { ELECTRON_RUN_AS_NODE: "1" },
|
|
99
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
100
|
-
});
|
|
101
|
-
if (proc.stdin) {
|
|
102
|
-
proc.stdin.write(code);
|
|
103
|
-
proc.stdin.end();
|
|
104
|
-
}
|
|
105
|
-
if (proc.stdout) {
|
|
106
|
-
proc.stdout.on("data", (chunk) => data = Buffer.concat([data, chunk]));
|
|
107
|
-
proc.stdout.on("error", (err) => logErr(err));
|
|
108
|
-
proc.stdout.on("end", () => resolve(data));
|
|
109
|
-
}
|
|
110
|
-
if (proc.stderr) {
|
|
111
|
-
proc.stderr.on("data", (chunk) => logErr("Error: ", chunk.toString()));
|
|
112
|
-
proc.stderr.on("error", (err) => logErr("Error: ", err));
|
|
113
|
-
}
|
|
114
|
-
proc.addListener("error", (err) => logErr(err));
|
|
115
|
-
proc.on("error", (err) => reject(err));
|
|
116
|
-
proc.on("exit", () => resolve(data));
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function convertArrowFunctionAndTemplate(code) {
|
|
120
|
-
const result = babel.transform(code, {
|
|
121
|
-
plugins: ["@babel/plugin-transform-arrow-functions", "@babel/plugin-transform-template-literals"]
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
code: result?.code || code,
|
|
125
|
-
map: result?.map
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
var decodeFn = ";function _0xstr_(a,b){return String.fromCharCode.apply(0,a.map(function(x){return x-b}))};";
|
|
129
|
-
function obfuscateString(input, offset = ~~(Math.random() * 16) + 1) {
|
|
130
|
-
const hexArray = input.split("").map((c) => `0x${(c.charCodeAt(0) + offset).toString(16)}`);
|
|
131
|
-
return `_0xstr_([${hexArray.join(",")}],${offset})`;
|
|
132
|
-
}
|
|
133
|
-
function convertLiteral(code, sourcemap, offset) {
|
|
134
|
-
const s = new MagicString(code);
|
|
135
|
-
let hasTransformed = false;
|
|
136
|
-
const ast = babel.parse(code, { ast: true });
|
|
137
|
-
if (!ast) {
|
|
138
|
-
throw new Error("Cannot parse code");
|
|
139
|
-
}
|
|
140
|
-
babel.traverse(ast, {
|
|
141
|
-
StringLiteral(path2) {
|
|
142
|
-
const parent = path2.parent;
|
|
143
|
-
const node = path2.node;
|
|
144
|
-
if (parent.type === "CallExpression") {
|
|
145
|
-
if (parent.callee.type === "Identifier" && parent.callee.name === "require") {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (parent.callee.type === "Import") {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (parent.type.startsWith("Export")) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (parent.type.startsWith("Import")) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (parent.type === "ObjectMethod" && parent.key === node) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (parent.type === "ObjectProperty" && parent.key === node) {
|
|
162
|
-
const result2 = `[${obfuscateString(node.value, offset)}]`;
|
|
163
|
-
const start2 = node.start;
|
|
164
|
-
const end2 = node.end;
|
|
165
|
-
if (start2 && end2) {
|
|
166
|
-
s.overwrite(start2, end2, result2);
|
|
167
|
-
hasTransformed = true;
|
|
168
|
-
}
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (!node.value.trim()) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const result = obfuscateString(node.value, offset);
|
|
175
|
-
const start = node.start;
|
|
176
|
-
const end = node.end;
|
|
177
|
-
if (start && end) {
|
|
178
|
-
s.overwrite(start, end, result);
|
|
179
|
-
hasTransformed = true;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
if (hasTransformed) {
|
|
184
|
-
s.append("\n").append(decodeFn);
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
code: s.toString(),
|
|
188
|
-
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export { bytecodeModuleLoader, bytecodeModuleLoaderCode, compileToBytecode, convertArrowFunctionAndTemplate, convertLiteral, defaultVersionJsonGenerator, electronMajorVersion, isUpdateJSON, toRelativePath, useStrict };
|
package/dist/chunk-TPTWE33H.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { log } from './chunk-5NKEXGI3.js';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
|
|
4
|
-
function readableSize(size) {
|
|
5
|
-
const units = ["B", "KB", "MB", "GB"];
|
|
6
|
-
let i = 0;
|
|
7
|
-
while (size >= 1024 && i < units.length - 1) {
|
|
8
|
-
size /= 1024;
|
|
9
|
-
i++;
|
|
10
|
-
}
|
|
11
|
-
return `${size.toFixed(2)} ${units[i]}`;
|
|
12
|
-
}
|
|
13
|
-
function copyAndSkipIfExist(from, to, skipIfExist) {
|
|
14
|
-
if (!skipIfExist || !fs.existsSync(to)) {
|
|
15
|
-
try {
|
|
16
|
-
fs.cpSync(from, to, { recursive: true });
|
|
17
|
-
} catch (error) {
|
|
18
|
-
log.warn(`Copy failed: ${error}`, { timestamp: true });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { copyAndSkipIfExist, readableSize };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { bytecodeId, bytecodeLog, esmId, id, log } from './chunk-5NKEXGI3.js';
|
package/dist/esm-4S4XCVEW.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { electronMajorVersion } from './chunk-LR7LR5WG.js';
|
|
2
|
-
import { esmId } from './chunk-5NKEXGI3.js';
|
|
3
|
-
import MagicString from 'magic-string';
|
|
4
|
-
|
|
5
|
-
// src/vite/esm/constant.ts
|
|
6
|
-
var CJSShim = `
|
|
7
|
-
// -- CommonJS Shims --
|
|
8
|
-
import __cjs_url__ from 'node:url';
|
|
9
|
-
import __cjs_path__ from 'node:path';
|
|
10
|
-
import __cjs_mod__ from 'node:module';
|
|
11
|
-
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
12
|
-
const __dirname = __cjs_path__.dirname(__filename);
|
|
13
|
-
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
14
|
-
`;
|
|
15
|
-
var CJSShim_electron_30 = `
|
|
16
|
-
// -- CommonJS Shims --
|
|
17
|
-
import __cjs_mod__ from 'node:module';
|
|
18
|
-
const __filename = import.meta.filename;
|
|
19
|
-
const __dirname = import.meta.dirname;
|
|
20
|
-
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
21
|
-
`;
|
|
22
|
-
var shim = electronMajorVersion >= 30 ? CJSShim_electron_30 : CJSShim;
|
|
23
|
-
|
|
24
|
-
// src/vite/esm/utils.ts
|
|
25
|
-
var ESMStaticImportRe = /(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<=")[^"]*[^\s"](?=\s*")|(?<=')[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
|
|
26
|
-
function findStaticImports(code) {
|
|
27
|
-
const matches = [];
|
|
28
|
-
for (const match of code.matchAll(ESMStaticImportRe)) {
|
|
29
|
-
matches.push({ end: (match.index || 0) + match[0].length });
|
|
30
|
-
}
|
|
31
|
-
return matches;
|
|
32
|
-
}
|
|
33
|
-
function insertCJSShim(code, sourcemap, insertPosition = 0) {
|
|
34
|
-
if (code.includes(shim) || !/__filename|__dirname|require\(|require\.resolve\(|require\.apply\(/.test(code)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const s = new MagicString(code);
|
|
38
|
-
s.appendRight(insertPosition, shim);
|
|
39
|
-
return {
|
|
40
|
-
code: s.toString(),
|
|
41
|
-
map: sourcemap ? s.generateMap({ hires: "boundary" }) : null
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/vite/esm/index.ts
|
|
46
|
-
function esm() {
|
|
47
|
-
let sourcemap;
|
|
48
|
-
return {
|
|
49
|
-
name: esmId,
|
|
50
|
-
enforce: "post",
|
|
51
|
-
configResolved(config) {
|
|
52
|
-
sourcemap = config.build.sourcemap;
|
|
53
|
-
},
|
|
54
|
-
renderChunk(code, _chunk, options) {
|
|
55
|
-
if (options.format === "es") {
|
|
56
|
-
const lastESMImport = findStaticImports(code).pop();
|
|
57
|
-
const pos = lastESMImport ? lastESMImport.end : 0;
|
|
58
|
-
return insertCJSShim(code, sourcemap, pos);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { esm };
|