update electron to v43
All checks were successful
Android Build / publish (push) Successful in 55s
Linux Build / publish (push) Successful in 1m6s

This commit is contained in:
olcxja 2026-07-09 22:38:33 +02:00
commit fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions

View file

@ -1,17 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WinPackager = void 0;
const bluebird_lst_1 = require("bluebird-lst");
const builder_util_1 = require("builder-util");
const builder_util_runtime_1 = require("builder-util-runtime");
const fs_1 = require("builder-util/out/fs");
const ci_info_1 = require("ci-info");
const crypto_1 = require("crypto");
const promises_1 = require("fs/promises");
const isCI = require("is-ci");
const lazy_val_1 = require("lazy-val");
const path = require("path");
const codesign_1 = require("./codeSign/codesign");
const asar_1 = require("./asar/asar");
const windowsCodeSign_1 = require("./codeSign/windowsCodeSign");
const windowsSignAzureManager_1 = require("./codeSign/windowsSignAzureManager");
const windowsSignToolManager_1 = require("./codeSign/windowsSignToolManager");
const core_1 = require("./core");
const platformPackager_1 = require("./platformPackager");
const NsisTarget_1 = require("./targets/nsis/NsisTarget");
@ -20,98 +19,33 @@ const WebInstallerTarget_1 = require("./targets/nsis/WebInstallerTarget");
const targetFactory_1 = require("./targets/targetFactory");
const cacheManager_1 = require("./util/cacheManager");
const flags_1 = require("./util/flags");
const resEdit_1 = require("./util/resEdit");
const timer_1 = require("./util/timer");
const vm_1 = require("./vm/vm");
const wine_1 = require("./wine");
class WinPackager extends platformPackager_1.PlatformPackager {
constructor(info) {
super(info, core_1.Platform.WINDOWS);
this.cscInfo = new lazy_val_1.Lazy(() => {
const platformSpecificBuildOptions = this.platformSpecificBuildOptions;
if (platformSpecificBuildOptions.certificateSubjectName != null || platformSpecificBuildOptions.certificateSha1 != null) {
return this.vm.value
.then(vm => windowsCodeSign_1.getCertificateFromStoreInfo(platformSpecificBuildOptions, vm))
.catch(e => {
// https://github.com/electron-userland/electron-builder/pull/2397
if (platformSpecificBuildOptions.sign == null) {
throw e;
}
else {
builder_util_1.log.debug({ error: e }, "getCertificateFromStoreInfo error");
return null;
}
});
}
const certificateFile = platformSpecificBuildOptions.certificateFile;
if (certificateFile != null) {
const certificatePassword = this.getCscPassword();
return Promise.resolve({
file: certificateFile,
password: certificatePassword == null ? null : certificatePassword.trim(),
});
}
const cscLink = this.getCscLink("WIN_CSC_LINK");
if (cscLink == null) {
return Promise.resolve(null);
}
return (codesign_1.importCertificate(cscLink, this.info.tempDirManager, this.projectDir)
// before then
.catch(e => {
if (e instanceof builder_util_1.InvalidConfigurationError) {
throw new builder_util_1.InvalidConfigurationError(`Env WIN_CSC_LINK is not correct, cannot resolve: ${e.message}`);
}
else {
throw e;
}
})
.then(path => {
return {
file: path,
password: this.getCscPassword(),
};
}));
});
this._iconPath = new lazy_val_1.Lazy(() => this.getOrConvertIcon("ico"));
this.vm = new lazy_val_1.Lazy(() => (process.platform === "win32" ? Promise.resolve(new vm_1.VmManager()) : vm_1.getWindowsVm(this.debugLogger)));
this.computedPublisherName = new lazy_val_1.Lazy(async () => {
const publisherName = this.platformSpecificBuildOptions.publisherName;
if (publisherName === null) {
return null;
}
else if (publisherName != null) {
return builder_util_1.asArray(publisherName);
}
const certInfo = await this.lazyCertInfo.value;
return certInfo == null ? null : [certInfo.commonName];
});
this.lazyCertInfo = new lazy_val_1.Lazy(async () => {
const cscInfo = await this.cscInfo.value;
if (cscInfo == null) {
return null;
}
if ("subject" in cscInfo) {
const bloodyMicrosoftSubjectDn = cscInfo.subject;
return {
commonName: builder_util_runtime_1.parseDn(bloodyMicrosoftSubjectDn).get("CN"),
bloodyMicrosoftSubjectDn,
};
}
const cscFile = cscInfo.file;
if (cscFile == null) {
return null;
}
return await windowsCodeSign_1.getCertInfo(cscFile, cscInfo.password || "");
});
}
get isForceCodeSigningVerification() {
return this.platformSpecificBuildOptions.verifyUpdateCodeSignature !== false;
}
constructor(info) {
super(info, core_1.Platform.WINDOWS);
this._iconPath = new lazy_val_1.Lazy(() => this.getOrConvertIcon("ico"));
this.vm = new lazy_val_1.Lazy(() => (process.platform === "win32" ? Promise.resolve(new vm_1.VmManager()) : (0, vm_1.getWindowsVm)(this.debugLogger)));
this.signingManager = new lazy_val_1.Lazy(async () => {
let manager;
if (this.platformSpecificBuildOptions.azureSignOptions != null) {
manager = new windowsSignAzureManager_1.WindowsSignAzureManager(this);
}
else {
manager = new windowsSignToolManager_1.WindowsSignToolManager(this);
}
await manager.initialize();
return manager;
});
this.signingQueue = Promise.resolve(true);
}
get defaultTarget() {
return ["nsis"];
}
doGetCscPassword() {
return platformPackager_1.chooseNotNull(platformPackager_1.chooseNotNull(this.platformSpecificBuildOptions.certificatePassword, process.env.WIN_CSC_KEY_PASSWORD), super.doGetCscPassword());
}
createTargets(targets, mapper) {
let copyElevateHelper;
const getCopyElevateHelper = () => {
@ -152,112 +86,84 @@ class WinPackager extends platformPackager_1.PlatformPackager {
return require("./targets/AppxTarget").default;
case "msi":
return require("./targets/MsiTarget").default;
case "msiwrapped":
return require("./targets/MsiWrappedTarget").default;
default:
return null;
}
})();
mapper(name, outDir => (targetClass === null ? targetFactory_1.createCommonTarget(name, outDir, this) : new targetClass(this, outDir, name)));
mapper(name, outDir => (targetClass === null ? (0, targetFactory_1.createCommonTarget)(name, outDir, this) : new targetClass(this, outDir, name)));
}
}
}
getIconPath() {
return this._iconPath.value;
}
async sign(file, logMessagePrefix) {
doGetCscPassword() {
var _a;
return (0, platformPackager_1.chooseNotNull)((0, platformPackager_1.chooseNotNull)((_a = this.platformSpecificBuildOptions.signtoolOptions) === null || _a === void 0 ? void 0 : _a.certificatePassword, process.env.WIN_CSC_KEY_PASSWORD), super.doGetCscPassword());
}
async signIf(file) {
const logFields = { file: builder_util_1.log.filePath(file) };
if (!this.shouldSignFile(file, true)) {
builder_util_1.log.info(logFields, "file signing skipped via signExts configuration");
return false;
}
if (this.platformSpecificBuildOptions.signExecutable === false) {
builder_util_1.log.info(logFields, "file signing skipped via signExecutable configuration");
return false;
}
const promise = this.signingQueue.then(() => this._sign(file));
this.signingQueue = promise.catch(e => {
builder_util_1.log.warn({ file: builder_util_1.log.filePath(file), error: e.message }, "signing failed for file, queue will continue to next file");
return false;
});
return promise;
}
async _sign(file) {
const signOptions = {
path: file,
name: this.appInfo.productName,
site: await this.appInfo.computePackageUrl(),
options: this.platformSpecificBuildOptions,
};
const cscInfo = await this.cscInfo.value;
if (cscInfo == null) {
if (this.platformSpecificBuildOptions.sign != null) {
await windowsCodeSign_1.sign(signOptions, this);
}
else if (this.forceCodeSigning) {
throw new builder_util_1.InvalidConfigurationError(`App is not signed and "forceCodeSigning" is set to true, please ensure that code signing configuration is correct, please see https://electron.build/code-signing`);
}
return;
}
if (logMessagePrefix == null) {
logMessagePrefix = "signing";
}
if ("file" in cscInfo) {
builder_util_1.log.info({
file: builder_util_1.log.filePath(file),
certificateFile: cscInfo.file,
}, logMessagePrefix);
}
else {
const info = cscInfo;
builder_util_1.log.info({
file: builder_util_1.log.filePath(file),
subject: info.subject,
thumbprint: info.thumbprint,
store: info.store,
user: info.isLocalMachineStore ? "local machine" : "current user",
}, logMessagePrefix);
}
await this.doSign({
...signOptions,
cscInfo,
options: {
...this.platformSpecificBuildOptions,
},
});
}
async doSign(options) {
for (let i = 0; i < 3; i++) {
try {
await windowsCodeSign_1.sign(options, this);
break;
}
catch (e) {
// https://github.com/electron-userland/electron-builder/issues/1414
const message = e.message;
if (message != null && message.includes("Couldn't resolve host name")) {
builder_util_1.log.warn({ error: message, attempt: i + 1 }, `cannot sign`);
continue;
}
throw e;
}
const didSignSuccessfully = await (0, windowsCodeSign_1.signWindows)(signOptions, this);
if (!didSignSuccessfully && this.forceCodeSigning) {
throw new builder_util_1.InvalidConfigurationError(`App is not signed and "forceCodeSigning" is set to true, please ensure that code signing configuration is correct, please see https://electron.build/code-signing`);
}
return didSignSuccessfully;
}
async signAndEditResources(file, arch, outDir, internalName, requestedExecutionLevel) {
var _a, _b;
const appInfo = this.appInfo;
const files = [];
const args = [
file,
"--set-version-string",
"FileDescription",
appInfo.productName,
"--set-version-string",
"ProductName",
appInfo.productName,
"--set-version-string",
"LegalCopyright",
appInfo.copyright,
"--set-file-version",
appInfo.shortVersion || appInfo.buildVersion,
"--set-product-version",
appInfo.shortVersionWindows || appInfo.getVersionInWeirdWindowsForm(),
];
const versionStrings = {
FileDescription: appInfo.productName,
ProductName: appInfo.productName,
LegalCopyright: appInfo.copyright,
};
if (internalName != null) {
args.push("--set-version-string", "InternalName", internalName, "--set-version-string", "OriginalFilename", "");
versionStrings.InternalName = internalName;
versionStrings.OriginalFilename = "";
}
if (requestedExecutionLevel != null && requestedExecutionLevel !== "asInvoker") {
args.push("--set-requested-execution-level", requestedExecutionLevel);
if (appInfo.companyName != null) {
versionStrings.CompanyName = appInfo.companyName;
}
if (this.platformSpecificBuildOptions.legalTrademarks != null) {
versionStrings.LegalTrademarks = this.platformSpecificBuildOptions.legalTrademarks;
}
builder_util_1.use(appInfo.companyName, it => args.push("--set-version-string", "CompanyName", it));
builder_util_1.use(this.platformSpecificBuildOptions.legalTrademarks, it => args.push("--set-version-string", "LegalTrademarks", it));
const iconPath = await this.getIconPath();
builder_util_1.use(iconPath, it => {
files.push(it);
args.push("--set-icon", it);
});
if (iconPath != null) {
files.push(iconPath);
}
const opts = {
file,
versionStrings,
fileVersion: appInfo.shortVersion || appInfo.buildVersion,
productVersion: appInfo.shortVersionWindows || appInfo.getVersionInWeirdWindowsForm(),
requestedExecutionLevel,
iconPath,
};
const config = this.config;
const cscInfoForCacheDigest = !flags_1.isBuildCacheEnabled() || isCI || config.electronDist != null ? null : await this.cscInfo.value;
const cscInfoForCacheDigest = !(0, flags_1.isBuildCacheEnabled)() || ci_info_1.isCI || config.electronDist != null ? null : await (await this.signingManager.value).cscInfo.value;
let buildCacheManager = null;
// resources editing doesn't change executable for the same input and executed quickly - no need to complicate
if (cscInfoForCacheDigest != null) {
@ -265,47 +171,61 @@ class WinPackager extends platformPackager_1.PlatformPackager {
if (cscFile != null) {
files.push(cscFile);
}
const timer = timer_1.time("executable cache");
const hash = crypto_1.createHash("sha512");
const timer = (0, timer_1.time)("executable cache");
const hash = (0, crypto_1.createHash)("sha512");
hash.update(config.electronVersion || "no electronVersion");
hash.update(JSON.stringify(this.platformSpecificBuildOptions));
hash.update(JSON.stringify(args));
hash.update(this.platformSpecificBuildOptions.certificateSha1 || "no certificateSha1");
hash.update(this.platformSpecificBuildOptions.certificateSubjectName || "no subjectName");
hash.update(JSON.stringify(opts));
hash.update(((_a = this.platformSpecificBuildOptions.signtoolOptions) === null || _a === void 0 ? void 0 : _a.certificateSha1) || "no certificateSha1");
hash.update(((_b = this.platformSpecificBuildOptions.signtoolOptions) === null || _b === void 0 ? void 0 : _b.certificateSubjectName) || "no subjectName");
const asar = path.resolve(this.getResourcesDir(outDir), "app.asar");
if (await (0, builder_util_1.exists)(asar)) {
hash.update((await (0, asar_1.readAsarHeader)(asar)).header);
}
else {
hash.update("no asar");
}
buildCacheManager = new cacheManager_1.BuildCacheManager(outDir, file, arch);
if (await buildCacheManager.copyIfValid(await cacheManager_1.digest(hash, files))) {
if (await buildCacheManager.copyIfValid(await (0, cacheManager_1.digest)(hash, files))) {
timer.end();
return;
}
timer.end();
}
const timer = timer_1.time("wine&sign");
// rcedit crashed of executed using wine, resourcehacker works
if (process.platform === "win32" || process.platform === "darwin") {
await builder_util_1.executeAppBuilder(["rcedit", "--args", JSON.stringify(args)], undefined /* child-process */, {}, 3 /* retry three times */);
}
else if (this.info.framework.name === "electron") {
const vendorPath = await windowsCodeSign_1.getSignVendorPath();
await wine_1.execWine(path.join(vendorPath, "rcedit-ia32.exe"), path.join(vendorPath, "rcedit-x64.exe"), args);
}
await this.sign(file);
const timer = (0, timer_1.time)("resource-edit&sign");
await (0, resEdit_1.editWindowsResources)(opts);
await this.signIf(file);
timer.end();
if (buildCacheManager != null) {
await buildCacheManager.save();
}
}
isSignDlls() {
return this.platformSpecificBuildOptions.signDlls === true;
shouldSignFile(file, fallbackValue = false) {
const isExe = file.endsWith(".exe");
const signExts = this.platformSpecificBuildOptions.signExts;
if (!(signExts === null || signExts === void 0 ? void 0 : signExts.length)) {
return isExe || fallbackValue;
}
// process patterns ( !exe => exclude .exe, .dll => include .dll )
// we process first to allow literal negatives in case a filename matches "help!.txt" or similar
if (signExts.some(ext => file.endsWith(ext))) {
return true;
}
// process negative patterns
if (signExts.some(ext => ext.startsWith("!") && file.endsWith(ext.substring(1)))) {
return false;
}
return isExe || fallbackValue;
}
createTransformerForExtraFiles(packContext) {
if (this.platformSpecificBuildOptions.signAndEditExecutable === false) {
if (this.platformSpecificBuildOptions.signAndEditExecutable === false || this.platformSpecificBuildOptions.signExecutable === false) {
return null;
}
return file => {
if (file.endsWith(".exe") || (this.isSignDlls() && file.endsWith(".dll"))) {
if (this.shouldSignFile(file)) {
const parentDir = path.dirname(file);
if (parentDir !== packContext.appOutDir) {
return new fs_1.CopyFileTransformer(file => this.sign(file));
return new builder_util_1.CopyFileTransformer(file => this.signIf(file));
}
}
return null;
@ -313,27 +233,38 @@ class WinPackager extends platformPackager_1.PlatformPackager {
}
async signApp(packContext, isAsar) {
const exeFileName = `${this.appInfo.productFilename}.exe`;
const signingDisabled = this.platformSpecificBuildOptions.signExecutable === false || this.platformSpecificBuildOptions.signAndEditExecutable === false;
if (signingDisabled && this.forceCodeSigning) {
throw new builder_util_1.InvalidConfigurationError("Signing is disabled (`signExecutable: false` or `signAndEditExecutable: false`) but `forceCodeSigning` is enabled. Remove one of these options.");
}
if (this.platformSpecificBuildOptions.signAndEditExecutable === false) {
return;
builder_util_1.log.info({ exe: builder_util_1.log.filePath(path.join(packContext.appOutDir, exeFileName)) }, "executable resource editing and code signing skipped — signAndEditExecutable is false. To skip only code signing while keeping icon and metadata applied, use signExecutable: false instead.");
return false;
}
await bluebird_lst_1.default.map(promises_1.readdir(packContext.appOutDir), (file) => {
const files = await (0, promises_1.readdir)(packContext.appOutDir);
for (const file of files) {
if (file === exeFileName) {
return this.signAndEditResources(path.join(packContext.appOutDir, exeFileName), packContext.arch, packContext.outDir, path.basename(exeFileName, ".exe"), this.platformSpecificBuildOptions.requestedExecutionLevel);
await this.signAndEditResources(path.join(packContext.appOutDir, exeFileName), packContext.arch, packContext.outDir, path.basename(exeFileName, ".exe"), this.platformSpecificBuildOptions.requestedExecutionLevel);
}
else if (file.endsWith(".exe") || (this.isSignDlls() && file.endsWith(".dll"))) {
return this.sign(path.join(packContext.appOutDir, file));
else if (this.shouldSignFile(file)) {
await this.signIf(path.join(packContext.appOutDir, file));
}
return null;
});
if (!isAsar) {
return;
}
const signPromise = (filepath) => {
const outDir = path.join(packContext.appOutDir, ...filepath);
return fs_1.walk(outDir, (file, stat) => stat.isDirectory() || file.endsWith(".exe") || (this.isSignDlls() && file.endsWith(".dll")));
};
const filesToSign = await Promise.all([signPromise(["resources", "app.asar.unpacked"]), signPromise(["swiftshader"])]);
await bluebird_lst_1.default.map(filesToSign.flat(1), file => this.sign(file), { concurrency: 4 });
if (!isAsar || this.platformSpecificBuildOptions.signExecutable === false) {
return true;
}
const filesToSign = await Promise.all([
this.walkSignableFiles(packContext.appOutDir, "resources", "app.asar.unpacked"),
// Note: The `swiftshader` directory is absent in modern electron versions. `swiftshader/` held Chromium's legacy SwiftShader GL fallback (libEGL.dll / libGLESv2.dll), removed in Chromium 102 (Electron 19+) in favor of SwANGLE (ANGLE + SwiftShader Vulkan). This is kept here only for backwards compat with older Electron; `walk` no-ops on a missing dir (readdir ENOENT is swallowed), so this is harmless when the directory is absent.
this.walkSignableFiles(packContext.appOutDir, "swiftshader"),
]);
for (const file of filesToSign.flat(1)) {
await this.signIf(file);
}
return true;
}
walkSignableFiles(baseDir, ...subpath) {
return (0, builder_util_1.walk)(path.join(baseDir, ...subpath), (file, stat) => stat.isDirectory() || this.shouldSignFile(file));
}
}
exports.WinPackager = WinPackager;